@h3ravel/core 1.17.0 → 1.18.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.
package/dist/index.cjs CHANGED
@@ -24,12 +24,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  require("reflect-metadata");
25
25
  let __h3ravel_shared = require("@h3ravel/shared");
26
26
  __h3ravel_shared = __toESM(__h3ravel_shared);
27
+ let __h3ravel_support = require("@h3ravel/support");
28
+ __h3ravel_support = __toESM(__h3ravel_support);
27
29
  let fast_glob = require("fast-glob");
28
30
  fast_glob = __toESM(fast_glob);
29
31
  let node_path = require("node:path");
30
32
  node_path = __toESM(node_path);
31
- let __h3ravel_support = require("@h3ravel/support");
32
- __h3ravel_support = __toESM(__h3ravel_support);
33
33
  let detect_port = require("detect-port");
34
34
  detect_port = __toESM(detect_port);
35
35
  let dotenv = require("dotenv");
@@ -40,6 +40,8 @@ let node_fs_promises = require("node:fs/promises");
40
40
  node_fs_promises = __toESM(node_fs_promises);
41
41
  let semver = require("semver");
42
42
  semver = __toESM(semver);
43
+ let __h3ravel_http = require("@h3ravel/http");
44
+ __h3ravel_http = __toESM(__h3ravel_http);
43
45
 
44
46
  //#region src/Container.ts
45
47
  var Container = class {
@@ -55,6 +57,19 @@ var Container = class {
55
57
  this.bindings.set(key, factory);
56
58
  }
57
59
  /**
60
+ * Remove one or more transient services from the container
61
+ */
62
+ unbind(key) {
63
+ if (Array.isArray(key)) for (let i = 0; i < key.length; i++) {
64
+ this.bindings.delete(key[i]);
65
+ this.singletons.delete(key[i]);
66
+ }
67
+ else {
68
+ this.bindings.delete(key);
69
+ this.singletons.delete(key);
70
+ }
71
+ }
72
+ /**
58
73
  * Bind a singleton service to the container
59
74
  */
60
75
  singleton(key, factory) {
@@ -111,7 +126,8 @@ var ContainerResolver = class ContainerResolver {
111
126
  /**
112
127
  * Resolve the bound dependencies
113
128
  */
114
- const args = params.filter((e) => ContainerResolver.isClass(e)).map((type) => {
129
+ const args = params.filter((e) => ContainerResolver.isClass(e) || e instanceof Application).map((type) => {
130
+ if (type instanceof Application) return type;
115
131
  return this.app.make(type);
116
132
  });
117
133
  return new Promise((resolve) => {
@@ -293,13 +309,15 @@ var ProviderRegistry = class {
293
309
  "node_modules/h3ravel-*/package.json"
294
310
  ]);
295
311
  const providers = [];
296
- for (const manifestPath of manifests) {
297
- const pkg = await this.getManifest(node_path.default.resolve(manifestPath));
298
- 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])));
299
- }
300
- if (autoRegister) for (const provider of providers) {
301
- const key = this.getKey(provider);
302
- this.providers.set(key, provider);
312
+ if (autoRegister) {
313
+ for (const manifestPath of manifests) {
314
+ const pkg = await this.getManifest(node_path.default.resolve(manifestPath));
315
+ 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])));
316
+ }
317
+ for (const provider of providers) {
318
+ const key = this.getKey(provider);
319
+ this.providers.set(key, provider);
320
+ }
303
321
  }
304
322
  return providers;
305
323
  }
@@ -459,13 +477,13 @@ var Application = class Application extends Container {
459
477
  ProviderRegistry.setSortable(false);
460
478
  ProviderRegistry.setFiltered(this.filteredProviders);
461
479
  ProviderRegistry.registerMany(providers);
462
- if (autoRegister) await ProviderRegistry.discoverProviders();
480
+ if (autoRegister) await ProviderRegistry.discoverProviders(autoRegister);
463
481
  ProviderRegistry.doSort();
464
- for (const ProviderClass of ProviderRegistry.all()) {
465
- if (!ProviderClass) continue;
482
+ ProviderRegistry.all().forEach(async (ProviderClass) => {
483
+ if (!ProviderClass) return;
466
484
  const provider = new ProviderClass(this);
467
485
  await this.register(provider);
468
- }
486
+ });
469
487
  }
