@h3ravel/shared 0.17.2 → 0.17.4

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/README.md CHANGED
@@ -1,8 +1,16 @@
1
- <p align="center"><a href="https://h3ravel.toneflix.net" target="_blank"><img src="https://raw.githubusercontent.com/h3ravel/assets/refs/heads/main/logo-full.svg" width="400" alt="H3ravel Logo"></a></p>
1
+ <div align="center">
2
+ <a href="https://h3ravel.toneflix.net" target="_blank">
3
+ <img src="https://raw.githubusercontent.com/h3ravel/assets/refs/heads/main/logo-full.svg" width="200" alt="H3ravel Logo">
4
+ </a>
5
+ <h1 align="center"><a href="https://h3ravel.toneflix.net/arquebus">H3ravel Shared</a></h1>
2
6
 
3
7
  [![Framework][ix]][lx]
4
8
  [![Shared Package Version][i1]][l1]
5
9
  [![Downloads][d1]][d1]
10
+ [![Tests][tei]][tel]
11
+ [![License][lini]][linl]
12
+
13
+ </div>
6
14
 
7
15
  # About H3ravel/shared
8
16
 
@@ -29,3 +37,7 @@ The H3ravel framework is open-sourced software licensed under the [MIT license](
29
37
  [i1]: https://img.shields.io/npm/v/%40h3ravel%2Fshared?style=flat-square&label=@h3ravel/shared&color=%230970ce
30
38
  [l1]: https://www.npmjs.com/package/@h3ravel/shared
31
39
  [d1]: https://img.shields.io/npm/dt/%40h3ravel%2Fshared?style=flat-square&label=Downloads&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40h3ravel%2Fshared
40
+ [linl]: https://github.com/h3ravel/framework/blob/main/LICENSE
41
+ [lini]: https://img.shields.io/github/license/h3ravel/framework
42
+ [tel]: https://github.com/h3ravel/framework/actions/workflows/test.yml
43
+ [tei]: https://github.com/h3ravel/framework/actions/workflows/test.yml/badge.svg
package/dist/index.cjs CHANGED
@@ -1,113 +1,241 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
8
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let chalk = require("chalk");
25
+ chalk = __toESM(chalk);
26
+ let path = require("path");
27
+ path = __toESM(path);
28
+
29
+ //#region src/Contracts/IHttp.ts
30
+ /**
31
+ * Represents the HTTP context for a single request lifecycle.
32
+ * Encapsulates the application instance, request, and response objects.
33
+ */
34
+ var HttpContext = class HttpContext {
35
+ constructor(app, request, response) {
36
+ this.app = app;
37
+ this.request = request;
38
+ this.response = response;
39
+ }
40
+ /**
41
+ * Factory method to create a new HttpContext instance from a context object.
42
+ * @param ctx - Object containing app, request, and response
43
+ * @returns A new HttpContext instance
44
+ */
45
+ static init(ctx) {
46
+ /**
47
+ * Return a new instance
48
+ */
49
+ return new HttpContext(ctx.app, ctx.request, ctx.response);
50
+ }
20
51
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
52
 
31
- // src/index.ts
32
- var index_exports = {};
33
- __export(index_exports, {
34
- HttpContext: () => HttpContext,
35
- PathLoader: () => PathLoader
36
- });
37
- module.exports = __toCommonJS(index_exports);
53
+ //#endregion
54
+ //#region src/Utils/EnvParser.ts
55
+ var EnvParser = class {
56
+ static parse(initial) {
57
+ const parsed = { ...initial };
58
+ for (const key in parsed) {
59
+ let value = parsed[key];
60
+ parsed[key] = this.parseValue(value);
61
+ }
62
+ return parsed;
63
+ }
64
+ static parseValue(value) {
65
+ /**
66
+ * Null/undefined stay untouched
67
+ */
68
+ if (value === null || value === void 0) return value;
69
+ /**
70
+ * Convert string "true"/"false" to boolean
71
+ */
72
+ if (value === "true") return true;
73
+ if (value === "false") return false;
74
+ /**
75
+ * Convert string numbers to number
76
+ */
77
+ if (!isNaN(value) && value.trim() !== "") return Number(value);
78
+ /**
79
+ * Convert string "null" and "undefined"
80
+ */
81
+ if (value === "null") return null;
82
+ if (value === "undefined") return void 0;
83
+ /**
84
+ * Otherwise return as-is (string)
85
+ */
86
+ return value;
87
+ }
88
+ };
38
89
 
39
- // src/Contracts/IHttp.ts
40
- var HttpContext = class _HttpContext {
41
- static {
42
- __name(this, "HttpContext");
43
- }
44
- app;
45
- request;
46
- response;
47
- constructor(app, request, response) {
48
- this.app = app;
49
- this.request = request;
50
- this.response = response;
51
- }
52
- /**
53
- * Factory method to create a new HttpContext instance from a context object.
54
- * @param ctx - Object containing app, request, and response
55
- * @returns A new HttpContext instance
56
- */
57
- static init(ctx) {
58
- return new _HttpContext(ctx.app, ctx.request, ctx.response);
59
- }
90
+ //#endregion
91
+ //#region src/Utils/Logger.ts
92
+ var Logger = class {
93
+ static twoColumnLog(name, value, log = true) {
94
+ const regex = /\x1b\[\d+m/g;
95
+ const width = Math.min(process.stdout.columns, 100);
96
+ const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
97
+ if (log) return console.log(name, chalk.default.gray(".".repeat(dots)), value);
98
+ else return [
99
+ name,
100
+ chalk.default.gray(".".repeat(dots)),
101
+ value
102
+ ];
103
+ }
104
+ /**
105
+ * Logs the message in two columns but allways passing status
106
+ *
107
+ * @param name
108
+ * @param value
109
+ * @param status
110
+ * @param exit
111
+ * @param preserveCol
112
+ */
113
+ static split(name, value, status, exit = false, preserveCol = false) {
114
+ status ??= "info";
115
+ const color = {
116
+ success: chalk.default.bgGreen,
117
+ info: chalk.default.bgBlue,
118
+ error: chalk.default.bgRed
119
+ };
120
+ const [_name, dots, val] = this.twoColumnLog(name, value, false);
121
+ console.log(this.textFormat(_name, color[status], preserveCol), dots, val);
122
+ if (exit) process.exit(0);
123
+ }
124
+ /**
125
+ * Wraps text with chalk
126
+ *
127
+ * @param txt
128
+ * @param color
129
+ * @param preserveCol
130
+ * @returns
131
+ */
132
+ static textFormat(txt, color, preserveCol = false) {
133
+ if (preserveCol) return String(txt);
134
+ return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
135
+ }
136
+ /**
137
+ * Logs a success message
138
+ *
139
+ * @param msg
140
+ * @param exit
141
+ * @param preserveCol
142
+ */
143
+ static success(msg, exit = false, preserveCol = false) {
144
+ console.log(chalk.default.green("✓"), this.textFormat(msg, chalk.default.bgGreen, preserveCol), "\n");
145
+ if (exit) process.exit(0);
146
+ }
147
+ /**
148
+ * Logs an informational message
149
+ *
150
+ * @param msg
151
+ * @param exit
152
+ * @param preserveCol
153
+ */
154
+ static info(msg, exit = false, preserveCol = false) {
155
+ console.log(chalk.default.blue("ℹ"), this.textFormat(msg, chalk.default.bgBlue, preserveCol), "\n");
156
+ if (exit) process.exit(0);
157
+ }
158
+ /**
159
+ * Logs an error message
160
+ *
161
+ * @param msg
162
+ * @param exit
163
+ * @param preserveCol
164
+ */
165
+ static error(msg, exit = true, preserveCol = false) {
166
+ if (msg instanceof Error) {
167
+ if (msg.message) console.error(chalk.default.red("✖"), this.textFormat("ERROR:" + msg.message, chalk.default.bgRed, preserveCol));
168
+ console.error(chalk.default.red(`${msg.detail ? `${msg.detail}\n` : ""}${msg.stack}`), "\n");
169
+ } else console.error(chalk.default.red("✖"), this.textFormat(msg, chalk.default.bgRed, preserveCol), "\n");
170
+ if (exit) process.exit(1);
171
+ }
172
+ /**
173
+ * Terminates the process
174
+ */
175
+ static quiet() {
176
+ process.exit(0);
177
+ }
178
+ static parse(config, joiner = " ", log = true) {
179
+ const string = config.map(([str, opt]) => {
180
+ return typeof chalk.default[opt] === "function" ? chalk.default[opt](str) : str;
181
+ }).join(joiner);
182
+ if (log) console.log(string);
183
+ else return string;
184
+ }
185
+ static log(config, joiner) {
186
+ if (typeof config === "string") {
187
+ const conf = [[config, joiner]];
188
+ return this.parse(conf);
189
+ } else if (config) return this.parse(config, joiner);
190
+ return this;
191
+ }
60
192
  };
61
193
 
62
- // src/Utils/PathLoader.ts
63
- var import_path = __toESM(require("path"), 1);
194
+ //#endregion
195
+ //#region src/Utils/PathLoader.ts
64
196
  var PathLoader = class {
65
- static {
66
- __name(this, "PathLoader");
67
- }
68
- paths = {
69
- base: "",
70
- views: "/src/resources/views",
71
- assets: "/public/assets",
72
- routes: "/src/routes",
73
- config: "/src/config",
74
- public: "/public",
75
- storage: "/storage"
76
- };
77
- /**
78
- * Dynamically retrieves a path property from the class.
79
- * Any property ending with "Path" is accessible automatically.
80
- *
81
- * @param name - The base name of the path property
82
- * @param base - The base path to include to the path
83
- * @returns
84
- */
85
- getPath(name, base) {
86
- let path;
87
- if (base && name !== "base") {
88
- path = import_path.default.join(base, this.paths[name]);
89
- } else {
90
- path = this.paths[name];
91
- }
92
- return path.replace("/src/", `/${process.env.SRC_PATH ?? "src"}/`.replace(/([^:]\/)\/+/g, "$1"));
93
- }
94
- /**
95
- * Programatically set the paths.
96
- *
97
- * @param name - The base name of the path property
98
- * @param path - The new path
99
- * @param base - The base path to include to the path
100
- */
101
- setPath(name, path, base) {
102
- if (base && name !== "base") {
103
- this.paths[name] = import_path.default.join(base, path);
104
- }
105
- this.paths[name] = path;
106
- }
197
+ paths = {
198
+ base: "",
199
+ views: "/src/resources/views",
200
+ assets: "/public/assets",
201
+ routes: "/src/routes",
202
+ config: "/src/config",
203
+ public: "/public",
204
+ storage: "/storage",
205
+ database: "/src/database"
206
+ };
207
+ /**
208
+ * Dynamically retrieves a path property from the class.
209
+ * Any property ending with "Path" is accessible automatically.
210
+ *
211
+ * @param name - The base name of the path property
212
+ * @param prefix - The base path to prefix to the path
213
+ * @returns
214
+ */
215
+ getPath(name, prefix) {
216
+ let path$1;
217
+ if (prefix && name !== "base") path$1 = path.default.join(prefix, this.paths[name]);
218
+ else path$1 = this.paths[name];
219
+ path$1 = path$1.replace("/src/", `/${process.env.SRC_PATH ?? "src"}/`.replace(/([^:]\/)\/+/g, "$1"));
220
+ if (name === "database" && process.env.SRC_PATH && !"/src/".includes(process.env.SRC_PATH)) return path.default.resolve(path$1.replace(process.env.SRC_PATH, ""));
221
+ return path$1;
222
+ }
223
+ /**
224
+ * Programatically set the paths.
225
+ *
226
+ * @param name - The base name of the path property
227
+ * @param path - The new path
228
+ * @param base - The base path to include to the path
229
+ */
230
+ setPath(name, path$1, base) {
231
+ if (base && name !== "base") this.paths[name] = path.default.join(base, path$1);
232
+ this.paths[name] = path$1;
233
+ }
107
234
  };
108
- // Annotate the CommonJS export names for ESM import in node:
109
- 0 && (module.exports = {
110
- HttpContext,
111
- PathLoader
112
- });
235
+
236
+ //#endregion
237
+ exports.EnvParser = EnvParser;
238
+ exports.HttpContext = HttpContext;
239
+ exports.Logger = Logger;
240
+ exports.PathLoader = PathLoader;
113
241
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/Contracts/IHttp.ts","../src/Utils/PathLoader.ts"],"sourcesContent":["export * from './Contracts/BindingsContract'\nexport * from './Contracts/IApplication'\nexport * from './Contracts/IContainer'\nexport * from './Contracts/IHttp'\nexport * from './Contracts/IRequest'\nexport * from './Contracts/IResponse'\nexport * from './Contracts/IServiceProvider'\nexport * from './Contracts/ObjContract'\nexport * from './Utils/PathLoader'\n","import type { Middleware, MiddlewareOptions } from 'h3'\n\nimport { IApplication } from './IApplication'\nimport { IRequest } from './IRequest'\nimport { IResponse } from './IResponse'\n\nexport type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';\n\n/**\n * Interface for the Router contract, defining methods for HTTP routing.\n */\nexport interface IRouter {\n /**\n * Registers a GET route.\n * @param path - The route path.\n * @param definition - The handler function or [controller class, method] array.\n * @param name - Optional route name.\n * @param middleware - Optional middleware array.\n */\n get (\n path: string,\n definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],\n name?: string,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd>;\n\n /**\n * Registers a POST route.\n * @param path - The route path.\n * @param definition - The handler function or [controller class, method] array.\n * @param name - Optional route name.\n * @param middleware - Optional middleware array.\n */\n post (\n path: string,\n definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],\n name?: string,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd>;\n\n /**\n * Registers a PUT route.\n * @param path - The route path.\n * @param definition - The handler function or [controller class, method] array.\n * @param name - Optional route name.\n * @param middleware - Optional middleware array.\n */\n put (\n path: string,\n definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],\n name?: string,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd>;\n\n /**\n * Registers a DELETE route.\n * @param path - The route path.\n * @param definition - The handler function or [controller class, method] array.\n * @param name - Optional route name.\n * @param middleware - Optional middleware array.\n */\n delete (\n path: string,\n definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],\n name?: string,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd>;\n\n /**\n * Registers an API resource with standard CRUD routes.\n * @param path - The base path for the resource.\n * @param controller - The controller class handling the resource.\n * @param middleware - Optional middleware array.\n */\n apiResource (\n path: string,\n controller: new (app: IApplication) => IController,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd | 'name'>;\n\n /**\n * Generates a URL for a named route.\n * @param name - The name of the route.\n * @param params - Optional parameters to replace in the route path.\n * @returns The generated URL or undefined if the route is not found.\n */\n route (name: string, params?: Record<string, string>): string | undefined;\n\n\n /**\n * Set the name of the current route\n * \n * @param name \n */\n name (name: string): this\n\n /**\n * Groups routes with shared prefix or middleware.\n * @param options - Configuration for prefix or middleware.\n * @param callback - Callback function defining grouped routes.\n */\n group (options: { prefix?: string; middleware?: EventHandler[] }, callback: () => this): this;\n\n /**\n * Registers middleware for a specific path.\n * @param path - The path to apply the middleware.\n * @param handler - The middleware handler.\n * @param opts - Optional middleware options.\n */\n middleware (path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;\n}\n\n/**\n * Represents the HTTP context for a single request lifecycle.\n * Encapsulates the application instance, request, and response objects.\n */\nexport class HttpContext {\n constructor(\n public app: IApplication,\n public request: IRequest,\n public response: IResponse\n ) { }\n\n /**\n * Factory method to create a new HttpContext instance from a context object.\n * @param ctx - Object containing app, request, and response\n * @returns A new HttpContext instance\n */\n static init (ctx: { app: IApplication; request: IRequest; response: IResponse }): HttpContext {\n /**\n * Return a new instance\n */\n return new HttpContext(ctx.app, ctx.request, ctx.response);\n }\n}\n\n\n/**\n * Type for EventHandler, representing a function that handles an H3 event.\n */\nexport type EventHandler = (ctx: HttpContext) => any\nexport type RouteEventHandler = (...args: any[]) => any\n\n/**\n * Defines the contract for all controllers.\n * Any controller implementing this must define these methods.\n */\nexport interface IController {\n show (...ctx: any[]): any\n index (...ctx: any[]): any\n store (...ctx: any[]): any\n update (...ctx: any[]): any\n destroy (...ctx: any[]): any\n}\n\n/**\n * Defines the contract for all middlewares.\n * Any middleware implementing this must define these methods.\n */\nexport interface IMiddleware {\n handle (context: HttpContext, next: () => Promise<any>): Promise<any>\n} \n","import { IPathName } from '../Contracts/IApplication'\nimport nodepath from 'path'\n\nexport class PathLoader {\n private paths = {\n base: '',\n views: '/src/resources/views',\n assets: '/public/assets',\n routes: '/src/routes',\n config: '/src/config',\n public: '/public',\n storage: '/storage',\n }\n\n /**\n * Dynamically retrieves a path property from the class.\n * Any property ending with \"Path\" is accessible automatically.\n *\n * @param name - The base name of the path property\n * @param base - The base path to include to the path\n * @returns \n */\n getPath (name: IPathName, base?: string): string {\n let path: string;\n\n if (base && name !== 'base') {\n path = nodepath.join(base, this.paths[name])\n } else {\n path = this.paths[name]\n }\n return path.replace('/src/', `/${process.env.SRC_PATH ?? 'src'}/`.replace(/([^:]\\/)\\/+/g, \"$1\"))\n }\n\n /**\n * Programatically set the paths.\n *\n * @param name - The base name of the path property\n * @param path - The new path\n * @param base - The base path to include to the path\n */\n setPath (name: IPathName, path: string, base?: string) {\n if (base && name !== 'base') {\n this.paths[name] = nodepath.join(base, path)\n }\n\n this.paths[name] = path\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACoHO,IAAMA,cAAN,MAAMA,aAAAA;EAJb,OAIaA;;;;;;EACT,YACWC,KACAC,SACAC,UACT;SAHSF,MAAAA;SACAC,UAAAA;SACAC,WAAAA;EACP;;;;;;EAOJ,OAAOC,KAAMC,KAAiF;AAI1F,WAAO,IAAIL,aAAYK,IAAIJ,KAAKI,IAAIH,SAASG,IAAIF,QAAQ;EAC7D;AACJ;;;ACrIA,kBAAqB;AAEd,IAAMG,aAAN,MAAMA;EAFb,OAEaA;;;EACDC,QAAQ;IACZC,MAAM;IACNC,OAAO;IACPC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;IACRC,SAAS;EACb;;;;;;;;;EAUAC,QAASC,MAAiBR,MAAuB;AAC7C,QAAIS;AAEJ,QAAIT,QAAQQ,SAAS,QAAQ;AACzBC,aAAOC,YAAAA,QAASC,KAAKX,MAAM,KAAKD,MAAMS,IAAAA,CAAK;IAC/C,OAAO;AACHC,aAAO,KAAKV,MAAMS,IAAAA;IACtB;AACA,WAAOC,KAAKG,QAAQ,SAAS,IAAIC,QAAQC,IAAIC,YAAY,KAAA,IAASH,QAAQ,gBAAgB,IAAA,CAAA;EAC9F;;;;;;;;EASAI,QAASR,MAAiBC,MAAcT,MAAe;AACnD,QAAIA,QAAQQ,SAAS,QAAQ;AACzB,WAAKT,MAAMS,IAAAA,IAAQE,YAAAA,QAASC,KAAKX,MAAMS,IAAAA;IAC3C;AAEA,SAAKV,MAAMS,IAAAA,IAAQC;EACvB;AACJ;","names":["HttpContext","app","request","response","init","ctx","PathLoader","paths","base","views","assets","routes","config","public","storage","getPath","name","path","nodepath","join","replace","process","env","SRC_PATH","setPath"]}
1
+ {"version":3,"file":"index.cjs","names":["app: IApplication","request: IRequest","response: IResponse","value: any","path: string","nodepath","path"],"sources":["../src/Contracts/IHttp.ts","../src/Utils/EnvParser.ts","../src/Utils/Logger.ts","../src/Utils/PathLoader.ts"],"sourcesContent":["import type { Middleware, MiddlewareOptions } from 'h3'\n\nimport { IApplication } from './IApplication'\nimport { IRequest } from './IRequest'\nimport { IResponse } from './IResponse'\n\nexport type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';\n\n/**\n * Interface for the Router contract, defining methods for HTTP routing.\n */\nexport interface IRouter {\n /**\n * Registers a GET route.\n * @param path - The route path.\n * @param definition - The handler function or [controller class, method] array.\n * @param name - Optional route name.\n * @param middleware - Optional middleware array.\n */\n get (\n path: string,\n definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],\n name?: string,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd>;\n\n /**\n * Registers a POST route.\n * @param path - The route path.\n * @param definition - The handler function or [controller class, method] array.\n * @param name - Optional route name.\n * @param middleware - Optional middleware array.\n */\n post (\n path: string,\n definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],\n name?: string,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd>;\n\n /**\n * Registers a PUT route.\n * @param path - The route path.\n * @param definition - The handler function or [controller class, method] array.\n * @param name - Optional route name.\n * @param middleware - Optional middleware array.\n */\n put (\n path: string,\n definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],\n name?: string,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd>;\n\n /**\n * Registers a DELETE route.\n * @param path - The route path.\n * @param definition - The handler function or [controller class, method] array.\n * @param name - Optional route name.\n * @param middleware - Optional middleware array.\n */\n delete (\n path: string,\n definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],\n name?: string,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd>;\n\n /**\n * Registers an API resource with standard CRUD routes.\n * @param path - The base path for the resource.\n * @param controller - The controller class handling the resource.\n * @param middleware - Optional middleware array.\n */\n apiResource (\n path: string,\n controller: new (app: IApplication) => IController,\n middleware?: IMiddleware[]\n ): Omit<this, RouterEnd | 'name'>;\n\n /**\n * Generates a URL for a named route.\n * @param name - The name of the route.\n * @param params - Optional parameters to replace in the route path.\n * @returns The generated URL or undefined if the route is not found.\n */\n route (name: string, params?: Record<string, string>): string | undefined;\n\n\n /**\n * Set the name of the current route\n * \n * @param name \n */\n name (name: string): this\n\n /**\n * Groups routes with shared prefix or middleware.\n * @param options - Configuration for prefix or middleware.\n * @param callback - Callback function defining grouped routes.\n */\n group (options: { prefix?: string; middleware?: EventHandler[] }, callback: () => this): this;\n\n /**\n * Registers middleware for a specific path.\n * @param path - The path to apply the middleware.\n * @param handler - The middleware handler.\n * @param opts - Optional middleware options.\n */\n middleware (path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;\n}\n\n/**\n * Represents the HTTP context for a single request lifecycle.\n * Encapsulates the application instance, request, and response objects.\n */\nexport class HttpContext {\n constructor(\n public app: IApplication,\n public request: IRequest,\n public response: IResponse\n ) { }\n\n /**\n * Factory method to create a new HttpContext instance from a context object.\n * @param ctx - Object containing app, request, and response\n * @returns A new HttpContext instance\n */\n static init (ctx: { app: IApplication; request: IRequest; response: IResponse }): HttpContext {\n /**\n * Return a new instance\n */\n return new HttpContext(ctx.app, ctx.request, ctx.response);\n }\n}\n\n\n/**\n * Type for EventHandler, representing a function that handles an H3 event.\n */\nexport type EventHandler = (ctx: HttpContext) => any\nexport type RouteEventHandler = (...args: any[]) => any\n\n/**\n * Defines the contract for all controllers.\n * Any controller implementing this must define these methods.\n */\nexport interface IController {\n show (...ctx: any[]): any\n index (...ctx: any[]): any\n store (...ctx: any[]): any\n update (...ctx: any[]): any\n destroy (...ctx: any[]): any\n}\n\n/**\n * Defines the contract for all middlewares.\n * Any middleware implementing this must define these methods.\n */\nexport interface IMiddleware {\n handle (context: HttpContext, next: () => Promise<any>): Promise<any>\n} \n","import { GenericWithNullableStringValues } from '../Contracts/ObjContract';\n\nexport class EnvParser {\n\n static parse (initial: GenericWithNullableStringValues) {\n const parsed = { ...initial }\n\n for (const key in parsed) {\n let value: any = parsed[key]\n parsed[key] = this.parseValue(value)\n }\n\n return parsed\n }\n\n static parseValue (value: any) {\n /**\n * Null/undefined stay untouched \n */\n if (value === null || value === undefined) return value;\n\n /**\n * Convert string \"true\"/\"false\" to boolean \n */\n if (value === 'true') return true;\n if (value === 'false') return false;\n\n /**\n * Convert string numbers to number \n */\n if (!isNaN(value) && value.trim() !== '') {\n return Number(value);\n }\n\n /**\n * Convert string \"null\" and \"undefined\"\n */\n if (value === 'null') return null;\n if (value === 'undefined') return undefined;\n\n /**\n * Otherwise return as-is (string)\n */\n return value;\n }\n}\n","import chalk, { type ChalkInstance } from 'chalk'\n\nexport class Logger {\n /**\n * Logs the message in two columns\n * @param name \n * @param value \n * @param log If set to false, array of [name, dots, value] output will be returned and not logged \n * @returns \n */\n static twoColumnLog (name: string, value: string, log?: true): void\n static twoColumnLog (name: string, value: string, log?: false): [string, string, string]\n static twoColumnLog (name: string, value: string, log = true): [string, string, string] | void {\n // eslint-disable-next-line no-control-regex\n const regex = /\\x1b\\[\\d+m/g\n const width = Math.min(process.stdout.columns, 100)\n const dots = Math.max(width - name.replace(regex, '').length - value.replace(regex, '').length - 10, 0)\n\n if (log) return console.log(name, chalk.gray('.'.repeat(dots)), value)\n else return [name, chalk.gray('.'.repeat(dots)), value]\n }\n\n /**\n * Logs the message in two columns but allways passing status\n * \n * @param name \n * @param value \n * @param status \n * @param exit \n * @param preserveCol \n */\n static split (name: string, value: string, status?: 'success' | 'info' | 'error', exit = false, preserveCol = false) {\n status ??= 'info'\n const color = { success: chalk.bgGreen, info: chalk.bgBlue, error: chalk.bgRed }\n\n const [_name, dots, val] = this.twoColumnLog(name, value, false)\n\n console.log(this.textFormat(_name, color[status], preserveCol), dots, val)\n\n if (exit) process.exit(0)\n }\n\n /**\n * Wraps text with chalk\n * \n * @param txt \n * @param color \n * @param preserveCol \n * @returns \n */\n static textFormat (txt: any, color: (txt: string) => string, preserveCol = false) {\n if (preserveCol) return String(txt)\n return String(txt).split(':').map((e, i, a) => i == 0 && a.length > 1 ? color(' ' + e + ': ') : e).join('')\n }\n\n /**\n * Logs a success message\n * \n * @param msg \n * @param exit \n * @param preserveCol \n */\n static success (msg: any, exit = false, preserveCol = false) {\n console.log(chalk.green('✓'), this.textFormat(msg, chalk.bgGreen, preserveCol), '\\n')\n if (exit) process.exit(0)\n }\n\n /**\n * Logs an informational message\n * \n * @param msg \n * @param exit \n * @param preserveCol \n */\n static info (msg: any, exit = false, preserveCol = false) {\n console.log(chalk.blue('ℹ'), this.textFormat(msg, chalk.bgBlue, preserveCol), '\\n')\n if (exit) process.exit(0)\n }\n\n /**\n * Logs an error message\n * \n * @param msg \n * @param exit \n * @param preserveCol \n */\n static error (msg: string | string[] | Error & { detail?: string }, exit = true, preserveCol = false) {\n if (msg instanceof Error) {\n if (msg.message) {\n console.error(chalk.red('✖'), this.textFormat('ERROR:' + msg.message, chalk.bgRed, preserveCol))\n }\n console.error(chalk.red(`${msg.detail ? `${msg.detail}\\n` : ''}${msg.stack}`), '\\n')\n }\n else {\n console.error(chalk.red('✖'), this.textFormat(msg, chalk.bgRed, preserveCol), '\\n')\n }\n if (exit) process.exit(1)\n }\n\n /**\n * Terminates the process\n */\n static quiet () {\n process.exit(0)\n }\n\n /**\n * Parse an array formated message and logs it\n * \n * @param config \n * @param joiner \n * @param log If set to false, string output will be returned and not logged \n */\n static parse (config: [string, keyof ChalkInstance][], joiner?: string, log?: true): void\n static parse (config: [string, keyof ChalkInstance][], joiner?: string, log?: false): string\n static parse (config: [string, keyof ChalkInstance][], joiner = ' ', log = true): string | void {\n const string = config.map(([str, opt]) => {\n return typeof chalk[opt] === 'function' ? (chalk as any)[opt](str) : str\n }).join(joiner)\n\n if (log) console.log(string)\n else return string\n }\n\n /**\n * Ouput formater object or format the output\n * \n * @returns \n */\n static log (): typeof Logger\n static log (config: string, joiner: keyof ChalkInstance): void\n static log (config: [string, keyof ChalkInstance][], joiner?: string): void\n static log (config?: string | [string, keyof ChalkInstance][], joiner?: string): void | Logger {\n if (typeof config === 'string') {\n const conf = [[config, joiner]] as [string, keyof ChalkInstance][]\n return this.parse(conf)\n } else if (config) {\n return this.parse(config, joiner)\n }\n return this\n }\n}\n","import { IPathName } from '../Contracts/IApplication'\nimport nodepath from 'path'\n\nexport class PathLoader {\n private paths = {\n base: '',\n views: '/src/resources/views',\n assets: '/public/assets',\n routes: '/src/routes',\n config: '/src/config',\n public: '/public',\n storage: '/storage',\n database: '/src/database',\n }\n\n /**\n * Dynamically retrieves a path property from the class.\n * Any property ending with \"Path\" is accessible automatically.\n *\n * @param name - The base name of the path property\n * @param prefix - The base path to prefix to the path\n * @returns \n */\n getPath (name: IPathName, prefix?: string): string {\n let path: string;\n\n if (prefix && name !== 'base') {\n path = nodepath.join(prefix, this.paths[name])\n } else {\n path = this.paths[name]\n }\n\n path = path.replace('/src/', `/${process.env.SRC_PATH ?? 'src'}/`.replace(/([^:]\\/)\\/+/g, \"$1\"))\n\n if (name === 'database' && process.env.SRC_PATH && !'/src/'.includes(process.env.SRC_PATH)) {\n return nodepath.resolve(path.replace(process.env.SRC_PATH, ''))\n }\n\n return path\n }\n\n /**\n * Programatically set the paths.\n *\n * @param name - The base name of the path property\n * @param path - The new path\n * @param base - The base path to include to the path\n */\n setPath (name: IPathName, path: string, base?: string) {\n if (base && name !== 'base') {\n this.paths[name] = nodepath.join(base, path)\n }\n\n this.paths[name] = path\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,IAAa,cAAb,MAAa,YAAY;CACrB,YACI,AAAOA,KACP,AAAOC,SACP,AAAOC,UACT;EAHS;EACA;EACA;;;;;;;CAQX,OAAO,KAAM,KAAiF;;;;AAI1F,SAAO,IAAI,YAAY,IAAI,KAAK,IAAI,SAAS,IAAI,SAAS;;;;;;AClIlE,IAAa,YAAb,MAAuB;CAEnB,OAAO,MAAO,SAA0C;EACpD,MAAM,SAAS,EAAE,GAAG,SAAS;AAE7B,OAAK,MAAM,OAAO,QAAQ;GACtB,IAAIC,QAAa,OAAO;AACxB,UAAO,OAAO,KAAK,WAAW,MAAM;;AAGxC,SAAO;;CAGX,OAAO,WAAY,OAAY;;;;AAI3B,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;;;;AAKlD,MAAI,UAAU,OAAQ,QAAO;AAC7B,MAAI,UAAU,QAAS,QAAO;;;;AAK9B,MAAI,CAAC,MAAM,MAAM,IAAI,MAAM,MAAM,KAAK,GAClC,QAAO,OAAO,MAAM;;;;AAMxB,MAAI,UAAU,OAAQ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