@webtypen/webframez-core 0.0.62 → 0.1.0

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 +22 -0
  5. package/dist/Router/Request.js +44 -0
  6. package/{lib → dist}/Router/Response.d.ts +1 -7
  7. package/{lib → dist}/Router/Response.js +5 -10
  8. package/{lib → dist}/Router/Router.d.ts +30 -16
  9. package/dist/Router/Router.js +383 -0
  10. package/{lib → dist}/WebApplication.js +2 -0
  11. package/package.json +38 -35
  12. package/src/Router/Request.ts +42 -15
  13. package/src/Router/Response.ts +102 -108
  14. package/src/Router/Router.ts +203 -372
  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,22 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage } from "http";
3
+ export declare class Request {
4
+ method: string;
5
+ url: string;
6
+ headers: any;
7
+ rawHeaders: any;
8
+ body: any;
9
+ bodyPlain: any;
10
+ query: any;
11
+ params: any;
12
+ files: any;
13
+ socket: any;
14
+ message: IncomingMessage | null;
15
+ skipOptionsForward: boolean;
16
+ /**
17
+ * Prevent the options request from getting an automatic 200 status code
18
+ * @param status
19
+ * @returns Response
20
+ */
21
+ setSkipOptionsForward(status: boolean): this;
22
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ // export type Request = {
3
+ // [key: string]: any;
4
+ // body?: any;
5
+ // bodyPlain?: any;
6
+ // params: object;
7
+ // httpVersionMajor: any;
8
+ // httpVersionMinor: any;
9
+ // httpVersion: any;
10
+ // headers: object;
11
+ // rawHeaders: object;
12
+ // url: string;
13
+ // method: string;
14
+ // on?: any;
15
+ // request?: any;
16
+ // };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Request = void 0;
19
+ class Request {
20
+ constructor() {
21
+ this.method = "GET";
22
+ this.url = "";
23
+ this.headers = {};
24
+ this.rawHeaders = {};
25
+ this.body = null;
26
+ this.bodyPlain = null;
27
+ this.query = {};
28
+ this.params = {};
29
+ this.files = {};
30
+ this.socket = undefined;
31
+ this.message = null;
32
+ this.skipOptionsForward = false;
33
+ }
34
+ /**
35
+ * Prevent the options request from getting an automatic 200 status code
36
+ * @param status
37
+ * @returns Response
38
+ */
39
+ setSkipOptionsForward(status) {
40
+ this.skipOptionsForward = status;
41
+ return this;
42
+ }
43
+ }
44
+ 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
@@ -93,6 +83,11 @@ class Response {
93
83
  }
94
84
  return this;
95
85
  }
86
+ end() {
87
+ var _a;
88
+ (_a = this.res) === null || _a === void 0 ? void 0 : _a.end();
89
+ return this;
90
+ }
96
91
  registerEvent(eventKey, func) {
97
92
  return __awaiter(this, void 0, void 0, function* () {
98
93
  this.events[eventKey].push({ function: func });
@@ -1,5 +1,7 @@
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
7
  component: any;
@@ -85,7 +87,14 @@ declare class RouterFacade {
85
87
  * @param req
86
88
  * @returns
87
89
  */
88
- dissolve(req: IncomingMessage | any | null): RouteObject | null;
90
+ dissolve(req: Request): RouteObject | null;
91
+ /**
92
+ * Extrahiert die Parameterwerte aus einer URL basierend auf einem Routenpfad.
93
+ * @param {string} path - Der Routenpfad.
94
+ * @param {Array} match - Das Match-Array des regulären Ausdrucks.
95
+ * @returns {Object} - Ein Objekt mit den extrahierten Parametern.
96
+ */
97
+ extractParams(path: string, match: any): any;
89
98
  /**
90
99
  * Dissolves the matching route based on the request-url and an object of routes
91
100
  *
@@ -93,32 +102,37 @@ declare class RouterFacade {
93
102
  * @param url
94
103
  * @returns
95
104
  */
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;
105
+ dissolveRoute(routes: any, url: string, request?: Request): any;
107
106
  /**
108
107
  * Processes a request
109
108
  *
110
109
  * @param req
111
110
  * @param res
112
111
  */
113
- handleRequest(req: null | IncomingMessage, res: null | ServerResponse, options?: any): Promise<void | {
112
+ handleRequest(req: null | IncomingMessage, res: null | ServerResponse, options?: any): Promise<{
113
+ statusCode: number;
114
+ body: any;
115
+ headers: {
116
+ [key: string]: any;
117
+ };
118
+ } | undefined>;
119
+ handleMiddleware(route: RouteObject, request: Request, response: Response): Promise<void>;
120
+ mapRequest(req: null | IncomingMessage, options?: any): Promise<Request>;
121
+ parseRequestBody(req: IncomingMessage): Promise<unknown>;
122
+ handleReturn(request: Request, response: Response, body: any): {
123
+ statusCode: number;
124
+ body: any;
125
+ headers: {
126
+ [key: string]: any;
127
+ };
128
+ } | undefined;
129
+ handleError(request: Request, response: Response, statusCode: number, error: Error | string): {
114
130
  statusCode: number;
115
131
  body: any;
116
132
  headers: {
117
133
  [key: string]: any;
118
134
  };
119
- }>;
120
- handleResponseAfter(response: any, req: any, payload: any): Promise<void>;
121
- requestConsoleLog(req: IncomingMessage, httpCode: number): void;
135
+ } | undefined;
122
136
  }
123
137
  export declare const Router: RouterFacade;
124
138
  export {};