File tree Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { isString } from "radashi";
33import { RedisKey , RedisKeyspace } from "./key" ;
44import { MessageEvent } from "./subscriber" ;
55import { RedisTransform } from "./transform" ;
6+ import { resolveName } from "./utils/resolve-name" ;
67
78/**
89 * Channels use the `SUBSCRIBE` command.
@@ -33,21 +34,19 @@ export class RedisChannel<
3334 name : K extends RedisKeyspace < infer Key > ? Key : string | number ,
3435 schema : TSchema = this . schema ,
3536 ) {
36- return new RedisChannel < any > (
37- `${ isString ( this . name ) ? this . name : this . name . name } :${ name } ` ,
38- schema ,
39- ) ;
37+ return new RedisChannel < any > ( `${ resolveName ( this ) } :${ name } ` , schema ) ;
4038 }
4139
4240 /**
4341 * Returns true if the event originated from this channel or a
4442 * subchannel.
4543 */
4644 test ( event : MessageEvent < any > ) : event is MessageEvent < T > {
45+ const name = resolveName ( this ) ;
4746 return (
4847 event . key === this ||
49- event . channel === this . name ||
50- event . channel . startsWith ( this . name + ":" )
48+ event . channel === name ||
49+ event . channel . startsWith ( name + ":" )
5150 ) ;
5251 }
5352}
Original file line number Diff line number Diff line change 11import * as Type from "@sinclair/typebox/type" ;
22import { StaticEncode , TObject , TSchema } from "@sinclair/typebox/type" ;
33import { Decode , Encode } from "@sinclair/typebox/value" ;
4- import { isString } from "radashi" ;
54import { RedisValue } from "./command" ;
65import { RedisTransform } from "./transform" ;
76import { JSONPath , resolveSchemaForJSONPath } from "./utils/json-path" ;
7+ import { resolveName } from "./utils/resolve-name" ;
88
99/**
1010 * Represents a namespace of keys in a Redis database.
@@ -59,10 +59,7 @@ export abstract class RedisKey<
5959 schema : TSchema ,
6060 ) => any ;
6161
62- return new RedisKey (
63- `${ isString ( this . name ) ? this . name : this . name . name } :${ name } ` ,
64- schema ,
65- ) ;
62+ return new RedisKey ( `${ resolveName ( this ) } :${ name } ` , schema ) ;
6663 }
6764}
6865
Original file line number Diff line number Diff line change 1+ import { isString } from "radashi" ;
2+ import { RedisKeyspace } from "../key" ;
3+
4+ export function resolveName ( key : { name : string | RedisKeyspace } ) {
5+ return isString ( key . name ) ? key . name : key . name . name ;
6+ }
You can’t perform that action at this time.
0 commit comments