topsyde-utils 1.3.1 → 2.0.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 (94) hide show
  1. package/dist/index.d.ts +2 -31
  2. package/dist/index.js +1 -27
  3. package/dist/index.js.map +1 -1
  4. package/dist/utils/Lib.d.ts +0 -12
  5. package/dist/utils/Lib.js +0 -65
  6. package/dist/utils/Lib.js.map +1 -1
  7. package/dist/websocket.shared.types.d.ts +25 -0
  8. package/dist/websocket.shared.types.js +4 -0
  9. package/dist/websocket.shared.types.js.map +1 -0
  10. package/package.json +1 -22
  11. package/src/index.ts +2 -51
  12. package/src/utils/Lib.ts +0 -77
  13. package/src/websocket.shared.types.ts +27 -0
  14. package/dist/application.d.ts +0 -18
  15. package/dist/application.js +0 -60
  16. package/dist/application.js.map +0 -1
  17. package/dist/server/base/base.database.d.ts +0 -10
  18. package/dist/server/base/base.database.js +0 -23
  19. package/dist/server/base/base.database.js.map +0 -1
  20. package/dist/server/base/index.d.ts +0 -2
  21. package/dist/server/base/index.js +0 -5
  22. package/dist/server/base/index.js.map +0 -1
  23. package/dist/server/bun/index.d.ts +0 -3
  24. package/dist/server/bun/index.js +0 -6
  25. package/dist/server/bun/index.js.map +0 -1
  26. package/dist/server/bun/router/controller-discovery.d.ts +0 -13
  27. package/dist/server/bun/router/controller-discovery.js +0 -83
  28. package/dist/server/bun/router/controller-discovery.js.map +0 -1
  29. package/dist/server/bun/router/index.d.ts +0 -6
  30. package/dist/server/bun/router/index.js +0 -9
  31. package/dist/server/bun/router/index.js.map +0 -1
  32. package/dist/server/bun/router/router.d.ts +0 -12
  33. package/dist/server/bun/router/router.internal.d.ts +0 -15
  34. package/dist/server/bun/router/router.internal.js +0 -51
  35. package/dist/server/bun/router/router.internal.js.map +0 -1
  36. package/dist/server/bun/router/router.js +0 -38
  37. package/dist/server/bun/router/router.js.map +0 -1
  38. package/dist/server/bun/router/routes.d.ts +0 -5
  39. package/dist/server/bun/router/routes.js +0 -2
  40. package/dist/server/bun/router/routes.js.map +0 -1
  41. package/dist/server/bun/websocket/Channel.d.ts +0 -68
  42. package/dist/server/bun/websocket/Channel.js +0 -263
  43. package/dist/server/bun/websocket/Channel.js.map +0 -1
  44. package/dist/server/bun/websocket/Client.d.ts +0 -87
  45. package/dist/server/bun/websocket/Client.js +0 -193
  46. package/dist/server/bun/websocket/Client.js.map +0 -1
  47. package/dist/server/bun/websocket/Message.d.ts +0 -10
  48. package/dist/server/bun/websocket/Message.js +0 -103
  49. package/dist/server/bun/websocket/Message.js.map +0 -1
  50. package/dist/server/bun/websocket/Websocket.d.ts +0 -171
  51. package/dist/server/bun/websocket/Websocket.js +0 -336
  52. package/dist/server/bun/websocket/Websocket.js.map +0 -1
  53. package/dist/server/bun/websocket/index.d.ts +0 -11
  54. package/dist/server/bun/websocket/index.js +0 -14
  55. package/dist/server/bun/websocket/index.js.map +0 -1
  56. package/dist/server/bun/websocket/websocket.enums.d.ts +0 -27
  57. package/dist/server/bun/websocket/websocket.enums.js +0 -31
  58. package/dist/server/bun/websocket/websocket.enums.js.map +0 -1
  59. package/dist/server/bun/websocket/websocket.guards.d.ts +0 -3
  60. package/dist/server/bun/websocket/websocket.guards.js +0 -17
  61. package/dist/server/bun/websocket/websocket.guards.js.map +0 -1
  62. package/dist/server/bun/websocket/websocket.types.d.ts +0 -235
  63. package/dist/server/bun/websocket/websocket.types.js +0 -2
  64. package/dist/server/bun/websocket/websocket.types.js.map +0 -1
  65. package/dist/server/controller.d.ts +0 -62
  66. package/dist/server/controller.js +0 -55
  67. package/dist/server/controller.js.map +0 -1
  68. package/dist/server/index.d.ts +0 -4
  69. package/dist/server/index.js +0 -7
  70. package/dist/server/index.js.map +0 -1
  71. package/dist/server/service.d.ts +0 -5
  72. package/dist/server/service.js +0 -38
  73. package/dist/server/service.js.map +0 -1
  74. package/src/application.ts +0 -73
  75. package/src/server/base/base.database.ts +0 -31
  76. package/src/server/base/index.ts +0 -5
  77. package/src/server/bun/index.ts +0 -6
  78. package/src/server/bun/router/controller-discovery.ts +0 -94
  79. package/src/server/bun/router/index.ts +0 -9
  80. package/src/server/bun/router/router.internal.ts +0 -64
  81. package/src/server/bun/router/router.ts +0 -51
  82. package/src/server/bun/router/routes.ts +0 -7
  83. package/src/server/bun/websocket/Channel.ts +0 -310
  84. package/src/server/bun/websocket/Client.ts +0 -243
  85. package/src/server/bun/websocket/ISSUES.md +0 -1175
  86. package/src/server/bun/websocket/Message.ts +0 -120
  87. package/src/server/bun/websocket/Websocket.ts +0 -402
  88. package/src/server/bun/websocket/index.ts +0 -14
  89. package/src/server/bun/websocket/websocket.enums.ts +0 -29
  90. package/src/server/bun/websocket/websocket.guards.ts +0 -22
  91. package/src/server/bun/websocket/websocket.types.ts +0 -252
  92. package/src/server/controller.ts +0 -121
  93. package/src/server/index.ts +0 -7
  94. package/src/server/service.ts +0 -36
