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

Function Service

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

Source from the content-addressed store, hash-verified

422 * @since 3.14.0
423 */
424export const Service = <Self>() =>
425<
426 const Id extends string,
427 const Options extends
428 | NoExcessProperties<{
429 readonly lookup: (key: any) => Layer.Layer<any, any, any>
430 readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined
431 readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined
432 /**
433 * Preloaded entries are retained only for their idle TTL. Keys whose idle
434 * TTL is zero are not preloaded (including when no TTL is specified).
435 */
436 readonly preloadKeys?:
437 | Iterable<Options extends { readonly lookup: (key: infer K) => any } ? K : never>
438 | undefined
439 }, Options>
440 | NoExcessProperties<{
441 readonly layers: Record<PropertyKey, Layer.Layer<any, any, any>>
442 readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined
443 readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined
444 /**
445 * Preloaded entries are retained only for their idle TTL. Keys whose idle
446 * TTL is zero are not preloaded (including when no TTL is specified).
447 */
448 readonly preload?: boolean | undefined
449 }, Options>
450>(
451 id: Id,
452 options: Options
453): TagClass<
454 Self,
455 Id,
456 Options extends { readonly lookup: (key: infer K) => any } ? K
457 : Options extends { readonly layers: infer Layers } ? keyof Layers
458 : never,
459 Service.Success<Options>,
460 Service.Error<Options>,
461 Service.Services<Options>,
462 Options extends { readonly preload: true } ? Service.Error<Options>
463 : Options extends { readonly preloadKeys: Iterable<any> } ? Service.Error<Options>
464 : never,
465 Options extends { readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>> } ? Options["dependencies"][number]
466 : never
467> => {
468 const limit = getStackTraceLimit()
469 let creationError: Error | undefined
470 if (limit !== 0) {
471 setStackTraceLimit(2)
472 creationError = new globalThis.Error()
473 setStackTraceLimit(limit)
474 }
475
476 function TagClass() {}
477 const TagClass_ = TagClass as any as Mutable<TagClass<Self, Id, string, any, any, any, any, any>>
478 Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.Service<Self, any>(id)))
479 TagClass.key = id
480 Object.defineProperty(TagClass, "stack", {
481 get() {

Callers

nothing calls this directly

Calls 10

getStackTraceLimitFunction · 0.90
setStackTraceLimitFunction · 0.90
contextEffectMethod · 0.80
contextEffectOptionMethod · 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