@webtypen/webframez-core 0.0.62 → 0.1.1

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.
Files changed (59) hide show
  1. package/dev/README.md +6 -0
  2. package/dev/app.ts +93 -0
  3. package/{lib → dist}/LambdaApplication.d.ts +2 -2
  4. package/dist/Router/Request.d.ts +23 -0
  5. package/dist/Router/Request.js +29 -0
  6. package/{lib → dist}/Router/Response.d.ts +1 -7
  7. package/{lib → dist}/Router/Response.js +11 -14
  8. package/{lib → dist}/Router/Router.d.ts +42 -18
  9. package/dist/Router/Router.js +408 -0
  10. package/{lib → dist}/WebApplication.js +2 -0
  11. package/package.json +38 -35
  12. package/src/Router/Request.ts +27 -15
  13. package/src/Router/Response.ts +104 -108
  14. package/src/Router/Router.ts +258 -394
  15. package/src/WebApplication.ts +2 -0
  16. package/tsconfig.json +15 -15
  17. package/lib/Router/Request.d.ts +0 -15
  18. package/lib/Router/Request.js +0 -2
  19. package/lib/Router/Router.js +0 -538
  20. /package/{lib → dist}/BaseKernel.d.ts +0 -0
  21. /package/{lib → dist}/BaseKernel.js +0 -0
  22. /package/{lib → dist}/BaseKernelConsole.d.ts +0 -0
  23. /package/{lib → dist}/BaseKernelConsole.js +0 -0
  24. /package/{lib → dist}/BaseKernelWeb.d.ts +0 -0
  25. /package/{lib → dist}/BaseKernelWeb.js +0 -0
  26. /package/{lib → dist}/Commands/BuildFinishCommand.d.ts +0 -0
  27. /package/{lib → dist}/Commands/BuildFinishCommand.js +0 -0
  28. /package/{lib → dist}/Commands/ConsoleCommand.d.ts +0 -0
  29. /package/{lib → dist}/Commands/ConsoleCommand.js +0 -0
  30. /package/{lib → dist}/Config.d.ts +0 -0
  31. /package/{lib → dist}/Config.js +0 -0
  32. /package/{lib → dist}/ConsoleApplication.d.ts +0 -0
  33. /package/{lib → dist}/ConsoleApplication.js +0 -0
  34. /package/{lib → dist}/Controller/Controller.d.ts +0 -0
  35. /package/{lib → dist}/Controller/Controller.js +0 -0
  36. /package/{lib → dist}/Database/BaseDBDriver.d.ts +0 -0
  37. /package/{lib → dist}/Database/BaseDBDriver.js +0 -0
  38. /package/{lib → dist}/Database/DBConnection.d.ts +0 -0
  39. /package/{lib → dist}/Database/DBConnection.js +0 -0
  40. /package/{lib → dist}/Database/DBDriver.d.ts +0 -0
  41. /package/{lib → dist}/Database/DBDriver.js +0 -0
  42. /package/{lib → dist}/Database/DBDrivers.d.ts +0 -0
  43. /package/{lib → dist}/Database/DBDrivers.js +0 -0
  44. /package/{lib → dist}/Database/Model.d.ts +0 -0
  45. /package/{lib → dist}/Database/Model.js +0 -0
  46. /package/{lib → dist}/Database/QueryBuilder.d.ts +0 -0
  47. /package/{lib → dist}/Database/QueryBuilder.js +0 -0
  48. /package/{lib → dist}/Functions/NumericFunctions.d.ts +0 -0
  49. /package/{lib → dist}/Functions/NumericFunctions.js +0 -0
  50. /package/{lib → dist}/Functions/PaginationFunctions.d.ts +0 -0
  51. /package/{lib → dist}/Functions/PaginationFunctions.js +0 -0
  52. /package/{lib → dist}/Functions/StringFunctions.d.ts +0 -0
  53. /package/{lib → dist}/Functions/StringFunctions.js +0 -0
  54. /package/{lib → dist}/LambdaApplication.js +0 -0
  55. /package/{lib → dist}/Router/Route.d.ts +0 -0
  56. /package/{lib → dist}/Router/Route.js +0 -0
  57. /package/{lib → dist}/WebApplication.d.ts +0 -0
  58. /package/{lib → dist}/index.d.ts +0 -0
  59. /package/{lib → dist}/index.js +0 -0
