@webtypen/webframez-core 0.3.12 → 0.3.14
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/dev/app.ts +8 -0
- package/dev/modules/index.ts +3 -0
- package/dev/modules/test-module/Controller/TestModuleController.ts +8 -0
- package/dev/modules/test-module/TestModuleProvider.ts +30 -0
- package/dist/Modules/ModuleProvider.d.ts +12 -0
- package/dist/Modules/ModuleProvider.js +17 -0
- package/dist/Modules/ModulesLoader.d.ts +6 -0
- package/dist/Modules/ModulesLoader.js +36 -0
- package/dist/Router/Router.js +6 -4
- package/dist/WebApplication.d.ts +2 -0
- package/dist/WebApplication.js +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/BaseKernelWeb.ts +2 -2
- package/src/Modules/ModuleProvider.ts +15 -0
- package/src/Modules/ModulesLoader.ts +34 -0
- package/src/Router/Router.ts +7 -4
- package/src/WebApplication.ts +11 -0
- package/src/index.ts +1 -0
package/dev/app.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { BaseKernelWeb } from "../src/BaseKernelWeb";
|
|
|
6
6
|
import { Route } from "../src/Router/Route";
|
|
7
7
|
import { Request } from "../src/Router/Request";
|
|
8
8
|
import { Response } from "../src/Router/Response";
|
|
9
|
+
import { MODULES } from "./modules";
|
|
9
10
|
|
|
10
11
|
class Kernel extends BaseKernelWeb {
|
|
11
12
|
static controller: { [key: string]: any } = {};
|
|
@@ -21,7 +22,14 @@ app.boot({
|
|
|
21
22
|
},
|
|
22
23
|
port: process.env.PORT ? process.env.PORT : 3000,
|
|
23
24
|
basename: process.env.BASENAME ? process.env.BASENAME : null,
|
|
25
|
+
modules: MODULES,
|
|
24
26
|
routesFunction: () => {
|
|
27
|
+
Route.get("/status", (req: Request, res: Response) => {
|
|
28
|
+
res.send({
|
|
29
|
+
message: "Seems to run ;)",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
25
33
|
Route.group({ prefix: "/main", middleware: [] }, () => {
|
|
26
34
|
Route.group({ prefix: "/test", middleware: [] }, () => {
|
|
27
35
|
Route.get("/:test/details", (req: Request, res: Response) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Request } from "../../../../src/Router/Request";
|
|
2
|
+
import { Response } from "../../../../src/Router/Response";
|
|
3
|
+
|
|
4
|
+
export class TestModuleController {
|
|
5
|
+
async test(req: Request, res: Response) {
|
|
6
|
+
res.send({ status: "success", message: "TestModuleController looks great ..." });
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ModuleProvider } from "../../../src/Modules/ModuleProvider";
|
|
2
|
+
import { Request } from "../../../src/Router/Request";
|
|
3
|
+
import { Response } from "../../../src/Router/Response";
|
|
4
|
+
import { Route } from "../../../src/Router/Route";
|
|
5
|
+
import { TestModuleController } from "./Controller/TestModuleController";
|
|
6
|
+
|
|
7
|
+
export class TestModuleProvider extends ModuleProvider {
|
|
8
|
+
static key = "test-module";
|
|
9
|
+
|
|
10
|
+
controller = {
|
|
11
|
+
TestModuleController: TestModuleController,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
routes() {
|
|
15
|
+
Route.group({ middleware: [] }, () => {
|
|
16
|
+
Route.get("/", (req: Request, res: Response) => {
|
|
17
|
+
res.send({
|
|
18
|
+
module: "TestModule",
|
|
19
|
+
status: "active",
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
Route.get("/testmodule", "TestModuleController@test");
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
boot() {
|
|
28
|
+
console.log("On Booot");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModuleProvider = void 0;
|
|
4
|
+
class ModuleProvider {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.controller = {};
|
|
7
|
+
this.middleware = {};
|
|
8
|
+
}
|
|
9
|
+
boot() { }
|
|
10
|
+
routes() { }
|
|
11
|
+
bootByRouter() {
|
|
12
|
+
this.boot();
|
|
13
|
+
this.routes();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ModuleProvider = ModuleProvider;
|
|
17
|
+
ModuleProvider.key = "example-module";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModulesLoader = void 0;
|
|
4
|
+
class ModulesLoader {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.loadedModules = {};
|
|
7
|
+
}
|
|
8
|
+
load(modules) {
|
|
9
|
+
for (let modClass of modules) {
|
|
10
|
+
if (!modClass || !modClass.key || modClass.disabled === true)
|
|
11
|
+
continue;
|
|
12
|
+
this.loadedModules[modClass.key] = new modClass();
|
|
13
|
+
this.loadedModules[modClass.key].boot();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
initRoutes() {
|
|
17
|
+
for (let key in this.loadedModules) {
|
|
18
|
+
this.loadedModules[key].routes();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
loadKernel(kernel) {
|
|
22
|
+
if (!kernel)
|
|
23
|
+
return;
|
|
24
|
+
for (let key in this.loadedModules) {
|
|
25
|
+
if (this.loadedModules[key].controller) {
|
|
26
|
+
for (let ctrlKey in this.loadedModules[key].controller) {
|
|
27
|
+
kernel.controller[ctrlKey] = this.loadedModules[key].controller[ctrlKey];
|
|
28
|
+
}
|
|
29
|
+
for (let mwKey in this.loadedModules[key].middleware) {
|
|
30
|
+
kernel.middleware[mwKey] = this.loadedModules[key].middleware[mwKey];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ModulesLoader = ModulesLoader;
|
package/dist/Router/Router.js
CHANGED
|
@@ -191,10 +191,12 @@ class RouterFacade {
|
|
|
191
191
|
else {
|
|
192
192
|
for (const route in routes) {
|
|
193
193
|
const routeObj = routes[route];
|
|
194
|
-
const regex =
|
|
195
|
-
.
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
const regex = "^" +
|
|
195
|
+
routeObj.path
|
|
196
|
+
.replace(/\/:\w+\?/g, "(?:/([^/]+))?")
|
|
197
|
+
.replace(/\/:\w+/g, "/([^/]+)")
|
|
198
|
+
.replace(/\//g, "\\/") +
|
|
199
|
+
"$";
|
|
198
200
|
const match = url.match(regex);
|
|
199
201
|
if (match) {
|
|
200
202
|
if (request) {
|
package/dist/WebApplication.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import http from "http";
|
|
3
|
+
import { ModulesLoader } from "./Modules/ModulesLoader";
|
|
3
4
|
export declare class WebApplication {
|
|
4
5
|
private server;
|
|
6
|
+
modulesLoader: ModulesLoader | null;
|
|
5
7
|
/**
|
|
6
8
|
* Init the routes and start the http-server
|
|
7
9
|
*/
|
package/dist/WebApplication.js
CHANGED
|
@@ -9,7 +9,11 @@ const Config_1 = require("./Config");
|
|
|
9
9
|
const Router_1 = require("./Router/Router");
|
|
10
10
|
const QueueJobsRegisty_1 = require("./Queue/QueueJobsRegisty");
|
|
11
11
|
const DatatableRegistry_1 = require("./Datatable/DatatableRegistry");
|
|
12
|
+
const ModulesLoader_1 = require("./Modules/ModulesLoader");
|
|
12
13
|
class WebApplication {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.modulesLoader = null;
|
|
16
|
+
}
|
|
13
17
|
/**
|
|
14
18
|
* Init the routes and start the http-server
|
|
15
19
|
*/
|
|
@@ -19,6 +23,11 @@ class WebApplication {
|
|
|
19
23
|
Config_1.Config.register(key, options.config[key]);
|
|
20
24
|
}
|
|
21
25
|
}
|
|
26
|
+
this.modulesLoader = new ModulesLoader_1.ModulesLoader();
|
|
27
|
+
this.modulesLoader.load(options && options.modules ? options.modules : []);
|
|
28
|
+
if (options && options.kernel) {
|
|
29
|
+
this.modulesLoader.loadKernel(options.kernel);
|
|
30
|
+
}
|
|
22
31
|
Router_1.Router.init({
|
|
23
32
|
mode: options && options.mode ? options.mode : null,
|
|
24
33
|
kernel: options && options.kernel ? options.kernel : null,
|
|
@@ -26,6 +35,7 @@ class WebApplication {
|
|
|
26
35
|
routesFunction: options && options.routesFunction ? options.routesFunction : null,
|
|
27
36
|
tempDir: options && options.tempDir ? options.tempDir : null,
|
|
28
37
|
});
|
|
38
|
+
this.modulesLoader.initRoutes();
|
|
29
39
|
if (options && options.datatables) {
|
|
30
40
|
DatatableRegistry_1.DatatableRegistry.registerMany(options.datatables);
|
|
31
41
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -46,4 +46,5 @@ __exportStar(require("./Queue/BaseQueueJob"), exports);
|
|
|
46
46
|
__exportStar(require("./Queue/QueueJob"), exports);
|
|
47
47
|
__exportStar(require("./Queue/QueueJobsRegisty"), exports);
|
|
48
48
|
__exportStar(require("./Commands/ConsoleOutputHelper"), exports);
|
|
49
|
+
__exportStar(require("./Modules/ModuleProvider"), exports);
|
|
49
50
|
__exportStar(require("./info"), exports);
|
package/package.json
CHANGED
package/src/BaseKernelWeb.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Controller } from "./Controller/Controller";
|
|
2
2
|
|
|
3
3
|
export class BaseKernelWeb {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
static controller: { [key: string]: Controller } = {};
|
|
5
|
+
static middleware: { [key: string]: any };
|
|
6
6
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class ModuleProvider {
|
|
2
|
+
static key: string = "example-module";
|
|
3
|
+
|
|
4
|
+
controller: { [key: string]: any } = {};
|
|
5
|
+
middleware: { [key: string]: any } = {};
|
|
6
|
+
|
|
7
|
+
boot() {}
|
|
8
|
+
|
|
9
|
+
routes() {}
|
|
10
|
+
|
|
11
|
+
bootByRouter() {
|
|
12
|
+
this.boot();
|
|
13
|
+
this.routes();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class ModulesLoader {
|
|
2
|
+
private loadedModules: { [key: string]: any } = {};
|
|
3
|
+
|
|
4
|
+
load(modules: any[]) {
|
|
5
|
+
for (let modClass of modules) {
|
|
6
|
+
if (!modClass || !modClass.key || modClass.disabled === true) continue;
|
|
7
|
+
|
|
8
|
+
this.loadedModules[modClass.key] = new modClass();
|
|
9
|
+
this.loadedModules[modClass.key].boot();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
initRoutes() {
|
|
14
|
+
for (let key in this.loadedModules) {
|
|
15
|
+
this.loadedModules[key].routes();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
loadKernel(kernel: any) {
|
|
20
|
+
if (!kernel) return;
|
|
21
|
+
|
|
22
|
+
for (let key in this.loadedModules) {
|
|
23
|
+
if (this.loadedModules[key].controller) {
|
|
24
|
+
for (let ctrlKey in this.loadedModules[key].controller) {
|
|
25
|
+
kernel.controller[ctrlKey] = this.loadedModules[key].controller[ctrlKey];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (let mwKey in this.loadedModules[key].middleware) {
|
|
29
|
+
kernel.middleware[mwKey] = this.loadedModules[key].middleware[mwKey];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/Router/Router.ts
CHANGED
|
@@ -223,10 +223,13 @@ class RouterFacade {
|
|
|
223
223
|
} else {
|
|
224
224
|
for (const route in routes) {
|
|
225
225
|
const routeObj = routes[route];
|
|
226
|
-
const regex =
|
|
227
|
-
|
|
228
|
-
.
|
|
229
|
-
|
|
226
|
+
const regex =
|
|
227
|
+
"^" +
|
|
228
|
+
routeObj.path
|
|
229
|
+
.replace(/\/:\w+\?/g, "(?:/([^/]+))?")
|
|
230
|
+
.replace(/\/:\w+/g, "/([^/]+)")
|
|
231
|
+
.replace(/\//g, "\\/") +
|
|
232
|
+
"$";
|
|
230
233
|
const match = url.match(regex);
|
|
231
234
|
|
|
232
235
|
if (match) {
|
package/src/WebApplication.ts
CHANGED
|
@@ -3,9 +3,11 @@ import { Config } from "./Config";
|
|
|
3
3
|
import { Router } from "./Router/Router";
|
|
4
4
|
import { QueueJobsRegisty } from "./Queue/QueueJobsRegisty";
|
|
5
5
|
import { DatatableRegistry } from "./Datatable/DatatableRegistry";
|
|
6
|
+
import { ModulesLoader } from "./Modules/ModulesLoader";
|
|
6
7
|
|
|
7
8
|
export class WebApplication {
|
|
8
9
|
private server!: Server;
|
|
10
|
+
modulesLoader: ModulesLoader | null = null;
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Init the routes and start the http-server
|
|
@@ -17,6 +19,13 @@ export class WebApplication {
|
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
this.modulesLoader = new ModulesLoader();
|
|
23
|
+
this.modulesLoader.load(options && options.modules ? options.modules : []);
|
|
24
|
+
|
|
25
|
+
if (options && options.kernel) {
|
|
26
|
+
this.modulesLoader.loadKernel(options.kernel);
|
|
27
|
+
}
|
|
28
|
+
|
|
20
29
|
Router.init({
|
|
21
30
|
mode: options && options.mode ? options.mode : null,
|
|
22
31
|
kernel: options && options.kernel ? options.kernel : null,
|
|
@@ -25,6 +34,8 @@ export class WebApplication {
|
|
|
25
34
|
tempDir: options && options.tempDir ? options.tempDir : null,
|
|
26
35
|
});
|
|
27
36
|
|
|
37
|
+
this.modulesLoader.initRoutes();
|
|
38
|
+
|
|
28
39
|
if (options && options.datatables) {
|
|
29
40
|
DatatableRegistry.registerMany(options.datatables);
|
|
30
41
|
}
|
package/src/index.ts
CHANGED