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

Function Service

packages/effect/src/unstable/rpc/RpcMiddleware.ts:258–314  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

256 * @since 4.0.0
257 */
258export const Service = <
259 Self,
260 Config extends {
261 requires?: any
262 provides?: any
263 clientError?: any
264 } = {
265 requires: never
266 provides: never
267 clientError: never
268 }
269>(): <
270 const Name extends string,
271 Error extends Schema.Top = Schema.Never,
272 const RequiredForClient extends boolean = false
273>(
274 id: Name,
275 options?: {
276 readonly error?: Error | undefined
277 readonly requiredForClient?: RequiredForClient | undefined
278 } | undefined
279) => ServiceClass<
280 Self,
281 Name,
282 "provides" extends keyof Config ? Config["provides"] : never,
283 Error,
284 "clientError" extends keyof Config ? Config["clientError"] : never,
285 "requires" extends keyof Config ? Config["requires"] : never,
286 RequiredForClient
287> =>
288(
289 id: string,
290 options?: {
291 readonly error?: Schema.Top | undefined
292 readonly requiredForClient?: boolean | undefined
293 }
294) => {
295 const Err = globalThis.Error as any
296 const limit = getStackTraceLimit()
297 setStackTraceLimit(2)
298 const creationError = new Err()
299 setStackTraceLimit(limit)
300
301 function ServiceClass() {}
302 const ServiceClass_ = ServiceClass as any as Mutable<AnyService>
303 Object.setPrototypeOf(ServiceClass, Object.getPrototypeOf(Context.Service<Self, any>(id)))
304 ServiceClass.key = id
305 Object.defineProperty(ServiceClass, "stack", {
306 get() {
307 return creationError.stack
308 }
309 })
310 ServiceClass_[TypeId] = TypeId
311 ServiceClass_.error = options?.error ?? Schema.Never
312 ServiceClass_.requiredForClient = options?.requiredForClient ?? false
313 return ServiceClass as any
314}
315

Callers

nothing calls this directly

Calls 2

getStackTraceLimitFunction · 0.90
setStackTraceLimitFunction · 0.90

Tested by

no test coverage detected