@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/dist/index.js CHANGED
@@ -1,77 +1,213 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import chalk from "chalk";
2
+ import nodepath from "path";
3
3
 
4
- // src/Contracts/IHttp.ts
5
- var HttpContext = class _HttpContext {
6
- static {
7
- __name(this, "HttpContext");
8
- }
9
- app;
10
- request;
11
- response;
12
- constructor(app, request, response) {
13
- this.app = app;
14
- this.request = request;
15
- this.response = response;
16
- }
17
- /**
18
- * Factory method to create a new HttpContext instance from a context object.
19
- * @param ctx - Object containing app, request, and response
20
- * @returns A new HttpContext instance
21
- */
22
- static init(ctx) {
23
- return new _HttpContext(ctx.app, ctx.request, ctx.response);
24
- }
4
+ //#region src/Contracts/IHttp.ts
5
+ /**
6
+ * Represents the HTTP context for a single request lifecycle.
7
+ * Encapsulates the application instance, request, and response objects.
8
+ */
9
+ var HttpContext = class HttpContext {
10
+ constructor(app, request, response) {
11
+ this.app = app;
12
+ this.request = request;
13
+ this.response = response;
14
+ }
15
+ /**
16
+ * Factory method to create a new HttpContext instance from a context object.
17
+ * @param ctx - Object containing app, request, and response
18
+ * @returns A new HttpContext instance
19
+ */
20
+ static init(ctx) {
21
+ /**
22
+ * Return a new instance
23
+ */
24
+ return new HttpContext(ctx.app, ctx.request, ctx.response);
25
+ }
25
26
  };
26
27
 
27
- // src/Utils/PathLoader.ts
28
- import nodepath from "path";
29
- var PathLoader = class {
30
- static {
31
- __name(this, "PathLoader");
32
- }
33
- paths = {
34
- base: "",
35
- views: "/src/resources/views",
36
- assets: "/public/assets",
37
- routes: "/src/routes",
38
- config: "/src/config",
39
- public: "/public",
40
- storage: "/storage"
41
- };
42
- /**
43
- * Dynamically retrieves a path property from the class.
44
- * Any property ending with "Path" is accessible automatically.
45
- *
46
- * @param name - The base name of the path property
47
- * @param base - The base path to include to the path
48
- * @returns
49
- */
50
- getPath(name, base) {
51
- let path;
52
- if (base && name !== "base") {
53
- path = nodepath.join(base, this.paths[name]);
54
- } else {
55
- path = this.paths[name];
56
- }
57
- return path.replace("/src/", `/${process.env.SRC_PATH ?? "src"}/`.replace(/([^:]\/)\/+/g, "$1"));
58
- }
59
- /**
60
- * Programatically set the paths.
61
- *
62
- * @param name - The base name of the path property
63
- * @param path - The new path
64
- * @param base - The base path to include to the path
65
- */
66
- setPath(name, path, base) {
67
- if (base && name !== "base") {
68
- this.paths[name] = nodepath.join(base, path);
69
- }
70
- this.paths[name] = path;
71
- }
28
+ //#endregion
29
+ //#region src/Utils/EnvParser.ts
30
+ var EnvParser = class {
31
+ static parse(initial) {
32
+ const parsed = { ...initial };
33
+ for (const key in parsed) {
34
+ let value = parsed[key];
35
+ parsed[key] = this.parseValue(value);
36
+ }
37
+ return parsed;
38
+ }
39
+ static parseValue(value) {
40
+ /**
41
+ * Null/undefined stay untouched
42
+ */
43
+ if (value === null || value === void 0) return value;
44
+ /**
45
+ * Convert string "true"/"false" to boolean
46
+ */
47
+ if (value === "true") return true;
48
+ if (value === "false") return false;
49
+ /**
50
+ * Convert string numbers to number
51
+ */
52
+ if (!isNaN(value) && value.trim() !== "") return Number(value);
53
+ /**
54
+ * Convert string "null" and "undefined"
55
+ */
56
+ if (value === "null") return null;
57
+ if (value === "undefined") return void 0;
58
+ /**
59
+ * Otherwise return as-is (string)
60
+ */
61
+ return value;
62
+ }
63
+ };
64
+
65
+ //#endregion
66
+ //#region src/Utils/Logger.ts
67
+ var Logger = class {
68
+ static twoColumnLog(name, value, log = true) {
69
+ const regex = /\x1b\[\d+m/g;
70
+ const width = Math.min(process.stdout.columns, 100);
71
+ const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
72
+ if (log) return console.log(name, chalk.gray(".".repeat(dots)), value);
73
+ else return [
74
+ name,
75
+ chalk.gray(".".repeat(dots)),
76
+ value
77
+ ];
78
+ }
79
+ /**
80
+ * Logs the message in two columns but allways passing status
81
+ *
82
+ * @param name
83
+ * @param value
84
+ * @param status
85
+ * @param exit
86
+ * @param preserveCol
87
+ */
88
+ static split(name, value, status, exit = false, preserveCol = false) {
89
+ status ??= "info";
90
+ const color = {
91
+ success: chalk.bgGreen,
92
+ info: chalk.bgBlue,
93
+ error: chalk.bgRed
94
+ };
95
+ const [_name, dots, val] = this.twoColumnLog(name, value, false);
96
+ console.log(this.textFormat(_name, color[status], preserveCol), dots, val);
97
+ if (exit) process.exit(0);
98
+ }
99
+ /**
100
+ * Wraps text with chalk
101
+ *
102
+ * @param txt
103
+ * @param color
104
+ * @param preserveCol
105
+ * @returns
106
+ */
107
+ static textFormat(txt, color, preserveCol = false) {
108
+ if (preserveCol) return String(txt);
109
+ return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
110
+ }
111
+ /**
112
+ * Logs a success message
113
+ *
114
+ * @param msg
115
+ * @param exit
116
+ * @param preserveCol
117
+ */
118
+ static success(msg, exit = false, preserveCol = false) {
119
+ console.log(chalk.green("✓"), this.textFormat(msg, chalk.bgGreen, preserveCol), "\n");
120
+ if (exit) process.exit(0);
121
+ }
122
+ /**
123
+ * Logs an informational message
124
+ *
125
+ * @param msg
126
+ * @param exit
127
+ * @param preserveCol
128
+ */
129
+ static info(msg, exit = false, preserveCol = false) {
130
+ console.log(chalk.blue("ℹ"), this.textFormat(msg, chalk.bgBlue, preserveCol), "\n");
131
+ if (exit) process.exit(0);
132
+ }
133
+ /**
134
+ * Logs an error message
135
+ *
136
+ * @param msg
137
+ * @param exit
138
+ * @param preserveCol
139
+ */
140
+ static error(msg, exit = true, preserveCol = false) {
141
+ if (msg instanceof Error) {
142
+ if (msg.message) console.error(chalk.red("✖"), this.textFormat("ERROR:" + msg.message, chalk.bgRed, preserveCol));
143
+ console.error(chalk.red(`${msg.detail ? `${msg.detail}\n` : ""}${msg.stack}`), "\n");
144
+ } else console.error(chalk.red("✖"), this.textFormat(msg, chalk.bgRed, preserveCol), "\n");
145
+ if (exit) process.exit(1);
146
+ }
147
+ /**
148
+ * Terminates the process
149
+ */
150
+ static quiet() {
151
+ process.exit(0);
152
+ }
153
+ static parse(config, joiner = " ", log = true) {
154
+ const string = config.map(([str, opt]) => {
155
+ return typeof chalk[opt] === "function" ? chalk[opt](str) : str;
156
+ }).join(joiner);
157
+ if (log) console.log(string);
158
+ else return string;
159
+ }
160
+ static log(config, joiner) {
161
+ if (typeof config === "string") {
162
+ const conf = [[config, joiner]];
163
+ return this.parse(conf);
164
+ } else if (config) return this.parse(config, joiner);
165
+ return this;
166
+ }
72
167
  };
73
- export {
74
- HttpContext,
75
- PathLoader
168
+
169
+ //#endregion
170
+ //#region src/Utils/PathLoader.ts
171
+ var PathLoader = class {
172
+ paths = {
173
+ base: "",
174
+ views: "/src/resources/views",
175
+ assets: "/public/assets",
176
+ routes: "/src/routes",
177
+ config: "/src/config",
178
+ public: "/public",
179
+ storage: "/storage",
180
+ database: "/src/database"
181
+ };
182
+ /**
183
+ * Dynamically retrieves a path property from the class.
184
+ * Any property ending with "Path" is accessible automatically.
185
+ *
186
+ * @param name - The base name of the path property
187
+ * @param prefix - The base path to prefix to the path
188
+ * @returns
189
+ */
190
+ getPath(name, prefix) {
191
+ let path;
192
+ if (prefix && name !== "base") path = nodepath.join(prefix, this.paths[name]);
193
+ else path = this.paths[name];
194
+ path = path.replace("/src/", `/${process.env.SRC_PATH ?? "src"}/`.replace(/([^:]\/)\/+/g, "$1"));
195
+ if (name === "database" && process.env.SRC_PATH && !"/src/".includes(process.env.SRC_PATH)) return nodepath.resolve(path.replace(process.env.SRC_PATH, ""));
196
+ return path;
197
+ }
198
+ /**
199
+ * Programatically set the paths.
200
+ *
201
+ * @param name - The base name of the path property
202
+ * @param path - The new path
203
+ * @param base - The base path to include to the path
204
+ */
205
+ setPath(name, path, base) {
206
+ if (base && name !== "base") this.paths[name] = nodepath.join(base, path);
207
+ this.paths[name] = path;
208
+ }
76
209
  };
210
+
211
+ //#endregion
212
+ export { EnvParser, HttpContext, Logger, PathLoader };
77
213
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Contracts/IHttp.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 { 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":";;;;AAoHO,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,OAAOG,cAAc;AAEd,IAAMC,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,SAASC,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,SAASC,KAAKX,MAAMS,IAAAA;IAC3C;AAEA,SAAKV,MAAMS,IAAAA,IAAQC;EACvB;AACJ;","names":["HttpContext","app","request","response","init","ctx","nodepath","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.js","names":["app: IApplication","request: IRequest","response: IResponse","value: any","path: string"],"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,QAAO;AAC7B,MAAI,UAAU,YAAa,QAAO;;;;AAKlC,SAAO;;;;;;ACzCf,IAAa,SAAb,MAAoB;CAUhB,OAAO,aAAc,MAAc,OAAe,MAAM,MAAuC;EAE3F,MAAM,QAAQ;EACd,MAAM,QAAQ,KAAK,IAAI,QAAQ,OAAO,SAAS,IAAI;EACnD,MAAM,OAAO,KAAK,IAAI,QAAQ,KAAK,QAAQ,OAAO,GAAG,CAAC,SAAS,MAAM,QAAQ,OAAO,GAAG,CAAC,SAAS,IAAI,EAAE;AAEv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AI,SAAS,cAAc,QAAQ,IAAI,YAAY,CAAC,QAAQ,SAAS,QAAQ,IAAI,SAAS,CACtF,QAAO,SAAS,QAAQ,KAAK,QAAQ,QAAQ,IAAI,UAAU,GAAG,CAAC;AAGnE,SAAO;;;;;;;;;CAUX,QAAS,MAAiB,MAAc,MAAe;AACnD,MAAI,QAAQ,SAAS,OACjB,MAAK,MAAM,QAAQ,SAAS,KAAK,MAAM,KAAK;AAGhD,OAAK,MAAM,QAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/shared",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "Shared Utilities.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -8,12 +8,18 @@
8
8
  "module": "./dist/index.js",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
11
  "import": "./dist/index.js",
13
12
  "require": "./dist/index.cjs"
14
13
  },
15
14
  "./tsconfig.json": "./tsconfig.json"
16
15
  },
16
+ "typesVersions": {
17
+ "*": {
18
+ "*": [
19
+ "dist/index.d.ts"
20
+ ]
21
+ }
22
+ },
17
23
  "files": [
18
24
  "dist",
19
25
  "tsconfig.json"
@@ -38,7 +44,8 @@
38
44
  "laravel"
39
45
  ],
40
46
  "dependencies": {
41
- "h3": "^2.0.0-beta.1",
47
+ "h3": "^2.0.0-beta.4",
48
+ "chalk": "^5.6.0",
42
49
  "edge.js": "^6.3.0"
43
50
  },
44
51
  "devDependencies": {
@@ -47,11 +54,12 @@
47
54
  "pnpm": "^10.14.0"
48
55
  },
49
56
  "scripts": {
50
- "build": "tsup",
57
+ "build": "tsdown --config-loader unconfig",
51
58
  "barrel": "barrelsby --directory src --delete --singleQuotes",
52
59
  "dev": "tsx watch src/index.ts",
53
60
  "start": "node dist/index.js",
54
61
  "lint": "eslint . --ext .ts",
55
- "test": "jest --passWithNoTests"
62
+ "test": "jest --passWithNoTests",
63
+ "release:patch": "pnpm build && pnpm version patch && git add . && git commit -m \"version: bump shared package and publish\" && pnpm publish --tag latest"
56
64
  }
57
65
  }
package/tsconfig.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "emitDecoratorMetadata": true,
5
5
  "target": "es2022",
6
6
  "module": "es2022",
7
- "moduleResolution": "Node",
7
+ "moduleResolution": "bundler",
8
8
  "esModuleInterop": true,
9
9
  "strict": true,
10
10
  "allowJs": true,