Module

Yoga.Om.Layer

Package
purescript-yoga-om-layer
Repository
rowtype-yoga/purescript-yoga-om-layer

#OmLayer Source

data OmLayer :: Row Type -> Row Type -> Type -> Typedata OmLayer req err a

A layer that requires dependencies (req), may fail with (err), and produces a value (typically Record prov). Each layer has a unique identity used for automatic memoization within a Scope.

Instances

#ParOmLayer Source

data ParOmLayer :: Row Type -> Row Type -> Type -> Typedata ParOmLayer req err a

Instances

#Scope Source

newtype Scope

A first-class representation of resource lifetime and memoization. Finalizers are registered via acquireRelease and run in reverse order when the scope is closed. Layers are automatically memoized by identity within a scope — the same layer value builds only once.

Instances

#makeLayer Source

makeLayer :: forall req err a. Om (Record req) err a -> OmLayer req err a

Create a layer from an Om computation. The layer is automatically memoized within a Scope — the same layer value used in multiple branches of a dependency graph builds only once.

#makeScopedLayer Source

makeScopedLayer :: forall req prov err. Om { scope :: Scope | req } err (Record prov) -> (Record prov -> Aff Unit) -> OmLayer (scope :: Scope | req) err (Record prov)

Create a scoped layer with acquire/release semantics. The release function runs when the enclosing scope closes. The layer requires scope :: Scope in its context.

#bracketLayer Source

bracketLayer :: forall req prov resource err. Om { scope :: Scope | req } err resource -> (resource -> Aff Unit) -> (resource -> Om { scope :: Scope | req } err (Record prov)) -> OmLayer (scope :: Scope | req) err (Record prov)

Bracket-style scoped layer: acquire a resource, register its release, then build provisions from it.

#acquireRelease Source

acquireRelease :: forall ctx err a. Om { scope :: Scope | ctx } err a -> (a -> Aff Unit) -> Om { scope :: Scope | ctx } err a

Acquire a resource and register its release with the current scope. This is the core scoped resource primitive — the PureScript equivalent of ZIO's ZIO.acquireRelease.

#fresh Source

fresh :: forall req err a. OmLayer req err a -> OmLayer req err a

Create a fresh (non-memoized) copy of a layer. The new layer has a unique identity and will always build independently, even within the same scope.

#runLayer Source

runLayer :: forall req err a available. CheckAllProvided req available => Record available -> OmLayer req err a -> Om (Record available) err a

Run a layer with a given context, with custom error if requirements aren't met.

#runScoped Source

runScoped :: forall prov. OmLayer (scope :: Scope) () (Record prov) -> Aff (Record prov)

Build a fully-provided scoped layer, return the provisions. All finalizers run after the provisions are returned. For layers with typed errors, use runScopedWith.

#runScopedWith Source

runScopedWith :: forall prov r rl err_ err. RowToList (exception :: Error -> Aff (Record prov) | r) rl => VariantMatchCases rl err_ (Aff (Record prov)) => Union err_ () (exception :: Error | err) => { exception :: Error -> Aff (Record prov) | r } -> OmLayer (scope :: Scope) err (Record prov) -> Aff (Record prov)

Like runScoped but accepts error handlers for layers with typed errors.

#withScoped Source

withScoped :: forall prov a. OmLayer (scope :: Scope) () (Record prov) -> (Record prov -> Aff a) -> Aff a

Build a fully-provided scoped layer and pass the provisions to a callback. A fresh Scope is created and closed when the callback completes, running all finalizers in reverse order — whether by success, failure, or interruption. For layers with typed errors, use withScopedWith.

#withScopedWith Source

withScopedWith :: forall prov a r rl err_ err. RowToList (exception :: Error -> Aff (Record prov) | r) rl => VariantMatchCases rl err_ (Aff (Record prov)) => Union err_ () (exception :: Error | err) => { exception :: Error -> Aff (Record prov) | r } -> OmLayer (scope :: Scope) err (Record prov) -> (Record prov -> Aff a) -> Aff a

Like withScoped but accepts error handlers for layers with typed errors.

#combineRequirements Source

combineRequirements :: forall req1 req2 prov1 prov2 err1 err2 provMerged reqMerged reqDeduped errMerged errDeduped _req1 _req2 _err1 _err2. Union req1 req2 reqMerged => Nub reqMerged reqDeduped => Union req1 _req1 reqDeduped => Union req2 _req2 reqDeduped => Union err1 err2 errMerged => Nub errMerged errDeduped => Union err1 _err1 errDeduped => Union err2 _err2 errDeduped => Union prov1 prov2 provMerged => Nub provMerged provMerged => Keys req1 => Keys req2 => OmLayer req1 err1 (Record prov1) -> OmLayer req2 err2 (Record prov2) -> OmLayer reqDeduped errDeduped (Record provMerged)

#provide Source

provide :: forall req prov1 prov2 err1 err2 req2 reqOut errMerged errDeduped _req _prov1 _err1 _err2. Union req _req req => Union prov1 _prov1 prov1 => Union err1 err2 errMerged => Nub errMerged errDeduped => Union err1 _err1 errDeduped => Union err2 _err2 errDeduped => Union prov1 req reqOut => Nub reqOut reqOut => Union req2 _prov1 reqOut => Keys req => Keys prov1 => Keys req2 => OmLayer req2 err2 (Record prov2) -> OmLayer req err1 (Record prov1) -> OmLayer req errDeduped (Record prov2)

#(>->) Source

Operator alias for Yoga.Om.Layer.provide (left-associative / precedence 9)

#recovering Source

