@h3ravel/shared 0.17.3 → 0.18.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.
- package/dist/index.cjs +220 -250
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +433 -397
- package/dist/index.d.ts +421 -397
- package/dist/index.js +201 -221
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,271 +1,241 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
20
17
|
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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);
|
|
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));
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Logger: () => Logger,
|
|
37
|
-
PathLoader: () => PathLoader
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(index_exports);
|
|
23
|
+
//#endregion
|
|
24
|
+
let chalk = require("chalk");
|
|
25
|
+
chalk = __toESM(chalk);
|
|
26
|
+
let path = require("path");
|
|
27
|
+
path = __toESM(path);
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
62
51
|
};
|
|
63
52
|
|
|
64
|
-
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/Utils/EnvParser.ts
|
|
65
55
|
var EnvParser = class {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
}
|
|
90
88
|
};
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/Utils/Logger.ts
|
|
94
92
|
var Logger = class {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}).join(joiner);
|
|
195
|
-
console.log(string);
|
|
196
|
-
}
|
|
197
|
-
static log(config, joiner) {
|
|
198
|
-
if (typeof config === "string") {
|
|
199
|
-
const conf = [
|
|
200
|
-
[
|
|
201
|
-
config,
|
|
202
|
-
joiner
|
|
203
|
-
]
|
|
204
|
-
];
|
|
205
|
-
return this.parse(conf);
|
|
206
|
-
} else if (config) {
|
|
207
|
-
return this.parse(config, joiner);
|
|
208
|
-
}
|
|
209
|
-
return this;
|
|
210
|
-
}
|
|
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 opt === "string" && typeof chalk.default[opt] === "function" ? chalk.default[opt](str) : typeof opt === "function" ? 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
|
+
}
|
|
211
192
|
};
|
|
212
193
|
|
|
213
|
-
|
|
214
|
-
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/Utils/PathLoader.ts
|
|
215
196
|
var PathLoader = class {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
* @param name - The base name of the path property
|
|
254
|
-
* @param path - The new path
|
|
255
|
-
* @param base - The base path to include to the path
|
|
256
|
-
*/
|
|
257
|
-
setPath(name, path, base) {
|
|
258
|
-
if (base && name !== "base") {
|
|
259
|
-
this.paths[name] = import_path.default.join(base, path);
|
|
260
|
-
}
|
|
261
|
-
this.paths[name] = path;
|
|
262
|
-
}
|
|
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
|
+
}
|
|
263
234
|
};
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
});
|
|
235
|
+
|
|
236
|
+
//#endregion
|
|
237
|
+
exports.EnvParser = EnvParser;
|
|
238
|
+
exports.HttpContext = HttpContext;
|
|
239
|
+
exports.Logger = Logger;
|
|
240
|
+
exports.PathLoader = PathLoader;
|
|
271
241
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/Contracts/IHttp.ts","../src/Utils/EnvParser.ts","../src/Utils/Logger.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/EnvParser'\nexport * from './Utils/Logger'\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 { 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 * @returns \n */\n static twoColumnLog (name: string, value: string) {\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 return console.log(name, chalk.gray('.'.repeat(dots)), value)\n }\n\n /**\n * Wraps text with chalk\n * \n * @param txt \n * @param color \n * @returns \n */\n static textFormat (txt: any, color: (txt: string) => string) {\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 */\n static success (msg: any, exit = false) {\n console.log(chalk.green('✓'), this.textFormat(msg, chalk.bgGreen), '\\n')\n if (exit) process.exit(0)\n }\n\n /**\n * Logs an informational message\n * \n * @param msg \n * @param exit \n */\n static info (msg: any, exit = false) {\n console.log(chalk.blue('ℹ'), this.textFormat(msg, chalk.bgBlue), '\\n')\n if (exit) process.exit(0)\n }\n\n /**\n * Logs an error message\n * \n * @param msg \n * @param exit \n */\n static error (msg: string | string[] | Error & { detail?: string }, exit = true) {\n if (msg instanceof Error) {\n if (msg.message) {\n console.error(chalk.red('✖'), this.textFormat('ERROR:' + msg.message, chalk.bgRed))\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), '\\n')\n }\n if (exit) process.exit(1)\n }\n\n /**\n * Logs a success message\n * \n * @param name \n * @param value \n * @param status \n * @param exit \n */\n static split (name: string, value: string, status?: 'success' | 'info' | 'error', exit = false) {\n status ??= 'info'\n const color = { success: chalk.bgGreen, info: chalk.bgBlue, error: chalk.bgRed }\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 console.log(this.textFormat(name, color[status]), chalk.gray('.'.repeat(dots)), value)\n if (exit) process.exit(0)\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 */\n static parse (config: [string, keyof ChalkInstance][], joiner = ' ') {\n const string = config.map(([str, opt]) => {\n return typeof chalk[opt] === 'function' ? (chalk as any)[opt](str) : str\n }).join(joiner)\n\n console.log(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')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aAAO,KAAKD,MAAMC,QAAQC,MAAAA;IAC9B;AACA,WAAO;EACX;AACJ;;;AC7HA,kBAAqB;AAEd,IAAMK,aAAN,MAAMA;EAFb,OAEaA;;;EACDC,QAAQ;IACZC,MAAM;IACNC,OAAO;IACPC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;IACRC,SAAS;IACTC,UAAU;EACd;;;;;;;;;EAUAC,QAASC,MAAiBC,QAAyB;AAC/C,QAAIC;AAEJ,QAAID,UAAUD,SAAS,QAAQ;AAC3BE,aAAOC,YAAAA,QAASC,KAAKH,QAAQ,KAAKX,MAAMU,IAAAA,CAAK;IACjD,OAAO;AACHE,aAAO,KAAKZ,MAAMU,IAAAA;IACtB;AAEAE,WAAOA,KAAKG,QAAQ,SAAS,IAAIC,QAAQC,IAAIC,YAAY,KAAA,IAASH,QAAQ,gBAAgB,IAAA,CAAA;AAE1F,QAAIL,SAAS,cAAcM,QAAQC,IAAIC,YAAY,CAAC,QAAQC,SAASH,QAAQC,IAAIC,QAAQ,GAAG;AACxF,aAAOL,YAAAA,QAASO,QAAQR,KAAKG,QAAQC,QAAQC,IAAIC,UAAU,EAAA,CAAA;IAC/D;AAEA,WAAON;EACX;;;;;;;;EASAS,QAASX,MAAiBE,MAAcX,MAAe;AACnD,QAAIA,QAAQS,SAAS,QAAQ;AACzB,WAAKV,MAAMU,IAAAA,IAAQG,YAAAA,QAASC,KAAKb,MAAMW,IAAAA;IAC3C;AAEA,SAAKZ,MAAMU,IAAAA,IAAQE;EACvB;AACJ;","names":["HttpContext","app","request","response","init","ctx","EnvParser","parse","initial","parsed","key","value","parseValue","undefined","isNaN","trim","Number","Logger","twoColumnLog","name","value","regex","width","Math","min","process","stdout","columns","dots","max","replace","length","console","log","chalk","gray","repeat","textFormat","txt","color","String","split","map","e","i","a","join","success","msg","exit","green","bgGreen","info","blue","bgBlue","error","Error","message","red","bgRed","detail","stack","status","quiet","parse","config","joiner","string","str","opt","conf","PathLoader","paths","base","views","assets","routes","config","public","storage","database","getPath","name","prefix","path","nodepath","join","replace","process","env","SRC_PATH","includes","resolve","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 | ChalkInstance][], joiner?: string, log?: true): void\n static parse (config: [string, keyof ChalkInstance | ChalkInstance][], joiner?: string, log?: false): string\n static parse (config: [string, keyof ChalkInstance | ChalkInstance][], joiner = ' ', log = true): string | void {\n const string = config.map(([str, opt]) => {\n return typeof opt === 'string' && typeof chalk[opt] === 'function'\n ? (chalk as any)[opt](str)\n : typeof opt === 'function' ? 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,Y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