Generator-emitted scaffold (pnpm turbo gen core-package realtime) plus the story-00-precedent coverage repairs (coverage provider devDep, symbols.ts exclude + tested allowlist mirror) and three minimal tests covering generator-emitted realtime code the template suite misses. Squash of 31d85e0 + review-fix cf11b38. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import type { z } from "zod";
|
|
import type { RealtimeRegistryProtocol } from "@repo/core-shared/di/bind-protocols";
|
|
import type { RealtimeChannelDescriptor } from "./realtime-channel";
|
|
import type { IInboundDescriptor } from "./realtime-handler.interface";
|
|
|
|
export interface IRealtimeHandlerRegistry extends RealtimeRegistryProtocol {
|
|
register<T>(entry: IInboundDescriptor<string, z.ZodType<T>>): void;
|
|
getInboundDescriptor(
|
|
channelName: string,
|
|
): IInboundDescriptor<string, z.ZodType> | null;
|
|
list(): IInboundDescriptor<string, z.ZodType>[];
|
|
/** Register an outbound-only channel so Gate 2 can authorize subscriptions to it. */
|
|
registerChannel(
|
|
descriptor: RealtimeChannelDescriptor<string, z.ZodType>,
|
|
): void;
|
|
listChannels(): RealtimeChannelDescriptor<string, z.ZodType>[];
|
|
}
|
|
|
|
export class RealtimeHandlerRegistry implements IRealtimeHandlerRegistry {
|
|
private readonly entries = new Map<
|
|
string,
|
|
IInboundDescriptor<string, z.ZodType>
|
|
>();
|
|
private readonly channels = new Map<
|
|
string,
|
|
RealtimeChannelDescriptor<string, z.ZodType>
|
|
>();
|
|
|
|
register<T>(entry: IInboundDescriptor<string, z.ZodType<T>>): void {
|
|
this.entries.set(
|
|
entry.descriptor.name,
|
|
entry as IInboundDescriptor<string, z.ZodType>,
|
|
);
|
|
// Also add the descriptor to the channel map so Gate 2 can authorize subscriptions.
|
|
this.channels.set(entry.descriptor.name, entry.descriptor);
|
|
}
|
|
|
|
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());
|
|
}
|
|
|
|
registerChannel(
|
|
descriptor: RealtimeChannelDescriptor<string, z.ZodType>,
|
|
): void {
|
|
this.channels.set(descriptor.name, descriptor);
|
|
}
|
|
|
|
listChannels(): RealtimeChannelDescriptor<string, z.ZodType>[] {
|
|
return Array.from(this.channels.values());
|
|
}
|
|
}
|