470
488
  /**
471
489
  * Register service providers
@@ -513,7 +531,7 @@ var Application = class Application extends Container {
513
531
  /**
514
532
  * If debug is enabled, let's show the loaded service provider info
515
533
  */
516
- if (process.env.APP_DEBUG === "true" && process.env.EXTENDED_DEBUG !== "false" && !this.providers.some((e) => e.runsInConsole)) ProviderRegistry.log(this.providers);
534
+ if ((process.env.APP_DEBUG === "true" && process.env.EXTENDED_DEBUG !== "false" || Number(process.env.VERBOSE) > 1) && !this.providers.some((e) => e.runsInConsole)) ProviderRegistry.log(this.providers);
517
535
  for (const provider of this.providers) if (provider.boot) if (Container.hasAnyDecorator(provider.boot))
518
536
  /**
519
537
  * If the service provider is decorated use the IoC container
@@ -528,17 +546,10 @@ var Application = class Application extends Container {
528
546
  this.booted = true;
529
547
  return this;
530
548
  }
531
- /**
532
- * Fire up the developement server using the user provided arguments
533
- *
534
- * Port will be auto assigned if provided one is not available
535
- *
536
- * @param h3App The current H3 app instance
537
- * @param preferedPort If provided, this will overide the port set in the evironment
538
- */
539
- async fire(h3App, preferedPort) {
549
+ async fire(h3App, preferredPort) {
550
+ if (!h3App) throw new __h3ravel_support.InvalidArgumentException("No valid H3 app instance was provided.");
540
551
  const serve = this.make("http.serve");
541
- const port = preferedPort ?? env("PORT", 3e3);
552
+ const port = preferredPort ?? env("PORT", 3e3);
542
553
  const tries = env("RETRIES", 1);
543
554
  const hostname = env("HOSTNAME", "localhost");
544
555
  try {
@@ -561,6 +572,7 @@ var Application = class Application extends Container {
561
572
  [e.stack, "red"]
562
573
  ], "\n");
563
574
  }
575
+ return this;
564
576
  }
565
577
  /**
566
578
  * Get the base path of the app
@@ -659,6 +671,43 @@ var ConfigException = class extends Error {
659
671
  }
660
672
  };
661
673
 
674
+ //#endregion
675
+ //#region src/H3ravel.ts
676
+ /**
677
+ * Simple global entry point for H3ravel applications
678
+ *
679
+ * @param providers
680
+ * @param basePath
681
+ * @param callback
682
+ */
683
+ const h3ravel = async (providers = [], basePath = process.cwd(), config = {
684
+ initialize: false,
685
+ autoload: false,
686
+ filteredProviders: []
687
+ }, middleware = async () => void 0) => {
688
+ let h3App;
689
+ const app = new Application(basePath);
690
+ await app.quickStartup(providers, config.filteredProviders, config.autoload);
691
+ try {
692
+ h3App = app.make("http.app");
693
+ const kernel = new Kernel((event) => __h3ravel_shared.HttpContext.init({
694
+ app,
695
+ request: new __h3ravel_http.Request(event, app),
696
+ response: new __h3ravel_http.Response(event, app)
697
+ }), [new __h3ravel_http.LogRequests()]);
698
+ h3App.use((event) => kernel.handle(event, middleware));
699
+ } catch {
700
+ if (!h3App && config.h3) h3App = config.h3;
701
+ }
702
+ const originalFire = app.fire.bind(app);
703
+ if (config.initialize && h3App) return await originalFire(h3App);
704
+ app.fire = () => {
705
+ if (!h3App) throw new ConfigException("Provide a H3 app instance in the config or install @h3ravel/http");
706
+ return originalFire(h3App);
707
+ };
708
+ return app;
709
+ };
710
+
662
711
  //#endregion
663
712
  //#region src/Http/Kernel.ts