package/dev/README.md ADDED
@@ -0,0 +1,6 @@
1
+ ### Run server for local dev
2
+
3
+ ```bash
4
+ $ npm install
5
+ ```
6
+
package/dev/app.ts ADDED
@@ -0,0 +1,93 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import Busboy from "busboy";
4
+ import { WebApplication } from "../src/WebApplication";
5
+ import { BaseKernelWeb } from "../src/BaseKernelWeb";
6
+ import { Route } from "../src/Router/Route";
7
+ import { Request } from "../src/Router/Request";
8
+ import { Response } from "../src/Router/Response";
9
+
10
+ class Kernel extends BaseKernelWeb {
11
+ static controller: { [key: string]: any } = {};
12
+ static middleware: { [key: string]: any } = {};
13
+ }
14
+
15
+ const app = new WebApplication();
16
+ app.boot({
17
+ kernel: Kernel,
18
+ config: {
19
+ application: {},
20
+ database: {},
21
+ },
22
+ port: process.env.PORT ? process.env.PORT : 3000,
23
+ basename: process.env.BASENAME ? process.env.BASENAME : null,
24
+ routesFunction: () => {
25
+ Route.group({ prefix: "/main", middleware: [] }, () => {
26
+ Route.group({ prefix: "/test", middleware: [] }, () => {
27
+ Route.get("/:test/details", (req: Request, res: Response) => {
28
+ res.send({
29
+ status: "success",
30
+ });
31
+ });
32
+ });
33
+ });
34
+
35
+ Route.post("/fileupload", (req: Request, res: Response) => {
36
+ if (!req.message) {
37
+ throw Error("Missing IncomingMessage ...");
38
+ }
39
+
40
+ const busboy = Busboy({ headers: req.headers, limits: { fileSize: 10 * 1024 * 1024 } }); // 10MB Limit
41
+ busboy.on("file", (fieldname: any, file: any, options: any) => {
42
+ console.log(`Uploading:`, options);
43
+
44
+ const saveTo = path.join(__dirname, "uploads", options.filename);
45
+ file.pipe(fs.createWriteStream(saveTo));
46
+
47
+ file.on("data", (data: any) => {
48
+ console.log(`Received ${data.length} bytes for ${options.filename}`);
49
+ });
50
+
51
+ file.on("end", () => {
52
+ console.log(`${options.filename} upload complete.`);
53
+ });
54
+
55
+ file.on("error", (err: any) => {
56
+ console.error(`Error uploading ${options.filename}:`, err);
57
+ });
58
+ });
59
+
60
+ busboy.on("finish", () => {
61
+ console.log("Upload complete.");
62
+ });
63
+
64
+ busboy.on("error", (err: any) => {
65
+ console.error("Error occurred during file upload:", err);
66
+ });
67
+
68
+ req.message.pipe(busboy); // Verwendet das native req-Objekt
69
+ });
70
+ },
71
+ });
72
+
73
+ function getBoundary(contentType: string) {
74
+ const match = contentType.match(/boundary=(.+)$/);
75
+ return match ? `--${match[1]}` : null;
76
+ }
77
+
78
+ function parseHeaders(headerPart: string) {
79
+ const headers: { [key: string]: string } = {};
80
+ const lines = headerPart.split("\r\n");
81
+ lines.forEach((line) => {
82
+ const parts = line.split(":");
83
+ if (parts.length === 2) {
84
+ headers[parts[0].trim()] = parts[1].trim();
85
+ }
86
+ });
87
+ return headers;
88
+ }
89
+
90
+ function getFilename(contentDisposition: string) {
91
+ const match = contentDisposition.match(/filename="(.+?)"/);
92
+ return match ? match[1] : null;
93
+ }
@@ -2,11 +2,11 @@ export declare class LambdaApplication {
2
2
  /**
3
3
  * Init the routes and handle the request
4
4
  */
5
- boot(event: any, context: any, options?: any): Promise<void | {
5
+ boot(event: any, context: any, options?: any): Promise<{
6
6
  statusCode: number;
7
7
  body: any;
8
8
  headers: {
9
9
  [key: string]: any;
10
10
  };
11
- }>;
11
+ } | undefined>;
12
12
  }
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage } from "http";
3
+ export declare class Request {
4
+ [key: string]: any;
5
+ method: string;
6
+ url: string;
7
+ headers: any;
8
+ rawHeaders: any;
9
+ body: any;
10
+ bodyPlain: any;
11
+ query: any;
12
+ params: any;
13
+ files: any;
14
+ socket: any;
15
+ message: IncomingMessage | null;
16
+ skipOptionsForward: boolean;
17
+ /**
18
+ * Prevent the options request from getting an automatic 200 status code
19
+ * @param status
20
+ * @returns Response
21
+ */
22
+ setSkipOptionsForward(status: boolean): this;
23
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Request = void 0;
4
+ class Request {
5
+ constructor() {
6
+ this.method = "GET";
7
+ this.url = "";
8
+ this.headers = {};
9
+ this.rawHeaders = {};
10
+ this.body = null;
11
+ this.bodyPlain = null;
12
+ this.query = {};
13
+ this.params = {};
14
+ this.files = {};
15
+ this.socket = undefined;
16
+ this.message = null;
17
+ this.skipOptionsForward = false;
18
+ }
19
+ /**
20
+ * Prevent the options request from getting an automatic 200 status code
21
+ * @param status
22
+ * @returns Response
23
+ */
24
+ setSkipOptionsForward(status) {
25
+ this.skipOptionsForward = status;
26
+ return this;
27
+ }
28
+ }
29
+ exports.Request = Request;
@@ -8,18 +8,11 @@ export declare class Response {
8
8
  [key: string]: any;
9
9
  };
10
10
  events: any;
11
- autoEnd: boolean;
12
11
  /**
13
12
  * Mode
14
13
  */
15
14
  mode: any | null;
16
15
  constructor(options?: any | null | undefined);
17
- /**
18
- * Set Response-Auto-End
19
- * @param status
20
- * @returns Response
21
- */
22
- setAutoEnd(status: boolean): this;
23
16
  /**
24
17
  * Sets the ServerResponse (res) Object (nodejs/http module)
25
18
  * @param res
@@ -49,6 +42,7 @@ export declare class Response {
49
42
  * @returns Response
50
43
  */
51
44
  send(content: any): this;
45
+ end(): this;
52
46
  registerEvent(eventKey: string, func: any): Promise<void>;
53
47
  /**
54
48
  * Runs the registered events for an event-type
@@ -15,22 +15,12 @@ class Response {
15
15
  this.statusCode = 200;
16
16
  this.headers = {};
17
17
  this.events = { after: [] };
18
- this.autoEnd = true;
19
18
  /**
20
19
  * Mode
21
20
  */
22
21
  this.mode = null;
23
22
  this.mode = options && options.mode ? options.mode : null;
24
23
  }
