mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
feat(dispatch)!: scope stop and fallback to each group
A match in one group must not suppress delivery in another group. Track regular matches and stopped scopes independently, and document the routing-table boundary. BREAKING CHANGE: stop and fallback no longer apply globally across groups. Put mutually exclusive routes in the same group and define fallback routes in each group that needs its own catch-all.
This commit is contained in:
1 parent
a8418c06d9
commit
a2ad4f699e
10 files changed
+78
-26
No files matched your search
@@ -61,10 +61,15 @@ export async function dispatchEvent(
|
||||
if (!groupAcceptsOwners(group, owners)) return false;
|
||||
return groupAcceptsProvider(group, event.provider);
|
||||
};
|
||||
const matched = config.routes.filter(
|
||||
(route) => !route.fallback && matchRoute(route, event) && accepted(route),
|
||||
// `stop` and `fallback` act within a route's own group (its routing table), so
|
||||
// one group's routes can never silence another group's.
|
||||
const scopeOf = (route: Route): string => route.groupId ?? "";
|
||||
const regularMatched = new Set(
|
||||
config.routes
|
||||
.filter((route) => !route.fallback && matchRoute(route, event) && accepted(route))
|
||||
.map(scopeOf),
|
||||
);
|
||||
const anyRegularMatched = matched.length > 0;
|
||||
const stopped = new Set<string>();
|
||||
|
||||
const attempts: DispatchAttempt[] = [];
|
||||
const sendLogs: SendRecord[] = [];
|
||||
@@ -88,16 +93,17 @@ export async function dispatchEvent(
|
||||
|
||||
const tasks: Promise<void>[] = [];
|
||||
for (const route of config.routes) {
|
||||
if (!accepted(route)) continue;
|
||||
const scope = scopeOf(route);
|
||||
if (stopped.has(scope) || !accepted(route)) continue;
|
||||
if (route.fallback) {
|
||||
if (!anyRegularMatched && matchRoute(route, event)) {
|
||||
if (!regularMatched.has(scope) && matchRoute(route, event)) {
|
||||
tasks.push(processRoute(route));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (matchRoute(route, event)) {
|
||||
tasks.push(processRoute(route));
|
||||
if (route.stop) break;
|
||||
if (route.stop) stopped.add(scope);
|
||||
}
|
||||
}
|
||||
await Promise.allSettled(tasks);
|
||||
|
||||
Reference in new issue
Block a user