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);
|
||||
|
||||
+8
-6
@@ -67,15 +67,17 @@ export interface Route {
|
||||
*/
|
||||
ast?: FilterNode;
|
||||
/**
|
||||
* Fallback route: only fires when no other (non-fallback) route matched the
|
||||
* event. Multiple fallback routes may exist; they are all skipped whenever at
|
||||
* least one regular route matches. Its own filters are ignored.
|
||||
* Fallback route: only fires when no other (non-fallback) route of the same
|
||||
* group matched the event. Multiple fallback routes may exist; a group's are
|
||||
* all skipped whenever one of its regular routes matches. Its own filters
|
||||
* still apply.
|
||||
*/
|
||||
fallback?: boolean;
|
||||
/**
|
||||
* Stop: when true and this route matches, no further routes are evaluated
|
||||
* for this event. Useful for exclusive routing where a match should prevent
|
||||
* fallthrough to subsequent routes.
|
||||
* Stop: when true and this route matches, no further routes of the same
|
||||
* group are evaluated for this event (other groups are unaffected). Useful
|
||||
* for exclusive routing where a match should prevent fallthrough to the
|
||||
* group's subsequent routes.
|
||||
*/
|
||||
stop?: boolean;
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user