Skip to content

Commit

Permalink
Fix: transport utils - ID and filter exclusivity check (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniGuardiola committed Dec 20, 2023
1 parent f93874e commit 4046d0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-jobs-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rpc-anywhere": patch
---

Fix: transport utils - ID and filter exclusivity check.
5 changes: 3 additions & 2 deletions src/transport-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export function rpcTransportMessageIn(
options: RPCTransportOptions,
): [ignore: false, message: any] | [ignore: true] {
const { transportId, filter } = options;
if (transportId != null && filter)
const filterResult = filter?.();
if (transportId != null && filterResult != null)
throw new Error(
"Cannot use both `transportId` and `filter` at the same time",
);
Expand All @@ -48,6 +49,6 @@ export function rpcTransportMessageIn(
if (message.transportId !== transportId) return [true];
data = message.data;
}
if (filter?.() === false) return [true];
if (filterResult === false) return [true];
return [false, data];
}

0 comments on commit 4046d0b

Please sign in to comment.