GitHub

LayerMapService

API reference for LayerMapService.

A tag for a LayerMap from K to the services I::

class Tenants(LayerMapService[str, Database]): ...

TenantsLive = Tenants.layer(tenant_database, idle_time_to_live=60)

Functions

layer

layer(lookup, *, idle_time_to_live=None, preload_keys=None) -> Layer[Self, Any, Any]

A layer making the LayerMap (see LayerMap.make). Provide its dependencies with .pipe(provide(...)).

ParameterTypeDescription
lookupCallable[[K], Layer[I, E, Any]]
idle_time_to_liveIdleTimeToLive[K] | None = None
preload_keysIterable[K] | None = None

Returns Layer[Self, Any, Any]

@classmethod
def layer(
    cls,
    lookup: Callable[[K], Layer[I, E, Any]],
    *,
    idle_time_to_live: IdleTimeToLive[K] | None = None,
    preload_keys: Iterable[K] | None = None,
) -> Layer[Self, Any, Any]:
    """A layer making the ``LayerMap`` (see ``LayerMap.make``). Provide
    its dependencies with ``.pipe(provide(...))``."""
    made: Effect[Any, Any, Any] = LayerMap.make(
        lookup, idle_time_to_live=idle_time_to_live, preload_keys=preload_keys
    )
    return layer_effect(cls, made)

layer_from_record

layer_from_record(layers, *, idle_time_to_live=None, preload=False) -> Layer[Self, Any, Any]

A layer making the LayerMap with LayerMap.from_record.

ParameterTypeDescription
layersMapping[K, Layer[I, E, Any]]
idle_time_to_liveIdleTimeToLive[K] | None = None
preloadbool = False

Returns Layer[Self, Any, Any]

@classmethod
def layer_from_record(
    cls,
    layers: Mapping[K, Layer[I, E, Any]],
    *,
    idle_time_to_live: IdleTimeToLive[K] | None = None,
    preload: bool = False,
) -> Layer[Self, Any, Any]:
    """A layer making the ``LayerMap`` with ``LayerMap.from_record``."""
    made: Effect[Any, Any, Any] = LayerMap.from_record(
        layers, idle_time_to_live=idle_time_to_live, preload=preload
    )
    return layer_effect(cls, made)

get

get(key) -> Layer[I, E, Self]

A layer giving the services for key, through this tag.

ParameterTypeDescription
keyK

Returns Layer[I, E, Self]

@classmethod
def get(cls, key: K) -> Layer[I, E, Self]:
    """A layer giving the services for ``key``, through this tag."""
    # Pyright can't solve ``unwrap``'s overloads against ``Self``.
    layer_of: Effect[Any, Any, Any] = cls._service().map(lambda m: m.get(key))
    return cast("Layer[I, E, Self]", unwrap(layer_of))

context_effect

context_effect(key) -> Effect[Context[I], E, Scope | Self]
ParameterTypeDescription
keyK

Returns Effect[Context[I], E, Scope | Self]

@classmethod
def context_effect(cls, key: K) -> Effect[Context[I], E, Scope | Self]:
    return cls._service().flat_map(lambda m: m.context_effect(key))

context_effect_option

context_effect_option(key) -> Effect[Option[Context[I]], E, Scope | Self]
ParameterTypeDescription
keyK

Returns Effect[Option[Context[I]], E, Scope | Self]

@classmethod
def context_effect_option(cls, key: K) -> Effect[Option[Context[I]], E, Scope | Self]:
    return cls._service().flat_map(lambda m: m.context_effect_option(key))

invalidate

invalidate(key) -> Effect[None, Never, Self]
ParameterTypeDescription
keyK

Returns Effect[None, Never, Self]

@classmethod
def invalidate(cls, key: K) -> Effect[None, Never, Self]:
    return cls._service().flat_map(lambda m: m.invalidate(key))