recovering :: forall req err rest a (handlersRL :: RowList Type) (handlers :: Row Type) (handled :: Row Type). RowToList handlers handlersRL => VariantMatchCases handlersRL handled (Om (Record req) err Boolean) => Union handled rest (exception :: Error | err) => RetryPolicyM (Om (Record req) err) -> (RetryStatus -> Record handlers) -> OmLayer req err a -> OmLayer req err a

#repeating Source

repeating :: forall req err a. RetryPolicyM (Om (Record req) err) -> (RetryStatus -> a -> Om (Record req) err Boolean) -> OmLayer req err a -> OmLayer req err a

#wireLayers Source

wireLayers :: forall layers rl req err prov. RowToList layers rl => WireLayersRL rl layers (scope :: Scope) () () req err prov => Record layers -> OmLayer req err (Record prov)

#wireLayersDebug Source

wireLayersDebug :: forall layers rl req err prov doc. RowToList layers rl => PrintLayersRL rl doc => Warn (Above (Text "") (Above (Text "%%{init: {\"flowchart\": {\"defaultRenderer\": \"elk\"}} }%%") (Above (Text "flowchart LR") doc))) => WireLayersRL rl layers (scope :: Scope) () () req err prov => Record layers -> OmLayer req err (Record prov)

#WireLayersRL Source

class WireLayersRL :: RowList Type -> Row Type -> Row Type -> Row Type -> Row Type -> Row Type -> Row Type -> Row Type -> Constraintclass WireLayersRL (rl :: RowList Type) (layers :: Row Type) (accReq :: Row Type) (accErr :: Row Type) (accProv :: Row Type) (resReq :: Row Type) (resErr :: Row Type) (resProv :: Row Type) | rl layers accReq accErr accProv -> resReq resErr resProv where

Members

Instances

  • WireLayersRL Nil layers accReq accErr accProv accReq accErr accProv
  • (IsSymbol sym, Cons sym (OmLayer nextReq nextErr (Record nextProv)) _rest layers, Union accProv accReq provReqOut, Nub provReqOut provReqOut, Union nextReq _nextReqRest provReqOut, Keys nextReq, Keys accReq, Keys accProv, Union accErr nextErr errMergedRaw, Nub errMergedRaw errMerged, Union accErr _e1 errMerged, Union nextErr _e2 errMerged, Union accProv nextProv provMerged, Nub provMerged provMerged, WireLayersRL tail layers accReq errMerged provMerged resReq resErr resProv) => WireLayersRL (Cons sym (OmLayer nextReq nextErr (Record nextProv)) tail) layers accReq accErr accProv resReq resErr resProv

#FilterScope Source

class FilterScope :: RowList Type -> RowList Type -> Constraintclass FilterScope (rl :: RowList Type) (out :: RowList Type) | rl -> out

Remove scope :: Scope from a RowList (it's always present, just noise).

Instances

#FindProvider Source

class FindProvider :: Symbol -> RowList Type -> Symbol -> Constraintclass FindProvider (label :: Symbol) (rl :: RowList Type) (provider :: Symbol) | label rl -> provider

Given a label, find which layer in the RowList provides it.

Instances

#FindProviderMatch Source

class FindProviderMatch :: Boolean -> Symbol -> Symbol -> RowList Type -> Symbol -> Constraintclass FindProviderMatch (hasIt :: Boolean) (label :: Symbol) (sym :: Symbol) (rl :: RowList Type) (provider :: Symbol) | hasIt label sym rl -> provider

Dispatch based on whether the current layer has the label.

Instances

#HasLabel Source

class HasLabel :: Symbol -> RowList Type -> Boolean -> Constraintclass HasLabel (label :: Symbol) (rl :: RowList Type) (result :: Boolean) | label rl -> result

Check if a RowList contains a given label.

Instances

#EmitEdges Source

class EmitEdges :: Symbol -> RowList Type -> RowList Type -> Doc -> Constraintclass EmitEdges (consumer :: Symbol) (reqRL :: RowList Type) (allLayers :: RowList Type) (doc :: Doc) | consumer reqRL allLayers -> doc

Emit D2 edges for one consumer: "provider -> consumer" per requirement.

Instances

#PrintLayersRL Source

class PrintLayersRL :: RowList Type -> Doc -> Constraintclass PrintLayersRL (rl :: RowList Type) (doc :: Doc) | rl -> doc

Walk all layers emitting D2 edges.

Instances

#PrintEdgesRL Source

class PrintEdgesRL :: RowList Type -> RowList Type -> Doc -> Constraintclass PrintEdgesRL (rl :: RowList Type) (allLayers :: RowList Type) (doc :: Doc) | rl allLayers -> doc

Instances

#CheckAllProvided Source

class CheckAllProvided :: Row Type -> Row Type -> Constraintclass CheckAllProvided (required :: Row Type) (available :: Row Type) 

Check if all required dependencies are provided.

Instances

#CheckAllLabelsExist Source

class CheckAllLabelsExist :: RowList Type -> RowList Type -> Row Type -> Row Type -> Constraintclass CheckAllLabelsExist (required :: RowList Type) (available :: RowList Type) (requiredRow :: Row Type) (availableRow :: Row Type) 

Check that all labels in required RowList exist in available RowList.

Instances

#CheckLabelExists Source

class CheckLabelExists :: Symbol -> Type -> RowList Type -> Row Type -> Row Type -> Constraintclass CheckLabelExists (label :: Symbol) (ty :: Type) (available :: RowList Type) (requiredRow :: Row Type) (availableRow :: Row Type) 

Check if a single label exists in the available RowList.

Instances

Modules
Yoga.Om.Layer