664
713
  /**
@@ -834,4 +883,5 @@ exports.Injectable = Injectable;
834
883
  exports.Kernel = Kernel;
835
884
  exports.ProviderRegistry = ProviderRegistry;
836
885
  exports.Registerer = Registerer;
837
- exports.ServiceProvider = ServiceProvider;
886
+ exports.ServiceProvider = ServiceProvider;
887
+ exports.h3ravel = h3ravel;
package/dist/index.d.cts CHANGED
@@ -2,10 +2,16 @@
2
2
  import { Bindings, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IServiceProvider, PathLoader, UseKey } from "@h3ravel/shared";
3
3
  import { H3, H3Event } from "h3";
4
4
 
5
+ //#region src/Contracts/ServiceProviderConstructor.d.ts
6
+ type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;
7
+ type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<ServiceProvider>;
8
+ type OServiceProvider = (new (_app: Application) => Partial<ServiceProvider>) & Partial<ServiceProvider>;
9
+ //#endregion
5
10
  //#region src/Container.d.ts
11
+ type IBinding = UseKey | (new (..._args: any[]) => unknown);
6
12
  declare class Container implements IContainer {
7
- private bindings;
8
- private singletons;
13
+ bindings: Map<IBinding, () => unknown>;
14
+ singletons: Map<IBinding, unknown>;
9
15
  /**
10
16
  * Check if the target has any decorators
11
17
  *
@@ -19,6 +25,10 @@ declare class Container implements IContainer {
19
25
  */
20
26
  bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
21
27
  bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
28
+ /**
29
+ * Remove one or more transient services from the container
30
+ */
31
+ unbind<T extends UseKey>(key: T | T[]): void;
22
32
  /**
23
33
  * Bind a singleton service to the container
24
34
  */
@@ -96,7 +106,6 @@ declare abstract class ServiceProvider extends Inference {
96
106
  }
97
107
  //#endregion
98
108
  //#region src/Application.d.ts