25
- /**
26
- * Set Response-Auto-End
27
- * @param status
28
- * @returns Response
29
- */
30
- setAutoEnd(status) {
31
- this.autoEnd = status;
32
- return this;
33
- }
34
24
  /**
35
25
  * Sets the ServerResponse (res) Object (nodejs/http module)
36
26
  * @param res
@@ -77,22 +67,29 @@ class Response {
77
67
  * @returns Response
78
68
  */
79
69
  send(content) {
80
- var _a, _b, _c;
70
+ var _a, _b, _c, _d;
81
71
  this.content = content;
82
72
  if (this.mode === "aws-lambda") {
83
73
  // Do nothing ... Store content in variable and use it later ...
84
74
  }
85
75
  else {
86
76
  if (typeof content === "object" && !Buffer.isBuffer(content)) {
87
- (_a = this.res) === null || _a === void 0 ? void 0 : _a.setHeader("Content-Type", "application/json");
88
- (_b = this.res) === null || _b === void 0 ? void 0 : _b.write(JSON.stringify(content));
77
+ if (!((_a = this.res) === null || _a === void 0 ? void 0 : _a.headersSent)) {
78
+ (_b = this.res) === null || _b === void 0 ? void 0 : _b.setHeader("Content-Type", "application/json");
79
+ }
80
+ (_c = this.res) === null || _c === void 0 ? void 0 : _c.write(JSON.stringify(content));
89
81
  }
90
82
  else {
91
- (_c = this.res) === null || _c === void 0 ? void 0 : _c.write(content);
83
+ (_d = this.res) === null || _d === void 0 ? void 0 : _d.write(content);
92
84
  }
93
85
  }
94
86
  return this;
95
87
  }
