@fraqjs/fraq 0.10.0 → 0.10.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.mjs +22 -8
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -241,6 +241,16 @@ var CommandBuilder = class {
|
|
|
241
241
|
};
|
|
242
242
|
//#endregion
|
|
243
243
|
//#region src/routing/tokenizer.ts
|
|
244
|
+
const WHITESPACE_CHARS = new Set([
|
|
245
|
+
" ",
|
|
246
|
+
" ",
|
|
247
|
+
"\n",
|
|
248
|
+
"\r",
|
|
249
|
+
"\v",
|
|
250
|
+
"\f",
|
|
251
|
+
"\xA0",
|
|
252
|
+
" "
|
|
253
|
+
]);
|
|
244
254
|
var Tokenizer = class {
|
|
245
255
|
segments;
|
|
246
256
|
offset = 0;
|
|
@@ -353,12 +363,12 @@ var Tokenizer = class {
|
|
|
353
363
|
}
|
|
354
364
|
findTextTokenStart(text, from) {
|
|
355
365
|
let offset = from;
|
|
356
|
-
while (offset < text.length && text[offset]
|
|
366
|
+
while (offset < text.length && WHITESPACE_CHARS.has(text[offset])) offset += 1;
|
|
357
367
|
return offset;
|
|
358
368
|
}
|
|
359
369
|
readTextToken(text, from) {
|
|
360
370
|
let offset = from;
|
|
361
|
-
while (offset < text.length && text[offset]
|
|
371
|
+
while (offset < text.length && !WHITESPACE_CHARS.has(text[offset])) offset += 1;
|
|
362
372
|
return text.slice(from, offset);
|
|
363
373
|
}
|
|
364
374
|
};
|
|
@@ -617,7 +627,7 @@ var Context = class Context {
|
|
|
617
627
|
eventBus = mitt();
|
|
618
628
|
plugins = [];
|
|
619
629
|
services = /* @__PURE__ */ new Map();
|
|
620
|
-
subContexts =
|
|
630
|
+
subContexts = /* @__PURE__ */ new Map();
|
|
621
631
|
parentEventForwarder;
|
|
622
632
|
timers = /* @__PURE__ */ new Set();
|
|
623
633
|
initialReconnectDelayMs;
|
|
@@ -636,7 +646,7 @@ var Context = class Context {
|
|
|
636
646
|
this.maxReconnectDelayMs = options?.reconnect?.maxDelayMs ?? DEFAULT_MAX_RECONNECT_DELAY_MS;
|
|
637
647
|
this.logHandler = options?.logHandler ?? parent?.logHandler;
|
|
638
648
|
this.name = name ?? "root";
|
|
639
|
-
this.logger = new Logger((message) => this.logHandler?.(message), this.name);
|
|
649
|
+
this.logger = new Logger((message) => this.logHandler?.(message), `context:${this.name}`);
|
|
640
650
|
this.parent = parent;
|
|
641
651
|
this.filter = filter;
|
|
642
652
|
if (parent) {
|
|
@@ -700,8 +710,12 @@ and implement the dispose method to clean up resources when the context stops.
|
|
|
700
710
|
return this.tryResolve(service) !== void 0;
|
|
701
711
|
}
|
|
702
712
|
fork(name, filter) {
|
|
713
|
+
if (this.subContexts.has(name)) {
|
|
714
|
+
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.`);
|
|
715
|
+
return this.subContexts.get(name);
|
|
716
|
+
}
|
|
703
717
|
const subContext = new Context(this.client, void 0, name, this, filter);
|
|
704
|
-
this.subContexts.
|
|
718
|
+
this.subContexts.set(name, subContext);
|
|
705
719
|
return subContext;
|
|
706
720
|
}
|
|
707
721
|
timeout(delayMs, callback) {
|
|
@@ -814,7 +828,7 @@ and implement the dispose method to clean up resources when the context stops.
|
|
|
814
828
|
async stopInternal() {
|
|
815
829
|
const errors = [];
|
|
816
830
|
this.clearTimers();
|
|
817
|
-
for (const subContext of [...this.subContexts].reverse()) try {
|
|
831
|
+
for (const subContext of [...this.subContexts.values()].reverse()) try {
|
|
818
832
|
await subContext.stop();
|
|
819
833
|
} catch (error) {
|
|
820
834
|
errors.push(error);
|
|
@@ -902,7 +916,7 @@ and implement the dispose method to clean up resources when the context stops.
|
|
|
902
916
|
context: this,
|
|
903
917
|
sortedPlugins
|
|
904
918
|
});
|
|
905
|
-
for (const subContext of this.subContexts) await subContext.recursiveApplyPlugins(appliedContextPlugins, startingContexts);
|
|
919
|
+
for (const subContext of this.subContexts.values()) await subContext.recursiveApplyPlugins(appliedContextPlugins, startingContexts);
|
|
906
920
|
}
|
|
907
921
|
async startPlugins(sortedPlugins) {
|
|
908
922
|
for (const installedPlugin of sortedPlugins) {
|
|
@@ -979,7 +993,7 @@ and implement the dispose method to clean up resources when the context stops.
|
|
|
979
993
|
return installedPlugin.proxy;
|
|
980
994
|
}
|
|
981
995
|
createProxyContextForPlugin(plugin) {
|
|
982
|
-
const proxyLogger = new Logger((message) => this.logHandler?.(message), plugin.name);
|
|
996
|
+
const proxyLogger = new Logger((message) => this.logHandler?.(message), `plugin:${this.name ? `${this.name}/` : ""}${plugin.name}`);
|
|
983
997
|
let proxyInjections;
|
|
984
998
|
if (plugin.inject) {
|
|
985
999
|
proxyInjections = {};
|