AtomRpc
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.
Constructors
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
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) => ExtractTag<Rpcs, Tag> extends Rpc<_Tag, _Payload, _Success, _Error, _Middleware, _Requires> ? [_Success] extends [Stream<_A, _E>] ? never : AtomResultFn<{ readonly headers?: Input; readonly payload: PayloadConstructor<ExtractTag>; readonly reactivityKeys?: readonly Array<unknown> | ReadonlyRecord<string, readonly Array<unknown>>; }, _Success["Type"], RpcClientError | _Error["Type"] | _Middleware["error"]["Type"]> : never; 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 timeToLive?: Input; }) => ExtractTag<Rpcs, Tag> extends Rpc<_Tag, _Payload, _Success, _Error, _Middleware, never> ? [_Success] extends [Stream<_A, _E>] ? Writable<PullResult<_A["Type"], RpcClientError | _E["Type"] | _Error["Type"] | _Middleware["error"]["Type"]>, void> : Atom<AsyncResult<_Success["Type"], RpcClientError | _Error["Type"] | _Middleware["error"]["Type"]>> : never; readonly runtime: AtomRuntime<Self>;}