@fraqjs/fraq 0.10.0 → 0.10.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.
Files changed (2) hide show
  1. package/dist/index.mjs +10 -6
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -617,7 +617,7 @@ var Context = class Context {
617
617
  eventBus = mitt();
618
618
  plugins = [];
619
619
  services = /* @__PURE__ */ new Map();
620
- subContexts = [];
620
+ subContexts = /* @__PURE__ */ new Map();
621
621
  parentEventForwarder;
622
622
  timers = /* @__PURE__ */ new Set();
623
623
  initialReconnectDelayMs;
@@ -636,7 +636,7 @@ var Context = class Context {
636
636
  this.maxReconnectDelayMs = options?.reconnect?.maxDelayMs ?? DEFAULT_MAX_RECONNECT_DELAY_MS;
637
637
  this.logHandler = options?.logHandler ?? parent?.logHandler;
638
638
  this.name = name ?? "root";
639
- this.logger = new Logger((message) => this.logHandler?.(message), this.name);
639
+ this.logger = new Logger((message) => this.logHandler?.(message), `context:${this.name}`);
640
640
  this.parent = parent;
641
641
  this.filter = filter;
642
642
  if (parent) {
@@ -700,8 +700,12 @@ and implement the dispose method to clean up resources when the context stops.
700
700
  return this.tryResolve(service) !== void 0;
701
701
  }
702
702
  fork(name, filter) {
703
+ if (this.subContexts.has(name)) {
704
+ if (filter) throw new Error(`Sub context "${name}" already exists, so the provided filter cannot be applied. Please use fork('${name}') without a filter to get the existing subcontext.`);
705
+ return this.subContexts.get(name);
706
+ }
703
707
  const subContext = new Context(this.client, void 0, name, this, filter);
704
- this.subContexts.push(subContext);
708
+ this.subContexts.set(name, subContext);
705
709
  return subContext;
706
710
  }
707
711
  timeout(delayMs, callback) {
@@ -814,7 +818,7 @@ and implement the dispose method to clean up resources when the context stops.
814
818
  async stopInternal() {
815
819
  const errors = [];
816
820
  this.clearTimers();
817
- for (const subContext of [...this.subContexts].reverse()) try {
821
+ for (const subContext of [...this.subContexts.values()].reverse()) try {
818
822
  await subContext.stop();
819
823
  } catch (error) {
820
824
  errors.push(error);
@@ -902,7 +906,7 @@ and implement the dispose method to clean up resources when the context stops.
902
906
  context: this,
903
907
  sortedPlugins
904
908
  });
905
- for (const subContext of this.subContexts) await subContext.recursiveApplyPlugins(appliedContextPlugins, startingContexts);
909
+ for (const subContext of this.subContexts.values()) await subContext.recursiveApplyPlugins(appliedContextPlugins, startingContexts);
906
910
  }
907
911
  async startPlugins(sortedPlugins) {
908
912
  for (const installedPlugin of sortedPlugins) {
@@ -979,7 +983,7 @@ and implement the dispose method to clean up resources when the context stops.
979
983
  return installedPlugin.proxy;
980
984
  }
981
985
  createProxyContextForPlugin(plugin) {
982
- const proxyLogger = new Logger((message) => this.logHandler?.(message), plugin.name);
986
+ const proxyLogger = new Logger((message) => this.logHandler?.(message), `plugin:${this.name ? `${this.name}/` : ""}${plugin.name}`);
983
987
  let proxyInjections;
984
988
  if (plugin.inject) {
985
989
  proxyInjections = {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fraqjs/fraq",
3
3
  "type": "module",
4
- "version": "0.10.0",
4
+ "version": "0.10.1",
5
5
  "description": "Milky Bot framework",
6
6
  "files": [
7
7
  "dist"