@h3ravel/router 1.8.3 → 1.9.1

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/Providers/AssetsServiceProvider.ts","../src/Route.ts","../src/Providers/RouteServiceProvider.ts"],"sourcesContent":["export * from './Controller'\nexport * from './Providers/AssetsServiceProvider'\nexport * from './Providers/RouteServiceProvider'\nexport * from './Route'\n","import { readFile, stat } from 'node:fs/promises'\n\nimport { ServiceProvider } from '@h3ravel/core'\nimport { before } from '@h3ravel/support'\nimport { join } from 'node:path'\nimport { serveStatic } from 'h3'\nimport { statSync } from 'node:fs'\n\n/**\n * Handles public assets loading\n * \n * Auto-Registered\n */\nexport class AssetsServiceProvider extends ServiceProvider {\n public static priority = 996;\n\n register () {\n const app = this.app.make('router')\n const config = this.app.make('config')\n const fsconfig = config.get('filesystem')\n const publicPath = this.app.getPath('public')\n\n app.middleware(`/${fsconfig.public_mask}/**`, (event) => {\n return serveStatic(event, {\n indexNames: ['/index.html'],\n getContents: (id) => {\n const newId = id.replace(`/${fsconfig.public_mask}/`, '')\n return <never>readFile(join(before(publicPath, newId), newId))\n },\n getMeta: async (id) => {\n const newId = id.replace(`/${fsconfig.public_mask}/`, '')\n const stats = await stat(join(before(publicPath, newId), newId)).catch(() => { })\n if (stats?.isFile()) {\n return {\n size: stats.size,\n mtime: stats.mtimeMs,\n }\n }\n },\n })\n })\n\n this.app.singleton('asset', () => {\n return (key: string, def = '') => {\n try {\n statSync(join(before(publicPath, key), key))\n } catch {\n key = def\n }\n\n return join(fsconfig.public_mask, key)\n }\n })\n }\n}\n","import 'reflect-metadata';\nimport { H3Event, Middleware, MiddlewareOptions, type H3 } from 'h3'\nimport { Application, Container, Kernel } from '@h3ravel/core'\nimport { Request, Response } from '@h3ravel/http'\nimport { singularize } from '@h3ravel/support'\nimport { HttpContext, RouteEventHandler, type EventHandler, type IController, type IMiddleware, type IRouter, type RouterEnd } from '@h3ravel/shared'\n\ninterface RouteDefinition {\n method: string\n path: string\n name?: string\n handler: EventHandler\n}\n\nexport class Router implements IRouter {\n private routes: RouteDefinition[] = []\n private nameMap: string[] = []\n private groupPrefix = ''\n private middlewareMap: IMiddleware[] = []\n private groupMiddleware: EventHandler[] = []\n\n constructor(protected h3App: H3, private app: Application) { }\n\n /**\n * Route Resolver\n * \n * @param handler \n * @param middleware \n * @returns \n */\n private resolveHandler (handler: EventHandler, middleware: IMiddleware[] = []) {\n return async (event: H3Event) => {\n const kernel = new Kernel(() => HttpContext.init({\n app: this.app,\n request: new Request(event, this.app),\n response: new Response(event, this.app)\n }), middleware)\n\n return kernel.handle(event, (ctx) => Promise.resolve(handler(ctx)))\n }\n }\n\n /**\n * Add a route to the stack\n * \n * @param method \n * @param path \n * @param handler \n * @param name \n * @param middleware \n */\n private addRoute (\n method: string,\n path: string,\n handler: EventHandler,\n name?: string,\n middleware: IMiddleware[] = []\n ) {\n /**\n * Join all defined route names to make a single route name\n */\n if (this.nameMap.length > 0) {\n name = this.nameMap.join('.')\n }\n\n /**\n * Join all defined middlewares\n */\n if (this.middlewareMap.length > 0) {\n middleware = this.middlewareMap\n }\n\n const fullPath = `${this.groupPrefix}${path}`.replace(/\\/+/g, '/')\n this.routes.push({ method, path: fullPath, name, handler })\n this.h3App[method as 'get'](fullPath, this.resolveHandler(handler, middleware))\n }\n\n /**\n * Resolves a route handler definition into an executable EventHandler.\n *\n * A handler can be:\n * - A function matching the EventHandler signature\n * - A controller class (optionally decorated for IoC resolution)\n *\n * If it’s a controller class, this method will:\n * - Instantiate it (via IoC or manually)\n * - Call the specified method (defaults to `index`)\n *\n * @param handler Event handler function OR controller class\n * @param methodName Method to invoke on the controller (defaults to 'index')\n */\n private resolveControllerOrHandler (\n handler: EventHandler | (new (...args: any[]) => Record<string, any>),\n methodName?: string\n ): EventHandler {\n /**\n * Checks if the handler is a function (either a plain function or a class constructor)\n */\n if (typeof handler === 'function' && typeof (handler as any).prototype !== 'undefined') {\n return (_ctx) => {\n let controller: IController\n\n if (Container.hasAnyDecorator(handler)) {\n /**\n * If the controller is decorated use the IoC container\n */\n controller = this.app.make<any, IController>(handler as any)\n } else {\n /**\n * Otherwise instantiate manually so that we can at least\n * pass the app instance\n */\n controller = new (handler as new (...args: any[]) => IController)(this.app)\n }\n\n /**\n * The method to execute (defaults to 'index')\n */\n const action = (methodName || 'index') as keyof IController\n\n /**\n * Ensure the method exists on the controller\n */\n if (typeof controller[action] !== 'function') {\n throw new Error(`Method \"${String(action)}\" not found on controller ${handler.name}`)\n }\n\n /**\n * Get param types for the controller method\n */\n const paramTypes: [] = Reflect.getMetadata('design:paramtypes', controller, action) || [];\n\n /**\n * Resolve the bound dependencies\n */\n let args: any[] = paramTypes.map((paramType: any) => {\n switch (paramType?.name) {\n case 'Application':\n return this.app\n case 'Request':\n return _ctx.request\n case 'Response':\n return _ctx.response\n case 'HttpContext':\n return _ctx\n default:\n return this.app.make(paramType);\n }\n });\n\n /**\n * Ensure that the HttpContext is always available\n */\n if (args.length < 1) {\n args = [_ctx]\n }\n\n /**\n * Call the controller method, passing all resolved dependencies\n */\n return controller[action](...args);\n }\n }\n\n return handler as EventHandler\n }\n\n /**\n * Registers a route that responds to HTTP GET requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n get (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n\n this.addRoute('get', path, this.resolveControllerOrHandler(handler, methodName), name, middleware)\n return this\n }\n\n /**\n * Registers a route that responds to HTTP POST requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n post (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n this.addRoute('post', path, this.resolveControllerOrHandler(handler, methodName), name, middleware)\n return this\n }\n\n /**\n * Registers a route that responds to HTTP PUT requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n put (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n this.addRoute('put', path, this.resolveControllerOrHandler(handler, methodName), name, middleware)\n return this\n }\n\n /**\n * Registers a route that responds to HTTP PATCH requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n patch (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n this.addRoute('patch', path, this.resolveControllerOrHandler(handler, methodName), name, middleware)\n return this\n }\n\n /**\n * Registers a route that responds to HTTP DELETE requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n delete (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n this.addRoute('delete', path, this.resolveControllerOrHandler(handler, methodName), name, middleware)\n return this\n }\n\n /**\n * API Resource support \n * \n * @param path \n * @param controller \n */\n apiResource (\n path: string,\n Controller: new (app: Application) => IController,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd | 'name'> {\n path = path.replace(/\\//g, '/')\n\n const basePath = `/${path}`.replace(/\\/+$/, '').replace(/(\\/)+/g, '$1');\n const name = basePath.substring(basePath.lastIndexOf('/') + 1).replaceAll(/\\/|:/g, '') || '';\n const param = singularize(name)\n\n this.get(basePath, [Controller, 'index'], `${name}.index`, middleware)\n this.post(basePath, [Controller, 'store'], `${name}.store`, middleware)\n this.get(`${basePath}/:${param}`, [Controller, 'show'], `${name}.show`, middleware)\n this.put(`${basePath}/:${param}`, [Controller, 'update'], `${name}.update`, middleware)\n this.patch(`${basePath}/:${param}`, [Controller, 'update'], `${name}.update`, middleware)\n this.delete(`${basePath}/:${param}`, [Controller, 'destroy'], `${name}.destroy`, middleware)\n\n return this\n }\n\n /**\n * Named route URL generator\n * \n * @param name \n * @param params \n * @returns \n */\n route (name: string, params: Record<string, string> = {}): string | undefined {\n const found = this.routes.find(r => r.name === name)\n if (!found) return undefined\n\n let url = found.path\n for (const [key, value] of Object.entries(params)) {\n url = url.replace(`:${key}`, value)\n }\n return url\n }\n\n /**\n * Grouping\n * \n * @param options \n * @param callback \n */\n group (options: { prefix?: string; middleware?: EventHandler[] }, callback: (_e: this) => void) {\n const prevPrefix = this.groupPrefix\n const prevMiddleware = [...this.groupMiddleware]\n\n this.groupPrefix += options.prefix || ''\n this.groupMiddleware.push(...(options.middleware || []))\n\n callback(this)\n\n /**\n * Restore state after group\n */\n this.groupPrefix = prevPrefix\n this.groupMiddleware = prevMiddleware\n return this\n }\n\n /**\n * Set the name of the current route\n * \n * @param name \n */\n name (name: string) {\n this.nameMap.push(name)\n return this\n }\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) {\n if (typeof path === 'string') {\n this.h3App.use(path, handler, opts)\n } else {\n this.middlewareMap.concat(path)\n }\n return this\n }\n}\n","import { Router } from '../Route'\nimport { ServiceProvider } from '@h3ravel/core'\nimport path from 'node:path'\nimport { readdir } from 'node:fs/promises'\n\n/**\n * Handles routing registration\n * \n * Load route files (web.ts, api.ts).\n * Map controllers to routes.\n * Register route-related middleware.\n * \n * Auto-Registered\n */\nexport class RouteServiceProvider extends ServiceProvider {\n public static priority = 997;\n\n register () {\n this.app.singleton('router', () => {\n const h3App = this.app.make('http.app')\n return new Router(h3App, this.app)\n })\n }\n\n /**\n * Load routes from src/routes\n */\n async boot () {\n try {\n const routePath = this.app.getPath('routes')\n\n const files = (await readdir(routePath)).filter((e) => {\n return !e.includes('.d.ts') && !e.includes('.map')\n })\n\n for (let i = 0; i < files.length; i++) {\n const routesModule = await import(path.join(routePath, files[i]))\n\n if (typeof routesModule.default === 'function') {\n const router = this.app.make('router')\n routesModule.default(router)\n }\n }\n } catch (e) {\n console.warn('No web routes found or failed to load:', e)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,sBAA+B;AAE/B,kBAAgC;AAChC,qBAAuB;AACvB,uBAAqB;AACrB,gBAA4B;AAC5B,qBAAyB;AAOlB,IAAMA,wBAAN,cAAo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AAKX,WAAWE,MAAMK,CAAAA,CAAE;AAE/D,YAAI,OAAOE,aAAaG,YAAY,YAAY;AAC5C,gBAAMC,SAAS,KAAKnB,IAAIG,KAAK,QAAA;AAC7BY,uBAAaG,QAAQC,MAAAA;QACzB;MACJ;IACJ,SAASR,GAAG;AACRS,cAAQC,KAAK,0CAA0CV,CAAAA;IAC3D;EACJ;AACJ;","names":["AssetsServiceProvider","ServiceProvider","priority","register","app","make","config","fsconfig","get","publicPath","getPath","middleware","public_mask","event","serveStatic","indexNames","getContents","id","newId","replace","readFile","join","before","getMeta","stats","stat","catch","isFile","size","mtime","mtimeMs","singleton","key","def","statSync","import_core","import_support","Router","routes","nameMap","groupPrefix","middlewareMap","groupMiddleware","h3App","app","resolveHandler","handler","middleware","event","kernel","Kernel","HttpContext","init","request","Request","response","Response","handle","ctx","Promise","resolve","addRoute","method","path","name","length","join","fullPath","replace","push","resolveControllerOrHandler","methodName","prototype","_ctx","controller","Container","hasAnyDecorator","make","action","Error","String","paramTypes","Reflect","getMetadata","args","map","paramType","get","definition","Array","isArray","undefined","post","put","patch","delete","apiResource","Controller","basePath","substring","lastIndexOf","replaceAll","param","singularize","route","params","found","find","r","url","key","value","Object","entries","group","options","callback","prevPrefix","prevMiddleware","prefix","opts","use","concat","import_core","import_node_path","import_promises","RouteServiceProvider","ServiceProvider","priority","register","app","singleton","h3App","make","Router","boot","routePath","getPath","files","readdir","filter","e","includes","i","length","routesModule","path","join","default","router","console","warn"]}
1
+ {"version":3,"file":"index.cjs","names":["params: string[]","match: RegExpExecArray | null","path","ServiceProvider","h3App: H3","app: Application","Kernel","HttpContext","Request","Response","path","controller: IController","Container","paramTypes: []","Model","ServiceProvider","path"],"sources":["../src/Helpers.ts","../src/Providers/AssetsServiceProvider.ts","../src/Route.ts","../src/Providers/RouteServiceProvider.ts"],"sourcesContent":["import { HttpContext } from '@h3ravel/shared'\nimport { Model } from '@h3ravel/database'\n\nexport class Helpers {\n /**\n * Extracts parameter names from a route path string.\n *\n * - Looks for segments prefixed with \":\" (e.g. \"/users/:id\")\n * - Captures only the param name (without the \":\")\n * - Returns all matches in order of appearance\n *\n * @param path - The route path string (e.g. \"/groups/:group/users/:user\")\n * @returns An array of parameter names (e.g. [\"group\", \"user\"])\n */\n static extractParams (path: string): string[] {\n const regex = /:([^/]+)/g\n const params: string[] = []\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(path)) !== null) {\n params.push(match[1])\n }\n\n return params\n }\n\n /**\n * Resolves route model binding for a given path, HTTP context, and model.\n * \n * - Extracts all route parameters from the given path\n * - If a parameter matches the model name, it attempts to resolve the model binding\n * using the provided value and binding field (defaults to \"id\" unless specified).\n * - For non-matching parameters, it simply returns the key-value pair as is.\n * - If no parameters are found, returns an empty object.\n *\n * @param path - The route path (e.g. \"/groups/:group/users/:user\")\n * @param ctx - The HTTP context containing the request\n * @param model - The model instance to resolve bindings against\n * @returns A resolved model instance or an object containing param values\n */\n static async resolveRouteModelBinding (path: string, ctx: HttpContext, model: Model): Promise<any> {\n const name = model.constructor.name.toLowerCase()\n /**\n * Extract field (defaults to 'id' if not specified after '|')\n */\n const field = name.split('|').at(1) ?? 'id'\n\n /**\n * Iterate through extracted parameters from the path\n */\n for await (const e of Helpers.extractParams(path)) {\n const value = ctx.request.params[e] ?? null\n if (e === name) return await model.resolveRouteBinding(value, field)\n else return { [e]: ctx.request.params[e] ?? {} }\n }\n\n return {}\n }\n}\n","import { readFile, stat } from 'node:fs/promises'\n\nimport { ServiceProvider } from '@h3ravel/core'\nimport { before } from '@h3ravel/support'\nimport { join } from 'node:path'\nimport { serveStatic } from 'h3'\nimport { statSync } from 'node:fs'\n\n/**\n * Handles public assets loading\n * \n * Auto-Registered\n */\nexport class AssetsServiceProvider extends ServiceProvider {\n public static priority = 996\n\n register () {\n const app = this.app.make('router')\n const config = this.app.make('config')\n const fsconfig = config.get('filesystem')\n const publicPath = this.app.getPath('public')\n\n app.middleware(`/${fsconfig.public_mask}/**`, (event) => {\n return serveStatic(event, {\n indexNames: ['/index.html'],\n getContents: (id) => {\n const newId = id.replace(`/${fsconfig.public_mask}/`, '')\n return <never>readFile(join(before(publicPath, newId), newId))\n },\n getMeta: async (id) => {\n const newId = id.replace(`/${fsconfig.public_mask}/`, '')\n const stats = await stat(join(before(publicPath, newId), newId)).catch(() => { })\n if (stats?.isFile()) {\n return {\n size: stats.size,\n mtime: stats.mtimeMs,\n }\n }\n },\n })\n })\n\n this.app.singleton('asset', () => {\n return (key: string, def = '') => {\n try {\n statSync(join(before(publicPath, key), key))\n } catch {\n key = def\n }\n\n return join(fsconfig.public_mask, key)\n }\n })\n }\n}\n","import 'reflect-metadata'\nimport { H3Event, Middleware, MiddlewareOptions, type H3 } from 'h3'\nimport { Application, Container, Kernel } from '@h3ravel/core'\nimport { Request, Response } from '@h3ravel/http'\nimport { singularize } from '@h3ravel/support'\nimport { HttpContext, RouteEventHandler } from '@h3ravel/shared'\nimport type { EventHandler, IController, IMiddleware, IRouter, RouterEnd } from '@h3ravel/shared'\nimport { Helpers } from './Helpers'\nimport { Model } from '@h3ravel/database'\n\ninterface RouteDefinition {\n method: string\n path: string\n name?: string\n handler: EventHandler\n}\n\nexport class Router implements IRouter {\n private routes: RouteDefinition[] = []\n private nameMap: string[] = []\n private groupPrefix = ''\n private middlewareMap: IMiddleware[] = []\n private groupMiddleware: EventHandler[] = []\n\n constructor(protected h3App: H3, private app: Application) { }\n\n /**\n * Route Resolver\n * \n * @param handler \n * @param middleware \n * @returns \n */\n private resolveHandler (handler: EventHandler, middleware: IMiddleware[] = []) {\n return async (event: H3Event) => {\n const kernel = new Kernel(() => HttpContext.init({\n app: this.app,\n request: new Request(event, this.app),\n response: new Response(event, this.app)\n }), middleware)\n\n return kernel.handle(event, (ctx) => Promise.resolve(handler(ctx)))\n }\n }\n\n /**\n * Add a route to the stack\n * \n * @param method \n * @param path \n * @param handler \n * @param name \n * @param middleware \n */\n private addRoute (\n method: string,\n path: string,\n handler: EventHandler,\n name?: string,\n middleware: IMiddleware[] = []\n ) {\n /**\n * Join all defined route names to make a single route name\n */\n if (this.nameMap.length > 0) {\n name = this.nameMap.join('.')\n }\n\n /**\n * Join all defined middlewares\n */\n if (this.middlewareMap.length > 0) {\n middleware = this.middlewareMap\n }\n\n const fullPath = `${this.groupPrefix}${path}`.replace(/\\/+/g, '/')\n this.routes.push({ method, path: fullPath, name, handler })\n this.h3App[method as 'get'](fullPath, this.resolveHandler(handler, middleware))\n }\n\n /**\n * Resolves a route handler definition into an executable EventHandler.\n *\n * A handler can be:\n * - A function matching the EventHandler signature\n * - A controller class (optionally decorated for IoC resolution)\n *\n * If it’s a controller class, this method will:\n * - Instantiate it (via IoC or manually)\n * - Call the specified method (defaults to `index`)\n *\n * @param handler Event handler function OR controller class\n * @param methodName Method to invoke on the controller (defaults to 'index')\n */\n private resolveControllerOrHandler (\n handler: EventHandler | (new (...args: any[]) => Record<string, any>),\n methodName?: string,\n path?: string,\n ): EventHandler {\n /**\n * Checks if the handler is a function (either a plain function or a class constructor)\n */\n if (typeof handler === 'function' && typeof (handler as any).prototype !== 'undefined') {\n return async (ctx) => {\n let controller: IController\n if (Container.hasAnyDecorator(handler)) {\n /**\n * If the controller is decorated use the IoC container\n */\n controller = this.app.make<any, IController>(handler as any)\n } else {\n /**\n * Otherwise instantiate manually so that we can at least\n * pass the app instance\n */\n controller = new (handler as new (...args: any[]) => IController)(this.app)\n }\n\n /**\n * The method to execute (defaults to 'index')\n */\n const action = (methodName || 'index') as keyof IController\n\n /**\n * Ensure the method exists on the controller\n */\n if (typeof controller[action] !== 'function') {\n throw new Error(`Method \"${String(action)}\" not found on controller ${handler.name}`)\n }\n\n /**\n * Get param types for the controller method\n */\n const paramTypes: [] = Reflect.getMetadata('design:paramtypes', controller, action) || []\n\n /**\n * Resolve the bound dependencies\n */\n let args = await Promise.all(\n paramTypes.map(async (paramType: any) => {\n switch (paramType?.name) {\n case 'Application':\n return this.app\n case 'Request':\n return ctx.request\n case 'Response':\n return ctx.response\n case 'HttpContext':\n return ctx\n default: {\n const inst = this.app.make(paramType)\n if (inst instanceof Model) {\n // Route model binding returns a Promise\n return await Helpers.resolveRouteModelBinding(path ?? '', ctx, inst)\n }\n return inst\n }\n }\n })\n )\n\n /**\n * Ensure that the HttpContext is always available\n */\n if (args.length < 1) {\n args = [ctx]\n }\n\n /**\n * Call the controller method, passing all resolved dependencies\n */\n return await controller[action](...args)\n }\n }\n\n return handler as EventHandler\n }\n\n /**\n * Registers a route that responds to HTTP GET requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n get (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n\n this.addRoute('get', path, this.resolveControllerOrHandler(handler, methodName, path), name, middleware)\n return this\n }\n\n /**\n * Registers a route that responds to HTTP POST requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n post (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n this.addRoute('post', path, this.resolveControllerOrHandler(handler, methodName, path), name, middleware)\n return this\n }\n\n /**\n * Registers a route that responds to HTTP PUT requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n put (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n this.addRoute('put', path, this.resolveControllerOrHandler(handler, methodName, path), name, middleware)\n return this\n }\n\n /**\n * Registers a route that responds to HTTP PATCH requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n patch (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n this.addRoute('patch', path, this.resolveControllerOrHandler(handler, methodName, path), name, middleware)\n return this\n }\n\n /**\n * Registers a route that responds to HTTP DELETE requests.\n *\n * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').\n * @param definition Either:\n * - An EventHandler function\n * - A tuple: [ControllerClass, methodName]\n * @param name Optional route name (for URL generation or referencing).\n * @param middleware Optional array of middleware functions to execute before the handler.\n */\n delete (\n path: string,\n definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string],\n name?: string,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd> {\n const handler = Array.isArray(definition) ? definition[0] : definition\n const methodName = Array.isArray(definition) ? definition[1] : undefined\n this.addRoute('delete', path, this.resolveControllerOrHandler(handler, methodName, path), name, middleware)\n return this\n }\n\n /**\n * API Resource support \n * \n * @param path \n * @param controller \n */\n apiResource (\n path: string,\n Controller: new (app: Application) => IController,\n middleware: IMiddleware[] = []\n ): Omit<this, RouterEnd | 'name'> {\n path = path.replace(/\\//g, '/')\n\n const basePath = `/${path}`.replace(/\\/+$/, '').replace(/(\\/)+/g, '$1')\n const name = basePath.substring(basePath.lastIndexOf('/') + 1).replaceAll(/\\/|:/g, '') || ''\n const param = singularize(name)\n\n this.get(basePath, [Controller, 'index'], `${name}.index`, middleware)\n this.post(basePath, [Controller, 'store'], `${name}.store`, middleware)\n this.get(`${basePath}/:${param}`, [Controller, 'show'], `${name}.show`, middleware)\n this.put(`${basePath}/:${param}`, [Controller, 'update'], `${name}.update`, middleware)\n this.patch(`${basePath}/:${param}`, [Controller, 'update'], `${name}.update`, middleware)\n this.delete(`${basePath}/:${param}`, [Controller, 'destroy'], `${name}.destroy`, middleware)\n\n return this\n }\n\n /**\n * Named route URL generator\n * \n * @param name \n * @param params \n * @returns \n */\n route (name: string, params: Record<string, string> = {}): string | undefined {\n const found = this.routes.find(r => r.name === name)\n if (!found) return undefined\n\n let url = found.path\n for (const [key, value] of Object.entries(params)) {\n url = url.replace(`:${key}`, value)\n }\n return url\n }\n\n /**\n * Grouping\n * \n * @param options \n * @param callback \n */\n group (options: { prefix?: string; middleware?: EventHandler[] }, callback: (_e: this) => void) {\n const prevPrefix = this.groupPrefix\n const prevMiddleware = [...this.groupMiddleware]\n\n this.groupPrefix += options.prefix || ''\n this.groupMiddleware.push(...(options.middleware || []))\n\n callback(this)\n\n /**\n * Restore state after group\n */\n this.groupPrefix = prevPrefix\n this.groupMiddleware = prevMiddleware\n return this\n }\n\n /**\n * Set the name of the current route\n * \n * @param name \n */\n name (name: string) {\n this.nameMap.push(name)\n return this\n }\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) {\n if (typeof path === 'string') {\n this.h3App.use(path, handler, opts)\n } else {\n this.middlewareMap.concat(path)\n }\n return this\n }\n}\n","import { Router } from '../Route'\nimport { ServiceProvider } from '@h3ravel/core'\nimport path from 'node:path'\nimport { readdir } from 'node:fs/promises'\n\n/**\n * Handles routing registration\n * \n * Load route files (web.ts, api.ts).\n * Map controllers to routes.\n * Register route-related middleware.\n * \n * Auto-Registered\n */\nexport class RouteServiceProvider extends ServiceProvider {\n public static priority = 997\n\n register () {\n this.app.singleton('router', () => {\n const h3App = this.app.make('http.app')\n return new Router(h3App, this.app)\n })\n }\n\n /**\n * Load routes from src/routes\n */\n async boot () {\n try {\n const routePath = this.app.getPath('routes')\n\n const files = (await readdir(routePath)).filter((e) => {\n return !e.includes('.d.ts') && !e.includes('.d.cts') && !e.includes('.map')\n })\n\n for (let i = 0; i < files.length; i++) {\n const routesModule = await import(path.join(routePath, files[i]))\n\n if (typeof routesModule.default === 'function') {\n const router = this.app.make('router')\n routesModule.default(router)\n }\n }\n } catch (e) {\n console.warn('No web routes found or failed to load:', e)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAa,UAAb,MAAa,QAAQ;;;;;;;;;;;CAWjB,OAAO,cAAe,QAAwB;EAC1C,MAAM,QAAQ;EACd,MAAMA,SAAmB,EAAE;EAC3B,IAAIC;AAEJ,UAAQ,QAAQ,MAAM,KAAKC,OAAK,MAAM,KAClC,QAAO,KAAK,MAAM,GAAG;AAGzB,SAAO;;;;;;;;;;;;;;;;CAiBX,aAAa,yBAA0B,QAAc,KAAkB,OAA4B;EAC/F,MAAM,OAAO,MAAM,YAAY,KAAK,aAAa;;;;EAIjD,MAAM,QAAQ,KAAK,MAAM,IAAI,CAAC,GAAG,EAAE,IAAI;;;;AAKvC,aAAW,MAAM,KAAK,QAAQ,cAAcA,OAAK,EAAE;GAC/C,MAAM,QAAQ,IAAI,QAAQ,OAAO,MAAM;AACvC,OAAI,MAAM,KAAM,QAAO,MAAM,MAAM,oBAAoB,OAAO,MAAM;OAC/D,QAAO,GAAG,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,SAAS,OAAO;KAC7E;AAEF,QAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;IACnC,MAAM,eAAe,MAAM,OAAOC,kBAAK,KAAK,WAAW,MAAM,GAAG;AAEhE,QAAI,OAAO,aAAa,YAAY,YAAY;KAC5C,MAAM,SAAS,KAAK,IAAI,KAAK,SAAS;AACtC,kBAAa,QAAQ,OAAO;;;WAG/B,GAAG;AACR,WAAQ,KAAK,0CAA0C,EAAE"}
package/dist/index.d.cts CHANGED
@@ -1,17 +1,51 @@
1
- import { ServiceProvider, Application } from '@h3ravel/core';
2
- import { H3, Middleware, MiddlewareOptions } from 'h3';
3
- import { IRouter, RouteEventHandler, IMiddleware, RouterEnd, IController, EventHandler } from '@h3ravel/shared';
1
+ /// <reference path="./app.globals.d.ts" />
2
+ import { EventHandler, HttpContext, IController, IMiddleware, IRouter, RouteEventHandler, RouterEnd } from "@h3ravel/shared";
3
+ import { Model } from "@h3ravel/database";
4
+ import { Application, ServiceProvider } from "@h3ravel/core";
5
+ import { H3, Middleware, MiddlewareOptions } from "h3";
4
6
 
7
+ //#region src/Helpers.d.ts
8
+ declare class Helpers {
9
+ /**
10
+ * Extracts parameter names from a route path string.
11
+ *
12
+ * - Looks for segments prefixed with ":" (e.g. "/users/:id")
13
+ * - Captures only the param name (without the ":")
14
+ * - Returns all matches in order of appearance
15
+ *
16
+ * @param path - The route path string (e.g. "/groups/:group/users/:user")
17
+ * @returns An array of parameter names (e.g. ["group", "user"])
18
+ */
19
+ static extractParams(path: string): string[];
20
+ /**
21
+ * Resolves route model binding for a given path, HTTP context, and model.
22
+ *
23
+ * - Extracts all route parameters from the given path
24
+ * - If a parameter matches the model name, it attempts to resolve the model binding
25
+ * using the provided value and binding field (defaults to "id" unless specified).
26
+ * - For non-matching parameters, it simply returns the key-value pair as is.
27
+ * - If no parameters are found, returns an empty object.
28
+ *
29
+ * @param path - The route path (e.g. "/groups/:group/users/:user")
30
+ * @param ctx - The HTTP context containing the request
31
+ * @param model - The model instance to resolve bindings against
32
+ * @returns A resolved model instance or an object containing param values
33
+ */
34
+ static resolveRouteModelBinding(path: string, ctx: HttpContext, model: Model): Promise<any>;
35
+ }
36
+ //#endregion
37
+ //#region src/Providers/AssetsServiceProvider.d.ts
5
38
  /**
6
39
  * Handles public assets loading
7
40
  *
8
41
  * Auto-Registered
9
42
  */
10
43
  declare class AssetsServiceProvider extends ServiceProvider {
11
- static priority: number;
12
- register(): void;
44
+ static priority: number;
45
+ register(): void;
13
46
  }
14
-
47
+ //#endregion
48
+ //#region src/Providers/RouteServiceProvider.d.ts
15
49
  /**
16
50
  * Handles routing registration
17
51
  *
@@ -22,149 +56,151 @@ declare class AssetsServiceProvider extends ServiceProvider {
22
56
  * Auto-Registered
23
57
  */
24
58
  declare class RouteServiceProvider extends ServiceProvider {
25
- static priority: number;
26
- register(): void;
27
- /**
28
- * Load routes from src/routes
29
- */
30
- boot(): Promise<void>;
59
+ static priority: number;
60
+ register(): void;
61
+ /**
62
+ * Load routes from src/routes
63
+ */
64
+ boot(): Promise<void>;
31
65
  }
32
-
66
+ //#endregion
67
+ //#region src/Route.d.ts
33
68
  declare class Router implements IRouter {
34
- protected h3App: H3;
35
- private app;
36
- private routes;
37
- private nameMap;
38
- private groupPrefix;
39
- private middlewareMap;
40
- private groupMiddleware;
41
- constructor(h3App: H3, app: Application);
42
- /**
43
- * Route Resolver
44
- *
45
- * @param handler
46
- * @param middleware
47
- * @returns
48
- */
49
- private resolveHandler;
50
- /**
51
- * Add a route to the stack
52
- *
53
- * @param method
54
- * @param path
55
- * @param handler
56
- * @param name
57
- * @param middleware
58
- */
59
- private addRoute;
60
- /**
61
- * Resolves a route handler definition into an executable EventHandler.
62
- *
63
- * A handler can be:
64
- * - A function matching the EventHandler signature
65
- * - A controller class (optionally decorated for IoC resolution)
66
- *
67
- * If it’s a controller class, this method will:
68
- * - Instantiate it (via IoC or manually)
69
- * - Call the specified method (defaults to `index`)
70
- *
71
- * @param handler Event handler function OR controller class
72
- * @param methodName Method to invoke on the controller (defaults to 'index')
73
- */
74
- private resolveControllerOrHandler;
75
- /**
76
- * Registers a route that responds to HTTP GET requests.
77
- *
78
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
79
- * @param definition Either:
80
- * - An EventHandler function
81
- * - A tuple: [ControllerClass, methodName]
82
- * @param name Optional route name (for URL generation or referencing).
83
- * @param middleware Optional array of middleware functions to execute before the handler.
84
- */
85
- get(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
86
- /**
87
- * Registers a route that responds to HTTP POST requests.
88
- *
89
- * @param path The URL pattern to match (can include parameters, e.g., '/users').
90
- * @param definition Either:
91
- * - An EventHandler function
92
- * - A tuple: [ControllerClass, methodName]
93
- * @param name Optional route name (for URL generation or referencing).
94
- * @param middleware Optional array of middleware functions to execute before the handler.
95
- */
96
- post(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
97
- /**
98
- * Registers a route that responds to HTTP PUT requests.
99
- *
100
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
101
- * @param definition Either:
102
- * - An EventHandler function
103
- * - A tuple: [ControllerClass, methodName]
104
- * @param name Optional route name (for URL generation or referencing).
105
- * @param middleware Optional array of middleware functions to execute before the handler.
106
- */
107
- put(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
108
- /**
109
- * Registers a route that responds to HTTP PATCH requests.
110
- *
111
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
112
- * @param definition Either:
113
- * - An EventHandler function
114
- * - A tuple: [ControllerClass, methodName]
115
- * @param name Optional route name (for URL generation or referencing).
116
- * @param middleware Optional array of middleware functions to execute before the handler.
117
- */
118
- patch(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
119
- /**
120
- * Registers a route that responds to HTTP DELETE requests.
121
- *
122
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
123
- * @param definition Either:
124
- * - An EventHandler function
125
- * - A tuple: [ControllerClass, methodName]
126
- * @param name Optional route name (for URL generation or referencing).
127
- * @param middleware Optional array of middleware functions to execute before the handler.
128
- */
129
- delete(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
130
- /**
131
- * API Resource support
132
- *
133
- * @param path
134
- * @param controller
135
- */
136
- apiResource(path: string, Controller: new (app: Application) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
137
- /**
138
- * Named route URL generator
139
- *
140
- * @param name
141
- * @param params
142
- * @returns
143
- */
144
- route(name: string, params?: Record<string, string>): string | undefined;
145
- /**
146
- * Grouping
147
- *
148
- * @param options
149
- * @param callback
150
- */
151
- group(options: {
152
- prefix?: string;
153
- middleware?: EventHandler[];
154
- }, callback: (_e: this) => void): this;
155
- /**
156
- * Set the name of the current route
157
- *
158
- * @param name
159
- */
160
- name(name: string): this;
161
- /**
162
- * Registers middleware for a specific path.
163
- * @param path - The path to apply the middleware.
164
- * @param handler - The middleware handler.
165
- * @param opts - Optional middleware options.
166
- */
167
- middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
69
+ protected h3App: H3;
70
+ private app;
71
+ private routes;
72
+ private nameMap;
73
+ private groupPrefix;
74
+ private middlewareMap;
75
+ private groupMiddleware;
76
+ constructor(h3App: H3, app: Application);
77
+ /**
78
+ * Route Resolver
79
+ *
80
+ * @param handler
81
+ * @param middleware
82
+ * @returns
83
+ */
84
+ private resolveHandler;
85
+ /**
86
+ * Add a route to the stack
87
+ *
88
+ * @param method
89
+ * @param path
90
+ * @param handler
91
+ * @param name
92
+ * @param middleware
93
+ */
94
+ private addRoute;
95
+ /**
96
+ * Resolves a route handler definition into an executable EventHandler.
97
+ *
98
+ * A handler can be:
99
+ * - A function matching the EventHandler signature
100
+ * - A controller class (optionally decorated for IoC resolution)
101
+ *
102
+ * If it’s a controller class, this method will:
103
+ * - Instantiate it (via IoC or manually)
104
+ * - Call the specified method (defaults to `index`)
105
+ *
106
+ * @param handler Event handler function OR controller class
107
+ * @param methodName Method to invoke on the controller (defaults to 'index')
108
+ */
109
+ private resolveControllerOrHandler;
110
+ /**
111
+ * Registers a route that responds to HTTP GET requests.
112
+ *
113
+ * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
114
+ * @param definition Either:
115
+ * - An EventHandler function
116
+ * - A tuple: [ControllerClass, methodName]
117
+ * @param name Optional route name (for URL generation or referencing).
118
+ * @param middleware Optional array of middleware functions to execute before the handler.
119
+ */
120
+ get(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
121
+ /**
122
+ * Registers a route that responds to HTTP POST requests.
123
+ *
124
+ * @param path The URL pattern to match (can include parameters, e.g., '/users').
125
+ * @param definition Either:
126
+ * - An EventHandler function
127
+ * - A tuple: [ControllerClass, methodName]
128
+ * @param name Optional route name (for URL generation or referencing).
129
+ * @param middleware Optional array of middleware functions to execute before the handler.
130
+ */
131
+ post(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
132
+ /**
133
+ * Registers a route that responds to HTTP PUT requests.
134
+ *
135
+ * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
136
+ * @param definition Either:
137
+ * - An EventHandler function
138
+ * - A tuple: [ControllerClass, methodName]
139
+ * @param name Optional route name (for URL generation or referencing).
140
+ * @param middleware Optional array of middleware functions to execute before the handler.
141
+ */
142
+ put(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
143
+ /**
144
+ * Registers a route that responds to HTTP PATCH requests.
145
+ *
146
+ * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
147
+ * @param definition Either:
148
+ * - An EventHandler function
149
+ * - A tuple: [ControllerClass, methodName]
150
+ * @param name Optional route name (for URL generation or referencing).
151
+ * @param middleware Optional array of middleware functions to execute before the handler.
152
+ */
153
+ patch(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
154
+ /**
155
+ * Registers a route that responds to HTTP DELETE requests.
156
+ *
157
+ * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
158
+ * @param definition Either:
159
+ * - An EventHandler function
160
+ * - A tuple: [ControllerClass, methodName]
161
+ * @param name Optional route name (for URL generation or referencing).
162
+ * @param middleware Optional array of middleware functions to execute before the handler.
163
+ */
164
+ delete(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
165
+ /**
166
+ * API Resource support
167
+ *
168
+ * @param path
169
+ * @param controller
170
+ */
171
+ apiResource(path: string, Controller: new (app: Application) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
172
+ /**
173
+ * Named route URL generator
174
+ *
175
+ * @param name
176
+ * @param params
177
+ * @returns
178
+ */
179
+ route(name: string, params?: Record<string, string>): string | undefined;
180
+ /**
181
+ * Grouping
182
+ *
183
+ * @param options
184
+ * @param callback
185
+ */
186
+ group(options: {
187
+ prefix?: string;
188
+ middleware?: EventHandler[];
189
+ }, callback: (_e: this) => void): this;
190
+ /**
191
+ * Set the name of the current route
192
+ *
193
+ * @param name
194
+ */
195
+ name(name: string): this;
196
+ /**
197
+ * Registers middleware for a specific path.
198
+ * @param path - The path to apply the middleware.
199
+ * @param handler - The middleware handler.
200
+ * @param opts - Optional middleware options.
201
+ */
202
+ middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
168
203
  }
169
-
170
- export { AssetsServiceProvider, RouteServiceProvider, Router };
204
+ //#endregion
205
+ export { AssetsServiceProvider, Helpers, RouteServiceProvider, Router };
206
+ //# sourceMappingURL=index.d.cts.map