@h3ravel/core 1.7.4 → 1.8.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Container.ts","../src/Registerer.ts","../src/Application.ts","../src/Contracts/ServiceProviderConstructor.ts","../src/Controller.ts","../src/Di/Inject.ts","../src/Exceptions/Handler.ts","../src/Http/Kernel.ts","../src/ServiceProvider.ts","../src/Providers/CoreServiceProvider.ts","../src/Providers/ViewServiceProvider.ts","../src/index.ts"],"sourcesContent":["import type { Bindings, IContainer, UseKey } from '@h3ravel/shared'\n\ntype IBinding = UseKey | (new (..._args: any[]) => unknown)\n\nexport class Container implements IContainer {\n private bindings = new Map<IBinding, () => unknown>()\n private singletons = new Map<IBinding, unknown>()\n\n /**\n * Check if the target has any decorators\n * \n * @param target \n * @returns \n */\n static hasAnyDecorator (target: Function): boolean {\n if (Reflect.getMetadataKeys(target).length > 0) return true\n\n const paramLength = target.length\n\n for (let i = 0; i < paramLength; i++) {\n if (Reflect.getMetadataKeys(target, `__param_${i}`).length > 0) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Bind a transient service to the container\n */\n bind<T> (key: new (...args: any[]) => T, factory: () => T): void\n bind<T extends UseKey> (key: T, factory: () => Bindings[T]): void\n bind<T extends UseKey> (\n key: T,\n factory: () => Bindings[T] | T\n ) {\n this.bindings.set(key, factory)\n }\n\n /**\n * Bind a singleton service to the container\n */\n singleton<T extends UseKey> (\n key: T | (new (..._args: any[]) => Bindings[T]),\n factory: () => Bindings[T]\n ) {\n this.bindings.set(key, () => {\n if (!this.singletons.has(key)) {\n this.singletons.set(key, factory())\n }\n return this.singletons.get(key)!\n })\n }\n\n /**\n * Resolve a service from the container\n */\n make<T extends UseKey, X = undefined> (\n key: T | (new (..._args: any[]) => Bindings[T])\n ): X extends undefined ? Bindings[T] : X {\n /**\n * Direct factory binding\n */\n if (this.bindings.has(key)) {\n return this.bindings.get(key)!() as Bindings[T]\n }\n\n /**\n * If this is a class constructor, auto-resolve via reflection\n */\n if (typeof key === 'function') {\n return this.build(key)\n }\n\n throw new Error(\n `No binding found for key: ${typeof key === 'string' ? key : (key as any)?.name}`\n )\n }\n\n /**\n * Automatically build a class with constructor dependency injection\n */\n private build<T extends UseKey> (ClassType: new (..._args: any[]) => Bindings[T]): Bindings[T] {\n let dependencies: any[] = [];\n\n if (Array.isArray((ClassType as any).__inject__)) {\n dependencies = (ClassType as any).__inject__.map((alias: any) => {\n return this.make(alias)\n });\n } else {\n const paramTypes: any[] = Reflect.getMetadata('design:paramtypes', ClassType) || []\n dependencies = paramTypes.map((dep) => this.make(dep))\n }\n\n return new ClassType(...dependencies);\n }\n\n /**\n * Check if a service is registered\n */\n has (key: UseKey): boolean {\n return this.bindings.has(key)\n }\n}\n","import { dd, dump } from '@h3ravel/support'\n\nexport class Registerer {\n static register () {\n globalThis.dd = dd\n globalThis.dump = dump\n }\n}\n","import { IApplication, IPathName, IServiceProvider } from '@h3ravel/shared'\n\nimport { Container } from './Container'\nimport { PathLoader } from '@h3ravel/shared'\nimport { Registerer } from './Registerer'\nimport dotenv from 'dotenv'\nimport path from 'node:path'\n\nexport class Application extends Container implements IApplication {\n paths = new PathLoader()\n private booted = false\n private versions = { app: '0', ts: '0' }\n private basePath: string\n\n private providers: IServiceProvider[] = []\n protected externalProviders: Array<new (_app: Application) => IServiceProvider> = []\n\n constructor(basePath: string) {\n super()\n this.basePath = basePath\n this.setPath('base', basePath)\n this.loadOptions()\n this.registerBaseBindings();\n Registerer.register()\n dotenv.config({ quiet: true })\n }\n\n /**\n * Register core bindings into the container\n */\n protected registerBaseBindings () {\n this.bind(Application, () => this)\n this.bind('path.base', () => this.basePath)\n this.bind('load.paths', () => this.paths)\n }\n\n /**\n * Dynamically register all configured providers\n */\n public async registerConfiguredProviders () {\n const providers = await this.getAllProviders()\n\n for (const ProviderClass of providers) {\n if (!ProviderClass) continue\n const provider = new ProviderClass(this)\n await this.register(provider)\n }\n }\n\n protected async loadOptions () {\n const app = await this.safeImport(this.getPath('base', 'package.json'))\n const core = await this.safeImport('../package.json')\n\n if (app && app.dependencies) {\n this.versions.app = app.dependencies['@h3ravel/core']\n }\n if (core && core.devDependencies) {\n this.versions.ts = app.devDependencies.typescript\n }\n }\n\n /**\n * Load default and optional providers dynamically\n * \n * Auto-Registration Behavior\n * \n * Minimal App: Loads only core, config, http, router by default.\n * Full-Stack App: Installs database, mail, queue, cache → they self-register via their providers.\n */\n protected async getConfiguredProviders (): Promise<Array<new (_app: Application) => IServiceProvider>> {\n return [\n (await import('@h3ravel/core')).CoreServiceProvider,\n (await import('@h3ravel/core')).ViewServiceProvider,\n ]\n }\n\n protected async getAllProviders (): Promise<Array<new (_app: Application) => IServiceProvider>> {\n const coreProviders = await this.getConfiguredProviders();\n const allProviders = [...coreProviders, ...this.externalProviders];\n\n /**\n * Deduplicate by class reference\n */\n const uniqueProviders = Array.from(new Set(allProviders));\n\n return this.sortProviders(uniqueProviders);\n }\n\n private sortProviders (providers: Array<new (_app: Application) => IServiceProvider>) {\n const priorityMap = new Map<string, number>();\n\n /**\n * Base priority (default 0)\n */\n providers.forEach((Provider) => {\n priorityMap.set(Provider.name, (Provider as any).priority ?? 0);\n });\n\n /**\n * Handle before/after adjustments\n */\n providers.forEach((Provider) => {\n const order = (Provider as any).order;\n if (!order) return;\n\n const [direction, target] = order.split(':');\n const targetPriority = priorityMap.get(target) ?? 0;\n\n if (direction === 'before') {\n priorityMap.set(Provider.name, targetPriority - 1);\n } else if (direction === 'after') {\n priorityMap.set(Provider.name, targetPriority + 1);\n }\n });\n\n /**\n * Sort the service providers based on thier name and priority\n */\n const sorted = providers.sort(\n (A, B) => (priorityMap.get(B.name) ?? 0) - (priorityMap.get(A.name) ?? 0)\n );\n\n /**\n * If debug is enabled, let's show the loaded service provider info\n */\n if (process.env.APP_DEBUG === 'true') {\n console.table(\n sorted.map((P) => ({\n Provider: P.name,\n Priority: priorityMap.get(P.name),\n Order: (P as any).order || 'N/A',\n }))\n );\n }\n\n return sorted\n }\n\n registerProviders (providers: Array<new (_app: Application) => IServiceProvider>): void {\n this.externalProviders.push(...providers)\n }\n\n /**\n * Register a provider\n */\n public async register (provider: IServiceProvider) {\n await provider.register()\n this.providers.push(provider)\n }\n\n /**\n * Boot all providers after registration\n */\n public async boot () {\n if (this.booted) return\n\n for (const provider of this.providers) {\n if (provider.boot) {\n await provider.boot()\n }\n }\n\n this.booted = true\n }\n\n /**\n * Attempt to dynamically import an optional module\n */\n private async safeImport (moduleName: string) {\n try {\n const mod = await import(moduleName)\n return mod.default ?? mod ?? {}\n } catch {\n return null\n }\n }\n\n /**\n * Get the base path of the app\n * \n * @returns \n */\n getBasePath (): string {\n return this.basePath\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 * @returns \n */\n getPath (name: IPathName, pth?: string) {\n return path.join(this.paths.getPath(name, this.basePath), pth ?? '')\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 * @returns \n */\n setPath (name: IPathName, path: string) {\n return this.paths.setPath(name, path, this.basePath)\n }\n\n /**\n * Returns the installed version of the system core and typescript.\n *\n * @returns \n */\n getVersion (key: 'app' | 'ts') {\n return this.versions[key]?.replaceAll(/\\^|~/g, '')\n }\n}\n","/// <reference path=\"../globals.d.ts\" />\n\nimport { Application, ServiceProvider } from \"..\";\n\nimport { IServiceProvider } from \"@h3ravel/shared\";\n\nexport type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;\n","import { Application } from '.'\nimport { IController } from '@h3ravel/shared'\n\n/**\n * Base controller class\n */\nexport abstract class Controller implements IController {\n protected app: Application\n\n constructor(app: Application) {\n this.app = app\n }\n\n public show (..._ctx: any[]): any { return }\n public index (..._ctx: any[]): any { return }\n public store (..._ctx: any[]): any { return }\n public update (..._ctx: any[]): any { return }\n public destroy (..._ctx: any[]): any { return }\n}\n","export function Inject (...dependencies: string[]) {\n return function (target: any) {\n target.__inject__ = dependencies;\n };\n}\n\n/**\n * Allows binding dependencies to both class and class methods \n * \n * @returns \n */\nexport function Injectable (): ClassDecorator & MethodDecorator {\n return (...args: any[]) => {\n if (args.length === 1) {\n void args[0]; // class target\n }\n if (args.length === 3) {\n void args[0]; // target\n void args[1]; // propertyKey\n void args[2]; // descriptor\n }\n };\n}\n","export default class { }\n","import { HttpContext, IMiddleware } from '@h3ravel/shared'\n\nimport type { H3Event } from 'h3'\n\n/**\n * Kernel class handles middleware execution and response transformations.\n * It acts as the core middleware pipeline for HTTP requests.\n */\nexport class Kernel {\n /**\n * @param context - A factory function that converts an H3Event into an HttpContext.\n * @param middleware - An array of middleware classes that will be executed in sequence.\n */\n constructor(\n protected context: (event: H3Event) => HttpContext,\n protected middleware: IMiddleware[] = [],\n ) { }\n\n /**\n * Handles an incoming request and passes it through middleware before invoking the next handler.\n * \n * @param event - The raw H3 event object.\n * @param next - A callback function that represents the next layer (usually the controller or final handler).\n * @returns A promise resolving to the result of the request pipeline.\n */\n async handle (\n event: H3Event,\n next: (ctx: HttpContext) => Promise<unknown>\n ): Promise<unknown> {\n /**\n * Convert the raw event into a standardized HttpContext\n */\n const ctx = this.context(event)\n const { app } = ctx.request\n\n /**\n * Dynamically bind the view renderer to the service container.\n * This allows any part of the request lifecycle to render templates using Edge.\n */\n app.bind('view', () => async (template: string, params?: Record<string, any>) => {\n const edge = app.make('edge')\n return ctx.response.html(await edge.render(template, params))\n })\n\n /**\n * Run middleware stack and obtain result\n */\n const result = await this.runMiddleware(ctx, () => next(ctx))\n\n /**\n * If a plain object is returned from a controller or middleware,\n * automatically set the JSON Content-Type header for the response.\n */\n if (result !== undefined && this.isPlainObject(result)) {\n event.res.headers.set('Content-Type', 'application/json; charset=UTF-8')\n }\n\n return result\n }\n\n /**\n * Sequentially runs middleware in the order they were registered.\n * \n * @param context - The standardized HttpContext.\n * @param next - Callback to execute when middleware completes.\n * @returns A promise resolving to the final handler's result.\n */\n private async runMiddleware (\n context: HttpContext,\n next: (ctx: HttpContext) => Promise<unknown>\n ) {\n let index = -1\n\n const runner = async (i: number): Promise<unknown> => {\n if (i <= index) throw new Error('next() called multiple times')\n index = i\n const middleware = this.middleware[i]\n\n if (middleware) {\n /**\n * Execute the current middleware and proceed to the next one\n */\n return middleware.handle(context, () => runner(i + 1))\n } else {\n /**\n * If no more middleware, call the final handler\n */\n return next(context)\n }\n }\n\n return runner(0)\n }\n\n /**\n * Utility function to determine if a value is a plain object or array.\n * \n * @param value - The value to check.\n * @returns True if the value is a plain object or array, otherwise false.\n */\n private isPlainObject (value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' &&\n value !== null &&\n (value.constructor === Object || value.constructor === Array)\n }\n}\n","import { Application } from './Application'\nimport { IServiceProvider } from '@h3ravel/shared'\n\nexport abstract class ServiceProvider implements IServiceProvider {\n public static order?: `before:${string}` | `after:${string}` | string | undefined;\n public static priority = 0;\n protected app: Application\n\n constructor(app: Application) {\n this.app = app\n }\n\n /**\n * Register bindings to the container.\n * Runs before boot().\n */\n abstract register (): void | Promise<void>\n\n /**\n * Perform post-registration booting of services.\n * Runs after all providers have been registered.\n */\n boot?(): void | Promise<void>\n}\n","import 'reflect-metadata'\n\nimport { ServiceProvider } from '../ServiceProvider'\n\n/**\n * Bootstraps core services and bindings.\n * \n * Bind essential services to the container (logger, config repository).\n * Register app-level singletons.\n * Set up exception handling.\n * \n * Auto-Registered\n */\nexport class CoreServiceProvider extends ServiceProvider {\n public static priority = 999;\n\n register () {\n }\n}\n","import { Edge } from 'edge.js'\nimport { ServiceProvider } from '../ServiceProvider'\n\nexport class ViewServiceProvider extends ServiceProvider {\n public static priority = 995;\n\n register (): void {\n const config = this.app.make('config')\n const edge = Edge.create({\n cache: process.env.NODE_ENV === 'production'\n })\n\n edge.mount(this.app.getPath('views'))\n\n edge.global('asset', this.app.make('asset'))\n edge.global('config', config.get)\n edge.global('app', this.app)\n\n this.app.bind('edge', () => edge)\n }\n}\n","export * from './Application'\nexport * from './Container'\nexport * from './Contracts/ServiceProviderConstructor'\nexport * from './Controller'\nexport * from './Di/Inject'\nexport * from './Exceptions/Handler'\nexport * from './Http/Kernel'\nexport * from './Providers/CoreServiceProvider'\nexport * from './Providers/ViewServiceProvider'\nexport * from './Registerer'\nexport * from './ServiceProvider'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAaA;AAAb;;;AAAO,IAAMA,YAAN,MAAMA;MAAb,OAAaA;;;MACDC,WAAW,oBAAIC,IAAAA;MACfC,aAAa,oBAAID,IAAAA;;;;;;;MAQzB,OAAOE,gBAAiBC,QAA2B;AAC/C,YAAIC,QAAQC,gBAAgBF,MAAAA,EAAQG,SAAS,EAAG,QAAO;AAEvD,cAAMC,cAAcJ,OAAOG;AAE3B,iBAASE,IAAI,GAAGA,IAAID,aAAaC,KAAK;AAClC,cAAIJ,QAAQC,gBAAgBF,QAAQ,WAAWK,CAAAA,EAAG,EAAEF,SAAS,GAAG;AAC5D,mBAAO;UACX;QACJ;AAEA,eAAO;MACX;MAOAG,KACIC,KACAC,SACF;AACE,aAAKZ,SAASa,IAAIF,KAAKC,OAAAA;MAC3B;;;;MAKAE,UACIH,KACAC,SACF;AACE,aAAKZ,SAASa,IAAIF,KAAK,MAAA;AACnB,cAAI,CAAC,KAAKT,WAAWa,IAAIJ,GAAAA,GAAM;AAC3B,iBAAKT,WAAWW,IAAIF,KAAKC,QAAAA,CAAAA;UAC7B;AACA,iBAAO,KAAKV,WAAWc,IAAIL,GAAAA;QAC/B,CAAA;MACJ;;;;MAKAM,KACIN,KACqC;AAIrC,YAAI,KAAKX,SAASe,IAAIJ,GAAAA,GAAM;AACxB,iBAAO,KAAKX,SAASgB,IAAIL,GAAAA,EAAAA;QAC7B;AAKA,YAAI,OAAOA,QAAQ,YAAY;AAC3B,iBAAO,KAAKO,MAAMP,GAAAA;QACtB;AAEA,cAAM,IAAIQ,MACN,6BA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;;;MACrC,OAAcC,WAAW;MAEzBC,WAAY;MACZ;IACJ;;;;;AClBA,iBAGaC;AAHb;;;kBAAqB;AACrB;AAEO,IAAMA,sBAAN,cAAkCC,gBAAAA;MAHzC,OAGyCA;;;MACrC,OAAcC,WAAW;MAEzBC,WAAkB;AACd,cAAMC,SAAS,KAAKC,IAAIC,KAAK,QAAA;AAC7B,cAAMC,OAAOC,iBAAKC,OAAO;UACrBC,OAAOC,QAAQC,IAAIC,aAAa;QACpC,CAAA;AAEAN,aAAKO,MAAM,KAAKT,IAAIU,QAAQ,OAAA,CAAA;AAE5BR,aAAKS,OAAO,SAAS,KAAKX,IAAIC,KAAK,OAAA,CAAA;AACnCC,aAAKS,OAAO,UAAUZ,OAAOa,GAAG;AAChCV,aAAKS,OAAO,OAAO,KAAKX,GAAG;AAE3B,aAAKA,IAAIa,KAAK,QAAQ,MAAMX,IAAAA;MAChC;IACJ;;;;;ACpBA;;;;;;;;;;;;;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;","names":["Container","bindings","Map","singletons","hasAnyDecorator","target","Reflect","getMetadataKeys","length","paramLength","i","bind","key","factory","set","singleton","has","get","make","build","Error","name","ClassType","dependencies","Array","isArray","__inject__","map","alias","paramTypes","getMetadata","dep","Registerer","register","globalThis","dd","dump","Application","Container","paths","PathLoader","booted","versions","app","ts","basePath","providers","externalProviders","setPath","loadOptions","registerBaseBindings","Registerer","register","dotenv","config","quiet","bind","registerConfiguredProviders","getAllProviders","ProviderClass","provider","safeImport","getPath","core","dependencies","devDependencies","typescript","getConfiguredProviders","CoreServiceProvider","ViewServiceProvider","coreProviders","allProviders","uniqueProviders","Array","from","Set","sortProviders","priorityMap","Map","forEach","Provider","set","name","priority","order","direction","target","split","targetPriority","get","sorted","sort","A","B","process","env","APP_DEBUG","console","table","map","P","Priority","Order","registerProviders","push","boot","moduleName","mod","default","getBasePath","pth","path","join","getVersion","key","replaceAll","Controller","app","show","_ctx","index","store","update","destroy","Inject","dependencies","target","__inject__","Injectable","args","length","Kernel","context","middleware","handle","event","next","ctx","app","request","bind","template","params","edge","make","response","html","render","result","runMiddleware","undefined","isPlainObject","res","headers","set","index","runner","i","Error","value","Object","Array","ServiceProvider","order","priority","app","CoreServiceProvider","ServiceProvider","priority","register","ViewServiceProvider","ServiceProvider","priority","register","config","app","make","edge","Edge","create","cache","process","env","NODE_ENV","mount","getPath","global","get","bind"]}
1
+ {"version":3,"file":"index.cjs","names":["dependencies: any[]","app: Application","params: any[]","args: any[]","app: Application","dd","dump","path","nodepath","PathLoader","port: number","tries: number","hostname: string","e: any","path","context: (event: H3Event) => HttpContext","middleware: IMiddleware[]","Edge"],"sources":["../src/Container.ts","../src/Di/ContainerResolver.ts","../src/Registerer.ts","../src/Application.ts","../src/Controller.ts","../src/Di/Inject.ts","../src/Http/Kernel.ts","../src/ServiceProvider.ts","../src/Providers/CoreServiceProvider.ts","../src/Providers/ViewServiceProvider.ts"],"sourcesContent":["import type { Bindings, IContainer, UseKey } from '@h3ravel/shared'\n\ntype IBinding = UseKey | (new (..._args: any[]) => unknown)\n\nexport class Container implements IContainer {\n private bindings = new Map<IBinding, () => unknown>()\n private singletons = new Map<IBinding, unknown>()\n\n /**\n * Check if the target has any decorators\n * \n * @param target \n * @returns \n */\n static hasAnyDecorator (target: Function): boolean {\n if (Reflect.getMetadataKeys(target).length > 0) return true\n\n const paramLength = target.length\n\n for (let i = 0; i < paramLength; i++) {\n if (Reflect.getMetadataKeys(target, `__param_${i}`).length > 0) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Bind a transient service to the container\n */\n bind<T> (key: new (...args: any[]) => T, factory: () => T): void\n bind<T extends UseKey> (key: T, factory: () => Bindings[T]): void\n bind<T extends UseKey> (\n key: T,\n factory: () => Bindings[T] | T\n ) {\n this.bindings.set(key, factory)\n }\n\n /**\n * Bind a singleton service to the container\n */\n singleton<T extends UseKey> (\n key: T | (new (..._args: any[]) => Bindings[T]),\n factory: () => Bindings[T]\n ) {\n this.bindings.set(key, () => {\n if (!this.singletons.has(key)) {\n this.singletons.set(key, factory())\n }\n return this.singletons.get(key)!\n })\n }\n\n /**\n * Resolve a service from the container\n */\n make<T extends UseKey, X = undefined> (\n key: T | (new (..._args: any[]) => Bindings[T])\n ): X extends undefined ? Bindings[T] : X {\n /**\n * Direct factory binding\n */\n if (this.bindings.has(key)) {\n return this.bindings.get(key)!() as Bindings[T]\n }\n\n /**\n * If this is a class constructor, auto-resolve via reflection\n */\n if (typeof key === 'function') {\n return this.build(key)\n }\n\n throw new Error(\n `No binding found for key: ${typeof key === 'string' ? key : (key as any)?.name}`\n )\n }\n\n /**\n * Automatically build a class with constructor dependency injection\n */\n private build<T extends UseKey> (ClassType: new (..._args: any[]) => Bindings[T]): Bindings[T] {\n let dependencies: any[] = [];\n\n if (Array.isArray((ClassType as any).__inject__)) {\n dependencies = (ClassType as any).__inject__.map((alias: any) => {\n return this.make(alias)\n });\n } else {\n const paramTypes: any[] = Reflect.getMetadata('design:paramtypes', ClassType) || []\n dependencies = paramTypes.map((dep) => this.make(dep))\n }\n\n return new ClassType(...dependencies);\n }\n\n /**\n * Check if a service is registered\n */\n has (key: UseKey): boolean {\n return this.bindings.has(key)\n }\n}\n","import 'reflect-metadata';\n\nimport { Application } from '..';\n\nexport class ContainerResolver {\n constructor(private app: Application) { }\n\n async resolveMethodParams<I extends Record<string, any>> (instance: I, method: keyof I, _default?: any) {\n /**\n * Get param types for instance method\n */\n let params: any[] = Reflect.getMetadata('design:paramtypes', instance, String(method)) || [];\n\n /**\n * Ensure that the Application class is always available\n */\n if (params.length < 1 && _default) {\n params = [_default]\n }\n\n /**\n * Resolve the bound dependencies\n */\n let args: any[] = params.filter(e => ContainerResolver.isClass(e)).map((type: any) => {\n return this.app.make(type)\n });\n\n return new Promise<I>((resolve) => {\n resolve(instance[method](...args))\n })\n }\n\n static isClass (C: any) {\n return typeof C === \"function\" &&\n C.prototype !== undefined &&\n Object.toString.call(C).substring(0, 5) === 'class'\n }\n}\n","import { dd, dump } from '@h3ravel/support'\n\nimport { Application } from '.'\nimport nodepath from 'node:path'\n\nexport class Registerer {\n constructor(private app: Application) { }\n\n static register (app: Application) {\n const reg = new Registerer(app)\n reg.bootRegister()\n }\n\n bootRegister () {\n globalThis.dd = dd\n globalThis.dump = dump\n globalThis.app_path = (path?: string) => this.appPath(path)\n globalThis.base_path = (path?: string) => this.basePath(path)\n globalThis.public_path = (path?: string) => this.publicPath(path)\n globalThis.storage_path = (path?: string) => this.storagePath(path)\n globalThis.database_path = (path?: string) => this.databasePath(path)\n }\n\n private appPath (path?: string) {\n return this.app.getPath(\n 'base', nodepath.join(`/${process.env.SRC_PATH ?? 'src'}/`.replace(/([^:]\\/)\\/+/g, \"$1\"), 'app', path ?? '')\n )\n }\n\n private basePath (path?: string) {\n return this.app.getPath('base', path)\n }\n\n private publicPath (path?: string) {\n return this.app.getPath('public', path)\n }\n\n private storagePath (path?: string) {\n return this.app.getPath('base', nodepath.join('storage', path ?? ''))\n }\n\n private databasePath (path?: string) {\n return this.app.getPath('database', path)\n }\n}\n","import 'reflect-metadata';\n\nimport { IApplication, IPathName, IServiceProvider, Logger } from '@h3ravel/shared'\n\nimport { Container } from './Container'\nimport { ContainerResolver } from './Di/ContainerResolver';\nimport type { H3 } from 'h3'\nimport { PathLoader } from '@h3ravel/shared'\nimport { Registerer } from './Registerer'\nimport chalk from 'chalk';\nimport { detect } from 'detect-port';\nimport dotenv from 'dotenv'\nimport dotenvExpand from 'dotenv-expand'\nimport path from 'node:path'\n\ntype AServiceProvider = (new (_app: Application) => IServiceProvider) & IServiceProvider\n\nexport class Application extends Container implements IApplication {\n public paths = new PathLoader()\n private tries: number = 0\n private booted = false\n private versions = { app: '0', ts: '0' }\n private basePath: string\n\n private providers: IServiceProvider[] = []\n protected externalProviders: Array<new (_app: Application) => IServiceProvider> = []\n\n /**\n * List of registered console commands\n */\n public registeredCommands: (new (app: any, kernel: any) => any)[] = [];\n\n constructor(basePath: string) {\n super()\n\n dotenvExpand.expand(dotenv.config({ quiet: true }))\n\n this.basePath = basePath\n this.setPath('base', basePath)\n this.loadOptions()\n this.registerBaseBindings();\n Registerer.register(this)\n }\n\n /**\n * Register core bindings into the container\n */\n protected registerBaseBindings () {\n this.bind(Application, () => this)\n this.bind('path.base', () => this.basePath)\n this.bind('load.paths', () => this.paths)\n }\n\n /**\n * Dynamically register all configured providers\n */\n public async registerConfiguredProviders () {\n const providers = await this.getAllProviders()\n\n for (const ProviderClass of providers) {\n if (!ProviderClass) continue\n const provider = new ProviderClass(this)\n await this.register(provider)\n }\n }\n\n protected async loadOptions () {\n const app = await this.safeImport(this.getPath('base', 'package.json'))\n const core = await this.safeImport('../package.json')\n\n if (app && app.dependencies) {\n this.versions.app = app.dependencies['@h3ravel/core']\n }\n if (core && core.devDependencies) {\n this.versions.ts = app.devDependencies.typescript\n }\n }\n\n /**\n * Get all registered providers\n */\n public getRegisteredProviders () {\n return this.providers;\n }\n\n /**\n * Load default and optional providers dynamically\n * \n * Auto-Registration Behavior\n * \n * Minimal App: Loads only core, config, http, router by default.\n * Full-Stack App: Installs database, mail, queue, cache → they self-register via their providers.\n */\n protected async getConfiguredProviders (): Promise<Array<AServiceProvider>> {\n return [\n (await import('@h3ravel/core')).CoreServiceProvider,\n (await import('@h3ravel/core')).ViewServiceProvider,\n ]\n }\n\n protected async getAllProviders (): Promise<Array<AServiceProvider>> {\n const coreProviders = await this.getConfiguredProviders();\n const allProviders = [...coreProviders, ...this.externalProviders];\n\n /**\n * Deduplicate by class reference\n */\n const uniqueProviders = Array.from(new Set(allProviders));\n\n return this.sortProviders(uniqueProviders);\n }\n\n private sortProviders (providers: Array<AServiceProvider>) {\n const priorityMap = new Map<string, number>();\n\n /**\n * Base priority (default 0)\n */\n providers.forEach((Provider) => {\n priorityMap.set(Provider.name, (Provider as any).priority ?? 0);\n });\n\n /**\n * Handle before/after adjustments\n */\n providers.forEach((Provider) => {\n const order = (Provider as any).order;\n if (!order) return;\n\n const [direction, target] = order.split(':');\n const targetPriority = priorityMap.get(target) ?? 0;\n\n if (direction === 'before') {\n priorityMap.set(Provider.name, targetPriority - 1);\n } else if (direction === 'after') {\n priorityMap.set(Provider.name, targetPriority + 1);\n }\n });\n\n /**\n * Service providers sorted based on thier name and priority\n */\n const sorted = providers.sort(\n (A, B) => (priorityMap.get(B.name) ?? 0) - (priorityMap.get(A.name) ?? 0)\n );\n\n /**\n * If debug is enabled, let's show the loaded service provider info\n */\n if (process.env.APP_DEBUG === 'true' && process.env.EXTENDED_DEBUG !== 'false' && !sorted.some(e => e.console)) {\n console.table(\n sorted.map((P) => ({\n Provider: P.name,\n Priority: priorityMap.get(P.name),\n Order: (P as any).order || 'N/A',\n }))\n );\n\n console.info(`Set ${chalk.bgCyan(' APP_DEBUG = false ')} in your .env file to hide this information`, \"\\n\")\n }\n\n return sorted\n }\n\n registerProviders (providers: Array<AServiceProvider>): void {\n this.externalProviders.push(...providers)\n }\n\n /**\n * Register a provider\n */\n public async register (provider: IServiceProvider) {\n await new ContainerResolver(this).resolveMethodParams(provider, 'register', this)\n if (provider.registeredCommands && provider.registeredCommands.length > 0) {\n this.registeredCommands.push(...provider.registeredCommands)\n }\n this.providers.push(provider)\n }\n\n /**\n * checks if the application is running in CLI\n */\n public runningInConsole (): boolean {\n return typeof process !== 'undefined'\n && !!process.stdout\n && !!process.stdin\n\n }\n\n public getRuntimeEnv (): 'browser' | 'node' | 'unknown' {\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n return 'browser'\n }\n if (typeof process !== 'undefined' && process.versions?.node) {\n return 'node'\n }\n return 'unknown'\n }\n\n /**\n * Boot all service providers after registration\n */\n public async boot () {\n if (this.booted) return\n\n for (const provider of this.providers) {\n if (provider.boot) {\n if (Container.hasAnyDecorator(provider.boot)) {\n /**\n * If the service provider is decorated use the IoC container\n */\n await this.make<any>(provider.boot)\n } else {\n /**\n * Otherwise instantiate manually so that we can at least\n * pass the app instance\n */\n await provider.boot(this)\n }\n }\n }\n\n this.booted = true\n }\n\n /**\n * Fire up the developement server using the user provided arguments\n * \n * Port will be auto assigned if provided one is not available\n * \n * @param h3App The current H3 app instance\n * @param preferedPort If provided, this will overide the port set in the evironment\n */\n public async fire (h3App: H3, preferedPort?: number) {\n const serve = this.make('http.serve')\n\n const port: number = preferedPort ?? env('PORT', 3000)\n const tries: number = env('RETRIES', 1)\n const hostname: string = env('HOSTNAME', 'localhost')\n\n try {\n const realPort = await detect(port)\n\n if (port == realPort) {\n const server = serve(h3App, {\n port,\n hostname,\n silent: true,\n })\n\n Logger.parse([\n [`🚀 H3ravel running at:`, 'green'],\n [`${server.options.protocol ?? 'http'}://${server.options.hostname}:${server.options.port}`, 'cyan']]\n )\n } else if (this.tries <= tries) {\n await this.fire(h3App, realPort)\n this.tries++\n } else {\n Logger.parse([\n ['ERROR:', 'bgRed'],\n ['No free port available', 'red'],\n ])\n }\n } catch (e: any) {\n Logger.parse([\n ['An error occured', 'bgRed'],\n [e.message, 'red'],\n [e.stack, 'red']\n ], \"\\n\")\n }\n }\n\n /**\n * Attempt to dynamically import an optional module\n */\n private async safeImport (moduleName: string) {\n try {\n const mod = await import(moduleName)\n return mod.default ?? mod ?? {}\n } catch {\n return null\n }\n }\n\n /**\n * Get the base path of the app\n * \n * @returns \n */\n getBasePath (): string {\n return this.basePath\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 * @returns \n */\n getPath (name: IPathName, suffix?: string) {\n return path.join(this.paths.getPath(name, this.basePath), suffix ?? '')\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 * @returns \n */\n setPath (name: IPathName, path: string) {\n return this.paths.setPath(name, path, this.basePath)\n }\n\n /**\n * Returns the installed version of the system core and typescript.\n *\n * @returns \n */\n getVersion (key: 'app' | 'ts') {\n return this.versions[key]?.replaceAll(/\\^|~/g, '')\n }\n}\n","import { Application } from '.'\nimport { IController } from '@h3ravel/shared'\n\n/**\n * Base controller class\n */\nexport abstract class Controller implements IController {\n protected app: Application\n\n constructor(app: Application) {\n this.app = app\n }\n\n public show (..._ctx: any[]): any { return }\n public index (..._ctx: any[]): any { return }\n public store (..._ctx: any[]): any { return }\n public update (..._ctx: any[]): any { return }\n public destroy (..._ctx: any[]): any { return }\n}\n","export function Inject (...dependencies: string[]) {\n return function (target: any) {\n target.__inject__ = dependencies;\n };\n}\n\n/**\n * Allows binding dependencies to both class and class methods \n * \n * @returns \n */\nexport function Injectable (): ClassDecorator & MethodDecorator {\n return (...args: any[]) => {\n if (args.length === 1) {\n void args[0]; // class target\n }\n if (args.length === 3) {\n void args[0]; // target\n void args[1]; // propertyKey\n void args[2]; // descriptor\n }\n };\n}\n\n// export function Injectable (): MethodDecorator & ClassDecorator {\n// return ((_target: any, _propertyKey?: string, descriptor?: PropertyDescriptor) => {\n// if (descriptor) {\n// const original = descriptor.value;\n// descriptor.value = async function (...args: any[]) {\n// const resolvedArgs = await Promise.all(args);\n// return original.apply(this, resolvedArgs);\n// };\n// }\n// }) as any;\n// }\n","import { HttpContext, IMiddleware } from '@h3ravel/shared'\n\nimport type { H3Event } from 'h3'\n\n/**\n * Kernel class handles middleware execution and response transformations.\n * It acts as the core middleware pipeline for HTTP requests.\n */\nexport class Kernel {\n /**\n * @param context - A factory function that converts an H3Event into an HttpContext.\n * @param middleware - An array of middleware classes that will be executed in sequence.\n */\n constructor(\n protected context: (event: H3Event) => HttpContext,\n protected middleware: IMiddleware[] = [],\n ) { }\n\n /**\n * Handles an incoming request and passes it through middleware before invoking the next handler.\n * \n * @param event - The raw H3 event object.\n * @param next - A callback function that represents the next layer (usually the controller or final handler).\n * @returns A promise resolving to the result of the request pipeline.\n */\n async handle (\n event: H3Event,\n next: (ctx: HttpContext) => Promise<unknown>\n ): Promise<unknown> {\n /**\n * Convert the raw event into a standardized HttpContext\n */\n const ctx = this.context(event)\n const { app } = ctx.request\n\n /**\n * Dynamically bind the view renderer to the service container.\n * This allows any part of the request lifecycle to render templates using Edge.\n */\n app.bind('view', () => async (template: string, params?: Record<string, any>) => {\n const edge = app.make('edge')\n return ctx.response.html(await edge.render(template, params))\n })\n\n /**\n * Run middleware stack and obtain result\n */\n const result = await this.runMiddleware(ctx, () => next(ctx))\n\n /**\n * If a plain object is returned from a controller or middleware,\n * automatically set the JSON Content-Type header for the response.\n */\n if (result !== undefined && this.isPlainObject(result)) {\n event.res.headers.set('Content-Type', 'application/json; charset=UTF-8')\n }\n\n return result\n }\n\n /**\n * Sequentially runs middleware in the order they were registered.\n * \n * @param context - The standardized HttpContext.\n * @param next - Callback to execute when middleware completes.\n * @returns A promise resolving to the final handler's result.\n */\n private async runMiddleware (\n context: HttpContext,\n next: (ctx: HttpContext) => Promise<unknown>\n ) {\n let index = -1\n\n const runner = async (i: number): Promise<unknown> => {\n if (i <= index) throw new Error('next() called multiple times')\n index = i\n const middleware = this.middleware[i]\n\n if (middleware) {\n /**\n * Execute the current middleware and proceed to the next one\n */\n return middleware.handle(context, () => runner(i + 1))\n } else {\n /**\n * If no more middleware, call the final handler\n */\n return next(context)\n }\n }\n\n return runner(0)\n }\n\n /**\n * Utility function to determine if a value is a plain object or array.\n * \n * @param value - The value to check.\n * @returns True if the value is a plain object or array, otherwise false.\n */\n private isPlainObject (value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' &&\n value !== null &&\n (value.constructor === Object || value.constructor === Array)\n }\n}\n","import { Application } from './Application'\nimport { IServiceProvider } from '@h3ravel/shared'\n\nexport abstract class ServiceProvider implements IServiceProvider {\n /**\n * Sort order\n */\n\n public static order?: `before:${string}` | `after:${string}` | string | undefined;\n\n /**\n * Sort priority\n */\n public static priority = 0;\n\n /**\n * Indicate that this service provider only runs in console\n */\n public static console = false;\n\n /**\n * List of registered console commands\n */\n public registeredCommands?: (new (app: any, kernel: any) => any)[];\n\n protected app: Application\n\n constructor(app: Application) {\n this.app = app\n }\n\n /**\n * Register bindings to the container.\n * Runs before boot().\n */\n abstract register (...app: unknown[]): void | Promise<void>;\n\n /**\n * Perform post-registration booting of services.\n * Runs after all providers have been registered.\n */\n boot?(...app: unknown[]): void | Promise<void>;\n\n /**\n * An array of console commands to register.\n */\n commands (commands: (new (app: any, kernel: any) => any)[]): void {\n this.registeredCommands = commands\n }\n}\n","import 'reflect-metadata'\n\nimport { ServiceProvider } from '../ServiceProvider'\n\n/**\n * Bootstraps core services and bindings.\n * \n * Bind essential services to the container (logger, config repository).\n * Register app-level singletons.\n * Set up exception handling.\n * \n * Auto-Registered\n */\nexport class CoreServiceProvider extends ServiceProvider {\n public static priority = 999;\n\n register () {\n }\n}\n","import { Edge } from 'edge.js'\nimport { ServiceProvider } from '../ServiceProvider'\n\nexport class ViewServiceProvider extends ServiceProvider {\n public static priority = 995;\n\n register (): void {\n const config = this.app.make('config')\n const edge = Edge.create({\n cache: process.env.NODE_ENV === 'production'\n })\n\n edge.mount(this.app.getPath('views'))\n\n edge.global('asset', this.app.make('asset'))\n edge.global('config', config.get)\n edge.global('app', this.app)\n\n this.app.bind('edge', () => edge)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAa,YAAb,MAA6C;CACzC,AAAQ,2BAAW,IAAI,KAA8B;CACrD,AAAQ,6BAAa,IAAI,KAAwB;;;;;;;CAQjD,OAAO,gBAAiB,QAA2B;AAC/C,MAAI,QAAQ,gBAAgB,OAAO,CAAC,SAAS,EAAG,QAAO;EAEvD,MAAM,cAAc,OAAO;AAE3B,OAAK,IAAI,IAAI,GAAG,IAAI,aAAa,IAC7B,KAAI,QAAQ,gBAAgB,QAAQ,WAAW,IAAI,CAAC,SAAS,EACzD,QAAO;AAIf,SAAO;;CAQX,KACI,KACA,SACF;AACE,OAAK,SAAS,IAAI,KAAK,QAAQ;;;;;CAMnC,UACI,KACA,SACF;AACE,OAAK,SAAS,IAAI,WAAW;AACzB,OAAI,CAAC,KAAK,WAAW,IAAI,IAAI,CACzB,MAA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IAAI;AACjC,OAAK,OAAO,OAAO,KAAK,IAAI;AAE5B,OAAK,IAAI,KAAK,cAAc,KAAK"}
package/dist/index.d.cts CHANGED
@@ -1,125 +1,162 @@
1
- import { IContainer, UseKey, Bindings, IApplication, PathLoader, IServiceProvider, IPathName, IController, HttpContext, IMiddleware } from '@h3ravel/shared';
2
- import { H3Event } from 'h3';
1
+ import { Bindings, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IServiceProvider, PathLoader, UseKey } from "@h3ravel/shared";
2
+ import { H3, H3Event } from "h3";
3
3
 
4
+ //#region src/Container.d.ts
4
5
  declare class Container implements IContainer {
5
- private bindings;
6
- private singletons;
7
- /**
8
- * Check if the target has any decorators
9
- *
10
- * @param target
11
- * @returns
12
- */
13
- static hasAnyDecorator(target: Function): boolean;
14
- /**
15
- * Bind a transient service to the container
16
- */
17
- bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
18
- bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
19
- /**
20
- * Bind a singleton service to the container
21
- */
22
- singleton<T extends UseKey>(key: T | (new (..._args: any[]) => Bindings[T]), factory: () => Bindings[T]): void;
23
- /**
24
- * Resolve a service from the container
25
- */
26
- make<T extends UseKey, X = undefined>(key: T | (new (..._args: any[]) => Bindings[T])): X extends undefined ? Bindings[T] : X;
27
- /**
28
- * Automatically build a class with constructor dependency injection
29
- */
30
- private build;
31
- /**
32
- * Check if a service is registered
33
- */
34
- has(key: UseKey): boolean;
6
+ private bindings;
7
+ private singletons;
8
+ /**
9
+ * Check if the target has any decorators
10
+ *
11
+ * @param target
12
+ * @returns
13
+ */
14
+ static hasAnyDecorator(target: Function): boolean;
15
+ /**
16
+ * Bind a transient service to the container
17
+ */
18
+ bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
19
+ bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
20
+ /**
21
+ * Bind a singleton service to the container
22
+ */
23
+ singleton<T extends UseKey>(key: T | (new (..._args: any[]) => Bindings[T]), factory: () => Bindings[T]): void;
24
+ /**
25
+ * Resolve a service from the container
26
+ */
27
+ make<T extends UseKey, X = undefined>(key: T | (new (..._args: any[]) => Bindings[T])): X extends undefined ? Bindings[T] : X;
28
+ /**
29
+ * Automatically build a class with constructor dependency injection
30
+ */
31
+ private build;
32
+ /**
33
+ * Check if a service is registered
34
+ */
35
+ has(key: UseKey): boolean;
35
36
  }
36
-
37
+ //#endregion
38
+ //#region src/Application.d.ts
39
+ type AServiceProvider = (new (_app: Application) => IServiceProvider) & IServiceProvider;
37
40
  declare class Application extends Container implements IApplication {
38
- paths: PathLoader;
39
- private booted;
40
- private versions;
41
- private basePath;
42
- private providers;
43
- protected externalProviders: Array<new (_app: Application) => IServiceProvider>;
44
- constructor(basePath: string);
45
- /**
46
- * Register core bindings into the container
47
- */
48
- protected registerBaseBindings(): void;
49
- /**
50
- * Dynamically register all configured providers
51
- */
52
- registerConfiguredProviders(): Promise<void>;
53
- protected loadOptions(): Promise<void>;
54
- /**
55
- * Load default and optional providers dynamically
56
- *
57
- * Auto-Registration Behavior
58
- *
59
- * Minimal App: Loads only core, config, http, router by default.
60
- * Full-Stack App: Installs database, mail, queue, cache → they self-register via their providers.
61
- */
62
- protected getConfiguredProviders(): Promise<Array<new (_app: Application) => IServiceProvider>>;
63
- protected getAllProviders(): Promise<Array<new (_app: Application) => IServiceProvider>>;
64
- private sortProviders;
65
- registerProviders(providers: Array<new (_app: Application) => IServiceProvider>): void;
66
- /**
67
- * Register a provider
68
- */
69
- register(provider: IServiceProvider): Promise<void>;
70
- /**
71
- * Boot all providers after registration
72
- */
73
- boot(): Promise<void>;
74
- /**
75
- * Attempt to dynamically import an optional module
76
- */
77
- private safeImport;
78
- /**
79
- * Get the base path of the app
80
- *
81
- * @returns
82
- */
83
- getBasePath(): string;
84
- /**
85
- * Dynamically retrieves a path property from the class.
86
- * Any property ending with "Path" is accessible automatically.
87
- *
88
- * @param name - The base name of the path property
89
- * @returns
90
- */
91
- getPath(name: IPathName, pth?: string): string;
92
- /**
93
- * Programatically set the paths.
94
- *
95
- * @param name - The base name of the path property
96
- * @param path - The new path
97
- * @returns
98
- */
99
- setPath(name: IPathName, path: string): void;
100
- /**
101
- * Returns the installed version of the system core and typescript.
102
- *
103
- * @returns
104
- */
105
- getVersion(key: 'app' | 'ts'): string;
41
+ paths: PathLoader;
42
+ private tries;
43
+ private booted;
44
+ private versions;
45
+ private basePath;
46
+ private providers;
47
+ protected externalProviders: Array<new (_app: Application) => IServiceProvider>;
48
+ /**
49
+ * List of registered console commands
50
+ */
51
+ registeredCommands: (new (app: any, kernel: any) => any)[];
52
+ constructor(basePath: string);
53
+ /**
54
+ * Register core bindings into the container
55
+ */
56
+ protected registerBaseBindings(): void;
57
+ /**
58
+ * Dynamically register all configured providers
59
+ */
60
+ registerConfiguredProviders(): Promise<void>;
61
+ protected loadOptions(): Promise<void>;
62
+ /**
63
+ * Get all registered providers
64
+ */
65
+ getRegisteredProviders(): IServiceProvider[];
66
+ /**
67
+ * Load default and optional providers dynamically
68
+ *
69
+ * Auto-Registration Behavior
70
+ *
71
+ * Minimal App: Loads only core, config, http, router by default.
72
+ * Full-Stack App: Installs database, mail, queue, cache → they self-register via their providers.
73
+ */
74
+ protected getConfiguredProviders(): Promise<Array<AServiceProvider>>;
75
+ protected getAllProviders(): Promise<Array<AServiceProvider>>;
76
+ private sortProviders;
77
+ registerProviders(providers: Array<AServiceProvider>): void;
78
+ /**
79
+ * Register a provider
80
+ */
81
+ register(provider: IServiceProvider): Promise<void>;
82
+ /**
83
+ * checks if the application is running in CLI
84
+ */
85
+ runningInConsole(): boolean;
86
+ getRuntimeEnv(): 'browser' | 'node' | 'unknown';
87
+ /**
88
+ * Boot all service providers after registration
89
+ */
90
+ boot(): Promise<void>;
91
+ /**
92
+ * Fire up the developement server using the user provided arguments
93
+ *
94
+ * Port will be auto assigned if provided one is not available
95
+ *
96
+ * @param h3App The current H3 app instance
97
+ * @param preferedPort If provided, this will overide the port set in the evironment
98
+ */
99
+ fire(h3App: H3, preferedPort?: number): Promise<void>;
100
+ /**
101
+ * Attempt to dynamically import an optional module
102
+ */
103
+ private safeImport;
104
+ /**
105
+ * Get the base path of the app
106
+ *
107
+ * @returns
108
+ */
109
+ getBasePath(): string;
110
+ /**
111
+ * Dynamically retrieves a path property from the class.
112
+ * Any property ending with "Path" is accessible automatically.
113
+ *
114
+ * @param name - The base name of the path property
115
+ * @returns
116
+ */
117
+ getPath(name: IPathName, suffix?: string): string;
118
+ /**
119
+ * Programatically set the paths.
120
+ *
121
+ * @param name - The base name of the path property
122
+ * @param path - The new path
123
+ * @returns
124
+ */
125
+ setPath(name: IPathName, path: string): void;
126
+ /**
127
+ * Returns the installed version of the system core and typescript.
128
+ *
129
+ * @returns
130
+ */
131
+ getVersion(key: 'app' | 'ts'): string;
106
132
  }
107
-
133
+ //#endregion
134
+ //#region src/Contracts/ServiceProviderConstructor.d.ts
108
135
  type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;
109
-
136
+ //#endregion
137
+ //#region src/Controller.d.ts
110
138
  /**
111
139
  * Base controller class
112
140
  */
113
141
  declare abstract class Controller implements IController {
114
- protected app: Application;
115
- constructor(app: Application);
116
- show(..._ctx: any[]): any;
117
- index(..._ctx: any[]): any;
118
- store(..._ctx: any[]): any;
119
- update(..._ctx: any[]): any;
120
- destroy(..._ctx: any[]): any;
142
+ protected app: Application;
143
+ constructor(app: Application);
144
+ show(..._ctx: any[]): any;
145
+ index(..._ctx: any[]): any;
146
+ store(..._ctx: any[]): any;
147
+ update(..._ctx: any[]): any;
148
+ destroy(..._ctx: any[]): any;
121
149
  }
122
-
150
+ //#endregion
151
+ //#region src/Di/ContainerResolver.d.ts
152
+ declare class ContainerResolver {
153
+ private app;
154
+ constructor(app: Application);
155
+ resolveMethodParams<I extends Record<string, any>>(instance: I, method: keyof I, _default?: any): Promise<I>;
156
+ static isClass(C: any): boolean;
157
+ }
158
+ //#endregion
159
+ //#region src/Di/Inject.d.ts
123
160
  declare function Inject(...dependencies: string[]): (target: any) => void;
124
161
  /**
125
162
  * Allows binding dependencies to both class and class methods
@@ -127,61 +164,82 @@ declare function Inject(...dependencies: string[]): (target: any) => void;
127
164
  * @returns
128
165
  */
129
166
  declare function Injectable(): ClassDecorator & MethodDecorator;
130
-
167
+ //#endregion
168
+ //#region src/Http/Kernel.d.ts
131
169
  /**
132
170
  * Kernel class handles middleware execution and response transformations.
133
171
  * It acts as the core middleware pipeline for HTTP requests.
134
172
  */
135
173
  declare class Kernel {
136
- protected context: (event: H3Event) => HttpContext;
137
- protected middleware: IMiddleware[];
138
- /**
139
- * @param context - A factory function that converts an H3Event into an HttpContext.
140
- * @param middleware - An array of middleware classes that will be executed in sequence.
141
- */
142
- constructor(context: (event: H3Event) => HttpContext, middleware?: IMiddleware[]);
143
- /**
144
- * Handles an incoming request and passes it through middleware before invoking the next handler.
145
- *
146
- * @param event - The raw H3 event object.
147
- * @param next - A callback function that represents the next layer (usually the controller or final handler).
148
- * @returns A promise resolving to the result of the request pipeline.
149
- */
150
- handle(event: H3Event, next: (ctx: HttpContext) => Promise<unknown>): Promise<unknown>;
151
- /**
152
- * Sequentially runs middleware in the order they were registered.
153
- *
154
- * @param context - The standardized HttpContext.
155
- * @param next - Callback to execute when middleware completes.
156
- * @returns A promise resolving to the final handler's result.
157
- */
158
- private runMiddleware;
159
- /**
160
- * Utility function to determine if a value is a plain object or array.
161
- *
162
- * @param value - The value to check.
163
- * @returns True if the value is a plain object or array, otherwise false.
164
- */
165
- private isPlainObject;
174
+ protected context: (event: H3Event) => HttpContext;
175
+ protected middleware: IMiddleware[];
176
+ /**
177
+ * @param context - A factory function that converts an H3Event into an HttpContext.
178
+ * @param middleware - An array of middleware classes that will be executed in sequence.
179
+ */
180
+ constructor(context: (event: H3Event) => HttpContext, middleware?: IMiddleware[]);
181
+ /**
182
+ * Handles an incoming request and passes it through middleware before invoking the next handler.
183
+ *
184
+ * @param event - The raw H3 event object.
185
+ * @param next - A callback function that represents the next layer (usually the controller or final handler).
186
+ * @returns A promise resolving to the result of the request pipeline.
187
+ */
188
+ handle(event: H3Event, next: (ctx: HttpContext) => Promise<unknown>): Promise<unknown>;
189
+ /**
190
+ * Sequentially runs middleware in the order they were registered.
191
+ *
192
+ * @param context - The standardized HttpContext.
193
+ * @param next - Callback to execute when middleware completes.
194
+ * @returns A promise resolving to the final handler's result.
195
+ */
196
+ private runMiddleware;
197
+ /**
198
+ * Utility function to determine if a value is a plain object or array.
199
+ *
200
+ * @param value - The value to check.
201
+ * @returns True if the value is a plain object or array, otherwise false.
202
+ */
203
+ private isPlainObject;
166
204
  }
167
-
205
+ //#endregion
206
+ //#region src/ServiceProvider.d.ts
168
207
  declare abstract class ServiceProvider implements IServiceProvider {
169
- static order?: `before:${string}` | `after:${string}` | string | undefined;
170
- static priority: number;
171
- protected app: Application;
172
- constructor(app: Application);
173
- /**
174
- * Register bindings to the container.
175
- * Runs before boot().
176
- */
177
- abstract register(): void | Promise<void>;
178
- /**
179
- * Perform post-registration booting of services.
180
- * Runs after all providers have been registered.
181
- */
182
- boot?(): void | Promise<void>;
208
+ /**
209
+ * Sort order
210
+ */
211
+ static order?: `before:${string}` | `after:${string}` | string | undefined;
212
+ /**
213
+ * Sort priority
214
+ */
215
+ static priority: number;
216
+ /**
217
+ * Indicate that this service provider only runs in console
218
+ */
219
+ static console: boolean;
220
+ /**
221
+ * List of registered console commands
222
+ */
223
+ registeredCommands?: (new (app: any, kernel: any) => any)[];
224
+ protected app: Application;
225
+ constructor(app: Application);
226
+ /**
227
+ * Register bindings to the container.
228
+ * Runs before boot().
229
+ */
230
+ abstract register(...app: unknown[]): void | Promise<void>;
231
+ /**
232
+ * Perform post-registration booting of services.
233
+ * Runs after all providers have been registered.
234
+ */
235
+ boot?(...app: unknown[]): void | Promise<void>;
236
+ /**
237
+ * An array of console commands to register.
238
+ */
239
+ commands(commands: (new (app: any, kernel: any) => any)[]): void;
183
240
  }
184
-
241
+ //#endregion
242
+ //#region src/Providers/CoreServiceProvider.d.ts
185
243
  /**
186
244
  * Bootstraps core services and bindings.
187
245
  *
@@ -192,17 +250,28 @@ declare abstract class ServiceProvider implements IServiceProvider {
192
250
  * Auto-Registered
193
251
  */
194
252
  declare class CoreServiceProvider extends ServiceProvider {
195
- static priority: number;
196
- register(): void;
253
+ static priority: number;
254
+ register(): void;
197
255
  }
198
-
256
+ //#endregion
257
+ //#region src/Providers/ViewServiceProvider.d.ts
199
258
  declare class ViewServiceProvider extends ServiceProvider {
200
- static priority: number;
201
- register(): void;
259
+ static priority: number;
260
+ register(): void;
202
261
  }
203
-
262
+ //#endregion
263
+ //#region src/Registerer.d.ts
204
264
  declare class Registerer {
205
- static register(): void;
265
+ private app;
266
+ constructor(app: Application);
267
+ static register(app: Application): void;
268
+ bootRegister(): void;
269
+ private appPath;
270
+ private basePath;
271
+ private publicPath;
272
+ private storagePath;
273
+ private databasePath;
206
274
  }
207
-
208
- export { Application, Container, Controller, CoreServiceProvider, Inject, Injectable, Kernel, Registerer, ServiceProvider, type ServiceProviderConstructor, ViewServiceProvider };
275
+ //#endregion
276
+ export { Application, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, Registerer, ServiceProvider, ServiceProviderConstructor, ViewServiceProvider };
277
+ //# sourceMappingURL=index.d.cts.map