@fraqjs/fraq 0.6.2 → 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
@@ -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
@@ -5708,7 +5709,9 @@ declare class Context {
5708
5709
  private stopEventStream;
5709
5710
  private acceptsParentEvent;
5710
5711
  private applyPlugins;
5712
+ private recursiveApplyPlugins;
5711
5713
  private startPlugins;
5714
+ private recursiveStartPlugins;
5712
5715
  private sortPlugins;
5713
5716
  private collectPendingProvidedServices;
5714
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 ?? []) {
@@ -839,6 +860,15 @@ let filter;
839
860
  return result;
840
861
  }
841
862
  _filter.and = and;
863
+ function not(filter) {
864
+ const result = {};
865
+ for (const key of eventKeys) result[key] = (event) => {
866
+ const predicate = filter[key];
867
+ return !predicate?.(event);
868
+ };
869
+ return result;
870
+ }
871
+ _filter.not = not;
842
872
  })(filter || (filter = {}));
843
873
  //#endregion
844
874
  //#region src/core/plugin.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fraqjs/fraq",
3
3
  "type": "module",
4
- "version": "0.6.2",
4
+ "version": "0.6.4",
5
5
  "description": "Milky Bot framework",
6
6
  "files": [
7
7
  "dist"