@fraqjs/fraq 0.6.3 → 0.6.4

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
@@ -5709,7 +5709,9 @@ declare class Context {
5709
5709
  private stopEventStream;
5710
5710
  private acceptsParentEvent;
5711
5711
  private applyPlugins;
5712
+ private recursiveApplyPlugins;
5712
5713
  private startPlugins;
5714
+ private recursiveStartPlugins;
5713
5715
  private sortPlugins;
5714
5716
  private collectPendingProvidedServices;
5715
5717
  private areRequiredServicesAvailable;
package/dist/index.mjs CHANGED
@@ -526,16 +526,16 @@ and implement the dispose method to clean up resources when the context stops.
526
526
  }
527
527
  }
528
528
  async startInternal() {
529
+ const appliedContextPlugins = [];
530
+ const startingContexts = [];
529
531
  try {
530
- const sortedPlugins = this.sortPlugins();
531
- await this.applyPlugins(sortedPlugins);
532
- await this.startPlugins(sortedPlugins);
532
+ await this.recursiveApplyPlugins(appliedContextPlugins, startingContexts);
533
+ await this.recursiveStartPlugins(appliedContextPlugins);
533
534
  } catch (error) {
534
- this.state = "idle";
535
+ for (const context of startingContexts) if (context.state === "starting") context.state = "idle";
535
536
  throw error;
536
537
  }
537
- for (const subContext of this.subContexts) await subContext.start();
538
- this.state = "started";
538
+ for (const { context } of appliedContextPlugins) context.state = "started";
539
539
  if (!this.parent) this.eventStreamTask = this.runEventStream();
540
540
  }
541
541
  getState() {
@@ -591,6 +591,24 @@ and implement the dispose method to clean up resources when the context stops.
591
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.`);
592
592
  }
593
593
  }
594
+ async recursiveApplyPlugins(appliedContextPlugins, startingContexts) {
595
+ if (this.state === "started") return;
596
+ if (this.state === "starting" && this.startPromise) {
597
+ await this.startPromise;
598
+ return;
599
+ }
600
+ if (this.state === "stopping") throw new Error(`Context "${this.name}" cannot be started while it is stopping.`);
601
+ if (this.state === "stopped") throw new Error(`Context "${this.name}" cannot be restarted after it has been stopped.`);
602
+ if (this.state === "idle") this.state = "starting";
603
+ startingContexts.push(this);
604
+ const sortedPlugins = this.sortPlugins();
605
+ await this.applyPlugins(sortedPlugins);
606
+ appliedContextPlugins.push({
607
+ context: this,
608
+ sortedPlugins
609
+ });
610
+ for (const subContext of this.subContexts) await subContext.recursiveApplyPlugins(appliedContextPlugins, startingContexts);
611
+ }
594
612
  async startPlugins(sortedPlugins) {
595
613
  for (const installedPlugin of sortedPlugins) {
596
614
  const { plugin } = installedPlugin;
@@ -599,6 +617,9 @@ and implement the dispose method to clean up resources when the context stops.
599
617
  await plugin.start(this.getPluginContext(installedPlugin));
600
618
  }
601
619
  }
620
+ async recursiveStartPlugins(appliedContextPlugins) {
621
+ for (const { context, sortedPlugins } of appliedContextPlugins) await context.startPlugins(sortedPlugins);
622
+ }
602
623
  sortPlugins() {
603
624
  const providers = /* @__PURE__ */ new Map();
604
625
  for (const { plugin } of this.plugins) for (const service of plugin.provides ?? []) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fraqjs/fraq",
3
3
  "type": "module",
4
- "version": "0.6.3",
4
+ "version": "0.6.4",
5
5
  "description": "Milky Bot framework",
6
6
  "files": [
7
7
  "dist"