@h3ravel/core 1.18.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 +30 -9
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +30 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -57,6 +57,19 @@ var Container = class {
|
|
|
57
57
|
this.bindings.set(key, factory);
|
|
58
58
|
}
|
|
59
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
|
+
/**
|
|
60
73
|
* Bind a singleton service to the container
|
|
61
74
|
*/
|
|
62
75
|
singleton(key, factory) {
|
|
@@ -672,18 +685,26 @@ const h3ravel = async (providers = [], basePath = process.cwd(), config = {
|
|
|
672
685
|
autoload: false,
|
|
673
686
|
filteredProviders: []
|
|
674
687
|
}, middleware = async () => void 0) => {
|
|
688
|
+
let h3App;
|
|
675
689
|
const app = new Application(basePath);
|
|
676
690
|
await app.quickStartup(providers, config.filteredProviders, config.autoload);
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
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
|
+
}
|
|
684
702
|
const originalFire = app.fire.bind(app);
|
|
685
|
-
if (config.initialize) return await originalFire(h3App);
|
|
686
|
-
app.fire = () =>
|
|
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
|
+
};
|
|
687
708
|
return app;
|
|
688
709
|
};
|
|
689
710
|
|
package/dist/index.d.cts
CHANGED
|
@@ -8,9 +8,10 @@ type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<S
|
|
|
8
8
|
type OServiceProvider = (new (_app: Application) => Partial<ServiceProvider>) & Partial<ServiceProvider>;
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/Container.d.ts
|
|
11
|
+
type IBinding = UseKey | (new (..._args: any[]) => unknown);
|
|
11
12
|
declare class Container implements IContainer {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
bindings: Map<IBinding, () => unknown>;
|
|
14
|
+
singletons: Map<IBinding, unknown>;
|
|
14
15
|
/**
|
|
15
16
|
* Check if the target has any decorators
|
|
16
17
|
*
|
|
@@ -24,6 +25,10 @@ declare class Container implements IContainer {
|
|
|
24
25
|
*/
|
|
25
26
|
bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
|
|
26
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;
|
|
27
32
|
/**
|
|
28
33
|
* Bind a singleton service to the container
|
|
29
34
|
*/
|
|
@@ -225,6 +230,11 @@ declare class Application extends Container implements IApplication {
|
|
|
225
230
|
//#endregion
|
|
226
231
|
//#region src/Contracts/H3ravelContract.d.ts
|
|
227
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;
|
|
228
238
|
/**
|
|
229
239
|
* Determines if we should initialize the app on call.
|
|
230
240
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -9,9 +9,10 @@ type AServiceProvider = (new (_app: Application) => ServiceProvider) & Partial<S
|
|
|
9
9
|
type OServiceProvider = (new (_app: Application) => Partial<ServiceProvider>) & Partial<ServiceProvider>;
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/Container.d.ts
|
|
12
|
+
type IBinding = UseKey | (new (..._args: any[]) => unknown);
|
|
12
13
|
declare class Container implements IContainer {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
bindings: Map<IBinding, () => unknown>;
|
|
15
|
+
singletons: Map<IBinding, unknown>;
|
|
15
16
|
/**
|
|
16
17
|
* Check if the target has any decorators
|
|
17
18
|
*
|
|
@@ -25,6 +26,10 @@ declare class Container implements IContainer {
|
|
|
25
26
|
*/
|
|
26
27
|
bind<T>(key: new (...args: any[]) => T, factory: () => T): void;
|
|
27
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;
|
|
28
33
|
/**
|
|
29
34
|
* Bind a singleton service to the container
|
|
30
35
|
*/
|
|
@@ -226,6 +231,11 @@ declare class Application extends Container implements IApplication {
|
|
|
226
231
|
//#endregion
|
|
227
232
|
//#region src/Contracts/H3ravelContract.d.ts
|
|
228
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;
|
|
229
239
|
/**
|
|
230
240
|
* Determines if we should initialize the app on call.
|
|
231
241
|
*
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,19 @@ var Container = class {
|
|
|
24
24
|
this.bindings.set(key, factory);
|
|
25
25
|
}
|
|
26
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
|
+
/**
|
|
27
40
|
* Bind a singleton service to the container
|
|
28
41
|
*/
|
|
29
42
|
singleton(key, factory) {
|
|
@@ -639,18 +652,26 @@ const h3ravel = async (providers = [], basePath = process.cwd(), config = {
|
|
|
639
652
|
autoload: false,
|
|
640
653
|
filteredProviders: []
|
|
641
654
|
}, middleware = async () => void 0) => {
|
|
655
|
+
let h3App;
|
|
642
656
|
const app = new Application(basePath);
|
|
643
657
|
await app.quickStartup(providers, config.filteredProviders, config.autoload);
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
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
|
+
}
|
|
651
669
|
const originalFire = app.fire.bind(app);
|
|
652
|
-
if (config.initialize) return await originalFire(h3App);
|
|
653
|
-
app.fire = () =>
|
|
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
|
+
};
|
|
654
675
|
return app;
|
|
655
676
|
};
|
|
656
677
|
|