@fraqjs/fraq 0.6.1 → 0.6.3
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 +4 -0
- package/dist/index.mjs +28 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5593,6 +5593,7 @@ declare namespace filter {
|
|
|
5593
5593
|
function admin(): Filter;
|
|
5594
5594
|
function or(...filters: Filter[]): Filter;
|
|
5595
5595
|
function and(...filters: Filter[]): Filter;
|
|
5596
|
+
function not(filter: Filter): Filter;
|
|
5596
5597
|
}
|
|
5597
5598
|
//#endregion
|
|
5598
5599
|
//#region src/core/logging.d.ts
|
|
@@ -5647,6 +5648,7 @@ interface Plugin<
|
|
|
5647
5648
|
optionalInject?: OI;
|
|
5648
5649
|
provides?: readonly ServiceClass[];
|
|
5649
5650
|
apply(ctx: Context & InjectedServices<I> & OptionalInjectedServices<OI>, ...args: T): void | Promise<void>;
|
|
5651
|
+
start?(ctx: Context & InjectedServices<I> & OptionalInjectedServices<OI>): void | Promise<void>;
|
|
5650
5652
|
}
|
|
5651
5653
|
declare function definePlugin<
|
|
5652
5654
|
T extends ParameterList,
|
|
@@ -5707,12 +5709,14 @@ declare class Context {
|
|
|
5707
5709
|
private stopEventStream;
|
|
5708
5710
|
private acceptsParentEvent;
|
|
5709
5711
|
private applyPlugins;
|
|
5712
|
+
private startPlugins;
|
|
5710
5713
|
private sortPlugins;
|
|
5711
5714
|
private collectPendingProvidedServices;
|
|
5712
5715
|
private areRequiredServicesAvailable;
|
|
5713
5716
|
private areOptionalServicesReady;
|
|
5714
5717
|
private collectAvailableServices;
|
|
5715
5718
|
private createUnresolvablePluginError;
|
|
5719
|
+
private getPluginContext;
|
|
5716
5720
|
private createProxyContextForPlugin;
|
|
5717
5721
|
private runEventStream;
|
|
5718
5722
|
private waitForReconnectDelay;
|
package/dist/index.mjs
CHANGED
|
@@ -527,7 +527,9 @@ and implement the dispose method to clean up resources when the context stops.
|
|
|
527
527
|
}
|
|
528
528
|
async startInternal() {
|
|
529
529
|
try {
|
|
530
|
-
|
|
530
|
+
const sortedPlugins = this.sortPlugins();
|
|
531
|
+
await this.applyPlugins(sortedPlugins);
|
|
532
|
+
await this.startPlugins(sortedPlugins);
|
|
531
533
|
} catch (error) {
|
|
532
534
|
this.state = "idle";
|
|
533
535
|
throw error;
|
|
@@ -580,14 +582,23 @@ and implement the dispose method to clean up resources when the context stops.
|
|
|
580
582
|
const predicate = this.filter[type];
|
|
581
583
|
return predicate?.(event) === true;
|
|
582
584
|
}
|
|
583
|
-
async applyPlugins() {
|
|
584
|
-
for (const
|
|
585
|
+
async applyPlugins(sortedPlugins) {
|
|
586
|
+
for (const installedPlugin of sortedPlugins) {
|
|
587
|
+
const { plugin, args } = installedPlugin;
|
|
585
588
|
const providedBeforeApply = new Set(this.services.keys());
|
|
586
589
|
this.logger.debug(`Applying plugin ${plugin.name}`);
|
|
587
|
-
await plugin.apply(this.
|
|
590
|
+
await plugin.apply(this.getPluginContext(installedPlugin), ...args);
|
|
588
591
|
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.`);
|
|
589
592
|
}
|
|
590
593
|
}
|
|
594
|
+
async startPlugins(sortedPlugins) {
|
|
595
|
+
for (const installedPlugin of sortedPlugins) {
|
|
596
|
+
const { plugin } = installedPlugin;
|
|
597
|
+
if (!plugin.start) continue;
|
|
598
|
+
this.logger.debug(`Plugin ${plugin.name} is starting...`);
|
|
599
|
+
await plugin.start(this.getPluginContext(installedPlugin));
|
|
600
|
+
}
|
|
601
|
+
}
|
|
591
602
|
sortPlugins() {
|
|
592
603
|
const providers = /* @__PURE__ */ new Map();
|
|
593
604
|
for (const { plugin } of this.plugins) for (const service of plugin.provides ?? []) {
|
|
@@ -647,6 +658,10 @@ and implement the dispose method to clean up resources when the context stops.
|
|
|
647
658
|
});
|
|
648
659
|
return /* @__PURE__ */ new Error(`Unable to resolve plugin service dependencies: ${lines.join("; ")}.`);
|
|
649
660
|
}
|
|
661
|
+
getPluginContext(installedPlugin) {
|
|
662
|
+
installedPlugin.proxy ??= this.createProxyContextForPlugin(installedPlugin.plugin);
|
|
663
|
+
return installedPlugin.proxy;
|
|
664
|
+
}
|
|
650
665
|
createProxyContextForPlugin(plugin) {
|
|
651
666
|
const proxyLogger = new Logger((message) => this.logHandler?.(message), plugin.name);
|
|
652
667
|
let proxyInjections;
|
|
@@ -824,6 +839,15 @@ let filter;
|
|
|
824
839
|
return result;
|
|
825
840
|
}
|
|
826
841
|
_filter.and = and;
|
|
842
|
+
function not(filter) {
|
|
843
|
+
const result = {};
|
|
844
|
+
for (const key of eventKeys) result[key] = (event) => {
|
|
845
|
+
const predicate = filter[key];
|
|
846
|
+
return !predicate?.(event);
|
|
847
|
+
};
|
|
848
|
+
return result;
|
|
849
|
+
}
|
|
850
|
+
_filter.not = not;
|
|
827
851
|
})(filter || (filter = {}));
|
|
828
852
|
//#endregion
|
|
829
853
|
//#region src/core/plugin.ts
|