UNPKG

@h3ravel/shared

Version:
113 lines (110 loc) 3.64 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { HttpContext: () => HttpContext, PathLoader: () => PathLoader }); module.exports = __toCommonJS(src_exports); // 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 var import_path = __toESM(require("path"), 1); 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 = import_path.default.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] = import_path.default.join(base, path); } this.paths[name] = path; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { HttpContext, PathLoader }); //# sourceMappingURL=index.cjs.map