@h3ravel/core 1.17.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +55 -26
- package/dist/index.d.cts +55 -5
- package/dist/index.d.ts +55 -5
- package/dist/index.js +53 -26
- package/package.json +1 -1
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 {
|
|
@@ -111,7 +113,8 @@ var ContainerResolver = class ContainerResolver {
|
|
|
111
113
|
/**
|
|
112
114
|
* Resolve the bound dependencies
|
|
113
115
|
*/
|
|
114
|
-
const args = params.filter((e) => ContainerResolver.isClass(e)).map((type) => {
|
|
116
|
+
const args = params.filter((e) => ContainerResolver.isClass(e) || e instanceof Application).map((type) => {
|
|
117
|
+
if (type instanceof Application) return type;
|
|
115
118
|
return this.app.make(type);
|
|
116
119
|
});
|
|
117
120
|
return new Promise((resolve) => {
|
|
@@ -293,13 +296,15 @@ var ProviderRegistry = class {
|
|
|
293
296
|
"node_modules/h3ravel-*/package.json"
|
|
294
297
|
]);
|
|
295
298
|
const providers = [];
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const
|
|
302
|
-
|
|
299
|
+
if (autoRegister) {
|
|
300
|
+
for (const manifestPath of manifests) {
|
|
301
|
+
const pkg = await this.getManifest(node_path.default.resolve(manifestPath));
|
|
302
|
+
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])));
|
|
303
|
+
}
|
|
304
|
+
for (const provider of providers) {
|
|
305
|
+
const key = this.getKey(provider);
|
|
306
|
+
this.providers.set(key, provider);
|
|
307
|
+
}
|
|
303
308
|
}
|
|
304
309
|
return providers;
|
|
305
310
|
}
|
|
@@ -459,13 +464,13 @@ var Application = class Application extends Container {
|
|
|
459
464
|
ProviderRegistry.setSortable(false);
|
|
460
465
|
ProviderRegistry.setFiltered(this.filteredProviders);
|
|
461
466
|
ProviderRegistry.registerMany(providers);
|
|
462
|
-
if (autoRegister) await ProviderRegistry.discoverProviders();
|
|
467
|
+
if (autoRegister) await ProviderRegistry.discoverProviders(autoRegister);
|
|
463
468
|
ProviderRegistry.doSort();
|
|
464
|
-
|
|
465
|
-
if (!ProviderClass)
|
|
469
|
+
ProviderRegistry.all().forEach(async (ProviderClass) => {
|
|
470
|
+
if (!ProviderClass) return;
|
|
466
471
|
const provider = new ProviderClass(this);
|
|
467
472
|
await this.register(provider);
|
|
468
|
-
}
|
|
473
|
+
});
|
|
469
474
|
}
|
|
470
475
|
/**
|
|
471
476
|
* Register service providers
|
|
@@ -513,7 +518,7 @@ var Application = class Application extends Container {
|
|
|
513
518
|
/**
|
|
514
519
|
* If debug is enabled, let's show the loaded service provider info
|
|
515
520
|
*/
|
|
516
|
-
if (process.env.APP_DEBUG === "true" && process.env.EXTENDED_DEBUG !== "false" && !this.providers.some((e) => e.runsInConsole)) ProviderRegistry.log(this.providers);
|
|
521
|
+
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
522
|
for (const provider of this.providers) if (provider.boot) if (Container.hasAnyDecorator(provider.boot))
|
|
518
523
|
/**
|
|
519
524
|
* If the service provider is decorated use the IoC container
|
|
@@ -528,17 +533,10 @@ var Application = class Application extends Container {
|
|
|
528
533
|
this.booted = true;
|
|
529
534
|
return this;
|
|
530
535
|
}
|
|
531
|
-
|
|
532
|
-
|
|
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) {
|
|
536
|
+
async fire(h3App, preferredPort) {
|
|
537
|
+
if (!h3App) throw new __h3ravel_support.InvalidArgumentException("No valid H3 app instance was provided.");
|
|
540
538
|
const serve = this.make("http.serve");
|
|
541
|
-
const port =
|
|
539
|
+
const port = preferredPort ?? env("PORT", 3e3);
|
|
542
540
|
const tries = env("RETRIES", 1);
|
|
543
541
|
const hostname = env("HOSTNAME", "localhost");
|
|
544
542
|
try {
|
|
@@ -561,6 +559,7 @@ var Application = class Application extends Container {
|
|
|
561
559
|
[e.stack, "red"]
|
|
562
560
|
], "\n");
|
|
563
561
|
}
|
|
562
|
+
return this;
|
|
564
563
|
}
|
|
565
564
|
/**
|
|
566
565
|
* Get the base path of the app
|
|
@@ -659,6 +658,35 @@ var ConfigException = class extends Error {
|
|
|
659
658
|
}
|
|
660
659
|
};
|
|
661
660
|
|
|
661
|
+
//#endregion
|
|
662
|
+
//#region src/H3ravel.ts
|
|
663
|
+
/**
|
|
664
|
+
* Simple global entry point for H3ravel applications
|
|
665
|
+
*
|
|
666
|
+
* @param providers
|
|
667
|
+
* @param basePath
|
|
668
|
+
* @param callback
|
|
669
|
+
*/
|
|
670
|
+
const h3ravel = async (providers = [], basePath = process.cwd(), config = {
|
|
671
|
+
initialize: false,
|
|
672
|
+
autoload: false,
|
|
673
|
+
filteredProviders: []
|
|
674
|
+
}, middleware = async () => void 0) => {
|
|
675
|
+
const app = new Application(basePath);
|
|
676
|
+
await app.quickStartup(providers, config.filteredProviders, config.autoload);
|
|
677
|
+
const h3App = app.make("http.app");
|
|
678
|
+
const kernel = new Kernel((event) => __h3ravel_shared.HttpContext.init({
|
|
679
|
+
app,
|
|
680
|
+
request: new __h3ravel_http.Request(event, app),
|
|
681
|
+
response: new __h3ravel_http.Response(event, app)
|
|
682
|
+
}), [new __h3ravel_http.LogRequests()]);
|
|
683
|
+
h3App.use((event) => kernel.handle(event, middleware));
|
|
684
|
+
const originalFire = app.fire.bind(app);
|
|
685
|
+
if (config.initialize) return await originalFire(h3App);
|
|
686
|
+
app.fire = () => originalFire(h3App);
|
|
687
|
+
return app;
|
|
688
|
+
};
|
|
689
|
+
|
|
662
690
|
//#endregion
|
|
663
691
|
//#region src/Http/Kernel.ts
|
|
664
692
|
/**
|
|
@@ -834,4 +862,5 @@ exports.Injectable = Injectable;
|
|
|
834
862
|
exports.Kernel = Kernel;
|
|
835
863
|
exports.ProviderRegistry = ProviderRegistry;
|
|
836
864
|
exports.Registerer = Registerer;
|
|
837
|
-
exports.ServiceProvider = ServiceProvider;
|
|
865
|
+
exports.ServiceProvider = ServiceProvider;
|
|
866
|
+
exports.h3ravel = h3ravel;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
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
|
|
6
11
|
declare class Container implements IContainer {
|
|
7
12
|
private bindings;
|
|
@@ -96,7 +101,6 @@ declare abstract class ServiceProvider extends Inference {
|
|
|
96
101
|
}
|
|
97
102
|
//#endregion
|
|
98
103
|
//#region src/Application.d.ts
|
|
99
|
-
type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<ServiceProvider>;
|
|
100
104
|
declare class Application extends Container implements IApplication {
|
|
101
105
|
paths: PathLoader;
|
|
102
106
|
private tries;
|
|
@@ -181,7 +185,8 @@ declare class Application extends Container implements IApplication {
|
|
|
181
185
|
* @param h3App The current H3 app instance
|
|
182
186
|
* @param preferedPort If provided, this will overide the port set in the evironment
|
|
183
187
|
*/
|
|
184
|
-
fire(
|
|
188
|
+
fire(): Promise<this>;
|
|
189
|
+
fire(h3App: H3, preferredPort?: number): Promise<this>;
|
|
185
190
|
/**
|
|
186
191
|
* Get the base path of the app
|
|
187
192
|
*
|
|
@@ -218,8 +223,27 @@ declare class Application extends Container implements IApplication {
|
|
|
218
223
|
static getVersion(key: string): string;
|
|
219
224
|
}
|
|
220
225
|
//#endregion
|
|
221
|
-
//#region src/Contracts/
|
|
222
|
-
|
|
226
|
+
//#region src/Contracts/H3ravelContract.d.ts
|
|
227
|
+
interface EntryConfig {
|
|
228
|
+
/**
|
|
229
|
+
* Determines if we should initialize the app on call.
|
|
230
|
+
*
|
|
231
|
+
* @default false
|
|
232
|
+
*/
|
|
233
|
+
initialize?: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Determines if service providers should be auto discovered and registered or not.
|
|
236
|
+
*
|
|
237
|
+
* @default false
|
|
238
|
+
*/
|
|
239
|
+
autoload?: boolean;
|
|
240
|
+
/**
|
|
241
|
+
* A list of service provider name strings we do not want to register at all cost
|
|
242
|
+
*
|
|
243
|
+
* @default []
|
|
244
|
+
*/
|
|
245
|
+
filteredProviders?: string[];
|
|
246
|
+
}
|
|
223
247
|
//#endregion
|
|
224
248
|
//#region src/Controller.d.ts
|
|
225
249
|
/**
|
|
@@ -258,6 +282,32 @@ declare class ConfigException extends Error {
|
|
|
258
282
|
constructor(key: string, type?: 'any' | 'config' | 'env', cause?: unknown);
|
|
259
283
|
}
|
|
260
284
|
//#endregion
|
|
285
|
+
//#region src/H3ravel.d.ts
|
|
286
|
+
/**
|
|
287
|
+
* Simple global entry point for H3ravel applications
|
|
288
|
+
*
|
|
289
|
+
* @param providers
|
|
290
|
+
* @param basePath
|
|
291
|
+
* @param callback
|
|
292
|
+
*/
|
|
293
|
+
declare const h3ravel: (
|
|
294
|
+
/**
|
|
295
|
+
* List of intial service providers to register with your app
|
|
296
|
+
*/
|
|
297
|
+
providers?: Exclude<OServiceProvider, "app" | "commands">[],
|
|
298
|
+
/**
|
|
299
|
+
* Entry path of your app
|
|
300
|
+
*/
|
|
301
|
+
basePath?: string,
|
|
302
|
+
/**
|
|
303
|
+
* Configuration option to pass to the initializer
|
|
304
|
+
*/
|
|
305
|
+
config?: EntryConfig,
|
|
306
|
+
/**
|
|
307
|
+
* final middleware function to call once the server is fired up
|
|
308
|
+
*/
|
|
309
|
+
middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
|
|
310
|
+
//#endregion
|
|
261
311
|
//#region src/Http/Kernel.d.ts
|
|
262
312
|
/**
|
|
263
313
|
* Kernel class handles middleware execution and response transformations.
|
|
@@ -419,4 +469,4 @@ declare class Registerer {
|
|
|
419
469
|
private databasePath;
|
|
420
470
|
}
|
|
421
471
|
//#endregion
|
|
422
|
-
export { Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, ProviderRegistry, Registerer, ServiceProvider, ServiceProviderConstructor };
|
|
472
|
+
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,6 +3,11 @@ 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
|
|
7
12
|
declare class Container implements IContainer {
|
|
8
13
|
private bindings;
|
|
@@ -97,7 +102,6 @@ declare abstract class ServiceProvider extends Inference {
|
|
|
97
102
|
}
|
|
98
103
|
//#endregion
|
|
99
104
|
//#region src/Application.d.ts
|
|
100
|
-
type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<ServiceProvider>;
|
|
101
105
|
declare class Application extends Container implements IApplication {
|
|
102
106
|
paths: PathLoader;
|
|
103
107
|
private tries;
|
|
@@ -182,7 +186,8 @@ declare class Application extends Container implements IApplication {
|
|
|
182
186
|
* @param h3App The current H3 app instance
|
|
183
187
|
* @param preferedPort If provided, this will overide the port set in the evironment
|
|
184
188
|
*/
|
|
185
|
-
fire(
|
|
189
|
+
fire(): Promise<this>;
|
|
190
|
+
fire(h3App: H3, preferredPort?: number): Promise<this>;
|
|
186
191
|
/**
|
|
187
192
|
* Get the base path of the app
|
|
188
193
|
*
|
|
@@ -219,8 +224,27 @@ declare class Application extends Container implements IApplication {
|
|
|
219
224
|
static getVersion(key: string): string;
|
|
220
225
|
}
|
|
221
226
|
//#endregion
|
|
222
|
-
//#region src/Contracts/
|
|
223
|
-
|
|
227
|
+
//#region src/Contracts/H3ravelContract.d.ts
|
|
228
|
+
interface EntryConfig {
|
|
229
|
+
/**
|
|
230
|
+
* Determines if we should initialize the app on call.
|
|
231
|
+
*
|
|
232
|
+
* @default false
|
|
233
|
+
*/
|
|
234
|
+
initialize?: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Determines if service providers should be auto discovered and registered or not.
|
|
237
|
+
*
|
|
238
|
+
* @default false
|
|
239
|
+
*/
|
|
240
|
+
autoload?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* A list of service provider name strings we do not want to register at all cost
|
|
243
|
+
*
|
|
244
|
+
* @default []
|
|
245
|
+
*/
|
|
246
|
+
filteredProviders?: string[];
|
|
247
|
+
}
|
|
224
248
|
//#endregion
|
|
225
249
|
//#region src/Controller.d.ts
|
|
226
250
|
/**
|
|
@@ -259,6 +283,32 @@ declare class ConfigException extends Error {
|
|
|
259
283
|
constructor(key: string, type?: 'any' | 'config' | 'env', cause?: unknown);
|
|
260
284
|
}
|
|
261
285
|
//#endregion
|
|
286
|
+
//#region src/H3ravel.d.ts
|
|
287
|
+
/**
|
|
288
|
+
* Simple global entry point for H3ravel applications
|
|
289
|
+
*
|
|
290
|
+
* @param providers
|
|
291
|
+
* @param basePath
|
|
292
|
+
* @param callback
|
|
293
|
+
*/
|
|
294
|
+
declare const h3ravel: (
|
|
295
|
+
/**
|
|
296
|
+
* List of intial service providers to register with your app
|
|
297
|
+
*/
|
|
298
|
+
providers?: Exclude<OServiceProvider, "app" | "commands">[],
|
|
299
|
+
/**
|
|
300
|
+
* Entry path of your app
|
|
301
|
+
*/
|
|
302
|
+
basePath?: string,
|
|
303
|
+
/**
|
|
304
|
+
* Configuration option to pass to the initializer
|
|
305
|
+
*/
|
|
306
|
+
config?: EntryConfig,
|
|
307
|
+
/**
|
|
308
|
+
* final middleware function to call once the server is fired up
|
|
309
|
+
*/
|
|
310
|
+
middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
|
|
311
|
+
//#endregion
|
|
262
312
|
//#region src/Http/Kernel.d.ts
|
|
263
313
|
/**
|
|
264
314
|
* Kernel class handles middleware execution and response transformations.
|
|
@@ -420,4 +470,4 @@ declare class Registerer {
|
|
|
420
470
|
private databasePath;
|
|
421
471
|
}
|
|
422
472
|
//#endregion
|
|
423
|
-
export { Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, ProviderRegistry, Registerer, ServiceProvider, ServiceProviderConstructor };
|
|
473
|
+
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 {
|
|
@@ -79,7 +80,8 @@ var ContainerResolver = class ContainerResolver {
|
|
|
79
80
|
/**
|
|
80
81
|
* Resolve the bound dependencies
|
|
81
82
|
*/
|
|
82
|
-
const args = params.filter((e) => ContainerResolver.isClass(e)).map((type) => {
|
|
83
|
+
const args = params.filter((e) => ContainerResolver.isClass(e) || e instanceof Application).map((type) => {
|
|
84
|
+
if (type instanceof Application) return type;
|
|
83
85
|
return this.app.make(type);
|
|
84
86
|
});
|
|
85
87
|
return new Promise((resolve) => {
|
|
@@ -261,13 +263,15 @@ var ProviderRegistry = class {
|
|
|
261
263
|
"node_modules/h3ravel-*/package.json"
|
|
262
264
|
]);
|
|
263
265
|
const providers = [];
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
|
|
266
|
+
if (autoRegister) {
|
|
267
|
+
for (const manifestPath of manifests) {
|
|
268
|
+
const pkg = await this.getManifest(path.resolve(manifestPath));
|
|
269
|
+
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])));
|
|
270
|
+
}
|
|
271
|
+
for (const provider of providers) {
|
|
272
|
+
const key = this.getKey(provider);
|
|
273
|
+
this.providers.set(key, provider);
|
|
274
|
+
}
|
|
271
275
|
}
|
|
272
276
|
return providers;
|
|
273
277
|
}
|
|
@@ -427,13 +431,13 @@ var Application = class Application extends Container {
|
|
|
427
431
|
ProviderRegistry.setSortable(false);
|
|
428
432
|
ProviderRegistry.setFiltered(this.filteredProviders);
|
|
429
433
|
ProviderRegistry.registerMany(providers);
|
|
430
|
-
if (autoRegister) await ProviderRegistry.discoverProviders();
|
|
434
|
+
if (autoRegister) await ProviderRegistry.discoverProviders(autoRegister);
|
|
431
435
|
ProviderRegistry.doSort();
|
|
432
|
-
|
|
433
|
-
if (!ProviderClass)
|
|
436
|
+
ProviderRegistry.all().forEach(async (ProviderClass) => {
|
|
437
|
+
if (!ProviderClass) return;
|
|
434
438
|
const provider = new ProviderClass(this);
|
|
435
439
|
await this.register(provider);
|
|
436
|
-
}
|
|
440
|
+
});
|
|
437
441
|
}
|
|
438
442
|
/**
|
|
439
443
|
* Register service providers
|
|
@@ -481,7 +485,7 @@ var Application = class Application extends Container {
|
|
|
481
485
|
/**
|
|
482
486
|
* If debug is enabled, let's show the loaded service provider info
|
|
483
487
|
*/
|
|
484
|
-
if (process.env.APP_DEBUG === "true" && process.env.EXTENDED_DEBUG !== "false" && !this.providers.some((e) => e.runsInConsole)) ProviderRegistry.log(this.providers);
|
|
488
|
+
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
489
|
for (const provider of this.providers) if (provider.boot) if (Container.hasAnyDecorator(provider.boot))
|
|
486
490
|
/**
|
|
487
491
|
* If the service provider is decorated use the IoC container
|
|
@@ -496,17 +500,10 @@ var Application = class Application extends Container {
|
|
|
496
500
|
this.booted = true;
|
|
497
501
|
return this;
|
|
498
502
|
}
|
|
499
|
-
|
|
500
|
-
|
|
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) {
|
|
503
|
+
async fire(h3App, preferredPort) {
|
|
504
|
+
if (!h3App) throw new InvalidArgumentException("No valid H3 app instance was provided.");
|
|
508
505
|
const serve = this.make("http.serve");
|
|
509
|
-
const port =
|
|
506
|
+
const port = preferredPort ?? env("PORT", 3e3);
|
|
510
507
|
const tries = env("RETRIES", 1);
|
|
511
508
|
const hostname = env("HOSTNAME", "localhost");
|
|
512
509
|
try {
|
|
@@ -529,6 +526,7 @@ var Application = class Application extends Container {
|
|
|
529
526
|
[e.stack, "red"]
|
|
530
527
|
], "\n");
|
|
531
528
|
}
|
|
529
|
+
return this;
|
|
532
530
|
}
|
|
533
531
|
/**
|
|
534
532
|
* Get the base path of the app
|
|
@@ -627,6 +625,35 @@ var ConfigException = class extends Error {
|
|
|
627
625
|
}
|
|
628
626
|
};
|
|
629
627
|
|
|
628
|
+
//#endregion
|
|
629
|
+
//#region src/H3ravel.ts
|
|
630
|
+
/**
|
|
631
|
+
* Simple global entry point for H3ravel applications
|
|
632
|
+
*
|
|
633
|
+
* @param providers
|
|
634
|
+
* @param basePath
|
|
635
|
+
* @param callback
|
|
636
|
+
*/
|
|
637
|
+
const h3ravel = async (providers = [], basePath = process.cwd(), config = {
|
|
638
|
+
initialize: false,
|
|
639
|
+
autoload: false,
|
|
640
|
+
filteredProviders: []
|
|
641
|
+
}, middleware = async () => void 0) => {
|
|
642
|
+
const app = new Application(basePath);
|
|
643
|
+
await app.quickStartup(providers, config.filteredProviders, config.autoload);
|
|
644
|
+
const h3App = app.make("http.app");
|
|
645
|
+
const kernel = new Kernel((event) => HttpContext.init({
|
|
646
|
+
app,
|
|
647
|
+
request: new Request(event, app),
|
|
648
|
+
response: new Response(event, app)
|
|
649
|
+
}), [new LogRequests()]);
|
|
650
|
+
h3App.use((event) => kernel.handle(event, middleware));
|
|
651
|
+
const originalFire = app.fire.bind(app);
|
|
652
|
+
if (config.initialize) return await originalFire(h3App);
|
|
653
|
+
app.fire = () => originalFire(h3App);
|
|
654
|
+
return app;
|
|
655
|
+
};
|
|
656
|
+
|
|
630
657
|
//#endregion
|
|
631
658
|
//#region src/Http/Kernel.ts
|
|
632
659
|
/**
|
|
@@ -791,4 +818,4 @@ var CoreServiceProvider = class extends ServiceProvider {
|
|
|
791
818
|
};
|
|
792
819
|
|
|
793
820
|
//#endregion
|
|
794
|
-
export { Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, ProviderRegistry, Registerer, ServiceProvider };
|
|
821
|
+
export { Application, ConfigException, Container, ContainerResolver, Controller, CoreServiceProvider, Inject, Injectable, Kernel, ProviderRegistry, Registerer, ServiceProvider, h3ravel };
|