MCPcopy Create free account
hub / github.com/Effect-TS/effect / Service

Function Service

packages/effect/src/unstable/reactivity/AtomRpc.ts:131–287  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

129 * @since 4.0.0
130 */
131export const Service = <Self>() =>
132<
133 const Id extends string,
134 Rpcs extends Rpc.Any,
135 ER,
136 RM =
137 | RpcClient.Protocol
138 | Rpc.MiddlewareClient<NoInfer<Rpcs>>
139 | Rpc.ServicesClient<NoInfer<Rpcs>>
140>(
141 id: Id,
142 options: {
143 readonly group: RpcGroup.RpcGroup<Rpcs>
144 readonly protocol:
145 | Layer.Layer<Exclude<NoInfer<RM>, Scope>, ER>
146 | ((get: Atom.AtomContext) => Layer.Layer<Exclude<NoInfer<RM>, Scope>, ER>)
147 readonly spanPrefix?: string | undefined
148 readonly spanAttributes?: Record<string, unknown> | undefined
149 readonly generateRequestId?: (() => RequestId) | undefined
150 readonly disableTracing?: boolean | undefined
151 readonly makeEffect?:
152 | Effect.Effect<
153 RpcClient.RpcClient.Flat<Rpcs, RpcClientError>,
154 never,
155 RM
156 >
157 | undefined
158 readonly runtime?: Atom.RuntimeFactory | undefined
159 }
160): AtomRpcClient<Self, Id, Rpcs> => {
161 const self: Mutable<AtomRpcClient<Self, Id, Rpcs>> = Context.Service<
162 Self,
163 RpcClient.RpcClient.Flat<Rpcs, RpcClientError>
164 >()(id) as any
165
166 const layer = Layer.effect(
167 self,
168 options.makeEffect ??
169 (RpcClient.make(options.group, {
170 ...options,
171 flatten: true
172 }) as Effect.Effect<
173 RpcClient.RpcClient.Flat<Rpcs, RpcClientError>,
174 never,
175 RM
176 >)
177 )
178 const runtimeFactory = options.runtime ?? Atom.runtime
179 self.runtime = runtimeFactory(
180 typeof options.protocol === "function" ?
181 (get) =>
182 Layer.provide(
183 layer,
184 Layer.orDie(
185 (options.protocol as ((get: Atom.AtomContext) => Layer.Layer<Exclude<NoInfer<RM>, Scope>, ER>))(get)
186 )
187 ) :
188 Layer.provide(layer, Layer.orDie(options.protocol))

Callers

nothing calls this directly

Calls 9

clientFunction · 0.85
SchemaMethod · 0.80
makeErrorSchemaFunction · 0.70
makeMethod · 0.65
getMethod · 0.65
pipeMethod · 0.65
useMethod · 0.65
provideMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected