@fraqjs/fraq 0.6.0 → 0.6.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.d.mts +2 -0
- package/dist/index.mjs +13 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5624,6 +5624,7 @@ interface Disposable {
|
|
|
5624
5624
|
dispose(): void | Promise<void>;
|
|
5625
5625
|
}
|
|
5626
5626
|
declare function isDisposable(service: object): service is Disposable;
|
|
5627
|
+
declare function implementsESNextDisposable(service: object): boolean;
|
|
5627
5628
|
//#endregion
|
|
5628
5629
|
//#region src/core/plugin.d.ts
|
|
5629
5630
|
type ParameterList = Array<any>;
|
|
@@ -5794,6 +5795,7 @@ export {
|
|
|
5794
5795
|
createMilkyClient,
|
|
5795
5796
|
definePlugin,
|
|
5796
5797
|
filter,
|
|
5798
|
+
implementsESNextDisposable,
|
|
5797
5799
|
isDisposable,
|
|
5798
5800
|
type types_d_exports as milky,
|
|
5799
5801
|
milkyPackageVersion,
|
package/dist/index.mjs
CHANGED
|
@@ -363,6 +363,9 @@ function combineLogHandlers(...handlers) {
|
|
|
363
363
|
function isDisposable(service) {
|
|
364
364
|
return "dispose" in service && typeof service.dispose === "function";
|
|
365
365
|
}
|
|
366
|
+
function implementsESNextDisposable(service) {
|
|
367
|
+
return Symbol.dispose in service && typeof service[Symbol.dispose] === "function";
|
|
368
|
+
}
|
|
366
369
|
//#endregion
|
|
367
370
|
//#region src/core/context.ts
|
|
368
371
|
const DEFAULT_INITIAL_RECONNECT_DELAY_MS = 1e3;
|
|
@@ -436,6 +439,14 @@ var Context = class Context {
|
|
|
436
439
|
}
|
|
437
440
|
provide(service, instance) {
|
|
438
441
|
if (this.services.has(service)) throw new Error(`Service ${service.name} has already been provided in this context.`);
|
|
442
|
+
if (implementsESNextDisposable(instance) && !isDisposable(instance)) throw new Error(`
|
|
443
|
+
Service ${service.name} implements ESNext Disposable but not Fraq Disposable.
|
|
444
|
+
Please explicitly import the interface like this:
|
|
445
|
+
|
|
446
|
+
import type { Disposable } from '@fraqjs/fraq';
|
|
447
|
+
|
|
448
|
+
and implement the dispose method to clean up resources when the context stops.
|
|
449
|
+
`.trim());
|
|
439
450
|
this.services.set(service, instance);
|
|
440
451
|
}
|
|
441
452
|
resolve(service) {
|
|
@@ -572,10 +583,9 @@ var Context = class Context {
|
|
|
572
583
|
async applyPlugins() {
|
|
573
584
|
for (const { plugin, args } of this.sortPlugins()) {
|
|
574
585
|
const providedBeforeApply = new Set(this.services.keys());
|
|
575
|
-
this.logger.
|
|
586
|
+
this.logger.debug(`Applying plugin ${plugin.name}`);
|
|
576
587
|
await plugin.apply(this.createProxyContextForPlugin(plugin), ...args);
|
|
577
588
|
for (const service of plugin.provides ?? []) if (!this.services.has(service) || providedBeforeApply.has(service)) throw new Error(`${plugin.name} declares service ${service.name} but did not provide it.`);
|
|
578
|
-
this.logger.debug(`Applied plugin ${plugin.name}`);
|
|
579
589
|
}
|
|
580
590
|
}
|
|
581
591
|
sortPlugins() {
|
|
@@ -1088,4 +1098,4 @@ let param;
|
|
|
1088
1098
|
_param.segment = segment;
|
|
1089
1099
|
})(param || (param = {}));
|
|
1090
1100
|
//#endregion
|
|
1091
|
-
export { Context, Logger, Parameter, Router, combineLogHandlers, createMilkyClient, definePlugin, filter, isDisposable, milkyPackageVersion, milkyVersion, msg, param, seg };
|
|
1101
|
+
export { Context, Logger, Parameter, Router, combineLogHandlers, createMilkyClient, definePlugin, filter, implementsESNextDisposable, isDisposable, milkyPackageVersion, milkyVersion, msg, param, seg };
|