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.

#scoped Source

scoped :: 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

#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 => TopoWire 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))) => TopoWire rl layers (scope :: Scope) () () req err prov => Record layers -> OmLayer req err (Record prov)

#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

#DashesFor Source

class DashesFor :: Symbol -> Symbol -> Constraintclass DashesFor (sym :: Symbol) (dashes :: Symbol) | sym -> dashes

Map a symbol to same-length dashes (for box borders).

Instances

#BoxTop Source

class BoxTop :: Symbol -> Symbol -> Constraintclass BoxTop (sym :: Symbol) (result :: Symbol) | sym -> result

Build box parts from a symbol.

Instances

#BoxMid Source

class BoxMid :: Symbol -> Symbol -> Constraintclass BoxMid (sym :: Symbol) (result :: Symbol) | sym -> result

Instances

#BoxBot Source

class BoxBot :: Symbol -> Symbol -> Constraintclass BoxBot (sym :: Symbol) (result :: Symbol) | sym -> result

Instances

#RenderDepChildNode Source

class RenderDepChildNode :: Boolean -> Symbol -> Symbol -> Type -> Symbol -> Symbol -> Symbol -> RowList Type -> Doc -> Constraintclass RenderDepChildNode (isNotProvided :: Boolean) (provider :: Symbol) (label :: Symbol) (ty :: Type) (prePrefix :: Symbol) (contPrefix :: Symbol) (branchPrefix :: Symbol) (allLayers :: RowList Type) (doc :: Doc) | isNotProvided provider label ty prePrefix contPrefix branchPrefix allLayers -> doc

Render a single dependency child node (dispatches on provided vs missing).

Instances

#IsNotProvided Source

class IsNotProvided :: Symbol -> Boolean -> Constraintclass IsNotProvided (provider :: Symbol) (result :: Boolean) | provider -> result

Is this provider the NotProvided marker?

Instances

#HasDirectMissing Source

class HasDirectMissing :: RowList Type -> RowList Type -> Boolean -> Constraintclass HasDirectMissing (reqRL :: RowList Type) (allLayers :: RowList Type) (result :: Boolean) | reqRL allLayers -> result

Does any requirement in this RowList resolve to NotProvided?

Instances

#HasDirectMissingOr Source

class HasDirectMissingOr :: Boolean -> RowList Type -> RowList Type -> Boolean -> Constraintclass HasDirectMissingOr (found :: Boolean) (tail :: RowList Type) (allLayers :: RowList Type) (result :: Boolean) | found tail allLayers -> result

Instances

#FindLayerReqs Source

class FindLayerReqs :: Symbol -> RowList Type -> RowList Type -> Constraintclass FindLayerReqs (sym :: Symbol) (allLayers :: RowList Type) (reqRL :: RowList Type) | sym allLayers -> reqRL

Look up a layer's requirements by name.

Instances

#RenderProviderDeps Source

class RenderProviderDeps :: Symbol -> Symbol -> RowList Type -> Doc -> Constraintclass RenderProviderDeps (provider :: Symbol) (prefix :: Symbol) (allLayers :: RowList Type) (doc :: Doc) | provider prefix allLayers -> doc

Render a provider's sub-tree (stops at NotProvided or roots).

Instances

#RenderDepTree Source

class RenderDepTree :: Symbol -> RowList Type -> RowList Type -> Doc -> Constraintclass RenderDepTree (prefix :: Symbol) (reqRL :: RowList Type) (allLayers :: RowList Type) (doc :: Doc) | prefix reqRL allLayers -> doc

Render a dependency tree with tree connectors.

Instances

#FirstProvLabel Source

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

Extract the first label from a RowList.

Instances

#PrintLayerDispatch Source

class PrintLayerDispatch :: Boolean -> Symbol -> RowList Type -> RowList Type -> RowList Type -> Doc -> Constraintclass PrintLayerDispatch (show :: Boolean) (displayName :: Symbol) (filteredReqRL :: RowList Type) (tail :: RowList Type) (allLayers :: RowList Type) (doc :: Doc) | show displayName filteredReqRL tail allLayers -> doc

Dispatch: skip layers without missing deps, render tree for others.

Instances

#PrintLayersRL Source

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

Walk all layers emitting D2 edges (mermaid format for wireLayersDebug).

Instances

#PrintEdgesRL Source

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

Instances

#PrintLayersASCII Source

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

Walk all layers emitting ASCII dependency trees (for error messages).

Instances

#PrintEdgesASCII Source

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

Instances

#NotProvided Source

type NotProvided :: Symboltype NotProvided = "???"

Marker symbol for unresolved dependencies.

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

#TopoWire Source

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

Topologically sort and wire layers. Each iteration finds a layer whose dependencies are already satisfied, processes it, and adds its provisions.

Members

Instances

  • TopoWire Nil layers accReq accErr accProv accReq accErr accProv
  • (RowToList layers allLayersRL, RowToList accProv accProvRL, RowToList accReq accReqRL, RowListAppend accProvRL accReqRL availableRL, FindReady remaining availableRL allLayersRL readySym (OmLayer nextReq nextErr (Record nextProv)) rest, IsSymbol readySym, Cons readySym (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, TopoWire rest layers accReq errMerged provMerged resReq resErr resProv) => TopoWire remaining layers accReq accErr accProv resReq resErr resProv

#AllLabelsIn Source

class AllLabelsIn :: RowList Type -> RowList Type -> Boolean -> Constraintclass AllLabelsIn (needles :: RowList Type) (haystack :: RowList Type) (result :: Boolean) | needles haystack -> result

Check if ALL labels in needles exist in haystack, returning a Boolean.

Instances

#FindReady Source

class FindReady :: RowList Type -> RowList Type -> RowList Type -> Symbol -> Type -> RowList Type -> Constraintclass FindReady (candidates :: RowList Type) (available :: RowList Type) (allLayersRL :: RowList Type) (sym :: Symbol) (layer :: Type) (rest :: RowList Type) | candidates available allLayersRL -> sym layer rest

Scan candidates for the first layer whose requirements are satisfied.

Instances

#FindReadyDispatch Source

class FindReadyDispatch :: Boolean -> Symbol -> Type -> RowList Type -> RowList Type -> RowList Type -> Symbol -> Type -> RowList Type -> Constraintclass FindReadyDispatch (ready :: Boolean) (sym :: Symbol) (layer :: Type) (tail :: RowList Type) (available :: RowList Type) (allLayersRL :: RowList Type) (foundSym :: Symbol) (foundLayer :: Type) (rest :: RowList Type) | ready sym layer tail available allLayersRL -> foundSym foundLayer rest

Dispatch based on whether a layer is ready (deps satisfied).

Instances

Modules
Yoga.Om.Layer