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

Function Service

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

Source from the content-addressed store, hash-verified

334 * ```
335 */
336export const Service = <Self>() =>
337<
338 const Id extends string,
339 Options extends
340 | NoExcessProperties<
341 {
342 readonly lookup: (key: any) => Layer.Layer<any, any, any>
343 readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>>
344 readonly idleTimeToLive?: Duration.DurationInput | undefined
345 /**
346 * Preloaded entries become idle immediately and follow the idle TTL.
347 * The default idle TTL is zero, so preloading only occurs when a nonzero
348 * `idleTimeToLive` is configured.
349 */
350 readonly preloadKeys?:
351 | Iterable<Options extends { readonly lookup: (key: infer K) => any } ? K : never>
352 | undefined
353 },
354 Options
355 >
356 | NoExcessProperties<{
357 readonly layers: Record<string, Layer.Layer<any, any, any>>
358 readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>>
359 readonly idleTimeToLive?: Duration.DurationInput | undefined
360 /**
361 * Preloaded entries become idle immediately and follow the idle TTL.
362 * The default idle TTL is zero, so preloading only occurs when a nonzero
363 * `idleTimeToLive` is configured.
364 */
365 readonly preload?: boolean
366 }, Options>
367>(
368 id: Id,
369 options: Options
370): TagClass<
371 Self,
372 Id,
373 Options extends { readonly lookup: (key: infer K) => any } ? K
374 : Options extends { readonly layers: infer Layers } ? keyof Layers
375 : never,
376 Service.Success<Options>,
377 Options extends { readonly preload: true } ? never : Service.Error<Options>,
378 Service.Context<Options>,
379 Options extends { readonly preload: true } ? Service.Error<Options>
380 : Options extends { readonly preloadKey: Iterable<any> } ? Service.Error<Options>
381 : never,
382 Options extends { readonly dependencies: ReadonlyArray<any> } ? Options["dependencies"][number] : never
383> => {
384 const Err = globalThis.Error as any
385 const limit = getStackTraceLimit()
386 setStackTraceLimit(2)
387 const creationError = new Err()
388 setStackTraceLimit(limit)
389
390 function TagClass() {}
391 const TagClass_ = TagClass as any as Mutable<TagClass<Self, Id, string, any, any, any, any, any>>
392 Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.GenericTag<Self, any>(id)))
393 TagClass.key = id

Callers

nothing calls this directly

Calls 9

runtimeMethod · 0.80
makeFunction · 0.70
fromRecordFunction · 0.70
provideMethod · 0.65
mapMethod · 0.65
getMethod · 0.65
invalidateMethod · 0.65
getStackTraceLimitFunction · 0.50
setStackTraceLimitFunction · 0.50

Tested by

no test coverage detected