Skip to content

Commit ae091c8

Browse files
committed
feat: add test method to RedisChannel
1 parent dcad772 commit ae091c8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/channel.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TSchema, TString, Type } from "@sinclair/typebox";
22
import { isString } from "radashi";
33
import { RedisKey } from "./key";
4+
import { MessageEvent } from "./subscriber";
45
import { RedisTransform } from "./transform";
56

67
/**
@@ -26,6 +27,18 @@ export class RedisChannel<
2627
if (keys.length === 0) return this;
2728
return new RedisChannel(`${this.name}:${keys.join(":")}`, this.schema);
2829
}
30+
31+
/**
32+
* Returns true if the event originated from this channel or a
33+
* subchannel.
34+
*/
35+
test(event: MessageEvent<any>): event is MessageEvent<T> {
36+
return (
37+
event.key === this ||
38+
event.channel === this.name ||
39+
event.channel.startsWith(this.name + ":")
40+
);
41+
}
2942
}
3043

3144
/**

0 commit comments

Comments
 (0)