GitHub

RpcGroup

API reference for RpcGroup.

A group of RPCs: subclass it with the RPCs as attributes. A group listing its RPCs' tags, class Users(RpcGroup[Literal["GetUser", "Users"]]), has its handlers checked by pyright: to_layer rejects them while an RPC has none (Effect's toLayer). The class is checked against the list when it is defined.

Attributes

AttributeTypeDescription
rpcsMapping[str, AnyRpc] = {}

The group's procedures, each wrapped by the group middleware: what is served, what a client calls, and what each RPC attribute of the class reads (the one source of all three).

Functions

handlers

handlers() -> Handlers[Self, Never, Tags_contra]

No handlers yet: add one per RPC with handle.

Returns Handlers[Self, Never, Tags_contra]

@classmethod
def handlers(cls) -> Handlers[Self, Never, Tags_contra]:
    """No handlers yet: add one per RPC with ``handle``."""
    return Handlers(cls, {})

to_layer

to_layer[R](handlers) -> Layer[HandlersFor[Self], Never, R]

The layer of the group's handlers (Effect's toLayer). Each handler runs with the services of the layer's context. An RPC left without a handler is a pyright error when the group lists its tags (RpcGroup[Literal[...]]), and a ValueError here either way.

ParameterTypeDescription
handlersHandlers[Self, R, Never]

Returns Layer[HandlersFor[Self], Never, R]

@classmethod
def to_layer[R](
    cls, handlers: Handlers[Self, R, Never], /
) -> Layer[HandlersFor[Self], Never, R]:
    """The layer of the group's handlers (Effect's ``toLayer``). Each
    handler runs with the services of the layer's context. An RPC left
    without a handler is a pyright error when the group lists its tags
    (``RpcGroup[Literal[...]]``), and a ``ValueError`` here either way."""
    message = cls._missing_handlers(handlers)
    if message is not None:
        raise ValueError(message)
    return cls.to_layer_effect(succeed(handlers))

to_layer_effect

to_layer_effect[EX, RR = Never](handlers) -> Layer[HandlersFor[Self], EX, RR]

to_layer with the handlers made by an effect.

ParameterTypeDescription
handlersEffect[Handlers[Self, RR, Never], EX, RR]

Returns Layer[HandlersFor[Self], EX, RR]

@classmethod
def to_layer_effect[EX, RR = Never](
    cls, handlers: Effect[Handlers[Self, RR, Never], EX, RR], /
) -> Layer[HandlersFor[Self], EX, RR]:
    """``to_layer`` with the handlers made by an effect."""
    require_effect(handlers, "handlers")
    return layer_effect_context(handlers.flat_map(cls._handler_context))