@h3ravel/shared 0.16.7 → 0.17.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 +25 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -8
- package/dist/index.d.ts +23 -8
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,10 +31,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
|
+
HttpContext: () => HttpContext,
|
|
34
35
|
PathLoader: () => PathLoader
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(src_exports);
|
|
37
38
|
|
|
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
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
38
62
|
// src/Utils/PathLoader.ts
|
|
39
63
|
var import_path = __toESM(require("path"), 1);
|
|
40
64
|
var PathLoader = class {
|
|
@@ -83,6 +107,7 @@ var PathLoader = class {
|
|
|
83
107
|
};
|
|
84
108
|
// Annotate the CommonJS export names for ESM import in node:
|
|
85
109
|
0 && (module.exports = {
|
|
110
|
+
HttpContext,
|
|
86
111
|
PathLoader
|
|
87
112
|
});
|
|
88
113
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/Utils/PathLoader.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * 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 { 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
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Contracts/IHttp.ts","../src/Utils/PathLoader.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * 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: () => void): 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\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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -229,7 +229,7 @@ interface IResponse {
|
|
|
229
229
|
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | 'group' | 'route';
|
|
232
|
+
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';
|
|
233
233
|
/**
|
|
234
234
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
235
235
|
*/
|
|
@@ -303,10 +303,25 @@ interface IRouter {
|
|
|
303
303
|
*/
|
|
304
304
|
middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
|
|
305
305
|
}
|
|
306
|
-
|
|
306
|
+
/**
|
|
307
|
+
* Represents the HTTP context for a single request lifecycle.
|
|
308
|
+
* Encapsulates the application instance, request, and response objects.
|
|
309
|
+
*/
|
|
310
|
+
declare class HttpContext {
|
|
307
311
|
app: IApplication;
|
|
308
312
|
request: IRequest;
|
|
309
313
|
response: IResponse;
|
|
314
|
+
constructor(app: IApplication, request: IRequest, response: IResponse);
|
|
315
|
+
/**
|
|
316
|
+
* Factory method to create a new HttpContext instance from a context object.
|
|
317
|
+
* @param ctx - Object containing app, request, and response
|
|
318
|
+
* @returns A new HttpContext instance
|
|
319
|
+
*/
|
|
320
|
+
static init(ctx: {
|
|
321
|
+
app: IApplication;
|
|
322
|
+
request: IRequest;
|
|
323
|
+
response: IResponse;
|
|
324
|
+
}): HttpContext;
|
|
310
325
|
}
|
|
311
326
|
/**
|
|
312
327
|
* Type for EventHandler, representing a function that handles an H3 event.
|
|
@@ -317,11 +332,11 @@ type EventHandler = (ctx: HttpContext) => any;
|
|
|
317
332
|
* Any controller implementing this must define these methods.
|
|
318
333
|
*/
|
|
319
334
|
interface IController {
|
|
320
|
-
show(ctx:
|
|
321
|
-
index(ctx:
|
|
322
|
-
store(ctx:
|
|
323
|
-
update(ctx:
|
|
324
|
-
destroy(ctx:
|
|
335
|
+
show(...ctx: any[]): any;
|
|
336
|
+
index(...ctx: any[]): any;
|
|
337
|
+
store(...ctx: any[]): any;
|
|
338
|
+
update(...ctx: any[]): any;
|
|
339
|
+
destroy(...ctx: any[]): any;
|
|
325
340
|
}
|
|
326
341
|
/**
|
|
327
342
|
* Defines the contract for all middlewares.
|
|
@@ -379,4 +394,4 @@ type Bindings = {
|
|
|
379
394
|
};
|
|
380
395
|
type UseKey = keyof RemoveIndexSignature<Bindings>;
|
|
381
396
|
|
|
382
|
-
export { type Bindings, type DotFlatten, type DotNestedKeys, type DotNestedValue, type EventHandler,
|
|
397
|
+
export { type Bindings, type DotFlatten, type DotNestedKeys, type DotNestedValue, type EventHandler, HttpContext, type IApplication, type IContainer, type IController, type IMiddleware, type IPathName, type IRequest, type IResponse, type IRouter, type IServiceProvider, PathLoader, type RouterEnd, type UseKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -229,7 +229,7 @@ interface IResponse {
|
|
|
229
229
|
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | 'group' | 'route';
|
|
232
|
+
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';
|
|
233
233
|
/**
|
|
234
234
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
235
235
|
*/
|
|
@@ -303,10 +303,25 @@ interface IRouter {
|
|
|
303
303
|
*/
|
|
304
304
|
middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
|
|
305
305
|
}
|
|
306
|
-
|
|
306
|
+
/**
|
|
307
|
+
* Represents the HTTP context for a single request lifecycle.
|
|
308
|
+
* Encapsulates the application instance, request, and response objects.
|
|
309
|
+
*/
|
|
310
|
+
declare class HttpContext {
|
|
307
311
|
app: IApplication;
|
|
308
312
|
request: IRequest;
|
|
309
313
|
response: IResponse;
|
|
314
|
+
constructor(app: IApplication, request: IRequest, response: IResponse);
|
|
315
|
+
/**
|
|
316
|
+
* Factory method to create a new HttpContext instance from a context object.
|
|
317
|
+
* @param ctx - Object containing app, request, and response
|
|
318
|
+
* @returns A new HttpContext instance
|
|
319
|
+
*/
|
|
320
|
+
static init(ctx: {
|
|
321
|
+
app: IApplication;
|
|
322
|
+
request: IRequest;
|
|
323
|
+
response: IResponse;
|
|
324
|
+
}): HttpContext;
|
|
310
325
|
}
|
|
311
326
|
/**
|
|
312
327
|
* Type for EventHandler, representing a function that handles an H3 event.
|
|
@@ -317,11 +332,11 @@ type EventHandler = (ctx: HttpContext) => any;
|
|
|
317
332
|
* Any controller implementing this must define these methods.
|
|
318
333
|
*/
|
|
319
334
|
interface IController {
|
|
320
|
-
show(ctx:
|
|
321
|
-
index(ctx:
|
|
322
|
-
store(ctx:
|
|
323
|
-
update(ctx:
|
|
324
|
-
destroy(ctx:
|
|
335
|
+
show(...ctx: any[]): any;
|
|
336
|
+
index(...ctx: any[]): any;
|
|
337
|
+
store(...ctx: any[]): any;
|
|
338
|
+
update(...ctx: any[]): any;
|
|
339
|
+
destroy(...ctx: any[]): any;
|
|
325
340
|
}
|
|
326
341
|
/**
|
|
327
342
|
* Defines the contract for all middlewares.
|
|
@@ -379,4 +394,4 @@ type Bindings = {
|
|
|
379
394
|
};
|
|
380
395
|
type UseKey = keyof RemoveIndexSignature<Bindings>;
|
|
381
396
|
|
|
382
|
-
export { type Bindings, type DotFlatten, type DotNestedKeys, type DotNestedValue, type EventHandler,
|
|
397
|
+
export { type Bindings, type DotFlatten, type DotNestedKeys, type DotNestedValue, type EventHandler, HttpContext, type IApplication, type IContainer, type IController, type IMiddleware, type IPathName, type IRequest, type IResponse, type IRouter, type IServiceProvider, PathLoader, type RouterEnd, type UseKey };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
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
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
4
27
|
// src/Utils/PathLoader.ts
|
|
5
28
|
import nodepath from "path";
|
|
6
29
|
var PathLoader = class {
|
|
@@ -48,6 +71,7 @@ var PathLoader = class {
|
|
|
48
71
|
}
|
|
49
72
|
};
|
|
50
73
|
export {
|
|
74
|
+
HttpContext,
|
|
51
75
|
PathLoader
|
|
52
76
|
};
|
|
53
77
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Utils/PathLoader.ts"],"sourcesContent":["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":";;;;
|
|
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: () => void): 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\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"]}
|