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.
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
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
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"]> : neverThe 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