@h3ravel/shared
Version:
Shared Utilities.
77 lines (75 loc) • 1.99 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/Contracts/IHttp.ts
var HttpContext = class _HttpContext {
static {
__name(this, "HttpContext");
}
app;
request;
response;
constructor(app, request, response) {
this.app = app;
this.request = request;
this.response = response;
}
/**
* Factory method to create a new HttpContext instance from a context object.
* @param ctx - Object containing app, request, and response
* @returns A new HttpContext instance
*/
static init(ctx) {
return new _HttpContext(ctx.app, ctx.request, ctx.response);
}
};
// src/Utils/PathLoader.ts
import nodepath from "path";
var PathLoader = class {
static {
__name(this, "PathLoader");
}
paths = {
base: "",
views: "/src/resources/views",
assets: "/public/assets",
routes: "/src/routes",
config: "/src/config",
public: "/public",
storage: "/storage"
};
/**
* Dynamically retrieves a path property from the class.
* Any property ending with "Path" is accessible automatically.
*
* @param name - The base name of the path property
* @param base - The base path to include to the path
* @returns
*/
getPath(name, base) {
let path;
if (base && name !== "base") {
path = nodepath.join(base, this.paths[name]);
} else {
path = this.paths[name];
}
return path.replace("/src/", `/${process.env.SRC_PATH ?? "src"}/`.replace(/([^:]\/)\/+/g, "$1"));
}
/**
* Programatically set the paths.
*
* @param name - The base name of the path property
* @param path - The new path
* @param base - The base path to include to the path
*/
setPath(name, path, base) {
if (base && name !== "base") {
this.paths[name] = nodepath.join(base, path);
}
this.paths[name] = path;
}
};
export {
HttpContext,
PathLoader
};
//# sourceMappingURL=index.js.map