88
+ end() {
89
+ var _a;
90
+ (_a = this.res) === null || _a === void 0 ? void 0 : _a.end();
91
+ return this;
92
+ }
96
93
  registerEvent(eventKey, func) {
97
94
  return __awaiter(this, void 0, void 0, function* () {
98
95
  this.events[eventKey].push({ function: func });
@@ -1,8 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingMessage, ServerResponse } from "http";
3
+ import { Response } from "./Response";
4
+ import { Request } from "./Request";
3
5
  type RouteObject = {
4
6
  path: string;
5
- component: any;
7
+ component?: any;
8
+ controller?: any;
9
+ method_name?: string;
6
10
  options: {
7
11
  [key: string]: any;
8
12
  };
@@ -67,9 +71,17 @@ declare class RouterFacade {
67
71
  };
68
72
  /**
69
73
  * Load the application-routes
70
- *
71
74
  */
72
75
  init(options?: any): void;
76
+ /**
77
+ * Dissolves 'MyController@myFunction'
78
+ *
79
+ * @param str
80
+ */
81
+ dissolveStringComponent(str: string, path: string): {
82
+ controller: any;
83
+ method_name: string;
84
+ };
73
85
  /**
74
86
  * Register a route
75
87
  *
@@ -85,7 +97,14 @@ declare class RouterFacade {
85
97
  * @param req
86
98
  * @returns
87
99
  */
88
- dissolve(req: IncomingMessage | any | null): RouteObject | null;
100
+ dissolve(req: Request): RouteObject | null;
101
+ /**
102
+ * Extrahiert die Parameterwerte aus einer URL basierend auf einem Routenpfad.
103
+ * @param {string} path - Der Routenpfad.
104
+ * @param {Array} match - Das Match-Array des regulären Ausdrucks.
105
+ * @returns {Object} - Ein Objekt mit den extrahierten Parametern.
106
+ */
107
+ extractParams(path: string, match: any): any;
89
108
  /**
90
109
  * Dissolves the matching route based on the request-url and an object of routes
91
110
  *
@@ -93,32 +112,37 @@ declare class RouterFacade {
93
112
  * @param url
94
113
  * @returns
95
114
  */
96
- dissolveRoute(routes: any, url: string): any;
97
- /**
98
- * Sends the default 404-Page
99
- *
100
- * @param res
101
- */
102
- sendError(res: ServerResponse, code: number, message?: string): void;
103
- /**
104
- * Parses JSON without exception
105
- */
106
- parseJson(jsonObject: any): any;
115
+ dissolveRoute(routes: any, url: string, request?: Request): any;
107
116
  /**
108
117
  * Processes a request
109
118
  *
110
119
  * @param req
111
120
  * @param res
112
121
  */
113
- handleRequest(req: null | IncomingMessage, res: null | ServerResponse, options?: any): Promise<void | {
122
+ handleRequest(req: null | IncomingMessage, res: null | ServerResponse, options?: any): Promise<{
123
+ statusCode: number;
124
+ body: any;
125
+ headers: {
126
+ [key: string]: any;
127
+ };
128
+ } | undefined>;
129
+ handleMiddleware(route: RouteObject, request: Request, response: Response): Promise<void>;
130
+ mapRequest(req: null | IncomingMessage, options?: any): Promise<Request>;
131
+ parseRequestBody(req: IncomingMessage): Promise<unknown>;
132
+ handleReturn(request: Request, response: Response, body: any): {
133
+ statusCode: number;
134
+ body: any;
135
+ headers: {
136
+ [key: string]: any;
137
+ };
138
+ } | undefined;
139
+ handleError(request: Request, response: Response, statusCode: number, error: Error | string): {
114
140
  statusCode: number;
115
141
  body: any;
116
142
  headers: {
117
143
  [key: string]: any;
118
144
  };
119
- }>;
120
- handleResponseAfter(response: any, req: any, payload: any): Promise<void>;
121
- requestConsoleLog(req: IncomingMessage, httpCode: number): void;
145
+ } | undefined;
122
146
  }
123
147
  export declare const Router: RouterFacade;
124
148
  export {};