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

Function Service

packages/effect/src/LayerMap.ts:370–436  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

368 * @since 3.14.0
369 */
370export const Service = <Self>() =>
371<
372 const Id extends string,
373 const Options extends
374 | NoExcessProperties<{
375 readonly lookup: (key: any) => Layer.Layer<any, any, any>
376 readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined
377 readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined
378 readonly preloadKeys?:
379 | Iterable<Options extends { readonly lookup: (key: infer K) => any } ? K : never>
380 | undefined
381 }, Options>
382 | NoExcessProperties<{
383 readonly layers: Record<string, Layer.Layer<any, any, any>>
384 readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined
385 readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined
386 readonly preload?: boolean | undefined
387 }, Options>
388>(
389 id: Id,
390 options: Options
391): TagClass<
392 Self,
393 Id,
394 Options extends { readonly lookup: (key: infer K) => any } ? K
395 : Options extends { readonly layers: infer Layers } ? keyof Layers
396 : never,
397 Service.Success<Options>,
398 Options extends { readonly preload: true } ? never : Service.Error<Options>,
399 Service.Services<Options>,
400 Options extends { readonly preload: true } ? Service.Error<Options>
401 : Options extends { readonly preloadKeys: Iterable<any> } ? Service.Error<Options>
402 : never,
403 Options extends { readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>> } ? Options["dependencies"][number]
404 : never
405> => {
406 const Err = globalThis.Error as any
407 const limit = getStackTraceLimit()
408 setStackTraceLimit(2)
409 const creationError = new Err()
410 setStackTraceLimit(limit)
411
412 function TagClass() {}
413 const TagClass_ = TagClass as any as Mutable<TagClass<Self, Id, string, any, any, any, any, any>>
414 Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.Service<Self, any>(id)))
415 TagClass.key = id
416 Object.defineProperty(TagClass, "stack", {
417 get() {
418 return creationError.stack
419 }
420 })
421
422 TagClass_.layerNoDeps = Layer.effect(TagClass_)(
423 "lookup" in options
424 ? make(options.lookup, options)
425 : fromRecord(options.layers as any, options) as any
426 )
427 TagClass_.layer = options.dependencies && options.dependencies.length > 0 ?

Callers

nothing calls this directly

Calls 9

getStackTraceLimitFunction · 0.90
setStackTraceLimitFunction · 0.90
contextEffectMethod · 0.80
makeFunction · 0.70
fromRecordFunction · 0.70
getMethod · 0.65
invalidateMethod · 0.65
provideMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected