Skip to content
// EFFECT DAYS 2026

AtomRpc unstable

Connects typed RPC clients to atoms.

The service created here exposes a flattened RPC client plus atom-based query and mutation helpers. Query atoms call RPCs and track asynchronous or streaming results, while mutations run RPC calls that can invalidate reactivity keys after success. Query atoms can also use request headers, time-to-live settings, and serialization keys for hydration.

4 exports Since v4.0.0 Source

Constructors

Service

unstable
Since v4.0.0

Creates a Context.Service class for an RPC client backed by an atom runtime.

Details

The options provide the RPC group, protocol layer, tracing options, request id generation, optional custom client effect, and runtime factory used by the query and mutation helpers.

Signature

declare function Service<Self>(): <Id extends string, Rpcs extends Any, ER, RM = Protocol | MiddlewareClient<NoInfer<Rpcs>> | ServicesClient<NoInfer<Rpcs>>>(id: Id, options: {
readonly disableTracing?: boolean;
readonly generateRequestId?: () => RequestId;
readonly group: RpcGroup<Rpcs>;
readonly makeEffect?: Effect<Flat<Rpcs, RpcClientError>, never, RM>;
readonly protocol: Layer<Exclude<NoInfer<RM>, Scope>, ER, never> | (get: AtomContext) => Layer<Exclude<NoInfer<RM>, Scope>, ER>;
readonly runtime?: RuntimeFactory;
readonly spanAttributes?: Record<string, unknown>;
readonly spanPrefix?: string;
}) => AtomRpcClient<Self, Id, Rpcs>

Services

AtomRpcClient

interface unstable
Since v4.0.0

A Context.Service for a flattened RPC client integrated with atom reactivity.

Details

It exposes the RPC client, an atom runtime, mutation helpers that return AtomResultFns, and query helpers that return atoms or pull atoms for RPC results.

Signature

interface AtomRpcClient<Self, Id extends string, Rpcs extends Rpc.Any> extends Service<Self, RpcClient.RpcClient.Flat<Rpcs, RpcClientError>> {
constructor(_: never);
readonly mutation: <Tag extends string>(arg: Tag) => Mutation<ExtractTag<Rpcs, Tag>>;
readonly query: <Tag extends string>(tag: Tag, payload: PayloadConstructor<ExtractTag<Rpcs, Tag>>, options?: {
readonly headers?: Input;
readonly reactivityKeys?: readonly Array<unknown> | ReadonlyRecord<string, readonly Array<unknown>>;
readonly serializationKey?: string;
readonly staleTime?: Input;
readonly timeToLive?: Input;
}) => Query<ExtractTag<Rpcs, Tag>>;
readonly runtime: AtomRuntime<Self>;
}

Utility Types

Mutation

type unstable
Since v4.1.3

The AtomResultFn produced by mutation for the given RPC(s). Distributes over a union of RPCs.

Signature

type Mutation<Current> = Current extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? [_Success] extends [RpcSchema.Stream<infer _A, infer _E>] ? never : Atom.AtomResultFn<{
readonly headers?: Headers.Input;
readonly payload: Rpc.PayloadConstructor<Current>;
readonly reactivityKeys?: Reactivity.KeysInput;
}, _Success["Type"], _Error["Type"] | RpcClientError | _Middleware["error"]["Type"] | _Middleware["~ClientError"]> : never

Query

type unstable
Since v4.1.3

The atom produced by query for the given RPC(s). Distributes over a union of RPCs.

Signature

type Query<Current> = Current extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? [_Success] extends [RpcSchema.Stream<infer _A, infer _E>] ? Atom.Writable<Atom.PullResult<_A["Type"], _E["Type"] | _Error["Type"] | RpcClientError | _Middleware["error"]["Type"] | _Middleware["~ClientError"]>, void> : Atom.Atom<AsyncResult.AsyncResult<_Success["Type"], _Error["Type"] | RpcClientError | _Middleware["error"]["Type"] | _Middleware["~ClientError"]>> : never