web_api_base 2.7.1 → 2.7.3
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/Application.d.ts +16 -0
- package/dist/Application.js +159 -0
- package/dist/Application.js.map +1 -0
- package/dist/ApplicationConfiguration.d.ts +14 -0
- package/dist/ApplicationConfiguration.js +118 -0
- package/dist/ApplicationConfiguration.js.map +1 -0
- package/dist/bin/CreateApplication.d.ts +1 -0
- package/dist/bin/CreateApplication.js +38 -0
- package/dist/bin/CreateApplication.js.map +1 -0
- package/dist/bin/CreateController.d.ts +1 -0
- package/dist/bin/CreateController.js +41 -0
- package/dist/bin/CreateController.js.map +1 -0
- package/dist/controllers/base/ControllerBase.d.ts +14 -0
- package/dist/controllers/base/ControllerBase.js +32 -0
- package/dist/controllers/base/ControllerBase.js.map +1 -0
- package/dist/decorators/controllers/ControllerDecorators.d.ts +36 -0
- package/dist/decorators/controllers/ControllerDecorators.js +112 -0
- package/dist/decorators/controllers/ControllerDecorators.js.map +1 -0
- package/dist/dependencyInjection/DependecyService.d.ts +28 -0
- package/dist/dependencyInjection/DependecyService.js +132 -0
- package/dist/dependencyInjection/DependecyService.js.map +1 -0
- package/dist/dependencyInjection/IDIContext.d.ts +7 -0
- package/dist/dependencyInjection/IDIContext.js +3 -0
- package/dist/dependencyInjection/IDIContext.js.map +1 -0
- package/dist/enums/httpVerbs/HttpVerbs.d.ts +6 -0
- package/dist/enums/httpVerbs/HttpVerbs.js +11 -0
- package/dist/enums/httpVerbs/HttpVerbs.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/IApplication.d.ts +7 -0
- package/dist/interfaces/IApplication.js +3 -0
- package/dist/interfaces/IApplication.js.map +1 -0
- package/dist/interfaces/IApplicationConfiguration.d.ts +8 -0
- package/dist/interfaces/IApplicationConfiguration.js +3 -0
- package/dist/interfaces/IApplicationConfiguration.js.map +1 -0
- package/dist/interfaces/IController.d.ts +5 -0
- package/dist/interfaces/IController.js +3 -0
- package/dist/interfaces/IController.js.map +1 -0
- package/dist/midlewares/IMidleware.d.ts +9 -0
- package/dist/midlewares/IMidleware.js +3 -0
- package/dist/midlewares/IMidleware.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Express } from "express";
|
|
2
|
+
import IApplication from "./interfaces/IApplication";
|
|
3
|
+
import IApplicationConfiguration from "./interfaces/IApplicationConfiguration";
|
|
4
|
+
import IController from "./interfaces/IController";
|
|
5
|
+
export default abstract class Application implements IApplication {
|
|
6
|
+
private ApplicationConfiguration;
|
|
7
|
+
Express: Express;
|
|
8
|
+
constructor();
|
|
9
|
+
StartAsync(): Promise<void>;
|
|
10
|
+
UseCors(): void;
|
|
11
|
+
protected UseControllers(root?: string): Promise<void>;
|
|
12
|
+
protected AppendController<T extends IController>(ctor: {
|
|
13
|
+
new (...args: any[]): T;
|
|
14
|
+
}): void;
|
|
15
|
+
abstract ConfigureAsync(appConfig: IApplicationConfiguration): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const express_1 = __importDefault(require("express"));
|
|
39
|
+
const ApplicationConfiguration_1 = __importDefault(require("./ApplicationConfiguration"));
|
|
40
|
+
const ControllerDecorators_1 = __importDefault(require("./decorators/controllers/ControllerDecorators"));
|
|
41
|
+
const DependecyService_1 = __importDefault(require("./dependencyInjection/DependecyService"));
|
|
42
|
+
const HttpVerbs_1 = require("./enums/httpVerbs/HttpVerbs");
|
|
43
|
+
const fs_1 = __importDefault(require("fs"));
|
|
44
|
+
const path_1 = __importDefault(require("path"));
|
|
45
|
+
class Application {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.ApplicationConfiguration = new ApplicationConfiguration_1.default();
|
|
48
|
+
this.Express = (0, express_1.default)();
|
|
49
|
+
}
|
|
50
|
+
StartAsync() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
yield this.ApplicationConfiguration.StartAsync();
|
|
53
|
+
this.Express.use(express_1.default.json({ limit: 50 * 1024 * 1024 }));
|
|
54
|
+
yield this.ConfigureAsync(this.ApplicationConfiguration);
|
|
55
|
+
this.Express.listen(this.ApplicationConfiguration.Port, this.ApplicationConfiguration.Host, () => {
|
|
56
|
+
console.log(`App running on ${this.ApplicationConfiguration.Host}:${this.ApplicationConfiguration.Port}`);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
UseCors() {
|
|
61
|
+
this.Express.use(require('cors')());
|
|
62
|
+
}
|
|
63
|
+
UseControllers(root) {
|
|
64
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
let controllersPath = path_1.default.join(root !== null && root !== void 0 ? root : this.ApplicationConfiguration.RootPath, "controllers");
|
|
66
|
+
console.debug(`reading controllers in ${controllersPath}`);
|
|
67
|
+
if (!fs_1.default.existsSync(controllersPath))
|
|
68
|
+
return;
|
|
69
|
+
let files = fs_1.default.readdirSync(controllersPath).filter(s => s.toLocaleLowerCase().endsWith("controller.js"));
|
|
70
|
+
for (let controllerFile of files) {
|
|
71
|
+
try {
|
|
72
|
+
let controllerClass = yield Promise.resolve().then(() => __importStar(require(path_1.default.join(controllersPath, controllerFile))));
|
|
73
|
+
let controller = Reflect.construct(controllerClass.default.prototype.constructor, []);
|
|
74
|
+
if (controller != undefined && controller != null) {
|
|
75
|
+
this.AppendController(controllerClass.default.prototype.constructor);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (_a) { }
|
|
79
|
+
}
|
|
80
|
+
resolve();
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
AppendController(ctor) {
|
|
84
|
+
let empty = new ctor();
|
|
85
|
+
let methods = Reflect.ownKeys(empty.constructor.prototype).filter(m => {
|
|
86
|
+
return typeof empty[m] == "function";
|
|
87
|
+
});
|
|
88
|
+
let route = ControllerDecorators_1.default.GetRoute(empty);
|
|
89
|
+
if (!route)
|
|
90
|
+
return;
|
|
91
|
+
for (let method of methods) {
|
|
92
|
+
let action = ControllerDecorators_1.default.GetAction(empty, method.toString());
|
|
93
|
+
if (!action) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
let verb = ControllerDecorators_1.default.GetVerb(empty, method.toString());
|
|
97
|
+
if (!verb)
|
|
98
|
+
verb = HttpVerbs_1.HTTPVerbs.GET;
|
|
99
|
+
console.debug("appended : ", verb, `${route}${action}`);
|
|
100
|
+
this.Express[verb.toString().toLowerCase()](`${route}${action}`, (request, response) => {
|
|
101
|
+
let midlewares = ControllerDecorators_1.default.GetMidlewares(empty).reverse();
|
|
102
|
+
midlewares.push(...ControllerDecorators_1.default.GetBefores(empty, method.toString()).reverse());
|
|
103
|
+
let handler = (context) => {
|
|
104
|
+
let args = ControllerDecorators_1.default.GetArgumentsHandler(empty, method.toString());
|
|
105
|
+
let params = [];
|
|
106
|
+
if (args) {
|
|
107
|
+
if (args.Arguments.length > 0) {
|
|
108
|
+
if (context.Request.body && verb == (HttpVerbs_1.HTTPVerbs.POST || verb == HttpVerbs_1.HTTPVerbs.PUT))
|
|
109
|
+
params = args.CreateArgumentsList(context.Request.body);
|
|
110
|
+
if (context.Request.query)
|
|
111
|
+
params.push(...args.CreateArgumentsList(context.Request.query));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
let controller = DependecyService_1.default.ResolveCtor(empty.constructor);
|
|
115
|
+
if (controller == undefined)
|
|
116
|
+
controller = new ctor();
|
|
117
|
+
DependecyService_1.default.CheckForDependenciesAndResolve(controller);
|
|
118
|
+
controller.Request = context.Request;
|
|
119
|
+
controller.Response = context.Response;
|
|
120
|
+
controller[method](...params);
|
|
121
|
+
};
|
|
122
|
+
if (midlewares && midlewares.length > 0) {
|
|
123
|
+
let httpRequestContexts = [];
|
|
124
|
+
let pipeline = [];
|
|
125
|
+
for (let i = 0; i <= midlewares.length; i++) {
|
|
126
|
+
httpRequestContexts.push({
|
|
127
|
+
Request: request,
|
|
128
|
+
Response: response,
|
|
129
|
+
Next: () => { }
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
for (let i = 0; i < httpRequestContexts.length; i++) {
|
|
133
|
+
let box = {
|
|
134
|
+
v: i
|
|
135
|
+
};
|
|
136
|
+
pipeline.push({
|
|
137
|
+
Execute: () => {
|
|
138
|
+
pipeline.length - 1 == box.v ? handler(httpRequestContexts[box.v]) : midlewares[box.v](httpRequestContexts[box.v]);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
for (let i = 0; i < pipeline.length; i++) {
|
|
143
|
+
httpRequestContexts[i].Next = i == pipeline.length - 1 ? () => { } : () => pipeline[i + 1].Execute();
|
|
144
|
+
}
|
|
145
|
+
pipeline[0].Execute();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
handler({
|
|
149
|
+
Request: request,
|
|
150
|
+
Response: response,
|
|
151
|
+
Next: () => { }
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.default = Application;
|
|
159
|
+
//# sourceMappingURL=Application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../Application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAAoC;AACpC,0FAAiE;AAIjE,yGAAkF;AAClF,8FAAsE;AACtE,2DAAwD;AAGxD,4CAAsB;AACtB,gDAAwB;AAGxB,MAA8B,WAAW;IAQrC;QAEI,IAAI,CAAC,wBAAwB,GAAG,IAAI,kCAAwB,EAAE,CAAC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AC,CAAC,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;4BAEvH,CAAC;yBACJ,CAAC,CAAC;qBACV;oBAED,KAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EACvC;wBACI,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAE,EAAE,GAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;qBACrG;oBAED,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;iBACzB;qBACG;oBAEA,OAAO,CAAC;wBACJ,OAAO,EAAG,OAAO;wBACjB,QAAQ,EAAG,QAAQ;wBACnB,IAAI,EAAG,GAAG,EAAE,GAAE,CAAC;qBAClB,CAAC,CAAC;iBACN;YAGL,CAAC,CAAC,CAAA;SACL;IAEL,CAAC;CAMJ;AA3MD,8BA2MC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import IApplicationConfiguration from './interfaces/IApplicationConfiguration';
|
|
2
|
+
export default class Configuration implements IApplicationConfiguration {
|
|
3
|
+
Host: string;
|
|
4
|
+
Port: number;
|
|
5
|
+
RootPath: string;
|
|
6
|
+
constructor();
|
|
7
|
+
AddScoped(type: Function, ctor?: (new (...args: any[]) => any) | undefined, builder?: (() => any) | undefined): void;
|
|
8
|
+
AddTransient(type: Function, ctor?: (new (...args: any[]) => any) | undefined, builder?: (() => any) | undefined): void;
|
|
9
|
+
AddSingleton(type: Function, ctor?: (new (...args: any[]) => any) | undefined, builder?: (() => any) | undefined): void;
|
|
10
|
+
StartAsync(): Promise<void>;
|
|
11
|
+
private CheckFileAsync;
|
|
12
|
+
private ReadFileAsync;
|
|
13
|
+
private CreateFileAsync;
|
|
14
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const fs_1 = __importDefault(require("fs"));
|
|
39
|
+
const DependecyService_1 = __importStar(require("./dependencyInjection/DependecyService"));
|
|
40
|
+
class Configuration {
|
|
41
|
+
constructor() {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
this.Host = "0.0.0.0";
|
|
44
|
+
this.Port = 5555;
|
|
45
|
+
this.RootPath = (_b = (_a = process.mainModule) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : __dirname;
|
|
46
|
+
}
|
|
47
|
+
AddScoped(type, ctor, builder) {
|
|
48
|
+
if (ctor) {
|
|
49
|
+
DependecyService_1.default.RegisterFor(type, ctor, DependecyService_1.DIEscope.SCOPED, builder);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
DependecyService_1.default.Register(type, DependecyService_1.DIEscope.SCOPED, builder);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
AddTransient(type, ctor, builder) {
|
|
56
|
+
if (ctor) {
|
|
57
|
+
DependecyService_1.default.RegisterFor(type, ctor, DependecyService_1.DIEscope.TRANSIENT, builder);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
DependecyService_1.default.Register(type, DependecyService_1.DIEscope.TRANSIENT, builder);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
AddSingleton(type, ctor, builder) {
|
|
64
|
+
if (ctor) {
|
|
65
|
+
DependecyService_1.default.RegisterFor(type, ctor, DependecyService_1.DIEscope.SINGLETON, builder);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
DependecyService_1.default.Register(type, DependecyService_1.DIEscope.SINGLETON, builder);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
StartAsync() {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (!(yield this.CheckFileAsync())) {
|
|
74
|
+
yield this.CreateFileAsync();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
yield this.ReadFileAsync();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
CheckFileAsync() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return new Promise((resolve, _) => resolve(fs_1.default.existsSync(`${__dirname}\\config.json`)));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
ReadFileAsync() {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
return new Promise((resolve, _) => {
|
|
89
|
+
fs_1.default.readFile(`${__dirname}\\config.json`, 'utf-8', (error, data) => {
|
|
90
|
+
if (error) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
let json = JSON.parse(data);
|
|
94
|
+
for (let key in this) {
|
|
95
|
+
if (json[key] != undefined) {
|
|
96
|
+
this[key] = json[key];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
resolve(true);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
CreateFileAsync() {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
return new Promise((resolve, _) => {
|
|
107
|
+
fs_1.default.writeFile(`${__dirname}\\config.json`, JSON.stringify(this), 'utf-8', error => {
|
|
108
|
+
if (error) {
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
resolve(true);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.default = Configuration;
|
|
118
|
+
//# sourceMappingURL=ApplicationConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApplicationConf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CAAC,CAAC;gBAElB,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAA;QAEN,CAAC;KAAA;CAEJ;AAjHD,gCAiHC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
var currentDirectoryPath = path_1.default.join(process.cwd());
|
|
9
|
+
var AppName = "App";
|
|
10
|
+
var app = `
|
|
11
|
+
import { Application, IApplicationConfiguration } from "web_api_base";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export default class ${AppName} extends Application
|
|
15
|
+
{
|
|
16
|
+
constructor()
|
|
17
|
+
{
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public override async ConfigureAsync(appConfig: IApplicationConfiguration): Promise<void>
|
|
22
|
+
{
|
|
23
|
+
|
|
24
|
+
this.UseCors();
|
|
25
|
+
|
|
26
|
+
this.UseControllers();
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
}`;
|
|
32
|
+
if (fs_1.default.existsSync(path_1.default.join(currentDirectoryPath, `${AppName}.ts`)))
|
|
33
|
+
console.log(`The class ${AppName} already exists`);
|
|
34
|
+
else {
|
|
35
|
+
fs_1.default.writeFileSync(path_1.default.join(currentDirectoryPath, `${AppName}.ts`), app, 'utf-8');
|
|
36
|
+
console.log(`The cçass ${AppName} created : ${path_1.default.join(currentDirectoryPath, `${AppName}.ts`)}`);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=CreateApplication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateApplication.js","sourceRoot":"","sources":["../../bin/CreateApplication.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,4CAAoB;AAEpB,IAAI,oBAAoB,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAEpD,IAAI,OAAO,GAAG,KAAK,CAAC;AAEpB,IAAI,GAAG,GAAG;;;;uBAIa,OAAO;;;;;;;;;;;;;;;;;EAiB5B,CAAC;AAGH,IAAG,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,OAAO,KAAK,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,aAAa,OAAO,iBAAiB,CAAC,CAAC;KAEnD;IACI,YAAE,CAAC,aAAa,CAAC,cAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,OAAO,KAAK,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,aAAa,OAAO,cAAc,cAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC;CACrG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
var currentDirectoryPath = path_1.default.join(process.cwd());
|
|
9
|
+
var controllerName = "SampleController";
|
|
10
|
+
var controller = `
|
|
11
|
+
import { ControllerBase, Route, Verb, Action, HTTPVerbs as verbs, Inject, InjectAbstract, Use } from "web_api_base";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@Route()
|
|
15
|
+
export default class ${controllerName} extends ControllerBase
|
|
16
|
+
{
|
|
17
|
+
|
|
18
|
+
constructor()
|
|
19
|
+
{
|
|
20
|
+
super();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Action()
|
|
24
|
+
public Ping() : void
|
|
25
|
+
{
|
|
26
|
+
this.OK({status : "pong"});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}`;
|
|
30
|
+
if (!(currentDirectoryPath.endsWith("controllers/") || currentDirectoryPath.endsWith("controllers"))) {
|
|
31
|
+
currentDirectoryPath = path_1.default.join(currentDirectoryPath, "controllers");
|
|
32
|
+
if (!fs_1.default.existsSync(currentDirectoryPath))
|
|
33
|
+
fs_1.default.mkdirSync(currentDirectoryPath);
|
|
34
|
+
}
|
|
35
|
+
if (fs_1.default.existsSync(path_1.default.join(currentDirectoryPath, `${controllerName}.ts`)))
|
|
36
|
+
console.log(`The controller ${controllerName} already exists`);
|
|
37
|
+
else {
|
|
38
|
+
fs_1.default.writeFileSync(path_1.default.join(currentDirectoryPath, `${controllerName}.ts`), controller, 'utf-8');
|
|
39
|
+
console.log(`The controller ${controllerName} created : ${path_1.default.join(currentDirectoryPath, `${controllerName}.ts`)}`);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=CreateController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateController.js","sourceRoot":"","sources":["../../bin/CreateController.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,4CAAoB;AAEpB,IAAI,oBAAoB,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAEpD,IAAI,cAAc,GAAG,kBAAkB,CAAC;AAExC,IAAI,UAAU,GAAG;;;;;uBAKM,cAAc;;;;;;;;;;;;;;EAcnC,CAAC;AAEH,IAAG,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,oBAAoB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,EACnG;IACI,oBAAoB,GAAG,cAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;IAEtE,IAAG,CAAC,YAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC;QACnC,YAAE,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;CAC1C;AAED,IAAG,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,cAAc,KAAK,CAAC,CAAC;IACrE,OAAO,CAAC,GAAG,CAAC,kBAAkB,cAAc,iBAAiB,CAAC,CAAC;KAE/D;IACI,YAAE,CAAC,aAAa,CAAC,cAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,cAAc,KAAK,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC/F,OAAO,CAAC,GAAG,CAAC,kBAAkB,cAAc,cAAc,cAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,cAAc,KAAK,CAAC,EAAE,CAAC,CAAC;CACxH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import IDIContext, { IDIItem } from "../../dependencyInjection/IDIContext";
|
|
2
|
+
import IController from "../../interfaces/IController";
|
|
3
|
+
import { Request, Response } from 'express';
|
|
4
|
+
export declare class ControllerBase implements IController, IDIContext {
|
|
5
|
+
Request: Request;
|
|
6
|
+
Response: Response;
|
|
7
|
+
Intances: IDIItem[];
|
|
8
|
+
constructor();
|
|
9
|
+
OK<T>(result: T): void;
|
|
10
|
+
Created(): void;
|
|
11
|
+
BadRequest<T>(result: T): void;
|
|
12
|
+
Error<T>(result: T): void;
|
|
13
|
+
SendResponse<T>(status: number, result: T): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ControllerBase = void 0;
|
|
4
|
+
class ControllerBase {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.Request = {};
|
|
7
|
+
this.Response = {};
|
|
8
|
+
this.Intances = [];
|
|
9
|
+
}
|
|
10
|
+
OK(result) {
|
|
11
|
+
this.Response.status(200);
|
|
12
|
+
this.Response.json(result);
|
|
13
|
+
}
|
|
14
|
+
Created() {
|
|
15
|
+
this.Response.status(201);
|
|
16
|
+
this.Response.end();
|
|
17
|
+
}
|
|
18
|
+
BadRequest(result) {
|
|
19
|
+
this.Response.status(400);
|
|
20
|
+
this.Response.json(result);
|
|
21
|
+
}
|
|
22
|
+
Error(result) {
|
|
23
|
+
this.Response.status(500);
|
|
24
|
+
this.Response.json(result);
|
|
25
|
+
}
|
|
26
|
+
SendResponse(status, result) {
|
|
27
|
+
this.Response.status(status);
|
|
28
|
+
this.Response.json(result);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ControllerBase = ControllerBase;
|
|
32
|
+
//# sourceMappingURL=ControllerBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControllerBase.js","sourceRoot":"","sources":["../../../controllers/base/ControllerBase.ts"],"names":[],"mappings":";;;AAKA,MAAa,cAAc;IAMvB;QAJA,YAAO,GAAa,EAAa,CAAC;QAClC,aAAQ,GAAc,EAAc,CAAC;QACrC,aAAQ,GAAc,EAAE,CAAC;IAKzB,CAAC;IAEM,EAAE,CAAI,MAAU;QAEnB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAEM,OAAO;QAEV,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IACxB,CAAC;IAEM,UAAU,CAAI,MAAU;QAE3B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAI,MAAU;QAEtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAEM,YAAY,CAAI,MAAe,EAAE,MAAU;QAE9C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CAEJ;AAzCD,wCAyCC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { HTTPVerbs } from '../../enums/httpVerbs/HttpVerbs';
|
|
3
|
+
import IController from '../../interfaces/IController';
|
|
4
|
+
import IMidleware from '../../midlewares/IMidleware';
|
|
5
|
+
export default class ControllersDecorators {
|
|
6
|
+
constructor();
|
|
7
|
+
private static RouteKeyMetadata;
|
|
8
|
+
private static ActionVerbKeyMetadata;
|
|
9
|
+
private static ActionNameKeyMetadata;
|
|
10
|
+
private static ArgumentsHandlerKeyMetadata;
|
|
11
|
+
private static ControllerMidlewaresKeyMetadata;
|
|
12
|
+
private static ActionsMidlewaresKeyMetadata;
|
|
13
|
+
static Route(route?: string): (target: Function) => void;
|
|
14
|
+
static Use(midleware: IMidleware): (target: Function) => void;
|
|
15
|
+
static GetMidlewares(controller: IController): IMidleware[];
|
|
16
|
+
static Before(midleware: IMidleware): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
17
|
+
static GetBefores(controller: IController, methodName: string): IMidleware[];
|
|
18
|
+
static GetRoute(controller: IController): string | undefined;
|
|
19
|
+
static Verb(verb: HTTPVerbs): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
20
|
+
static GetVerb(target: IController, methodName: string): HTTPVerbs | undefined;
|
|
21
|
+
static Action(actionName?: String): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
22
|
+
static GetAction(target: IController, methodName: string): string | undefined;
|
|
23
|
+
static Argument<T>(argName1: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
24
|
+
static Argument<T, U>(argName1: string, argName2?: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
25
|
+
static Argument<T, U, K>(argName1: string, argName2?: string, argName3?: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
26
|
+
static Argument<T, U, K, Y>(argName1: string, argName2?: string, argName3?: string, argName4?: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
27
|
+
static Argument<T, U, K, Y, J>(argName1: string, argName2?: string, argName3?: string, argName4?: string, argName5?: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
28
|
+
static GetArgumentsHandler(target: IController, methodName: string): IArgumentResolverHandler | undefined;
|
|
29
|
+
private static SetMetaData;
|
|
30
|
+
private static GetMetaData;
|
|
31
|
+
}
|
|
32
|
+
interface IArgumentResolverHandler {
|
|
33
|
+
Arguments: string[];
|
|
34
|
+
CreateArgumentsList: (args: any) => any[];
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
class ControllersDecorators {
|
|
5
|
+
constructor() {
|
|
6
|
+
}
|
|
7
|
+
static Route(route) {
|
|
8
|
+
return function (target) {
|
|
9
|
+
let value = route !== null && route !== void 0 ? route : target.name.toLocaleLowerCase().replace("controller", "");
|
|
10
|
+
Reflect.defineMetadata(ControllersDecorators.RouteKeyMetadata, value, target);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
static Use(midleware) {
|
|
14
|
+
return function (target) {
|
|
15
|
+
var _a;
|
|
16
|
+
let current = (_a = Reflect.getMetadata(ControllersDecorators.ControllerMidlewaresKeyMetadata, target)) !== null && _a !== void 0 ? _a : [];
|
|
17
|
+
current.push(midleware);
|
|
18
|
+
Reflect.defineMetadata(ControllersDecorators.ControllerMidlewaresKeyMetadata, current, target);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
static GetMidlewares(controller) {
|
|
22
|
+
var _a;
|
|
23
|
+
return (_a = Reflect.getMetadata(ControllersDecorators.ControllerMidlewaresKeyMetadata, controller.constructor)) !== null && _a !== void 0 ? _a : [];
|
|
24
|
+
}
|
|
25
|
+
static Before(midleware) {
|
|
26
|
+
return function (target, methodName, propertyDescriptor) {
|
|
27
|
+
var _a;
|
|
28
|
+
let current = (_a = Reflect.getMetadata(ControllersDecorators.ActionsMidlewaresKeyMetadata, target, methodName)) !== null && _a !== void 0 ? _a : [];
|
|
29
|
+
current.push(midleware);
|
|
30
|
+
ControllersDecorators.SetMetaData(ControllersDecorators.ActionsMidlewaresKeyMetadata, target, methodName, current);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
static GetBefores(controller, methodName) {
|
|
34
|
+
var _a;
|
|
35
|
+
return (_a = this.GetMetaData(ControllersDecorators.ActionsMidlewaresKeyMetadata, controller, methodName)) !== null && _a !== void 0 ? _a : [];
|
|
36
|
+
}
|
|
37
|
+
static GetRoute(controller) {
|
|
38
|
+
let meta = Reflect.getMetadata(ControllersDecorators.RouteKeyMetadata, controller.constructor);
|
|
39
|
+
if (meta && meta[0] != '/') {
|
|
40
|
+
return `/${meta}`.toLocaleLowerCase();
|
|
41
|
+
}
|
|
42
|
+
return meta === null || meta === void 0 ? void 0 : meta.toLocaleLowerCase();
|
|
43
|
+
}
|
|
44
|
+
static Verb(verb) {
|
|
45
|
+
return function (target, methodName, propertyDescriptor) {
|
|
46
|
+
ControllersDecorators.SetMetaData(ControllersDecorators.ActionVerbKeyMetadata, target, methodName, verb);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
static GetVerb(target, methodName) {
|
|
50
|
+
let meta = this.GetMetaData(ControllersDecorators.ActionVerbKeyMetadata, target, methodName);
|
|
51
|
+
return meta;
|
|
52
|
+
}
|
|
53
|
+
static Action(actionName) {
|
|
54
|
+
return function (target, methodName, propertyDescriptor) {
|
|
55
|
+
ControllersDecorators.SetMetaData(ControllersDecorators.ActionNameKeyMetadata, target, methodName, actionName !== null && actionName !== void 0 ? actionName : methodName.toLocaleLowerCase());
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
static GetAction(target, methodName) {
|
|
59
|
+
let meta = this.GetMetaData(ControllersDecorators.ActionNameKeyMetadata, target, methodName);
|
|
60
|
+
if (meta && meta[0] != '/') {
|
|
61
|
+
return `/${meta}`.toLocaleLowerCase();
|
|
62
|
+
}
|
|
63
|
+
return meta === null || meta === void 0 ? void 0 : meta.toLocaleLowerCase();
|
|
64
|
+
}
|
|
65
|
+
static Argument(argName1, argName2, argName3, argName4, argName5, argName6) {
|
|
66
|
+
return function (target, methodName, propertyDescriptor) {
|
|
67
|
+
ControllersDecorators.SetMetaData(ControllersDecorators.ArgumentsHandlerKeyMetadata, target, methodName, {
|
|
68
|
+
Arguments: [argName1, argName2, argName3, argName4, argName5, argName6],
|
|
69
|
+
CreateArgumentsList: (args) => {
|
|
70
|
+
let results = [];
|
|
71
|
+
if (argName1 && args[argName1] != undefined)
|
|
72
|
+
results[0] = args[argName1];
|
|
73
|
+
if (argName2 && args[argName2] != undefined)
|
|
74
|
+
results[1] = args[argName2];
|
|
75
|
+
if (argName3 && args[argName3] != undefined)
|
|
76
|
+
results[2] = args[argName3];
|
|
77
|
+
if (argName4 && args[argName4] != undefined)
|
|
78
|
+
results[3] = args[argName4];
|
|
79
|
+
if (argName5 && args[argName5] != undefined)
|
|
80
|
+
results[4] = args[argName5];
|
|
81
|
+
if (argName6 && args[argName6] != undefined)
|
|
82
|
+
results[5] = args[argName6];
|
|
83
|
+
return results;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
static GetArgumentsHandler(target, methodName) {
|
|
89
|
+
let handler = this.GetMetaData(ControllersDecorators.ArgumentsHandlerKeyMetadata, target, methodName);
|
|
90
|
+
return handler;
|
|
91
|
+
}
|
|
92
|
+
static SetMetaData(key, target, methodName, value) {
|
|
93
|
+
var meta = Reflect.getOwnMetadata(key, target, methodName);
|
|
94
|
+
if (!meta)
|
|
95
|
+
Reflect.defineMetadata(key, value, target, methodName);
|
|
96
|
+
}
|
|
97
|
+
static GetMetaData(key, target, methodName) {
|
|
98
|
+
var meta = Reflect.getMetadata(key, target, methodName);
|
|
99
|
+
if (meta != undefined)
|
|
100
|
+
return meta;
|
|
101
|
+
else
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.default = ControllersDecorators;
|
|
106
|
+
ControllersDecorators.RouteKeyMetadata = "meta:controllerRoute";
|
|
107
|
+
ControllersDecorators.ActionVerbKeyMetadata = "meta:actionVerb";
|
|
108
|
+
ControllersDecorators.ActionNameKeyMetadata = "meta:actionName";
|
|
109
|
+
ControllersDecorators.ArgumentsHandlerKeyMetadata = "meta:argHandler";
|
|
110
|
+
ControllersDecorators.ControllerMidlewaresKeyMetadata = "meta:controllerMidlewaresKey";
|
|
111
|
+
ControllersDecorators.ActionsMidlewaresKeyMetadata = "meta:actionMidlewaresKey";
|
|
112
|
+
//# sourceMappingURL=ControllerDecorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControllerDecorators.js","sourceRoot":"","sources":["../../../decorators/controllers/ControllerDecorators.ts"],"names":[],"mappings":";;AACA,4BAA0B;AAM1B,MAAqB,qBAAqB;IAEtC;IAGA,CAAC;IAUM,MAAM,CAAC,KAAK,CAAC,KAAe;QAE/B,OAAO,UAAU,MAAiB;YAE9B,IAAI,KAA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AC1C,2CAAqB,GAAG,iBAAiB,CAAC;AAC1C,iDAA2B,GAAG,iBAAiB,CAAC;AAChD,qDAA+B,GAAG,8BAA8B,CAAC;AACjE,kDAA4B,GAAG,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import IDIContext from './IDIContext';
|
|
3
|
+
export default class DependecyService {
|
|
4
|
+
private static _services;
|
|
5
|
+
private static _injectableKey;
|
|
6
|
+
private static _injectableTypeKey;
|
|
7
|
+
static RegisterFor(type: Function, ctor: {
|
|
8
|
+
new (...args: any[]): any;
|
|
9
|
+
}, scope?: DIEscope, builder?: () => any): void;
|
|
10
|
+
static Register(type: Function, scope?: DIEscope, builder?: () => any): void;
|
|
11
|
+
private static DefaultObjectBuilder;
|
|
12
|
+
static Resolve<T>(type: Function, context?: IDIContext): T | undefined;
|
|
13
|
+
static ResolveCtor(ctor: Function, context?: IDIContext): any | undefined;
|
|
14
|
+
static Injectable(): (target: Object, property: string | symbol) => void;
|
|
15
|
+
static IsInjectable(target: object, property: string): boolean;
|
|
16
|
+
static InjectOne(cTor: Function): (target: Object, property: string | symbol) => void;
|
|
17
|
+
static GetDIType(target: object, property: string): {
|
|
18
|
+
new (...args: any[]): unknown;
|
|
19
|
+
} | undefined;
|
|
20
|
+
static CheckForDependenciesAndResolve(object: any, context?: IDIContext): void;
|
|
21
|
+
static Build<T extends Function>(Ctor: T): T;
|
|
22
|
+
private static IsDIConext;
|
|
23
|
+
}
|
|
24
|
+
export declare enum DIEscope {
|
|
25
|
+
SCOPED = 0,
|
|
26
|
+
TRANSIENT = 1,
|
|
27
|
+
SINGLETON = 2
|
|
28
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIEscope = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
class DependecyService {
|
|
6
|
+
static RegisterFor(type, ctor, scope, builder) {
|
|
7
|
+
let defaultBuilder = DependecyService.DefaultObjectBuilder(type, ctor);
|
|
8
|
+
let exist = this._services.find(s => s.Type == type);
|
|
9
|
+
if (exist === undefined)
|
|
10
|
+
this._services.push({ Type: type, Builder: builder !== null && builder !== void 0 ? builder : defaultBuilder, Scope: scope !== null && scope !== void 0 ? scope : DIEscope.TRANSIENT });
|
|
11
|
+
else {
|
|
12
|
+
exist.Scope = scope !== null && scope !== void 0 ? scope : exist.Scope;
|
|
13
|
+
exist.Builder = builder !== null && builder !== void 0 ? builder : defaultBuilder;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
static Register(type, scope, builder) {
|
|
17
|
+
let defaultBuilder = DependecyService.DefaultObjectBuilder(type);
|
|
18
|
+
let exist = this._services.find(s => s.Type == type);
|
|
19
|
+
if (exist === undefined)
|
|
20
|
+
this._services.push({ Type: type, Builder: builder !== null && builder !== void 0 ? builder : defaultBuilder, Scope: scope !== null && scope !== void 0 ? scope : DIEscope.TRANSIENT });
|
|
21
|
+
else {
|
|
22
|
+
exist.Scope = scope !== null && scope !== void 0 ? scope : exist.Scope;
|
|
23
|
+
exist.Builder = builder !== null && builder !== void 0 ? builder : defaultBuilder;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
static DefaultObjectBuilder(type, ctor) {
|
|
27
|
+
return function (context) {
|
|
28
|
+
let service = DependecyService._services.find(u => u.Type == type);
|
|
29
|
+
if (context && context.Intances && (service === null || service === void 0 ? void 0 : service.Scope) == DIEscope.SCOPED) {
|
|
30
|
+
let scopped = context.Intances.filter(s => s.Type == type);
|
|
31
|
+
if (scopped.length > 0 && scopped[0].Object) {
|
|
32
|
+
return scopped[0].Object;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let insance = Reflect.construct(ctor !== null && ctor !== void 0 ? ctor : type, []);
|
|
36
|
+
DependecyService.CheckForDependenciesAndResolve(insance, (context !== null && context !== void 0 ? context : DependecyService.IsDIConext(insance)) ? insance : undefined);
|
|
37
|
+
return insance;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
static Resolve(type, context) {
|
|
41
|
+
let service = this._services.find(u => u.Type == type);
|
|
42
|
+
if (!service)
|
|
43
|
+
return undefined;
|
|
44
|
+
let insance = service.Builder(context);
|
|
45
|
+
if (service.Scope == DIEscope.SINGLETON) {
|
|
46
|
+
service.Builder = () => insance;
|
|
47
|
+
}
|
|
48
|
+
return insance;
|
|
49
|
+
}
|
|
50
|
+
static ResolveCtor(ctor, context) {
|
|
51
|
+
let service = this._services.find(u => u.Type == ctor);
|
|
52
|
+
if (!service)
|
|
53
|
+
return undefined;
|
|
54
|
+
let insance = service.Builder(context);
|
|
55
|
+
if (service.Scope == DIEscope.SINGLETON) {
|
|
56
|
+
service.Builder = () => insance;
|
|
57
|
+
}
|
|
58
|
+
return insance;
|
|
59
|
+
}
|
|
60
|
+
static Injectable() {
|
|
61
|
+
return function (target, property) {
|
|
62
|
+
Reflect.defineMetadata(DependecyService._injectableKey, true, target.constructor, property);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
static IsInjectable(target, property) {
|
|
66
|
+
var _a;
|
|
67
|
+
let marked = (_a = Reflect.getMetadata(DependecyService._injectableKey, target, property)) !== null && _a !== void 0 ? _a : false;
|
|
68
|
+
let type = Reflect.getMetadata(DependecyService._injectableTypeKey, target, property) != undefined;
|
|
69
|
+
return marked || type;
|
|
70
|
+
}
|
|
71
|
+
static InjectOne(cTor) {
|
|
72
|
+
return function (target, property) {
|
|
73
|
+
Reflect.defineMetadata(DependecyService._injectableTypeKey, cTor, target.constructor, property);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
static GetDIType(target, property) {
|
|
77
|
+
let type = Reflect.getMetadata(DependecyService._injectableTypeKey, target.constructor, property);
|
|
78
|
+
if (!type)
|
|
79
|
+
type = Reflect.getMetadata("design:type", target, property);
|
|
80
|
+
return type;
|
|
81
|
+
}
|
|
82
|
+
static CheckForDependenciesAndResolve(object, context) {
|
|
83
|
+
for (let k of Object.keys(object)) {
|
|
84
|
+
if (object[k] != 'function') {
|
|
85
|
+
if (DependecyService.IsInjectable(object.constructor, k)) {
|
|
86
|
+
let tp = DependecyService.GetDIType(object, k);
|
|
87
|
+
if (tp == undefined)
|
|
88
|
+
throw new Error(`Can not resolve the dependecy of ${object.constructor.name}.${k}`);
|
|
89
|
+
let service = this._services.find(u => u.Type == tp);
|
|
90
|
+
if (context && context.Intances && (service === null || service === void 0 ? void 0 : service.Scope) == DIEscope.SCOPED) {
|
|
91
|
+
let scopped = context.Intances.filter(s => s.Type == tp);
|
|
92
|
+
if (scopped.length > 0 && scopped[0]) {
|
|
93
|
+
object[k] = scopped[0].Object;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let instance = DependecyService.Resolve(tp);
|
|
98
|
+
if (instance == undefined)
|
|
99
|
+
throw new Error(`Can not resolve the dependecy of ${object.constructor.name}.${k}`);
|
|
100
|
+
if (DependecyService.IsDIConext(object) && (service === null || service === void 0 ? void 0 : service.Scope) == DIEscope.SCOPED) {
|
|
101
|
+
if (!object.Intances)
|
|
102
|
+
object.Intances = [];
|
|
103
|
+
object.Intances.push({
|
|
104
|
+
Object: instance,
|
|
105
|
+
Type: tp
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
object[k] = instance;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
static Build(Ctor) {
|
|
114
|
+
let object = Reflect.construct(Ctor, []);
|
|
115
|
+
this.CheckForDependenciesAndResolve(object);
|
|
116
|
+
return object;
|
|
117
|
+
}
|
|
118
|
+
static IsDIConext(object) {
|
|
119
|
+
return "Intances" in object;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.default = DependecyService;
|
|
123
|
+
DependecyService._services = [];
|
|
124
|
+
DependecyService._injectableKey = "di:injectable";
|
|
125
|
+
DependecyService._injectableTypeKey = "di:injectable-type";
|
|
126
|
+
var DIEscope;
|
|
127
|
+
(function (DIEscope) {
|
|
128
|
+
DIEscope[DIEscope["SCOPED"] = 0] = "SCOPED";
|
|
129
|
+
DIEscope[DIEscope["TRANSIENT"] = 1] = "TRANSIENT";
|
|
130
|
+
DIEscope[DIEscope["SINGLETON"] = 2] = "SINGLETON";
|
|
131
|
+
})(DIEscope = exports.DIEscope || (exports.DIEscope = {}));
|
|
132
|
+
//# sourceMappingURL=DependecyService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DependecyService.js","sourceRoot":"","sources":["../../dependencyInjection/DependecyService.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAG1B,MAAqB,gBAAgB;IAO1B,MAAM,CAAC,WAAW,CAAC,IAAe,EAAE,IAAsC,EAAE,KAAkB,EAAE,OAAoB;QAEvH,IAAI,cAAc,GAAG,gBAAgB,CAAC,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAEvE,IAAI,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;QAErD,IAAG,KAAK,KAAK,SAAS;YAClB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAG,IAAI,EAAE,OAAO,EAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,cAAc,EAAE,KAAK,EAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;aAC/G;YACA,KAAK,CAAC,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC,KAAK,CAAC;YACnC,KAAK,CAAC,OAAO,GAAI,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,cAAc,CAAC;SAC9C;IAEL,CAAC;IAGM,MAAM,CAAC,QAAQ,CAAC,IAAe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AC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,KAAI,QAAQ,CAAC,MAAM,EAC3E;wBACI,IAAG,CAAC,MAAM,CAAC,QAAQ;4BACf,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAC;wBAEzB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAChB;4BACI,MAAM,EAAG,QAAQ;4BACjB,IAAI,EAAG,EAAE;yBACZ,CAAC,CAAC;qBACV;oBAED,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;iBACxB;aACJ;SACJ;IACL,CAAC;IAGM,MAAM,CAAC,KAAK,CAAqB,IAAQ;QAE5C,IAAI,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAEzC,IAAI,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;QAE5C,OAAO,MAAW,CAAC;IACvB,CAAC;IAEO,MAAM,CAAC,UAAU,CAAC,MAAY;QAElC,OAAO,UAAU,IAAI,MAAM,CAAC;IAChC,CAAC;;AA/LL,mCAkMC;AAhMkB,0BAAS,GAAgB,EAAE,CAAC;AAE5B,+BAAc,GAAY,eAAe,CAAC;AAC1C,mCAAkB,GAAY,oBAAoB,CAAC;AA+LtE,IAAY,QAKX;AALD,WAAY,QAAQ;IAEhB,2CAAM,CAAA;IACN,iDAAS,CAAA;IACT,iDAAS,CAAA;AACb,CAAC,EALW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAKnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDIContext.js","sourceRoot":"","sources":["../../dependencyInjection/IDIContext.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HTTPVerbs = void 0;
|
|
4
|
+
var HTTPVerbs;
|
|
5
|
+
(function (HTTPVerbs) {
|
|
6
|
+
HTTPVerbs["GET"] = "GET";
|
|
7
|
+
HTTPVerbs["POST"] = "POST";
|
|
8
|
+
HTTPVerbs["PUT"] = "PUT";
|
|
9
|
+
HTTPVerbs["DELETE"] = "DELETE";
|
|
10
|
+
})(HTTPVerbs = exports.HTTPVerbs || (exports.HTTPVerbs = {}));
|
|
11
|
+
//# sourceMappingURL=HttpVerbs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpVerbs.js","sourceRoot":"","sources":["../../../enums/httpVerbs/HttpVerbs.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAMX;AAND,WAAY,SAAS;IAEjB,wBAAW,CAAA;IACX,0BAAa,CAAA;IACb,wBAAW,CAAA;IACX,8BAAiB,CAAA;AACrB,CAAC,EANW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAMpB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { default as Application } from "./Application";
|
|
2
|
+
export { default as ApplicationConfiguration } from "./ApplicationConfiguration";
|
|
3
|
+
export { default as ControllersDecorators } from "./decorators/controllers/ControllerDecorators";
|
|
4
|
+
export { ControllerBase } from "./controllers/base/ControllerBase";
|
|
5
|
+
export { HTTPVerbs } from './enums/httpVerbs/HttpVerbs';
|
|
6
|
+
export { default as DependecyService } from "./dependencyInjection/DependecyService";
|
|
7
|
+
export { default as IMidleware } from './midlewares/IMidleware';
|
|
8
|
+
export { default as IApplicationConfiguration } from "./interfaces/IApplicationConfiguration";
|
|
9
|
+
export { default as IApplication } from "./interfaces/IApplication";
|
|
10
|
+
export { default as IApplicatiIControllernConfiguration } from "./interfaces/IController";
|
|
11
|
+
import { HTTPVerbs } from "./enums/httpVerbs/HttpVerbs";
|
|
12
|
+
import IMidleware from "./midlewares/IMidleware";
|
|
13
|
+
export declare function Use(midleware: IMidleware): (target: Function) => void;
|
|
14
|
+
export declare function Run(midleware: IMidleware): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
15
|
+
export declare function Action(actionName?: String): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
16
|
+
export declare function Route(route?: string): (target: Function) => void;
|
|
17
|
+
export declare function Verb(verb: HTTPVerbs): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
18
|
+
export declare function Inject(): (target: Object, property: string | symbol) => void;
|
|
19
|
+
export declare function InjectAbstract(cTor: Function): (target: Object, property: string | symbol) => void;
|
|
20
|
+
export declare function Argument<T>(argName1: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
21
|
+
export declare function Argument<T, U>(argName1: string, argName2?: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
22
|
+
export declare function Argument<T, U, K>(argName1: string, argName2?: string, argName3?: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
23
|
+
export declare function Argument<T, U, K, Y>(argName1: string, argName2?: string, argName3?: string, argName4?: string): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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.Argument = exports.InjectAbstract = exports.Inject = exports.Verb = exports.Route = exports.Action = exports.Run = exports.Use = exports.DependecyService = exports.HTTPVerbs = exports.ControllerBase = exports.ControllersDecorators = exports.ApplicationConfiguration = exports.Application = void 0;
|
|
7
|
+
var Application_1 = require("./Application");
|
|
8
|
+
Object.defineProperty(exports, "Application", { enumerable: true, get: function () { return __importDefault(Application_1).default; } });
|
|
9
|
+
var ApplicationConfiguration_1 = require("./ApplicationConfiguration");
|
|
10
|
+
Object.defineProperty(exports, "ApplicationConfiguration", { enumerable: true, get: function () { return __importDefault(ApplicationConfiguration_1).default; } });
|
|
11
|
+
var ControllerDecorators_1 = require("./decorators/controllers/ControllerDecorators");
|
|
12
|
+
Object.defineProperty(exports, "ControllersDecorators", { enumerable: true, get: function () { return __importDefault(ControllerDecorators_1).default; } });
|
|
13
|
+
var ControllerBase_1 = require("./controllers/base/ControllerBase");
|
|
14
|
+
Object.defineProperty(exports, "ControllerBase", { enumerable: true, get: function () { return ControllerBase_1.ControllerBase; } });
|
|
15
|
+
var HttpVerbs_1 = require("./enums/httpVerbs/HttpVerbs");
|
|
16
|
+
Object.defineProperty(exports, "HTTPVerbs", { enumerable: true, get: function () { return HttpVerbs_1.HTTPVerbs; } });
|
|
17
|
+
var DependecyService_1 = require("./dependencyInjection/DependecyService");
|
|
18
|
+
Object.defineProperty(exports, "DependecyService", { enumerable: true, get: function () { return __importDefault(DependecyService_1).default; } });
|
|
19
|
+
const ControllerDecorators_2 = __importDefault(require("./decorators/controllers/ControllerDecorators"));
|
|
20
|
+
const DependecyService_2 = __importDefault(require("./dependencyInjection/DependecyService"));
|
|
21
|
+
function Use(midleware) {
|
|
22
|
+
return ControllerDecorators_2.default.Use(midleware);
|
|
23
|
+
}
|
|
24
|
+
exports.Use = Use;
|
|
25
|
+
;
|
|
26
|
+
function Run(midleware) {
|
|
27
|
+
return ControllerDecorators_2.default.Before(midleware);
|
|
28
|
+
}
|
|
29
|
+
exports.Run = Run;
|
|
30
|
+
;
|
|
31
|
+
function Action(actionName) {
|
|
32
|
+
return ControllerDecorators_2.default.Action(actionName);
|
|
33
|
+
}
|
|
34
|
+
exports.Action = Action;
|
|
35
|
+
;
|
|
36
|
+
function Route(route) {
|
|
37
|
+
return ControllerDecorators_2.default.Route(route);
|
|
38
|
+
}
|
|
39
|
+
exports.Route = Route;
|
|
40
|
+
;
|
|
41
|
+
function Verb(verb) {
|
|
42
|
+
return ControllerDecorators_2.default.Verb(verb);
|
|
43
|
+
}
|
|
44
|
+
exports.Verb = Verb;
|
|
45
|
+
;
|
|
46
|
+
function Inject() {
|
|
47
|
+
return DependecyService_2.default.Injectable();
|
|
48
|
+
}
|
|
49
|
+
exports.Inject = Inject;
|
|
50
|
+
function InjectAbstract(cTor) {
|
|
51
|
+
return DependecyService_2.default.InjectOne(cTor);
|
|
52
|
+
}
|
|
53
|
+
exports.InjectAbstract = InjectAbstract;
|
|
54
|
+
function Argument(argName1, argName2, argName3, argName4, argName5) {
|
|
55
|
+
return ControllerDecorators_2.default.Argument(argName1, argName2, argName3, argName4, argName5);
|
|
56
|
+
}
|
|
57
|
+
exports.Argument = Argument;
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAsD;AAA7C,2HAAA,OAAO,OAAe;AAC/B,uEAAiF;AAAxE,qJAAA,OAAO,OAA4B;AAE5C,sFAAiG;AAAxF,8IAAA,OAAO,OAAyB;AACzC,oEAAmE;AAA1D,gHAAA,cAAc,OAAA;AAEvB,yDAAwD;AAA/C,sGAAA,SAAS,OAAA;AAElB,2EAAqF;AAA5E,qIAAA,OAAO,OAAoB;AAQpC,yGAAkF;AAClF,8FAAsE;AAItE,SAAgB,GAAG,CAAC,SAAsB;IAEtC,OAAO,8BAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAChD,CAAC;AAHD,kBAGC;AAAC,CAAC;AAEH,SAAgB,GAAG,CAAC,SAAsB;IAEtC,OAAO,8BAAqB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACnD,CAAC;AAHD,kBAGC;AAAC,CAAC;AAEH,SAAgB,MAAM,CAAC,UAAoB;IAEvC,OAAO,8BAAqB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACpD,CAAC;AAHD,wBAGC;AAAC,CAAC;AAEH,SAAgB,KAAK,CAAC,KAAe;IAEjC,OAAO,8BAAqB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC;AAHD,sBAGC;AAAC,CAAC;AAGH,SAAgB,IAAI,CAAC,IAAgB;IAGjC,OAAO,8BAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAJD,oBAIC;AAAC,CAAC;AAEH,SAAgB,MAAM;IAElB,OAAO,0BAAgB,CAAC,UAAU,EAAE,CAAC;AACzC,CAAC;AAHD,wBAGC;AAED,SAAgB,cAAc,CAAC,IAAe;IAE1C,OAAO,0BAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAHD,wCAGC;AAQD,SAAgB,QAAQ,CAAiB,QAAiB,EAAE,QAAkB,EAAE,QAAkB,EAAE,QAAkB,EAAE,QAAkB;IAEtI,OAAO,8BAAqB,CAAC,QAAQ,CAAiB,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5G,CAAC;AAHD,4BAGC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Express } from "express";
|
|
2
|
+
import IApplicationConfiguration from './IApplicationConfiguration';
|
|
3
|
+
export default interface IApplication {
|
|
4
|
+
Express: Express;
|
|
5
|
+
StartAsync(): Promise<void>;
|
|
6
|
+
ConfigureAsync(appConfig: IApplicationConfiguration): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IApplication.js","sourceRoot":"","sources":["../../interfaces/IApplication.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default interface IApplicationConfiguration {
|
|
2
|
+
Host: string;
|
|
3
|
+
Port: number;
|
|
4
|
+
RootPath: string;
|
|
5
|
+
AddScoped(type: Function, ctor?: (new (...args: any[]) => any) | undefined, builder?: (() => any) | undefined): void;
|
|
6
|
+
AddTransient(type: Function, ctor?: (new (...args: any[]) => any) | undefined, builder?: (() => any) | undefined): void;
|
|
7
|
+
AddSingleton(type: Function, ctor?: (new (...args: any[]) => any) | undefined, builder?: (() => any) | undefined): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IApplicationConfiguration.js","sourceRoot":"","sources":["../../interfaces/IApplicationConfiguration.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IController.js","sourceRoot":"","sources":["../../interfaces/IController.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMidleware.js","sourceRoot":"","sources":["../../midlewares/IMidleware.ts"],"names":[],"mappings":""}
|