@fraqjs/fraq 0.6.1 → 0.6.2

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 CHANGED
@@ -5647,6 +5647,7 @@ interface Plugin<
5647
5647
  optionalInject?: OI;
5648
5648
  provides?: readonly ServiceClass[];
5649
5649
  apply(ctx: Context & InjectedServices<I> & OptionalInjectedServices<OI>, ...args: T): void | Promise<void>;
5650
+ start?(ctx: Context & InjectedServices<I> & OptionalInjectedServices<OI>): void | Promise<void>;
5650
5651
  }
5651
5652
  declare function definePlugin<
5652
5653
  T extends ParameterList,
@@ -5707,12 +5708,14 @@ declare class Context {
5707
5708
  private stopEventStream;
5708
5709
  private acceptsParentEvent;
5709
5710
  private applyPlugins;
5711
+ private startPlugins;
5710
5712
  private sortPlugins;
5711
5713
  private collectPendingProvidedServices;
5712
5714
  private areRequiredServicesAvailable;
5713
5715
  private areOptionalServicesReady;
5714
5716
  private collectAvailableServices;
5715
5717
  private createUnresolvablePluginError;
5718
+ private getPluginContext;
5716
5719
  private createProxyContextForPlugin;
5717
5720
  private runEventStream;
5718
5721
  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
- await this.applyPlugins();
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 { plugin, args } of this.sortPlugins()) {
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.createProxyContextForPlugin(plugin), ...args);
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fraqjs/fraq",
3
3
  "type": "module",
4
- "version": "0.6.1",
4
+ "version": "0.6.2",
5
5
  "description": "Milky Bot framework",
6
6
  "files": [
7
7
  "dist"