package/src/index.ts CHANGED
@@ -5,29 +5,15 @@
5
5
  export * from "./errors";
6
6
  export * from "./singleton";
7
7
  export * from "./initializable";
8
- export * from "./application";
9
8
  export * from "./consts";
10
9
  export * from "./types";
10
+ export * from "./websocket.shared.types";
11
11
  export * from "./throwable";
12
12
  export * from "./enums";
13
13
  export * from "./client/api/base.api";
14
14
  export * from "./client/rxjs/useRxjs";
15
15
  export * from "./client/vite/plugins/topsydeUtilsVitePlugin";
16
16
  export * from "./external/re-exports";
17
- export * from "./server/controller";
18
- export * from "./server/service";
19
- export * from "./server/base/base.database";
20
- export * from "./server/bun/router/controller-discovery";
21
- export * from "./server/bun/router/routes";
22
- export * from "./server/bun/router/router";
23
- export * from "./server/bun/router/router.internal";
24
- export * from "./server/bun/websocket/Websocket";
25
- export * from "./server/bun/websocket/websocket.guards";
26
- export * from "./server/bun/websocket/Message";
27
- export * from "./server/bun/websocket/Channel";
28
- export * from "./server/bun/websocket/Client";
29
- export * from "./server/bun/websocket/websocket.enums";
30
- export * from "./server/bun/websocket/websocket.types";
31
17
  export * from "./utils/Rxjs";
32
18
  export * from "./utils/Lib";
33
19
  export * from "./utils/Guards";
@@ -39,19 +25,9 @@ export * from "./utils/dto_validators/IsNumberOrRangeConstraint";
39
25
  // Export default classes
40
26
  export { default as Singleton } from "./singleton";
41
27
  export { default as Initializable } from "./initializable";
42
- export { default as Application } from "./application";
43
28
  export { default as Throwable } from "./throwable";
44
29
  export { default as BaseAPI } from "./client/api/base.api";
45
30
  export { default as TopsydeUtilsVitePlugin } from "./client/vite/plugins/topsydeUtilsVitePlugin";
46
- export { default as Controller } from "./server/controller";
47
- export { default as Service } from "./server/service";
48
- export { default as Database } from "./server/base/base.database";
49
- export { default as Router } from "./server/bun/router/router";
50
- export { default as Router_Internal } from "./server/bun/router/router.internal";
51
- export { default as Websocket } from "./server/bun/websocket/Websocket";
52
- export { default as Message } from "./server/bun/websocket/Message";
53
- export { default as Channel } from "./server/bun/websocket/Channel";
54
- export { default as Client } from "./server/bun/websocket/Client";
55
31
  export { default as Lib } from "./utils/Lib";
56
32
  export { default as Guards } from "./utils/Guards";
57
33
  export { default as BaseEntity } from "./utils/BaseEntity";
@@ -60,9 +36,9 @@ export { default as Console } from "./utils/Console";
60
36
  // Re-export specific items for backward compatibility
61
37
  export { ERROR_CODE, HTTP_ERROR_CODE, WS_ERROR_CODE } from "./errors";
62
38
  export { InitializableOptions, InitializableEvent } from "./initializable";
63
- export { RESPONSE_INIT, HEADERS_INIT, RESPONSE_METHOD_OPTIONS } from "./application";
64
39
  export { DEFAULT_FALSE_RESPONSE, LOG_COLORS, LOG_ICONS } from "./consts";
65
40
  export { ClassConstructor, NonNullableType, ObjectKeys, KVObj, I_ApplicationResponse } from "./types";
41
+ export { WebsocketEntityId, WebsocketEntityName, WebsocketEntityData, WebsocketMessage, WebsocketStructuredMessage } from "./websocket.shared.types";
66
42
  export { E_IS, E_ENVIRONMENTS } from "./enums";
67
43
  export { RxjsDataType, NamespaceActions, MultiNamespaceActions } from "./client/rxjs/useRxjs";
68
44
  export {
@@ -86,29 +62,4 @@ export {
86
62
  IsNotEmpty,
87
63
  IsNotEmptyObject,
88
64
  } from "./external/re-exports";
89
- export { ControllerResponse, ControllerAction, ControllerMap, ControllerOptions } from "./server/controller";
90
- export { Routes } from "./server/bun/router/routes";
91
- export { WebsocketConstructorOptions, I_WebsocketConstructor } from "./server/bun/websocket/Websocket";
92
- export { E_WebsocketMessageType, E_WebsocketMessagePriority, E_ClientState } from "./server/bun/websocket/websocket.enums";
93
- export {
94
- BunWebsocketMessage,
95
- WebsocketChannel,
96
- WebsocketClients,
97
- WebsocketMessageOptions,
98
- WebsocketMessage,
99
- WebsocketStructuredMessage,
100
- WebsocketEntityId,
101
- WebsocketEntityName,
102
- WebsocketEntityData,
103
- I_WebsocketEntity,
104
- I_WebsocketClient,
105
- I_WebsocketChannelEntity,
106
- BroadcastOptions,
107
- AddMemberResult,
108
- AddMemberOptions,
109
- RemoveMemberOptions,
110
- I_WebsocketChannel,
111
- WebsocketInterfaceHandlers,
112
- I_WebsocketInterface,
113
- } from "./server/bun/websocket/websocket.types";
114
65
  export { E_SUBJET_TYPE, I_RxjsPayload, RxjsNamespaces, AsyncSubject, BehaviorSubject, ReplaySubject, Subject, Subscription } from "./utils/Rxjs";
package/src/utils/Lib.ts CHANGED
@@ -1,5 +1,3 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
1
  import { E_IS } from "../enums";
4
2
  import Throwable from "../throwable";
5
3
 
@@ -328,63 +326,10 @@ class Lib {
328
326
  }
329
327
  }
330
328
 
331
- public static GetProjectRoot(startDir: string = __dirname, rootReference = "package.json"): string {
332
- let currentDir = startDir;
333
-
334
- while (!fs.existsSync(path.join(currentDir, rootReference))) {
335
- const parentDir = path.resolve(currentDir, "..");
336
- if (parentDir === currentDir) {
337
- throw new Error("Unable to find project root");
338
- }
339
- currentDir = parentDir;
340
- }
341
-
342
- return currentDir;
343
- }
344
-
345
329
  public static async RunTaskWithTimeout(task: () => Promise<void>, timeout: number) {
346
330
  return Promise.race([task(), new Promise((_, reject) => setTimeout(() => reject(new Error("Task timed out")), timeout))]);
347
331
  }
348
332
 
349
- public static GetFolderPath(folder: string): string {
350
- return path.join(this.GetProjectRoot(), folder);
351
- }
352
-
353
- public static GetFilePath(folder: string, file: string): string {
354
- return path.join(this.GetFolderPath(folder), file);
355
- }
356
-
357
- public static async CreateDirectory(folderToCreate: string) {
358
- const directoryPath = Lib.GetFolderPath(folderToCreate);
359
- await fs.promises.access(directoryPath, fs.constants.F_OK).catch(async () => {
360
- await fs.promises.mkdir(directoryPath, { recursive: true });
361
- });
362
- return directoryPath;
363
- }
364
-
365
- public static async DeleteDirectory(folderToDelete: string) {
366
- const directoryPath = path.join(this.GetProjectRoot(), folderToDelete);
367
- await fs.promises.rm(directoryPath, { recursive: true, force: true });
368
- }
369
-
370
- public static async CreateFile(folderPath: string, filePath: string, content: string) {
371
- await Lib.CreateDirectory(folderPath);
372
- const file = Lib.GetFilePath(folderPath, filePath);
373
- await fs.promises.writeFile(file, content, "utf8");
374
- }
375
-
376
- public static GetFile(filePathFromRoot: string) {
377
- return fs.createReadStream(filePathFromRoot);
378
- }
379
-
380
- public static GetFilesInDirectory(directoryPath: string): string[] {
381
- return fs.readdirSync(directoryPath);
382
- }
383
-
384
- public static async DeleteFile(filePathFromRoot: string) {
385
- await fs.promises.unlink(filePathFromRoot);
386
- }
387
-
388
333
  public static Timestamp(log = false) {
389
334
  const currentTime = new Date().toLocaleTimeString();
390
335
  if (log) console.log(`[${currentTime}]`);
@@ -455,10 +400,6 @@ class Lib {
455
400
  return x.filter((x) => !y.includes(x));
456
401
  }
457
402
 
458
- public static async ReadFileContent(filePath: string): Promise<string> {
459
- return fs.promises.readFile(filePath, "utf8");
460
- }
461
-
462
403
  public static async measureExecutionTime<T extends (...args: any[]) => any, U extends ReturnType<T>>(
463
404
  func: T,
464
405
  ...args: Parameters<T>
@@ -521,22 +462,4 @@ export class Debug {
521
462
  Lib.LogObject(object, text);
522
463
  }
523
464
 
524
- public static GetLocalIpAddress(): string {
525
- try {
526
- const { networkInterfaces } = require("os");
527
- const nets = networkInterfaces();
528
-
529
- for (const name of Object.keys(nets)) {
530
- for (const net of nets[name]) {
531
- // Skip internal and non-IPv4 addresses
532
- if (!net.internal && net.family === "IPv4") {
533
- return net.address;
534
- }
535
- }
536
- }
537
- return "127.0.0.1"; // Fallback to localhost
538
- } catch (err) {
539
- return "127.0.0.1"; // Fallback to localhost
540
- }
541
- }
542
465
  }
@@ -0,0 +1,27 @@
1
+ export type WebsocketEntityId = string;
2
+ export type WebsocketEntityName = string;
3
+ export type WebsocketEntityData = { id: WebsocketEntityId; name: WebsocketEntityName };
4
+
5
+ export type WebsocketMessage<T extends Record<string, any> = Record<string, any>> = {
6
+ type: string;
7
+ content: T;
8
+ channel?: string;
9
+ timestamp?: string;
10
+ [key: string]: any;
11
+ };
12
+
13
+ export type WebsocketStructuredMessage<T extends Record<string, any> = Record<string, any>> = {
14
+ type: string;
15
+ content: T;
16
+ channel?: string;
17
+ timestamp?: string;
18
+ client?: WebsocketEntityData;
19
+ metadata?: Record<string, string>;
20
+ priority?: number;
21
+ expiresAt?: number;
22
+ [key: string]: any;
23
+ };
24
+
25
+ export function IsWebsocketStructuredMessage(message: any): message is WebsocketStructuredMessage {
26
+ return typeof message === "object" && message !== null && "type" in message && "content" in message;
27
+ }
@@ -1,18 +0,0 @@
1
- import { I_ApplicationResponse } from "./types";
2
- export declare const RESPONSE_INIT: (status?: number, headers?: HeadersInit) => ResponseInit;
3
- export declare const HEADERS_INIT: (headers?: HeadersInit) => HeadersInit;
4
- export declare const RESPONSE_METHOD_OPTIONS: {
5
- name: string;
6
- value: string;
7
- };
8
- declare class Application {
9
- static Response<T>(data: T | I_ApplicationResponse<T>, options?: {
10
- after_action?: () => void | Promise<void>;
11
- before_action?: () => void;
12
- }, status?: number, headers?: HeadersInit): Response;
13
- private static AfterAction;
14
- private static BeforeAction;
15
- static Error<T extends BodyInit | unknown | Error>(error: T | I_ApplicationResponse<T>, status?: number, headers?: HeadersInit): Response;
16
- static Throw<T extends BodyInit | unknown | Error>(error: T | I_ApplicationResponse<T>, status?: number, headers?: HeadersInit): Response;
17
- }
18
- export default Application;
@@ -1,60 +0,0 @@
1
- export const RESPONSE_INIT = (status, headers) => {
2
- return {
3
- status: status ?? 200,
4
- headers: HEADERS_INIT(headers),
5
- };
6
- };
7
- export const HEADERS_INIT = (headers) => {
8
- return {
9
- "Access-Control-Allow-Origin": "*", // Specific origin
10
- "Content-Type": "application/json",
11
- "Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, DELETE",
12
- "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With, Origin, Accept",
13
- "Access-Control-Allow-Credentials": "true",
14
- "Access-Control-Max-Age": "86400", // 24 hours
15
- ...headers,
16
- };
17
- };
18
- export const RESPONSE_METHOD_OPTIONS = {
19
- name: "Access-Control-Max-Age",
20
- value: "86400",
21
- };
22
- function isApplicationResponse(data) {
23
- return typeof data === "object" && data !== null && "status" in data;
24
- }
25
- class Application {
26
- static Response(data, options, status = 200, headers) {
27
- const { after_action, before_action } = options || {};
28
- Application.BeforeAction(before_action);
29
- const response = isApplicationResponse(data) ? data : { status: true, data };
30
- const output = Response.json(response, RESPONSE_INIT(status, headers));
31
- Application.AfterAction(after_action);
32
- return output;
33
- }
34
- static AfterAction(after_action) {
35
- if (after_action) {
36
- queueMicrotask(async () => {
37
- try {
38
- await after_action();
39
- }
40
- catch (error) {
41
- console.error("[Application] After-action error:", error);
42
- }
43
- });
44
- }
45
- }
46
- static BeforeAction(before_action) {
47
- if (before_action)
48
- before_action();
49
- }
50
- static Error(error, status = 200, headers) {
51
- const response = isApplicationResponse(error) ? error : { status: false, data: error, error };
52
- return Response.json(response, RESPONSE_INIT(status, headers));
53
- }
54
- static Throw(error, status = 400, headers) {
55
- const response = isApplicationResponse(error) ? error : { status: false, data: error, error };
56
- return Response.json(response, RESPONSE_INIT(status, headers));
57
- }
58
- }
59
- export default Application;
60
- //# sourceMappingURL=application.js.map
@@ -1 +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O,CAAC,CAAC,CAAC;IAChE,CAAC;CACD;AAED,eAAe,WAAW,CAAC","sourcesContent":["import { I_ApplicationResponse } from \"./types\";\n\nexport const RESPONSE_INIT = (status?: number, headers?: HeadersInit): ResponseInit => {\n\treturn {\n\t\tstatus: status ?? 200,\n\t\theaders: HEADERS_INIT(headers),\n\t};\n};\n\nexport const HEADERS_INIT = (headers?: HeadersInit): HeadersInit => {\n\treturn {\n\t\t\"Access-Control-Allow-Origin\": \"*\", // Specific origin\n\t\t\"Content-Type\": \"application/json\",\n\t\t\"Access-Control-Allow-Methods\": \"GET, POST, OPTIONS, PUT, DELETE\",\n\t\t\"Access-Control-Allow-Headers\": \"Content-Type, Authorization, X-Requested-With, Origin, Accept\",\n\t\t\"Access-Control-Allow-Credentials\": \"true\",\n\t\t\"Access-Control-Max-Age\": \"86400\", // 24 hours\n\t\t...headers,\n\t};\n};\n\nexport const RESPONSE_METHOD_OPTIONS = {\n\tname: \"Access-Control-Max-Age\",\n\tvalue: \"86400\",\n};\n\nfunction isApplicationResponse<T>(data: T | I_ApplicationResponse<T>): data is I_ApplicationResponse<T> {\n\treturn typeof data === \"object\" && data !== null && \"status\" in data;\n}\n\nclass Application {\n\tpublic static Response<T>(\n\t\tdata: T | I_ApplicationResponse<T>,\n\t\toptions?: { after_action?: () => void | Promise<void>; before_action?: () => void },\n\t\tstatus = 200,\n\t\theaders?: HeadersInit,\n\t): Response {\n\t\tconst { after_action, before_action } = options || {};\n\t\tApplication.BeforeAction(before_action);\n\t\tconst response = isApplicationResponse(data) ? data : { status: true, data };\n\t\tconst output = Response.json(response, RESPONSE_INIT(status, headers));\n\t\tApplication.AfterAction(after_action);\n\t\treturn output;\n\t}\n\n\tprivate static AfterAction(after_action?: () => void | Promise<void>) {\n\t\tif (after_action) {\n\t\t\tqueueMicrotask(async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait after_action();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(\"[Application] After-action error:\", error);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate static BeforeAction(before_action?: () => void) {\n\t\tif (before_action) before_action();\n\t}\n\n\tpublic static Error<T extends BodyInit | unknown | Error>(error: T | I_ApplicationResponse<T>, status = 200, headers?: HeadersInit): Response {\n\t\tconst response = isApplicationResponse(error) ? error : { status: false, data: error, error };\n\t\treturn Response.json(response, RESPONSE_INIT(status, headers));\n\t}\n\n\tpublic static Throw<T extends BodyInit | unknown | Error>(error: T | I_ApplicationResponse<T>, status = 400, headers?: HeadersInit): Response {\n\t\tconst response = isApplicationResponse(error) ? error : { status: false, data: error, error };\n\t\treturn Response.json(response, RESPONSE_INIT(status, headers));\n\t}\n}\n\nexport default Application;\n"]}
@@ -1,10 +0,0 @@
1
- import Singleton from "../../singleton";
2
- declare abstract class Database extends Singleton {
3
- constructor();
4
- abstract connect(): Promise<void>;
5
- abstract disconnect(): Promise<void>;
6
- protected connected: boolean;
7
- protected processing: boolean;
8
- static Connection<T extends (new (...args: any[]) => Database) & typeof Singleton>(this: T, ...args: ConstructorParameters<T>): Promise<InstanceType<T>>;
9
- }
10
- export default Database;
@@ -1,23 +0,0 @@
1
- import Singleton from "../../singleton.js";
2
- class Database extends Singleton {
3
- constructor() {
4
- super();
5
- this.connected = false;
6
- this.processing = false;
7
- }
8
- static async Connection(...args) {
9
- try {
10
- const instance = this.GetInstance(...args);
11
- if (!instance.connected && !instance.processing) {
12
- await instance.connect();
13
- }
14
- return instance;
15
- }
16
- catch (e) {
17
- console.error(e);
18
- throw e;
19
- }
20
- }
21
- }
22
- export default Database;
23
- //# sourceMappingURL=base.database.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.database.js","sourceRoot":"","sources":["../../../src/server/base/base.database.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,MAAe,QAAS,SAAQ,SAAS;IACxC;QACC,KAAK,EAAE,CAAC;QAMC,cAAS,GAAY,KAAK,CAAC;QAC3B,eAAU,GAAY,KAAK,CAAC;IANtC,CAAC;IAQM,MAAM,CAAC,KAAK,CAAC,UAAU,CAE7B,GAAG,IAA8B;QAEjC,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAoB,CAAC;YAC9D,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;gBACjD,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC1B,CAAC;YACD,OAAO,QAAQ,CAAC;QACjB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,MAAM,CAAC,CAAC;QACT,CAAC;IACF,CAAC;CACD;AAED,eAAe,QAAQ,CAAC","sourcesContent":["import Singleton from \"../../singleton\";\n\nabstract class Database extends Singleton {\n\tconstructor() {\n\t\tsuper();\n\t}\n\n\tpublic abstract connect(): Promise<void>;\n\tpublic abstract disconnect(): Promise<void>;\n\n\tprotected connected: boolean = false;\n\tprotected processing: boolean = false;\n\n\tpublic static async Connection<T extends (new (...args: any[]) => Database) & typeof Singleton>(\n\t\tthis: T,\n\t\t...args: ConstructorParameters<T>\n\t): Promise<InstanceType<T>> {\n\t\ttry {\n\t\t\tconst instance = this.GetInstance(...args) as InstanceType<T>;\n\t\t\tif (!instance.connected && !instance.processing) {\n\t\t\t\tawait instance.connect();\n\t\t\t}\n\t\t\treturn instance;\n\t\t} catch (e) {\n\t\t\tconsole.error(e);\n\t\t\tthrow e;\n\t\t}\n\t}\n}\n\nexport default Database;\n"]}
@@ -1,2 +0,0 @@
1
- export * from './base.database';
2
- export { default as Database } from './base.database';
@@ -1,5 +0,0 @@
1
- // This file is auto-generated by scripts/generate-indexes.ts
2
- // Do not edit this file directly
3
- export * from './base.database.js';
4
- export { default as Database } from './base.database.js';
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/base/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,iCAAiC;AAEjC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-indexes.ts\n// Do not edit this file directly\n\nexport * from './base.database';\nexport { default as Database } from './base.database';\n"]}
@@ -1,3 +0,0 @@
1
- export * from './websocket/Websocket';
2
- export { default as Websocket } from './websocket/Websocket';
3
- export * from './websocket';
@@ -1,6 +0,0 @@
1
- // This file is auto-generated by scripts/generate-indexes.sh
2
- // Do not edit this file directly
3
- export * from './websocket/Websocket.js';
4
- export { default as Websocket } from './websocket/Websocket.js';
5
- export * from './websocket/index.js';
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/bun/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,iCAAiC;AAEjC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC7D,cAAc,aAAa,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-indexes.sh\n// Do not edit this file directly\n\nexport * from './websocket/Websocket';\nexport { default as Websocket } from './websocket/Websocket';\nexport * from './websocket';\n"]}
@@ -1,13 +0,0 @@
1
- import { Routes } from './routes';
2
- /**
3
- * Dynamically discovers and loads controllers from the components directory
4
- */
5
- export declare class ControllerDiscovery {
6
- static DiscoverRoutes(componentPaths: string[]): Promise<Routes>;
7
- /**
8
- * Discovers controllers in the specified directory
9
- * @param componentsPath Optional custom path to components directory (relative to project root)
10
- * @returns Routes object with discovered controllers
11
- */
12
- static Find(componentsPath?: string): Promise<Routes>;
13
- }
@@ -1,83 +0,0 @@
1
- import { join } from 'path';
2
- import { readdirSync, statSync } from 'fs';
3
- import { Lib } from '../../../utils/index.js';
4
- const fallbackRoutes = {};
5
- /**
6
- * Dynamically discovers and loads controllers from the components directory
7
- */
8
- export class ControllerDiscovery {
9
- static async DiscoverRoutes(componentPaths) {
10
- try {
11
- const allDiscoveredRoutes = {};
12
- // Discover controllers in all specified component paths
13
- for (const path of componentPaths) {
14
- const discoveredRoutes = await ControllerDiscovery.Find(path);
15
- // Merge discovered routes
16
- Object.assign(allDiscoveredRoutes, discoveredRoutes);
17
- }
18
- // Use discovered routes if any were found, otherwise use fallback
19
- if (Object.keys(allDiscoveredRoutes).length > 0) {
20
- Lib.Log(`Using auto-discovered routes from paths: ${componentPaths.join(', ')}`);
21
- return allDiscoveredRoutes;
22
- }
23
- else {
24
- Lib.Log('No routes discovered, using fallback routes');
25
- return fallbackRoutes;
26
- }
27
- }
28
- catch (error) {
29
- // If auto-discovery fails, use fallback routes
30
- Lib.Warn('Controller auto-discovery failed, using fallback routes:', error);
31
- return fallbackRoutes;
32
- }
33
- }
34
- /**
35
- * Discovers controllers in the specified directory
36
- * @param componentsPath Optional custom path to components directory (relative to project root)
37
- * @returns Routes object with discovered controllers
38
- */
39
- static async Find(componentsPath) {
40
- const routes = {};
41
- // Get project root - use process.cwd() to get the root of the project using this library
42
- const projectRoot = process.cwd();
43
- // Use provided path or default to components directory
44
- const componentsDir = componentsPath
45
- ? join(projectRoot, componentsPath) // From project root
46
- : join(projectRoot, 'src', 'components'); // Default location
47
- Lib.Log(`Looking for controllers in: ${componentsDir}`);
48
- try {
49
- // Get all component directories
50
- const componentFolders = readdirSync(componentsDir).filter(folder => statSync(join(componentsDir, folder)).isDirectory());
51
- // Process each component folder
52
- for (const componentName of componentFolders) {
53
- const controllerPath = join(componentsDir, componentName, `${componentName}.controller.ts`);
54
- try {
55
- // Check if controller file exists
56
- const controllerFile = Bun.file(controllerPath);
57
- if (await controllerFile.exists()) {
58
- // Import the controller
59
- try {
60
- const module = await import(controllerPath);
61
- const Controller = module.default;
62
- if (Controller && typeof Controller === 'function') {
63
- routes[componentName] = Controller;
64
- Lib.Log(`Registered controller: ${componentName}`);
65
- }
66
- }
67
- catch (err) {
68
- Lib.Warn(`Failed to import controller for ${componentName}:`, err);
69
- }
70
- }
71
- }
72
- catch (err) {
73
- Lib.Warn(`Error processing component ${componentName}:`, err);
74
- }
75
- }
76
- }
77
- catch (err) {
78
- Lib.Warn(`Error discovering controllers in ${componentsDir}:`, err);
79
- }
80
- return routes;
81
- }
82
- }
83
- //# sourceMappingURL=controller-discovery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"controller-discovery.js","sourceRoot":"","sources":["../../../../src/server/bun/router/controller-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGrC,MAAM,cAAc,GAAW,EAAE,CAAC;AAElC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IACxB,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,cAAwB;QAC1D,IAAI,CAAC;YACJ,MAAM,mBAAmB,GAAW,EAAE,CAAC;YAEvC,wDAAwD;YACxD,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;gBACnC,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAE9D,0BAA0B;gBAC1B,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAC;YACtD,CAAC;YAED,kEAAkE;YAClE,IAAI,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACjD,GAAG,CAAC,GAAG,CAAC,4CAA4C,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACjF,OAAO,mBAAmB,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACP,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B,IAAI,CAAC;4BACJ,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;4BAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC;4BAElC,IAAI,UAAU,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE,CAAC;gCACpD,MAAM,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC;gCACnC,GAAG,CAAC,GAAG,CAAC,0BAA0B,aAAa,EAAE,CAAC,CAAC;4BACpD,CAAC;wBACF,CAAC;wBAAC,OAAO,GAAG,EAAE,CAAC;4BACd,GAAG,CAAC,IAAI,CAAC,mCAAmC,aAAa,GAAG,EAAE,GAAG,CAAC,CAAC;wBACpE,CAAC;oBACF,CAAC;gBACF,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACd,GAAG,CAAC,IAAI,CAAC,8BAA8B,aAAa,GAAG,EAAE,GAAG,CAAC,CAAC;gBAC/D,CAAC;YACF,CAAC;QACF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,GAAG,CAAC,IAAI,CAAC,oCAAoC,aAAa,GAAG,EAAE,GAAG,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;CACD","sourcesContent":["import { join } from 'path';\nimport { readdirSync, statSync } from 'fs';\nimport { Lib } from '../../../utils';\nimport { Routes } from './routes';\n\nconst fallbackRoutes: Routes = {};\n\n/**\n * Dynamically discovers and loads controllers from the components directory\n */\nexport class ControllerDiscovery {\n\tpublic static async DiscoverRoutes(componentPaths: string[]) {\n\t\ttry {\n\t\t\tconst allDiscoveredRoutes: Routes = {};\n\n\t\t\t// Discover controllers in all specified component paths\n\t\t\tfor (const path of componentPaths) {\n\t\t\t\tconst discoveredRoutes = await ControllerDiscovery.Find(path);\n\n\t\t\t\t// Merge discovered routes\n\t\t\t\tObject.assign(allDiscoveredRoutes, discoveredRoutes);\n\t\t\t}\n\n\t\t\t// Use discovered routes if any were found, otherwise use fallback\n\t\t\tif (Object.keys(allDiscoveredRoutes).length > 0) {\n\t\t\t\tLib.Log(`Using auto-discovered routes from paths: ${componentPaths.join(', ')}`);\n\t\t\t\treturn allDiscoveredRoutes;\n\t\t\t} else {\n\t\t\t\tLib.Log('No routes discovered, using fallback routes');\n\t\t\t\treturn fallbackRoutes;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// If auto-discovery fails, use fallback routes\n\t\t\tLib.Warn('Controller auto-discovery failed, using fallback routes:', error);\n\t\t\treturn fallbackRoutes;\n\t\t}\n\t}\n\n\t/**\n\t * Discovers controllers in the specified directory\n\t * @param componentsPath Optional custom path to components directory (relative to project root)\n\t * @returns Routes object with discovered controllers\n\t */\n\tpublic static async Find(componentsPath?: string): Promise<Routes> {\n\t\tconst routes: Routes = {};\n\t\t\n\t\t// Get project root - use process.cwd() to get the root of the project using this library\n\t\tconst projectRoot = process.cwd();\n\t\t\n\t\t// Use provided path or default to components directory\n\t\tconst componentsDir = componentsPath\n\t\t\t? join(projectRoot, componentsPath) // From project root\n\t\t\t: join(projectRoot, 'src', 'components'); // Default location\n\t\t\n\t\tLib.Log(`Looking for controllers in: ${componentsDir}`);\n\n\t\ttry {\n\t\t\t// Get all component directories\n\t\t\tconst componentFolders = readdirSync(componentsDir).filter(folder =>\n\t\t\t\tstatSync(join(componentsDir, folder)).isDirectory()\n\t\t\t);\n\n\t\t\t// Process each component folder\n\t\t\tfor (const componentName of componentFolders) {\n\t\t\t\tconst controllerPath = join(componentsDir, componentName, `${componentName}.controller.ts`);\n\n\t\t\t\ttry {\n\t\t\t\t\t// Check if controller file exists\n\t\t\t\t\tconst controllerFile = Bun.file(controllerPath);\n\t\t\t\t\tif (await controllerFile.exists()) {\n\t\t\t\t\t\t// Import the controller\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst module = await import(controllerPath);\n\t\t\t\t\t\t\tconst Controller = module.default;\n\n\t\t\t\t\t\t\tif (Controller && typeof Controller === 'function') {\n\t\t\t\t\t\t\t\troutes[componentName] = Controller;\n\t\t\t\t\t\t\t\tLib.Log(`Registered controller: ${componentName}`);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\tLib.Warn(`Failed to import controller for ${componentName}:`, err);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tLib.Warn(`Error processing component ${componentName}:`, err);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tLib.Warn(`Error discovering controllers in ${componentsDir}:`, err);\n\t\t}\n\n\t\treturn routes;\n\t}\n}\n"]}
@@ -1,6 +0,0 @@
1
- export * from './controller-discovery';
2
- export * from './routes';
3
- export * from './router';
4
- export * from './router.internal';
5
- export { default as Router } from './router';
6
- export { default as Router_Internal } from './router.internal';
@@ -1,9 +0,0 @@
1
- // This file is auto-generated by scripts/generate-indexes.ts
2
- // Do not edit this file directly
3
- export * from './controller-discovery.js';
4
- export * from './routes.js';
5
- export * from './router.js';
6
- export * from './router.internal.js';
7
- export { default as Router } from './router.js';
8
- export { default as Router_Internal } from './router.internal.js';
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/server/bun/router/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,iCAAiC;AAEjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-indexes.ts\n// Do not edit this file directly\n\nexport * from './controller-discovery';\nexport * from './routes';\nexport * from './router';\nexport * from './router.internal';\nexport { default as Router } from './router';\nexport { default as Router_Internal } from './router.internal';\n"]}
@@ -1,12 +0,0 @@
1
- import Singleton from "../../../singleton";
2
- import { Routes } from "./routes";
3
- declare class Router extends Singleton {
4
- private internal;
5
- constructor(routes?: Routes);
6
- private setRoutes;
7
- static Call<T>(request: Request): Promise<T>;
8
- static SetRoutes(routes: Routes): void;
9
- private static getMethodMap;
10
- static GetQueryParams(request: Request): URLSearchParams;
11
- }
12
- export default Router;
@@ -1,15 +0,0 @@
1
- import { Routes } from "./routes";
2
- declare class Router_Internal {
3
- private registry;
4
- private routes;
5
- constructor(routes?: Routes);
6
- post<T>(req: Request): Promise<T>;
7
- get<T>(req: Request): Promise<T>;
8
- private handleRequest;
9
- private getPath;
10
- private resolve;
11
- private register;
12
- setRoutes(routes: Routes): void;
13
- private controllerFactory;
14
- }
15
- export default Router_Internal;
@@ -1,51 +0,0 @@
1
- import { Throwable } from "../../../index.js";
2
- import { ERROR_CODE } from "../../../errors.js";
3
- import { Debug } from "../../../utils/Lib.js";
4
- class Router_Internal {
5
- constructor(routes) {
6
- this.registry = new Map();
7
- this.routes = routes ?? {};
8
- }
9
- async post(req) {
10
- return await this.handleRequest(req);
11
- }
12
- async get(req) {
13
- return await this.handleRequest(req);
14
- }
15
- async handleRequest(request) {
16
- const path = this.getPath(request);
17
- const output = await this.resolve(path).call(request);
18
- return output;
19
- }
20
- getPath(request) {
21
- return new URL(request.url).pathname;
22
- }
23
- resolve(path) {
24
- const controllerKey = path.split("/")[1];
25
- return this.register(controllerKey, () => this.controllerFactory(controllerKey));
26
- }
27
- register(controllerKey, factory) {
28
- if (!this.registry.has(controllerKey)) {
29
- this.registry.set(controllerKey, factory());
30
- Debug.Log(`Caching controller: /${controllerKey}`);
31
- }
32
- return this.registry.get(controllerKey);
33
- }
34
- setRoutes(routes) {
35
- this.routes = routes;
36
- }
37
- controllerFactory(controllerKey) {
38
- try {
39
- if (!(controllerKey in this.routes))
40
- throw new Throwable(`${ERROR_CODE.INVALID_CONTROLLER}: ${controllerKey}`, { logError: false });
41
- const ControllerClass = this.routes[controllerKey];
42
- return new ControllerClass();
43
- }
44
- catch (err) {
45
- console.error("controllerFactory", err);
46
- throw err;
47
- }
48
- }
49
- }
50
- export default Router_Internal;
51
- //# sourceMappingURL=router.internal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"router.internal.js","sourceRoot":"","sources":["../../../../src/server/bun/router/router.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,MAAM,eAAe;IAIpB,YAAY,MAAe;QAHnB,aAAQ,GAAG,IAAI,GAAG,EAAsB,CAAC;QAIhD,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,IAAI,CAAI,GAAY;QACzB,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,GAAG,CAAI,GAAY;QACxB,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IAEO,KAAK,CAAC,aAAa,CAAI,OAAgB;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAI,OAAO,CAAC,CAAC;QACzD,OAAO,MAAM,CAAC;IACf,CAAC;IAEO,OAAO,CAAC,OAAgB;QAC/B,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACtC,CAAC;IAEO,OAAO,CAAC,IAAY;QAC3B,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC;IAClF,CAAC;IAEO,QAAQ,CAAC,aAAqB,EAAE,OAAyB;QAChE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5C,KAAK,CAAC,GAAG,CAAC,wBAAwB,aAAa,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAe,CAAC;IACvD,CAAC;IAEM,SAAS,CAAC,MAAc;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAEO,iBAAiB,CAAC,aAAqB;QAC9C,IAAI,CAAC;YACJ,IAAI,CAAC,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC;gBAAE,MAAM,IAAI,SAAS,CAAC,GAAG,UAAU,CAAC,kBAAkB,KAAK,aAAa,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;YAEpI,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,aAAyC,CAAC,CAAC;YAE/E,OAAO,IAAI,eAAe,EAAE,CAAC;QAC9B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;YACxC,MAAM,GAAG,CAAC;QACX,CAAC;IACF,CAAC;CACD;AAED,eAAe,eAAe,CAAC","sourcesContent":["import { Throwable } from \"../../..\";\nimport { ERROR_CODE } from \"../../../errors\";\nimport Controller from \"../../controller\";\nimport { Debug } from \"../../../utils/Lib\";\nimport { Routes } from \"./routes\";\n\nclass Router_Internal {\n\tprivate registry = new Map<string, Controller>();\n\tprivate routes: Routes;\n\n\tconstructor(routes?: Routes) {\n\t\tthis.routes = routes ?? {};\n\t}\n\n\tasync post<T>(req: Request): Promise<T> {\n\t\treturn await this.handleRequest(req);\n\t}\n\n\tasync get<T>(req: Request): Promise<T> {\n\t\treturn await this.handleRequest(req);\n\t}\n\n\tprivate async handleRequest<T>(request: Request): Promise<T> {\n\t\tconst path = this.getPath(request);\n\t\tconst output = await this.resolve(path).call<T>(request);\n\t\treturn output;\n\t}\n\n\tprivate getPath(request: Request): string {\n\t\treturn new URL(request.url).pathname;\n\t}\n\n\tprivate resolve(path: string): Controller {\n\t\tconst controllerKey = path.split(\"/\")[1];\n\t\treturn this.register(controllerKey, () => this.controllerFactory(controllerKey));\n\t}\n\n\tprivate register(controllerKey: string, factory: () => Controller): Controller {\n\t\tif (!this.registry.has(controllerKey)) {\n\t\t\tthis.registry.set(controllerKey, factory());\n\t\t\tDebug.Log(`Caching controller: /${controllerKey}`);\n\t\t}\n\t\treturn this.registry.get(controllerKey) as Controller;\n\t}\n\n\tpublic setRoutes(routes: Routes): void {\n\t\tthis.routes = routes;\n\t}\n\n\tprivate controllerFactory(controllerKey: string): Controller {\n\t\ttry {\n\t\t\tif (!(controllerKey in this.routes)) throw new Throwable(`${ERROR_CODE.INVALID_CONTROLLER}: ${controllerKey}`, { logError: false });\n\n\t\t\tconst ControllerClass = this.routes[controllerKey as keyof typeof this.routes];\n\n\t\t\treturn new ControllerClass();\n\t\t} catch (err) {\n\t\t\tconsole.error(\"controllerFactory\", err);\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\nexport default Router_Internal;\n"]}