ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Registry.CachedDocument

Description

The cached and served raw document as an opaque carrier with a private constructor.

The serve path caches an upstream packument's raw document and rebuilds the served body from it, but the neutral pipeline and the metadata cache must hold that document without reading it: every structural operation over it is an injected adapter capability (the fetch that produces it, the assembly that merges it, the serialisation that encodes it). CachedDoc makes that opacity a property the compiler enforces rather than a discipline the neutral code must keep: the constructor is not exported, so a module outside this one can cache, thread, and hand back a CachedDoc but cannot inspect what it carries.

An ecosystem works in its own representation and crosses this boundary through an inject/project pair (npmCached for npm, whose representation is a JSON Value): it injects on the way into the cache and pipeline and projects on the way out, at its own capabilities. The cache weighs a held document through weighCachedDoc without projecting it.

Synopsis

Documentation

data CachedDoc Source #

A raw document the metadata cache holds and the neutral serve pipeline threads. The representation: an npm packument as a JSON Value. Exported abstract -- the constructor is private, so only this module's boundary pairs cross it and the neutral core cannot read the document a CachedDoc carries. The derived Show and Eq are a debug and test affordance (a failure message, a round-trip assertion), not a projection: they give the neutral core no way to recover the underlying document to assemble or serialise it.

Instances

Instances details
Show CachedDoc Source # 
Instance details

Defined in Ecluse.Core.Registry.CachedDocument

Eq CachedDoc Source # 
Instance details

Defined in Ecluse.Core.Registry.CachedDocument

weighCachedDoc :: CachedDoc -> Int64 Source #

A held document's resident-size estimate: the byte length of its compact encoding, the figure the metadata cache weighs an entry by. Computed here, where the arm is known, so the cache need not project the document back to an ecosystem representation to size it.

npmCached :: (Value -> CachedDoc, CachedDoc -> Maybe Value) Source #

npm's boundary pair: inject a packument Value into a CachedDoc, and project one back to the Value npm assembles and serialises over. npm is the injector for every document it later projects, so a document it injected always projects back (Just); the Maybe is the projection's type, matched at npm's own capabilities.