@h3ravel/core 1.18.0 → 1.19.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 +35 -14
- package/dist/index.d.cts +14 -4
- package/dist/index.d.ts +14 -4
- package/dist/index.js +35 -14
- 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) {
|
|
@@ -181,7 +194,7 @@ var ProviderRegistry = class {
|
|
|
181
194
|
}
|
|
182
195
|
}
|
|
183
196
|
/**
|
|
184
|
-
*
|
|
197
|
+
* Set the filtered providers.
|
|
185
198
|
*
|
|
186
199
|
* @returns
|
|
187
200
|
*/
|
|
@@ -367,6 +380,7 @@ var Application = class Application extends Container {
|
|
|
367
380
|
paths = new __h3ravel_shared.PathLoader();
|
|
368
381
|
tries = 0;
|
|
369
382
|
booted = false;
|
|
383
|
+
basePath;
|
|
370
384
|
versions = {
|
|
371
385
|
app: "0.0.0",
|
|
372
386
|
ts: "0.0.0"
|
|
@@ -375,7 +389,6 @@ var Application = class Application extends Container {
|
|
|
375
389
|
app: "0.0.0",
|
|
376
390
|
ts: "0.0.0"
|
|
377
391
|
};
|
|
378
|
-
basePath;
|
|
379
392
|
providers = [];
|
|
380
393
|
externalProviders = [];
|
|
381
394
|
filteredProviders = [];
|
|
@@ -466,11 +479,11 @@ var Application = class Application extends Container {
|
|
|
466
479
|
ProviderRegistry.registerMany(providers);
|
|
467
480
|
if (autoRegister) await ProviderRegistry.discoverProviders(autoRegister);
|
|
468
481
|
ProviderRegistry.doSort();
|
|
469
|
-
ProviderRegistry.all()
|
|
470
|
-
if (!ProviderClass)
|
|
482
|
+
for (const ProviderClass of ProviderRegistry.all()) {
|
|
483
|
+
if (!ProviderClass) continue;
|
|
471
484
|
const provider = new ProviderClass(this);
|
|
472
485
|
await this.register(provider);
|
|
473
|
-
}
|
|
486
|
+
}
|
|
474
487
|
}
|
|
475
488
|
/**
|
|
476
489
|
* Register service providers
|
|
@@ -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
|
*/
|
|
@@ -105,9 +110,9 @@ declare class Application extends Container implements IApplication {
|
|
|
105
110
|
paths: PathLoader;
|
|
106
111
|
private tries;
|
|
107
112
|
private booted;
|
|
113
|
+
private basePath;
|
|
108
114
|
private versions;
|
|
109
115
|
private static versions;
|
|
110
|
-
private basePath;
|
|
111
116
|
private providers;
|
|
112
117
|
protected externalProviders: Array<AServiceProvider>;
|
|
113
118
|
protected filteredProviders: Array<string>;
|
|
@@ -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
|
*
|
|
@@ -382,7 +392,7 @@ declare class ProviderRegistry {
|
|
|
382
392
|
*/
|
|
383
393
|
static registerMany(providers: ProviderCtor[]): void;
|
|
384
394
|
/**
|
|
385
|
-
*
|
|
395
|
+
* Set the filtered providers.
|
|
386
396
|
*
|
|
387
397
|
* @returns
|
|
388
398
|
*/
|
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
|
*/
|
|
@@ -106,9 +111,9 @@ declare class Application extends Container implements IApplication {
|
|
|
106
111
|
paths: PathLoader;
|
|
107
112
|
private tries;
|
|
108
113
|
private booted;
|
|
114
|
+
private basePath;
|
|
109
115
|
private versions;
|
|
110
116
|
private static versions;
|
|
111
|
-
private basePath;
|
|
112
117
|
private providers;
|
|
113
118
|
protected externalProviders: Array<AServiceProvider>;
|
|
114
119
|
protected filteredProviders: Array<string>;
|
|
@@ -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
|
*
|
|
@@ -383,7 +393,7 @@ declare class ProviderRegistry {
|
|
|
383
393
|
*/
|
|
384
394
|
static registerMany(providers: ProviderCtor[]): void;
|
|
385
395
|
/**
|
|
386
|
-
*
|
|
396
|
+
* Set the filtered providers.
|
|
387
397
|
*
|
|
388
398
|
* @returns
|
|
389
399
|
*/
|
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) {
|
|
@@ -148,7 +161,7 @@ var ProviderRegistry = class {
|
|
|
148
161
|
}
|
|
149
162
|
}
|
|
150
163
|
/**
|
|
151
|
-
*
|
|
164
|
+
* Set the filtered providers.
|
|
152
165
|
*
|
|
153
166
|
* @returns
|
|
154
167
|
*/
|
|
@@ -334,6 +347,7 @@ var Application = class Application extends Container {
|
|
|
334
347
|
paths = new PathLoader();
|
|
335
348
|
tries = 0;
|
|
336
349
|
booted = false;
|
|
350
|
+
basePath;
|
|
337
351
|
versions = {
|
|
338
352
|
app: "0.0.0",
|
|
339
353
|
ts: "0.0.0"
|
|
@@ -342,7 +356,6 @@ var Application = class Application extends Container {
|
|
|
342
356
|
app: "0.0.0",
|
|
343
357
|
ts: "0.0.0"
|
|
344
358
|
};
|
|
345
|
-
basePath;
|
|
346
359
|
providers = [];
|
|
347
360
|
externalProviders = [];
|
|
348
361
|
filteredProviders = [];
|
|
@@ -433,11 +446,11 @@ var Application = class Application extends Container {
|
|
|
433
446
|
ProviderRegistry.registerMany(providers);
|
|
434
447
|
if (autoRegister) await ProviderRegistry.discoverProviders(autoRegister);
|
|
435
448
|
ProviderRegistry.doSort();
|
|
436
|
-
ProviderRegistry.all()
|
|
437
|
-
if (!ProviderClass)
|
|
449
|
+
for (const ProviderClass of ProviderRegistry.all()) {
|
|
450
|
+
if (!ProviderClass) continue;
|
|
438
451
|
const provider = new ProviderClass(this);
|
|
439
452
|
await this.register(provider);
|
|
440
|
-
}
|
|
453
|
+
}
|
|
441
454
|
}
|
|
442
455
|
/**
|
|
443
456
|
* Register service providers
|
|
@@ -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
|
|