99
- type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<ServiceProvider>;
100
109
  declare class Application extends Container implements IApplication {
101
110
  paths: PathLoader;
102
111
  private tries;
@@ -181,7 +190,8 @@ declare class Application extends Container implements IApplication {
181
190
  * @param h3App The current H3 app instance
182
191
  * @param preferedPort If provided, this will overide the port set in the evironment
183
192
  */
184
- fire(h3App: H3, preferedPort?: number): Promise<void>;
193
+ fire(): Promise<this>;
194
+ fire(h3App: H3, preferredPort?: number): Promise<this>;
185
195
  /**
186
196
  * Get the base path of the app
187
197
  *
@@ -218,8 +228,32 @@ declare class Application extends Container implements IApplication {
218
228
  static getVersion(key: string): string;
219
229
  }
220
230
  //#endregion
221
- //#region src/Contracts/ServiceProviderConstructor.d.ts
222
- type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;
231
+ //#region src/Contracts/H3ravelContract.d.ts
232
+ interface EntryConfig {
233
+ /**
234
+ * @param h3 You can provide your own `H3` app instance, this is usefull when `@h3ravel/http`
235
+ * is not installed.
236
+ */
237
+ h3?: H3;
238
+ /**
239
+ * Determines if we should initialize the app on call.
240
+ *
241
+ * @default false
242
+ */
243
+ initialize?: boolean;
244
+ /**
245
+ * Determines if service providers should be auto discovered and registered or not.
246
+ *
247
+ * @default false
248
+ */
249
+ autoload?: boolean;
250
+ /**
251
+ * A list of service provider name strings we do not want to register at all cost
252
+ *
253
+ * @default []
254
+ */
255
+ filteredProviders?: string[];
256
+ }
223
257
  //#endregion
224
258
  //#region src/Controller.d.ts
225
259
  /**
@@ -258,6 +292,32 @@ declare class ConfigException extends Error {
258
292
  constructor(key: string, type?: 'any' | 'config' | 'env', cause?: unknown);
259
293
  }
260
294
  //#endregion
295
+ //#region src/H3ravel.d.ts
296
+ /**
297
+ * Simple global entry point for H3ravel applications
298
+ *
299
+ * @param providers
300
+ * @param basePath
301
+ * @param callback
302
+ */
303
+ declare const h3ravel: (
304
+ /**
305
+ * List of intial service providers to register with your app
306
+ */
307
+ providers?: Exclude<OServiceProvider, "app" | "commands">[],
308
+ /**
309
+ * Entry path of your app
310
+ */
311
+ basePath?: string,
312
+ /**
313
+ * Configuration option to pass to the initializer
314
+ */
315
+ config?: EntryConfig,
316
+ /**
317
+ * final middleware function to call once the server is fired up
318
+ */
319
+ middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
320
+ //#endregion
261
321
  //#region src/Http/Kernel.d.ts
262
322
  /**
263
323
  * Kernel class handles middleware execution and response transformations.
@@ -419,4 +479,4 @@ declare class Registerer {
419
479
  private databasePath;
420
480
  }
421
481
  //#endregion
422
- export { Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, ProviderRegistry, Registerer, ServiceProvider, ServiceProviderConstructor };
482
+ export { AServiceProvider, Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, EntryConfig, Inject, Injectable, Kernel, OServiceProvider, ProviderRegistry, Registerer, ServiceProvider, ServiceProviderConstructor, h3ravel };
package/dist/index.d.ts CHANGED
@@ -3,10 +3,16 @@ import "reflect-metadata";
3
3
  import { Bindings, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IServiceProvider, PathLoader, UseKey } from "@h3ravel/shared";
4
4
  import { H3, H3Event } from "h3";
5
5
 
6
+ //#region src/Contracts/ServiceProviderConstructor.d.ts
7
+ type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;
8
+ type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<ServiceProvider>;
9
+ type OServiceProvider = (new (_app: Application) => Partial<ServiceProvider>) & Partial<ServiceProvider>;
10
+ //#endregion
6
11
  //#region src/Container.d.ts
12
+ type IBinding = UseKey | (new (..._args: any[]) => unknown);
7
13
  declare class Container implements IContainer {
8
- private bindings;
9
- private singletons;
14
+ bindings: Map<IBinding, () => unknown>;
15
+ singletons: Map<IBinding, unknown>;
10
16
  /**
11
17
  * Check if the target has any decorators
12
18
  *
@@ -20,6 +26,10 @@ declare class Container implements IContainer {
20
26
  */
21
27
  bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
22
28
  bind<T extends UseKey>(key: T, factory: () => Bindings[T]): void;
29
+ /**
30
+ * Remove one or more transient services from the container
31
+ */
32
+ unbind<T extends UseKey>(key: T | T[]): void;
23
33
  /**
24
34
  * Bind a singleton service to the container
25
35
  */
@@ -97,7 +107,6 @@ declare abstract class ServiceProvider extends Inference {
97
107
  }
98
108
  //#endregion
99
109
  //#region src/Application.d.ts
100
- type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<ServiceProvider>;
101
110
  declare class Application extends Container implements IApplication {
102
111
  paths: PathLoader;
103
112
  private tries;
@@ -182,7 +191,8 @@ declare class Application extends Container implements IApplication {
182
191
  * @param h3App The current H3 app instance
183
192
  * @param preferedPort If provided, this will overide the port set in the evironment
184
193
  */
185
- fire(h3App: H3, preferedPort?: number): Promise<void>;
194
+ fire(): Promise<this>;
195
+ fire(h3App: H3, preferredPort?: number): Promise<this>;
186
196
  /**
187
197
  * Get the base path of the app
188
198
  *
@@ -219,8 +229,32 @@ declare class Application extends Container implements IApplication {
219
229
  static getVersion(key: string): string;
220
230
  }
221
231
  //#endregion
222
- //#region src/Contracts/ServiceProviderConstructor.d.ts
223
- type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;
232
+ //#region src/Contracts/H3ravelContract.d.ts
233
+ interface EntryConfig {
234
+ /**
235
+ * @param h3 You can provide your own `H3` app instance, this is usefull when `@h3ravel/http`
236
+ * is not installed.
237
+ */
238
+ h3?: H3;
239
+ /**
240
+ * Determines if we should initialize the app on call.
241
+ *
242
+ * @default false
243
+ */
244
+ initialize?: boolean;
245
+ /**
246
+ * Determines if service providers should be auto discovered and registered or not.
247
+ *
248
+ * @default false
249
+ */
250
+ autoload?: boolean;
251
+ /**
252
+ * A list of service provider name strings we do not want to register at all cost
253
+ *
254
+ * @default []
255
+ */
256
+ filteredProviders?: string[];
257
+ }
224
258
  //#endregion
225
259
  //#region src/Controller.d.ts
226
260
  /**
@@ -259,6 +293,32 @@ declare class ConfigException extends Error {
259
293
  constructor(key: string, type?: 'any' | 'config' | 'env', cause?: unknown);
260
294
  }
261
295
  //#endregion
296
+ //#region src/H3ravel.d.ts
297
+ /**
298
+ * Simple global entry point for H3ravel applications
299
+ *
300
+ * @param providers
301
+ * @param basePath
302
+ * @param callback
303
+ */
304
+ declare const h3ravel: (
305
+ /**
306
+ * List of intial service providers to register with your app
307
+ */
308
+ providers?: Exclude<OServiceProvider, "app" | "commands">[],
309
+ /**
310
+ * Entry path of your app
311
+ */
312
+ basePath?: string,
313
+ /**
314
+ * Configuration option to pass to the initializer
315
+ */
316
+ config?: EntryConfig,
317
+ /**
318
+ * final middleware function to call once the server is fired up
319
+ */
320
+ middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
321
+ //#endregion
262
322
  //#region src/Http/Kernel.d.ts
263
323
  /**
264
324
  * Kernel class handles middleware execution and response transformations.
@@ -420,4 +480,4 @@ declare class Registerer {
420
480
  private databasePath;
421
481
  }
422
482
  //#endregion
423
- export { Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, ProviderRegistry, Registerer, ServiceProvider, ServiceProviderConstructor };
483
+ export { AServiceProvider, Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, EntryConfig, Inject, Injectable, Kernel, OServiceProvider, ProviderRegistry, Registerer, ServiceProvider, ServiceProviderConstructor, h3ravel };
package/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import "reflect-metadata";
2
- import { FileSystem, Logger, PathLoader } from "@h3ravel/shared";
2
+ import { FileSystem, HttpContext, Logger, PathLoader } from "@h3ravel/shared";
3
+ import { InvalidArgumentException, Str, dd, dump, str } from "@h3ravel/support";
3
4
  import fg from "fast-glob";
4
5
  import path from "node:path";
5
- import { Str, dd, dump, str } from "@h3ravel/support";
6
6
  import { detect } from "detect-port";
7
7
  import dotenv from "dotenv";
8
8
  import dotenvExpand from "dotenv-expand";
9
9
  import { readFile } from "node:fs/promises";
10
10
  import semver from "semver";
11
+ import { LogRequests, Request, Response } from "@h3ravel/http";
11
12
 
12
13
  //#region src/Container.ts
13
14
  var Container = class {
@@ -23,6 +24,19 @@ var Container = class {
23
24
  this.bindings.set(key, factory);
24
25
  }
25
26
  /**
27
+ * Remove one or more transient services from the container
28
+ */
29
+ unbind(key) {
30
+ if (Array.isArray(key)) for (let i = 0; i < key.length; i++) {
31
+ this.bindings.delete(key[i]);
32
+ this.singletons.delete(key[i]);
33
+ }
34
+ else {
35
+ this.bindings.delete(key);
36
+ this.singletons.delete(key);
37
+ }
38
+ }
39
+ /**
26
40
  * Bind a singleton service to the container
27
41
  */
28
42
  singleton(key, factory) {
@@ -79,7 +93,8 @@ var ContainerResolver = class ContainerResolver {
79
93
  /**
80
94
  * Resolve the bound dependencies
81
95
  */
82
- const args = params.filter((e) => ContainerResolver.isClass(e)).map((type) => {
96
+ const args = params.filter((e) => ContainerResolver.isClass(e) || e instanceof Application).map((type) => {
97
+ if (type instanceof Application) return type;
83
98
  return this.app.make(type);
84
99
  });
85
100
  return new Promise((resolve) => {
@@ -261,13 +276,15 @@ var ProviderRegistry = class {
261
276
  "node_modules/h3ravel-*/package.json"
262
277
  ]);
263
278
  const providers = [];
264
- for (const manifestPath of manifests) {
265
- const pkg = await this.getManifest(path.resolve(manifestPath));
266
- 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])));
267
- }
268
- if (autoRegister) for (const provider of providers) {
269
- const key = this.getKey(provider);
270
- this.providers.set(key, provider);
279
+ if (autoRegister) {
280
+ for (const manifestPath of manifests) {
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.js")))[name])));
283
+ }
284
+ for (const provider of providers) {
285
+ const key = this.getKey(provider);
286
+ this.providers.set(key, provider);
287
+ }
271
288
  }
272
289
  return providers;
273
290
  }
@@ -427,13 +444,13 @@ var Application = class Application extends Container {
427
444
  ProviderRegistry.setSortable(false);
428
445
  ProviderRegistry.setFiltered(this.filteredProviders);
429
446
  ProviderRegistry.registerMany(providers);
430
- if (autoRegister) await ProviderRegistry.discoverProviders();
447
+ if (autoRegister) await ProviderRegistry.discoverProviders(autoRegister);
431
448
  ProviderRegistry.doSort();
432
- for (const ProviderClass of ProviderRegistry.all()) {
433
- if (!ProviderClass) continue;
449
+ ProviderRegistry.all().forEach(async (ProviderClass) => {
450
+ if (!ProviderClass) return;
434
451
  const provider = new ProviderClass(this);
435
452
  await this.register(provider);
436
- }
453
+ });
437
454
  }
438
455
  /**
439
456
  * Register service providers
@@ -481,7 +498,7 @@ var Application = class Application extends Container {
481
498
  /**
482
499
  * If debug is enabled, let's show the loaded service provider info
483
500
  */
484
- if (process.env.APP_DEBUG === "true" && process.env.EXTENDED_DEBUG !== "false" && !this.providers.some((e) => e.runsInConsole)) ProviderRegistry.log(this.providers);
501
+ if ((process.env.APP_DEBUG === "true" && process.env.EXTENDED_DEBUG !== "false" || Number(process.env.VERBOSE) > 1) && !this.providers.some((e) => e.runsInConsole)) ProviderRegistry.log(this.providers);
485
502
  for (const provider of this.providers) if (provider.boot) if (Container.hasAnyDecorator(provider.boot))
486
503
  /**
487
504
  * If the service provider is decorated use the IoC container
@@ -496,17 +513,10 @@ var Application = class Application extends Container {
496
513
  this.booted = true;
497
514
  return this;
498
515
  }
499
- /**
500
- * Fire up the developement server using the user provided arguments
501
- *
502
- * Port will be auto assigned if provided one is not available
503
- *
504
- * @param h3App The current H3 app instance
505
- * @param preferedPort If provided, this will overide the port set in the evironment
506
- */
507
- async fire(h3App, preferedPort) {
516
+ async fire(h3App, preferredPort) {
517
+ if (!h3App) throw new InvalidArgumentException("No valid H3 app instance was provided.");
508
518
  const serve = this.make("http.serve");
509
- const port = preferedPort ?? env("PORT", 3e3);
519
+ const port = preferredPort ?? env("PORT", 3e3);
510
520
  const tries = env("RETRIES", 1);
511
521
  const hostname = env("HOSTNAME", "localhost");
512
522
  try {
@@ -529,6 +539,7 @@ var Application = class Application extends Container {
529
539
  [e.stack, "red"]
530
540
  ], "\n");
531
541
  }
542
+ return this;
532
543
  }
533
544
  /**
534
545
  * Get the base path of the app
@@ -627,6 +638,43 @@ var ConfigException = class extends Error {
627
638
  }
628
639
  };
629
640
 
641
+ //#endregion
642
+ //#region src/H3ravel.ts
643
+ /**
644
+ * Simple global entry point for H3ravel applications
645
+ *
646
+ * @param providers
647
+ * @param basePath
648
+ * @param callback
649
+ */
650
+ const h3ravel = async (providers = [], basePath = process.cwd(), config = {
651
+ initialize: false,
652
+ autoload: false,
653
+ filteredProviders: []
654
+ }, middleware = async () => void 0) => {
655
+ let h3App;
656
+ const app = new Application(basePath);
657
+ await app.quickStartup(providers, config.filteredProviders, config.autoload);
658
+ try {
659
+ h3App = app.make("http.app");
660
+ const kernel = new Kernel((event) => HttpContext.init({
661
+ app,
662
+ request: new Request(event, app),
663
+ response: new Response(event, app)
664
+ }), [new LogRequests()]);
665
+ h3App.use((event) => kernel.handle(event, middleware));
666
+ } catch {
667
+ if (!h3App && config.h3) h3App = config.h3;
668
+ }
669
+ const originalFire = app.fire.bind(app);
670
+ if (config.initialize && h3App) return await originalFire(h3App);
671
+ app.fire = () => {
672
+ if (!h3App) throw new ConfigException("Provide a H3 app instance in the config or install @h3ravel/http");
673
+ return originalFire(h3App);
674
+ };
675
+ return app;
676
+ };
677
+
630
678
  //#endregion
631
679
  //#region src/Http/Kernel.ts
632
680
  /**
@@ -791,4 +839,4 @@ var CoreServiceProvider = class extends ServiceProvider {
791
839
  };
792
840
 
793
841
  //#endregion
794
- export { Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, ProviderRegistry, Registerer, ServiceProvider };
842
+ export { Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, ProviderRegistry, Registerer, ServiceProvider, h3ravel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/core",
3
- "version": "1.17.0",
3
+ "version": "1.18.1",
4
4
  "description": "Core application container, lifecycle management and service providers for H3ravel.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",