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";
3
3
import { RedisKey , RedisKeyspace } from "./key" ;
4
4
import { MessageEvent } from "./subscriber" ;
5
5
import { RedisTransform } from "./transform" ;
6
+ import { resolveName } from "./utils/resolve-name" ;
6
7
7
8
/**
8
9
* Channels use the `SUBSCRIBE` command.
@@ -33,21 +34,19 @@ export class RedisChannel<
33
34
name : K extends RedisKeyspace < infer Key > ? Key : string | number ,
34
35
schema : TSchema = this . schema ,
35
36
) {
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 ) ;
40
38
}
41
39
42
40
/**
43
41
* Returns true if the event originated from this channel or a
44
42
* subchannel.
45
43
*/
46
44
test ( event : MessageEvent < any > ) : event is MessageEvent < T > {
45
+ const name = resolveName ( this ) ;
47
46
return (
48
47
event . key === this ||
49
- event . channel === this . name ||
50
- event . channel . startsWith ( this . name + ":" )
48
+ event . channel === name ||
49
+ event . channel . startsWith ( name + ":" )
51
50
) ;
52
51
}
53
52
}
Original file line number Diff line number Diff line change 1
1
import * as Type from "@sinclair/typebox/type" ;
2
2
import { StaticEncode , TObject , TSchema } from "@sinclair/typebox/type" ;
3
3
import { Decode , Encode } from "@sinclair/typebox/value" ;
4
- import { isString } from "radashi" ;
5
4
import { RedisValue } from "./command" ;
6
5
import { RedisTransform } from "./transform" ;
7
6
import { JSONPath , resolveSchemaForJSONPath } from "./utils/json-path" ;
7
+ import { resolveName } from "./utils/resolve-name" ;
8
8
9
9
/**
10
10
* Represents a namespace of keys in a Redis database.
@@ -59,10 +59,7 @@ export abstract class RedisKey<
59
59
schema : TSchema ,
60
60
) => any ;
61
61
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 ) ;
66
63
}
67
64
}
68
65
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