feat(core-realtime): RealtimeHandlerRegistry
This commit is contained in:
24
packages/core-realtime/src/realtime-handler-registry.ts
Normal file
24
packages/core-realtime/src/realtime-handler-registry.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { z } from "zod";
|
||||
import type { IInboundDescriptor } from "./realtime-handler.interface";
|
||||
|
||||
export interface IRealtimeHandlerRegistry {
|
||||
register<T>(entry: IInboundDescriptor<string, z.ZodType<T>>): void;
|
||||
getInboundDescriptor(channelName: string): IInboundDescriptor<string, z.ZodType> | null;
|
||||
list(): IInboundDescriptor<string, z.ZodType>[];
|
||||
}
|
||||
|
||||
export class RealtimeHandlerRegistry implements IRealtimeHandlerRegistry {
|
||||
private readonly entries = new Map<string, IInboundDescriptor<string, z.ZodType>>();
|
||||
|
||||
register<T>(entry: IInboundDescriptor<string, z.ZodType<T>>): void {
|
||||
this.entries.set(entry.descriptor.name, entry as IInboundDescriptor<string, z.ZodType>);
|
||||
}
|
||||
|
||||
getInboundDescriptor(channelName: string): IInboundDescriptor<string, z.ZodType> | null {
|
||||
return this.entries.get(channelName) ?? null;
|
||||
}
|
||||
|
||||
list(): IInboundDescriptor<string, z.ZodType>[] {
|
||||
return Array.from(this.entries.values());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user