effect-rpc
    Preparing search index...

    Type Alias RpcGroupRegistry<T>

    Represents a registry for managing groups of RPC handlers, providing type-safe operations for registering, retrieving, and querying handler groups by their unique tags.

    0.8.0

    type RpcGroupRegistry<T extends Record<RegistryKey, RpcGroup.RpcGroup<any>>> = {
        get<K extends string>(tag: K): TaggedRPCGroup<K, T[K]>;
        getTags(): (keyof T)[];
        has<K extends string>(tag: K): tag is K & keyof T;
        registerGetGroup<K extends string, V extends RpcGroup<any>>(
            tag: K extends keyof T ? never : K,
            rpcGroup: V,
        ): TaggedRPCGroup<
            K extends keyof T ? never : K,
            (T & Record<K, V>)[K extends keyof T ? never : K],
        >;
        registerGroup<K extends string, V extends RpcGroup<any>>(
            tag: K extends keyof T ? never : K,
            rpcGroup: V,
        ): RpcGroupRegistry<T & Record<K, V>>;
    }

    Type Parameters

    • T extends Record<RegistryKey, RpcGroup.RpcGroup<any>>

      A record mapping registry keys to their corresponding RpcGroup.RpcGroup instances.

    Index

    Methods

    • Checks if a handler group exists for the specified tag.

      Type Parameters

      • K extends string

        The tag to check for existence.

      Parameters

      • tag: K

        The tag to check in the registry.

      Returns tag is K & keyof T

      true if the handler group exists for the tag, otherwise false.

    • Registers a new RPC handler group and immediately returns the registered handler for the given tag. The tag must not already exist in the registry.

      This is useful to re-use the TaggedHandler directly.

      Type Parameters

      • K extends string

        The unique tag for the handler group.

      • V extends RpcGroup<any>

        The handler group instance to register.

      Parameters

      • tag: K extends keyof T ? never : K

        The unique identifier for the handler group. Must not already exist in the registry.

      • rpcGroup: V

        The handler group instance to register.

      Returns TaggedRPCGroup<
          K extends keyof T ? never : K,
          (T & Record<K, V>)[K extends keyof T ? never : K],
      >

      The TaggedRPCGroup for the newly registered group.

      export const helloRouter = RpcGroup.make(
      Rpc.fromTaggedRequest(SayHelloReq),
      Rpc.fromTaggedRequest(SayByeReq),
      );

      export const helloRequests = createRpcGroupRegistry().registerGetGroup('hello', helloRouter);

      It registers the hello group and returns it. Then you can do something like:

      // in /app/api/route.ts, for example
      import { helloRequests } from './requests';

      const program = helloRequests.getRequest('SayHelloReq', { name });

      This is shorter than just using registerGroup which would require to get the hello handlers first.

    • Registers a new RPC handler group under the specified tag. The tag must not already exist in the registry.

      Type Parameters

      • K extends string

        The unique tag for the handler group.

      • V extends RpcGroup<any>

        The handler group instance to register.

      Parameters

      • tag: K extends keyof T ? never : K

        The unique identifier for the handler group. Must not already exist in the registry.

      • rpcGroup: V

        The handler group instance to register.

      Returns RpcGroupRegistry<T & Record<K, V>>

      A new RpcGroupRegistry instance including the newly registered group.