singular-registry
LicenseApache-2.0
Safe HaskellNone
LanguageGHC2021

Singular.Provider.Koios.Recorded

Description

A Transport that answers each request from a fixture directory recorded from a live Koios service by the koios-http recorder. The answers are raw — status, headers and body — so the client pages and decodes them exactly as it does live answers.

Each fixture is one JSON file holding the request, the Koios schema revision, the time of recording, the SHA-256 of the answer body and the answer. Loading a directory refuses a fixture whose body does not match its hash, a set whose fixtures disagree on the schema revision, two fixtures for one request, and an empty directory. A request with no fixture is answered by NoRecording, which the client reports as NotRecorded.

Synopsis

Fixtures

data Fixture Source #

One recorded answer.

Constructors

Fixture 

Fields

Instances

Instances details
Show Fixture Source # 
Instance details

Defined in Singular.Provider.Koios.Recorded

Methods

showsPrec :: Int -> Fixture -> ShowS Source #

show :: Fixture -> String Source #

showList :: [Fixture] -> ShowS Source #

Eq Fixture Source # 
Instance details

Defined in Singular.Provider.Koios.Recorded

Methods

(==) :: Fixture -> Fixture -> Bool Source #

(/=) :: Fixture -> Fixture -> Bool Source #

data FixtureRequest Source #

The part of a request a fixture is keyed by: call, method, path, query in sorted order, and body. Headers, such as a bearer token, are never part of it.

Constructors

FixtureRequest 

Fields

Instances

Instances details
Show FixtureRequest Source # 
Instance details

Defined in Singular.Provider.Koios.Recorded

Methods

showsPrec :: Int -> FixtureRequest -> ShowS Source #

show :: FixtureRequest -> String Source #

showList :: [FixtureRequest] -> ShowS Source #

Eq FixtureRequest Source # 
Instance details

Defined in Singular.Provider.Koios.Recorded

Methods

(==) :: FixtureRequest -> FixtureRequest -> Bool Source #

(/=) :: FixtureRequest -> FixtureRequest -> Bool Source #

fixtureRequestOf :: RawRequest -> FixtureRequest Source #

The fixture key of a raw request.

fixtureFileName :: FixtureRequest -> FilePath Source #

A file name derived from the request alone.

encodeFixture :: Fixture -> ByteString Source #

The JSON text of a fixture.

decodeFixture :: ByteString -> Either Text Fixture Source #

Read a fixture's JSON text.

bodySha256 :: ByteString -> Text Source #

Hex SHA-256 of an answer body.

Fixture sets

data FixtureSet Source #

A loaded fixture directory, all under one schema revision.

Constructors

FixtureSet 

Fields

Instances

Instances details
Show FixtureSet Source # 
Instance details

Defined in Singular.Provider.Koios.Recorded

Methods

showsPrec :: Int -> FixtureSet -> ShowS Source #

show :: FixtureSet -> String Source #

showList :: [FixtureSet] -> ShowS Source #

Eq FixtureSet Source # 
Instance details

Defined in Singular.Provider.Koios.Recorded

Methods

(==) :: FixtureSet -> FixtureSet -> Bool Source #

(/=) :: FixtureSet -> FixtureSet -> Bool Source #

data FixtureFailure Source #

Why a fixture directory cannot be used.

Constructors

FixtureUnreadable FilePath Text

A file that is not a fixture, or a directory that cannot be read

FixtureHashMismatch FilePath

A fixture whose body does not hash to its recorded SHA-256

RevisionMismatch [(FilePath, Text)]

Fixtures recorded under different schema revisions

DuplicateRequest FilePath FilePath

Two fixtures for one request

NoFixtures FilePath

A directory with no fixture

Instances

Instances details
Show FixtureFailure Source # 
Instance details

Defined in Singular.Provider.Koios.Recorded

Methods

showsPrec :: Int -> FixtureFailure -> ShowS Source #

show :: FixtureFailure -> String Source #

showList :: [FixtureFailure] -> ShowS Source #

Eq FixtureFailure Source # 
Instance details

Defined in Singular.Provider.Koios.Recorded

Methods

(==) :: FixtureFailure -> FixtureFailure -> Bool Source #

(/=) :: FixtureFailure -> FixtureFailure -> Bool Source #

loadFixtureSet :: FilePath -> IO (Either FixtureFailure FixtureSet) Source #

Load every .json fixture of a directory.

Transport

recordedTransport :: forall (m :: Type -> Type). Applicative m => FixtureSet -> Transport m Source #

Answer each request from the set; one attempt per request.