Skip to content

Commit c9eb170

Browse files
committed
feat: simplify router class structure
1 parent cd265ba commit c9eb170

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

packages/interfaces/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export * from "./constants.js";
1818
export * from "./local_storage.js";
1919
export * from "./sharding.js";
2020
export * from "./health_status.js";
21+
export type { ShardInfo } from "./sharding.js";

packages/utils/src/common/sharding/routing_info.ts

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ import {
2020
export type RoutingInfo = AutoShardingRoutingInfo | StaticShardingRoutingInfo;
2121

2222
export abstract class BaseRoutingInfo {
23+
public pubsubTopic: PubsubTopic;
24+
public shardId: ShardId;
25+
2326
protected constructor(
2427
public networkConfig: NetworkConfig,
25-
public pubsubTopic: PubsubTopic,
26-
public shardId: ShardId
27-
) {}
28+
pubsubTopic: PubsubTopic,
29+
shardId: ShardId
30+
) {
31+
this.pubsubTopic = pubsubTopic;
32+
this.shardId = shardId;
33+
}
2834

29-
public abstract get isAutoSharding(): boolean;
30-
public abstract get isStaticSharding(): boolean;
35+
public get clusterId(): ClusterId {
36+
return this.networkConfig.clusterId;
37+
}
3138
}
3239

3340
export class AutoShardingRoutingInfo
@@ -61,24 +68,12 @@ export class AutoShardingRoutingInfo
6168
*/
6269
private constructor(
6370
public networkConfig: AutoSharding,
64-
public pubsubTopic: PubsubTopic,
65-
public shardId: ShardId,
71+
pubsubTopic: PubsubTopic,
72+
shardId: ShardId,
6673
public contentTopic: string
6774
) {
6875
super(networkConfig, pubsubTopic, shardId);
6976
}
70-
71-
public get clusterId(): number {
72-
return this.networkConfig.clusterId;
73-
}
74-
75-
public get isAutoSharding(): boolean {
76-
return true;
77-
}
78-
79-
public get isStaticSharding(): boolean {
80-
return false;
81-
}
8277
}
8378

8479
export class StaticShardingRoutingInfo
@@ -127,35 +122,23 @@ export class StaticShardingRoutingInfo
127122
*/
128123
private constructor(
129124
public networkConfig: StaticSharding,
130-
public pubsubTopic: PubsubTopic,
131-
public shardId: ShardId
125+
pubsubTopic: PubsubTopic,
126+
shardId: ShardId
132127
) {
133128
super(networkConfig, pubsubTopic, shardId);
134129
}
135-
136-
public get clusterId(): ClusterId {
137-
return this.networkConfig.clusterId;
138-
}
139-
140-
public get isAutoSharding(): boolean {
141-
return false;
142-
}
143-
144-
public get isStaticSharding(): boolean {
145-
return true;
146-
}
147130
}
148131

149132
export function isAutoShardingRoutingInfo(
150133
routingInfo: BaseRoutingInfo
151134
): routingInfo is AutoShardingRoutingInfo {
152-
return routingInfo.isAutoSharding;
135+
return routingInfo instanceof AutoShardingRoutingInfo;
153136
}
154137

155138
export function isStaticShardingRoutingInfo(
156139
routingInfo: BaseRoutingInfo
157140
): routingInfo is StaticShardingRoutingInfo {
158-
return routingInfo.isStaticSharding;
141+
return routingInfo instanceof StaticShardingRoutingInfo;
159142
}
160143

161144
export function createRoutingInfo(

0 commit comments

Comments
 (0)