@h3ravel/core 1.21.3 → 1.21.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -307,7 +307,7 @@ var ProviderRegistry = class {
307
307
  if (autoRegister) {
308
308
  for (const manifestPath of manifests) {
309
309
  const pkg = await this.getManifest(node_path.default.resolve(manifestPath));
310
- if (pkg.h3ravel?.providers) providers.push(...await Promise.all(pkg.h3ravel.providers.map(async (name) => (await import(node_path.default.resolve(node_path.default.dirname(manifestPath), "dist/index.mjs")))[name])));
310
+ if (pkg.h3ravel?.providers) providers.push(...await Promise.all(pkg.h3ravel.providers.map(async (name) => (await import(node_path.default.resolve(node_path.default.dirname(manifestPath), "dist/index.js")))[name])));
311
311
  }
312
312
  for (const provider of providers) {
313
313
  const key = this.getKey(provider);
@@ -702,11 +702,32 @@ const h3ravel = async (providers = [], basePath = process.cwd(), config = {
702
702
  } catch {
703
703
  if (!h3App && config.h3) h3App = config.h3;
704
704
  }
705
- const originalFire = app.fire.bind(app);
706
- if (config.initialize && h3App) return await originalFire(h3App);
707
- app.fire = () => {
705
+ const originalFire = app.fire;
706
+ const proxyThis = (function makeProxy(appRef, orig) {
707
+ return new Proxy(appRef, {
708
+ get(target, prop, receiver) {
709
+ if (prop === "fire") return orig;
710
+ return Reflect.get(target, prop, receiver);
711
+ },
712
+ has(target, prop) {
713
+ if (prop === "fire") return true;
714
+ return Reflect.has(target, prop);
715
+ },
716
+ getOwnPropertyDescriptor(target, prop) {
717
+ if (prop === "fire") return {
718
+ configurable: true,
719
+ enumerable: false,
720
+ writable: true,
721
+ value: orig
722
+ };
723
+ return Reflect.getOwnPropertyDescriptor(target, prop);
724
+ }
725
+ });
726
+ })(app, originalFire);
727
+ if (config.initialize && h3App) return await Reflect.apply(originalFire, app, [h3App]);
728
+ app.fire = async function() {
708
729
  if (!h3App) throw new ConfigException("Provide a H3 app instance in the config or install @h3ravel/http");
709
- return originalFire(h3App);
730
+ return await Reflect.apply(originalFire, proxyThis, [h3App]);
710
731
  };
711
732
  return app;
712
733
  };
@@ -279,7 +279,7 @@ var ProviderRegistry = class {
279
279
  if (autoRegister) {
280
280
  for (const manifestPath of manifests) {
281
281
  const pkg = await this.getManifest(path.resolve(manifestPath));
282
- if (pkg.h3ravel?.providers) providers.push(...await Promise.all(pkg.h3ravel.providers.map(async (name) => (await import(path.resolve(path.dirname(manifestPath), "dist/index.mjs")))[name])));
282
+ if (pkg.h3ravel?.providers) providers.push(...await Promise.all(pkg.h3ravel.providers.map(async (name) => (await import(path.resolve(path.dirname(manifestPath), "dist/index.js")))[name])));
283
283
  }
284
284
  for (const provider of providers) {
285
285
  const key = this.getKey(provider);
@@ -674,11 +674,32 @@ const h3ravel = async (providers = [], basePath = process.cwd(), config = {
674
674
  } catch {
675
675
  if (!h3App && config.h3) h3App = config.h3;
676
676
  }
677
- const originalFire = app.fire.bind(app);
678
- if (config.initialize && h3App) return await originalFire(h3App);
679
- app.fire = () => {
677
+ const originalFire = app.fire;
678
+ const proxyThis = (function makeProxy(appRef, orig) {
679
+ return new Proxy(appRef, {
680
+ get(target, prop, receiver) {
681
+ if (prop === "fire") return orig;
682
+ return Reflect.get(target, prop, receiver);
683
+ },
684
+ has(target, prop) {
685
+ if (prop === "fire") return true;
686
+ return Reflect.has(target, prop);
687
+ },
688
+ getOwnPropertyDescriptor(target, prop) {
689
+ if (prop === "fire") return {
690
+ configurable: true,
691
+ enumerable: false,
692
+ writable: true,
693
+ value: orig
694
+ };
695
+ return Reflect.getOwnPropertyDescriptor(target, prop);
696
+ }
697
+ });
698
+ })(app, originalFire);
699
+ if (config.initialize && h3App) return await Reflect.apply(originalFire, app, [h3App]);
700
+ app.fire = async function() {
680
701
  if (!h3App) throw new ConfigException("Provide a H3 app instance in the config or install @h3ravel/http");
681
- return originalFire(h3App);
702
+ return await Reflect.apply(originalFire, proxyThis, [h3App]);
682
703
  };
683
704
  return app;
684
705
  };
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@h3ravel/core",
3
- "version": "1.21.3",
3
+ "version": "1.21.6",
4
4
  "description": "Core application container, lifecycle management and service providers for H3ravel.",
5
5
  "type": "module",
6
- "main": "./dist/index.mjs",
7
- "types": "./dist/index.d.mts",
8
- "module": "./dist/index.mjs",
6
+ "main": "./dist/index.cjs",
7
+ "types": "./dist/index.d.ts",
8
+ "module": "./dist/index.js",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.mts",
12
- "import": "./dist/index.mjs",
11
+ "import": "./dist/index.js",
13
12
  "require": "./dist/index.cjs"
14
- }
13
+ },
14
+ "./*": "./*"
15
15
  },
16
16
  "typesVersions": {
17
17
  "*": {
@@ -54,17 +54,18 @@
54
54
  "semver": "^7.7.2",
55
55
  "srvx": "^0.8.7",
56
56
  "tslib": "^2.8.1",
57
- "@h3ravel/shared": "^0.27.3",
58
- "@h3ravel/support": "^0.15.3"
57
+ "@h3ravel/support": "^0.15.6",
58
+ "@h3ravel/shared": "^0.27.7"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/semver": "^7.7.1",
62
62
  "typescript": "^5.9.2"
63
63
  },
64
64
  "scripts": {
65
+ "barrel": "barrelsby --directory src --delete --singleQuotes",
65
66
  "build": "tsdown --config-loader unconfig",
66
67
  "dev": "tsx watch src/index.ts",
67
- "start": "node dist/index.mjs",
68
+ "start": "node dist/index.js",
68
69
  "lint": "eslint . --ext .ts",
69
70
  "test": "jest --passWithNoTests",
70
71
  "version-patch": "pnpm version patch",
package/dist/index.d.mts DELETED
@@ -1,485 +0,0 @@
1
- /// <reference path="./app.globals.d.ts" />
2
- import "reflect-metadata";
3
- import { Bindings, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IServiceProvider, PathLoader, UseKey } from "@h3ravel/shared";
4
- import { HttpContext as HttpContext$1 } from "@h3ravel/http";
5
- import { H3, H3Event } from "h3";
6
-
7
- //#region src/Contracts/ServiceProviderConstructor.d.ts
8
- type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;
9
- type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<ServiceProvider>;
10
- type OServiceProvider = (new (_app: Application) => Partial<ServiceProvider>) & Partial<ServiceProvider>;
11
- //#endregion
12
- //#region src/Container.d.ts
13
- type IBinding = UseKey | (new (..._args: any[]) => unknown);
14
- declare class Container implements IContainer {
15
- bindings: Map<IBinding, () => unknown>;
16
- singletons: Map<IBinding, unknown>;
17
- /**
18
- * Check if the target has any decorators
19
- *
20
- * @param target
21
- * @returns
22
- */
23
- static hasAnyDecorator<C extends abstract new (...args: any[]) => any>(target: C): boolean;
24
- static hasAnyDecorator<F extends (...args: any[]) => any>(target: F): boolean;
25
- /**
26
- * Bind a transient service to the container
27
- */
28
- bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
29
- bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
30
- /**
31
- * Remove one or more transient services from the container
32
- */
33
- unbind<T extends UseKey>(key: T | T[]): void;
34
- /**
35
- * Bind a singleton service to the container
36
- */
37
- singleton<T extends UseKey>(key: T | (new (..._args: any[]) => Bindings[T]), factory: (app: this) => Bindings[T]): void;
38
- /**
39
- * Resolve a service from the container
40
- */
41
- make<T extends UseKey>(key: T): Bindings[T];
42
- make<C extends abstract new (...args: any[]) => any>(key: C): InstanceType<C>;
43
- make<F extends (...args: any[]) => any>(key: F): ReturnType<F>;
44
- /**
45
- * Automatically build a class with constructor dependency injection
46
- */
47
- private build;
48
- /**
49
- * Check if a service is registered
50
- */
51
- has(key: UseKey): boolean;
52
- }
53
- //#endregion
54
- //#region src/ServiceProvider.d.ts
55
- declare const Inference: {
56
- new (): IServiceProvider;
57
- };
58
- declare abstract class ServiceProvider extends Inference {
59
- /**
60
- * The current app instance
61
- */
62
- protected app: Application;
63
- /**
64
- * Unique Identifier for the service providers
65
- */
66
- static uid?: number;
67
- /**
68
- * Sort order
69
- */
70
- static order?: `before:${string}` | `after:${string}` | string | undefined;
71
- /**
72
- * Sort priority
73
- */
74
- static priority: number;
75
- /**
76
- * Indicate that this service provider only runs in console
77
- */
78
- static console: boolean;
79
- /**
80
- * List of registered console commands
81
- */
82
- registeredCommands?: (new (app: any, kernel: any) => any)[];
83
- constructor(app: Application);
84
- /**
85
- * Register bindings to the container.
86
- * Runs before boot().
87
- */
88
- abstract register(...app: unknown[]): void | Promise<void>;
89
- /**
90
- * Perform post-registration booting of services.
91
- * Runs after all providers have been registered.
92
- */
93
- boot?(...app: unknown[]): void | Promise<void>;
94
- /**
95
- * Register the listed service providers.
96
- *
97
- * @param commands An array of console commands to register.
98
- *
99
- * @deprecated since version 1.16.0. Will be removed in future versions, use `registerCommands` instead
100
- */
101
- commands(commands: (new (app: any, kernel: any) => any)[]): void;
102
- /**
103
- * Register the listed service providers.
104
- *
105
- * @param commands An array of console commands to register.
106
- */
107
- registerCommands(commands: (new (app: any, kernel: any) => any)[]): void;
108
- }
109
- //#endregion
110
- //#region src/Application.d.ts
111
- declare class Application extends Container implements IApplication {
112
- paths: PathLoader;
113
- context?: (event: H3Event) => Promise<HttpContext>;
114
- private tries;
115
- private booted;
116
- private basePath;
117
- private versions;
118
- private static versions;
119
- private providers;
120
- protected externalProviders: Array<AServiceProvider>;
121
- protected filteredProviders: Array<string>;
122
- /**
123
- * List of registered console commands
124
- */
125
- registeredCommands: (new (app: any, kernel: any) => any)[];
126
- constructor(basePath: string);
127
- /**
128
- * Register core bindings into the container
129
- */
130
- protected registerBaseBindings(): void;
131
- protected loadOptions(): Promise<void>;
132
- /**
133
- * Get all registered providers
134
- */
135
- getRegisteredProviders(): ServiceProvider[];
136
- /**
137
- * Load default and optional providers dynamically
138
- *
139
- * Auto-Registration Behavior
140
- *
141
- * Minimal App: Loads only core, config, http, router by default.
142
- * Full-Stack App: Installs database, mail, queue, cache → they self-register via their providers.
143
- */
144
- protected getConfiguredProviders(): Promise<Array<AServiceProvider>>;
145
- protected getAllProviders(): Promise<Array<AServiceProvider>>;
146
- /**
147
- * Configure and Dynamically register all configured service providers, then boot the app.
148
- *
149
- * @param providers All regitererable service providers
150
- * @param filtered A list of service provider name strings we do not want to register at all cost
151
- * @param autoRegisterProviders If set to false, service providers will not be auto discovered and registered.
152
- *
153
- * @returns
154
- */
155
- quickStartup(providers: Array<AServiceProvider>, filtered?: string[], autoRegisterProviders?: boolean): Promise<this>;
156
- /**
157
- * Dynamically register all configured providers
158
- *
159
- * @param autoRegister If set to false, service providers will not be auto discovered and registered.
160
- */
161
- registerConfiguredProviders(autoRegister?: boolean): Promise<void>;
162
- /**
163
- * Register service providers
164
- *
165
- * @param providers
166
- * @param filtered
167
- */
168
- registerProviders(providers: Array<AServiceProvider>, filtered?: string[]): void;
169
- /**
170
- * Register a provider
171
- */
172
- register(provider: ServiceProvider): Promise<void>;
173
- /**
174
- * Register the listed service providers.
175
- *
176
- * @param commands An array of console commands to register.
177
- */
178
- withCommands(commands: (new (app: any, kernel: any) => any)[]): this;
179
- /**
180
- * checks if the application is running in CLI
181
- */
182
- runningInConsole(): boolean;
183
- getRuntimeEnv(): 'browser' | 'node' | 'unknown';
184
- /**
185
- * Boot all service providers after registration
186
- */
187
- boot(): Promise<this>;
188
- /**
189
- * Fire up the developement server using the user provided arguments
190
- *
191
- * Port will be auto assigned if provided one is not available
192
- *
193
- * @param h3App The current H3 app instance
194
- * @param preferedPort If provided, this will overide the port set in the evironment
195
- */
196
- fire(): Promise<this>;
197
- fire(h3App: H3, preferredPort?: number): Promise<this>;
198
- /**
199
- * Get the base path of the app
200
- *
201
- * @returns
202
- */
203
- getBasePath(): string;
204
- /**
205
- * Dynamically retrieves a path property from the class.
206
- * Any property ending with "Path" is accessible automatically.
207
- *
208
- * @param name - The base name of the path property
209
- * @returns
210
- */
211
- getPath(name: IPathName, suffix?: string): string;
212
- /**
213
- * Programatically set the paths.
214
- *
215
- * @param name - The base name of the path property
216
- * @param path - The new path
217
- * @returns
218
- */
219
- setPath(name: IPathName, path: string): void;
220
- /**
221
- * Returns the installed version of the system core and typescript.
222
- *
223
- * @returns
224
- */
225
- getVersion(key: string): string;
226
- /**
227
- * Returns the installed version of the system core and typescript.
228
- *
229
- * @returns
230
- */
231
- static getVersion(key: string): string;
232
- }
233
- //#endregion
234
- //#region src/Contracts/H3ravelContract.d.ts
235
- interface EntryConfig {
236
- /**
237
- * @param h3 You can provide your own `H3` app instance, this is usefull when `@h3ravel/http`
238
- * is not installed.
239
- */
240
- h3?: H3;
241
- /**
242
- * Determines if we should initialize the app on call.
243
- *
244
- * @default false
245
- */
246
- initialize?: boolean;
247
- /**
248
- * Determines if service providers should be auto discovered and registered or not.
249
- *
250
- * @default false
251
- */
252
- autoload?: boolean;
253
- /**
254
- * A list of service provider name strings we do not want to register at all cost
255
- *
256
- * @default []
257
- */
258
- filteredProviders?: string[];
259
- }
260
- //#endregion
261
- //#region src/Controller.d.ts
262
- /**
263
- * Base controller class
264
- */
265
- declare abstract class Controller implements IController {
266
- protected app: Application;
267
- constructor(app: Application);
268
- show?(..._ctx: any[]): any;
269
- index?(..._ctx: any[]): any;
270
- store?(..._ctx: any[]): any;
271
- update?(..._ctx: any[]): any;
272
- destroy?(..._ctx: any[]): any;
273
- }
274
- //#endregion
275
- //#region src/Di/ContainerResolver.d.ts
276
- declare class ContainerResolver {
277
- private app;
278
- constructor(app: Application);
279
- resolveMethodParams<I extends Record<string, any>>(instance: I, method: keyof I, ..._default: any[]): Promise<I>;
280
- static isClass(C: any): boolean;
281
- }
282
- //#endregion
283
- //#region src/Di/Inject.d.ts
284
- declare function Inject(...dependencies: string[]): (target: any) => void;
285
- /**
286
- * Allows binding dependencies to both class and class methods
287
- *
288
- * @returns
289
- */
290
- declare function Injectable(): ClassDecorator & MethodDecorator;
291
- //#endregion
292
- //#region src/Exceptions/ConfigException.d.ts
293
- declare class ConfigException extends Error {
294
- key: string;
295
- constructor(key: string, type?: 'any' | 'config' | 'env', cause?: unknown);
296
- }
297
- //#endregion
298
- //#region src/H3ravel.d.ts
299
- /**
300
- * Simple global entry point for H3ravel applications
301
- *
302
- * @param providers
303
- * @param basePath
304
- * @param callback
305
- */
306
- declare const h3ravel: (
307
- /**
308
- * List of intial service providers to register with your app
309
- */
310
- providers?: Exclude<OServiceProvider, "app" | "commands">[],
311
- /**
312
- * Entry path of your app
313
- */
314
- basePath?: string,
315
- /**
316
- * Configuration option to pass to the initializer
317
- */
318
- config?: EntryConfig,
319
- /**
320
- * final middleware function to call once the server is fired up
321
- */
322
- middleware?: (ctx: HttpContext$1) => Promise<unknown>) => Promise<Application>;
323
- //#endregion
324
- //#region src/Http/Kernel.d.ts
325
- /**
326
- * Kernel class handles middleware execution and response transformations.
327
- * It acts as the core middleware pipeline for HTTP requests.
328
- */
329
- declare class Kernel {
330
- protected context: (event: H3Event) => HttpContext | Promise<HttpContext>;
331
- protected middleware: IMiddleware[];
332
- /**
333
- * @param context - A factory function that converts an H3Event into an HttpContext.
334
- * @param middleware - An array of middleware classes that will be executed in sequence.
335
- */
336
- constructor(context: (event: H3Event) => HttpContext | Promise<HttpContext>, middleware?: IMiddleware[]);
337
- /**
338
- * Handles an incoming request and passes it through middleware before invoking the next handler.
339
- *
340
- * @param event - The raw H3 event object.
341
- * @param next - A callback function that represents the next layer (usually the controller or final handler).
342
- * @returns A promise resolving to the result of the request pipeline.
343
- */
344
- handle(event: H3Event, next: (ctx: HttpContext) => Promise<unknown>): Promise<unknown>;
345
- /**
346
- * Sequentially runs middleware in the order they were registered.
347
- *
348
- * @param context - The standardized HttpContext.
349
- * @param next - Callback to execute when middleware completes.
350
- * @returns A promise resolving to the final handler's result.
351
- */
352
- private runMiddleware;
353
- /**
354
- * Utility function to determine if a value is a plain object or array.
355
- *
356
- * @param value - The value to check.
357
- * @returns True if the value is a plain object or array, otherwise false.
358
- */
359
- private isPlainObject;
360
- }
361
- //#endregion
362
- //#region src/ProviderRegistry.d.ts
363
- type ProviderCtor = (new (_app: Application) => ServiceProvider) & Partial<ServiceProvider>;
364
- declare class ProviderRegistry {
365
- private static providers;
366
- private static priorityMap;
367
- private static filteredProviders;
368
- private static sortable;
369
- /**
370
- * Set wether providers should be sorted or not.
371
- *
372
- * @returns
373
- */
374
- static setSortable(sort?: boolean): void;
375
- /**
376
- * Get a unique identifier for the Provider.
377
- *
378
- * @param provider
379
- * @returns
380
- */
381
- private static getKey;
382
- /**
383
- * Register one or more providers.
384
- * Duplicate constructors will be ignored.
385
- *
386
- * @param providers
387
- * @returns
388
- */
389
- static register(...providers: ProviderCtor[]): void;
390
- /**
391
- * Bulk register providers from an array.
392
- *
393
- * @param providers
394
- * @returns
395
- */
396
- static registerMany(providers: ProviderCtor[]): void;
397
- /**
398
- * Set the filtered providers.
399
- *
400
- * @returns
401
- */
402
- static setFiltered(filtered: string[]): void;
403
- /**
404
- * Resolve (instantiate) all providers with the given application or Service Container.
405
- *
406
- * @param app
407
- * @returns
408
- */
409
- static resolve(app: Application, useServiceContainer?: boolean): Promise<ServiceProvider[]>;
410
- /**
411
- * Sort the service providers
412
- *
413
- * @param providers
414
- * @returns
415
- */
416
- static sort(providers: ProviderCtor[]): ProviderCtor[];
417
- /**
418
- * Sort service providers
419
- */
420
- static doSort(): void;
421
- /**
422
- * Log the service providers in a table
423
- *
424
- * @param priorityMap
425
- */
426
- static log<P extends ServiceProvider>(providers?: Array<P> | Map<string, P>): void;
427
- /**
428
- * Get all registered providers as an array.
429
- *
430
- * @returns
431
- */
432
- static all(): ProviderCtor[];
433
- /**
434
- * Check if a provider is already registered.
435
- *
436
- * @param provider
437
- * @returns
438
- */
439
- static has(provider: ProviderCtor): boolean;
440
- /**
441
- * Automatically search for and discover service providers in packages.
442
- *
443
- * @param autoRegister
444
- * @returns
445
- */
446
- static discoverProviders(autoRegister?: boolean): Promise<ProviderCtor[]>;
447
- /**
448
- * Get the content of the package.json file
449
- *
450
- * @param manifestPath
451
- * @returns
452
- */
453
- private static getManifest;
454
- }
455
- //#endregion
456
- //#region src/Providers/CoreServiceProvider.d.ts
457
- /**
458
- * Bootstraps core services and bindings.
459
- *
460
- * Bind essential services to the container (logger, config repository).
461
- * Register app-level singletons.
462
- * Set up exception handling.
463
- *
464
- * Auto-Registered
465
- */
466
- declare class CoreServiceProvider extends ServiceProvider {
467
- static priority: number;
468
- register(): void;
469
- boot(): void | Promise<void>;
470
- }
471
- //#endregion
472
- //#region src/Registerer.d.ts
473
- declare class Registerer {
474
- private app;
475
- constructor(app: Application);
476
- static register(app: Application): void;
477
- bootRegister(): void;
478
- private appPath;
479
- private basePath;
480
- private publicPath;
481
- private storagePath;
482
- private databasePath;
483
- }
484
- //#endregion
485
- export { AServiceProvider, Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, EntryConfig, Inject, Injectable, Kernel, OServiceProvider, ProviderRegistry, Registerer, ServiceProvider, ServiceProviderConstructor, h3ravel };
File without changes