-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Utilities for generating JSON-API payloads -- -- Provides utilities for deriving JSON payloads conformant to the -- json-api specification @package json-api-lib @version 0.1.1.0 -- | Module representing a JSON-API link object. -- -- Specification: http://jsonapi.org/format/#document-links module Network.JSONApi.Link -- | Type representing a JSON-API link object. -- -- Links are an abstraction around an underlying Map consisting of -- relevance identifiers as keys and URIs as values. -- -- Example JSON: "links": { "self": -- "http://example.com/posts/1" } -- -- Specification: http://jsonapi.org/format/#document-links data Links type Rel = Text type Href = Text -- | Constructor function for building Links mkLinks :: [(Rel, Text)] -> Links instance GHC.Generics.Generic Network.JSONApi.Link.Links instance Data.Aeson.Types.FromJSON.FromJSON Network.JSONApi.Link.Links instance Data.Aeson.Types.ToJSON.ToJSON Network.JSONApi.Link.Links instance GHC.Classes.Ord Network.JSONApi.Link.Links instance GHC.Classes.Eq Network.JSONApi.Link.Links instance GHC.Show.Show Network.JSONApi.Link.Links -- | Module representing a JSON-API meta object. -- -- Specification: http://jsonapi.org/format/#document-meta module Network.JSONApi.Meta -- | Type representing a JSON-API meta object. -- -- Meta is an abstraction around an underlying Map consisting of -- resource-specific metadata. -- -- Example JSON: "meta": { "copyright": "Copyright 2015 Example -- Corp.", "authors": [ "Andre Dawson", "Kirby Puckett", "Don Mattingly", -- "Ozzie Guillen" ] } -- -- Specification: http://jsonapi.org/format/#document-meta data Meta -- | Convienience class for constructing a Meta type -- -- Example usage: @ data Pagination = Pagination { currentPage :: Int , -- totalPages :: Int } deriving (Show, Generic) -- -- instance ToJSON Pagination instance MetaObject Pagination where -- typeName _ = "pagination" @ class (ToJSON a) => MetaObject a typeName :: MetaObject a => a -> Text -- | Pagination is arguably a meta object not covered by the Spec. The spec -- instead opts for links which are supported by this library. However if -- you would like to throw a generic Pagination meta object into your -- response payload this type may be used. data Pagination Pagination :: Maybe Int -> Maybe Int -> Maybe Int -> Pagination [pageSize] :: Pagination -> Maybe Int [currentPage] :: Pagination -> Maybe Int [totalDocuments] :: Pagination -> Maybe Int -- | Convienience constructor function for the Meta type -- -- Useful on its own or in combination with Meta's monoid instance -- -- Example usage: See MetaSpec.hs for an example mkMeta :: MetaObject a => a -> Meta instance Data.Aeson.Types.ToJSON.ToJSON Network.JSONApi.Meta.Pagination instance Data.Aeson.Types.FromJSON.FromJSON Network.JSONApi.Meta.Pagination instance Network.JSONApi.Meta.MetaObject Network.JSONApi.Meta.Pagination instance GHC.Show.Show Network.JSONApi.Meta.Pagination instance GHC.Classes.Eq Network.JSONApi.Meta.Pagination instance GHC.Generics.Generic Network.JSONApi.Meta.Meta instance GHC.Classes.Eq Network.JSONApi.Meta.Meta instance GHC.Show.Show Network.JSONApi.Meta.Meta instance Data.Aeson.Types.ToJSON.ToJSON Network.JSONApi.Meta.Meta instance Data.Aeson.Types.FromJSON.FromJSON Network.JSONApi.Meta.Meta -- | Module representing a JSON-API resource object. -- -- Specification: -- http://jsonapi.org/format/#document-resource-objects module Network.JSONApi.Identifier -- | Typeclass indicating how to access an Identifier for a given -- datatype class HasIdentifier a identifier :: HasIdentifier a => a -> Identifier -- | Identifiers are used to encapsulate the minimum amount of information -- to uniquely identify a resource. -- -- This object will be found at multiple levels of the JSON-API structure -- -- Specification: -- http://jsonapi.org/format/#document-resource-identifier-objects data Identifier Identifier :: Text -> Text -> Maybe Meta -> Identifier [_ident] :: Identifier -> Text [_datatype] :: Identifier -> Text [_metadata] :: Identifier -> Maybe Meta datatype :: Lens' Identifier Text ident :: Lens' Identifier Text metadata :: Lens' Identifier (Maybe Meta) instance GHC.Classes.Eq Network.JSONApi.Identifier.Identifier instance GHC.Show.Show Network.JSONApi.Identifier.Identifier instance Data.Aeson.Types.ToJSON.ToJSON Network.JSONApi.Identifier.Identifier instance Data.Aeson.Types.FromJSON.FromJSON Network.JSONApi.Identifier.Identifier -- | Module representing a JSON-API error object. -- -- Error objects are used for providing application-specific detail to -- unsuccessful API responses. -- -- Specification: http://jsonapi.org/format/#error-objects module Network.JSONApi.Error -- | Type for providing application-specific detail to unsuccessful API -- responses. -- -- Specification: http://jsonapi.org/format/#error-objects data Error a Error :: Maybe Text -> Maybe Links -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Meta -> Error a [id] :: Error a -> Maybe Text [links] :: Error a -> Maybe Links [status] :: Error a -> Maybe Text [code] :: Error a -> Maybe Text [title] :: Error a -> Maybe Text [detail] :: Error a -> Maybe Text [meta] :: Error a -> Maybe Meta instance GHC.Generics.Generic (Network.JSONApi.Error.Error a) instance GHC.Classes.Eq (Network.JSONApi.Error.Error a) instance GHC.Show.Show (Network.JSONApi.Error.Error a) instance Data.Aeson.Types.ToJSON.ToJSON a => Data.Aeson.Types.ToJSON.ToJSON (Network.JSONApi.Error.Error a) instance Data.Aeson.Types.FromJSON.FromJSON a => Data.Aeson.Types.FromJSON.FromJSON (Network.JSONApi.Error.Error a) instance Data.Default.Class.Default (Network.JSONApi.Error.Error a) -- | Module representing a JSON-API resource object. -- -- Specification: -- http://jsonapi.org/format/#document-resource-objects module Network.JSONApi.Resource newtype PageNum PageNum :: Int -> PageNum [getPageNum] :: PageNum -> Int -- | We can specify limits on the number of rows we would like back from -- the database newtype PageSize PageSize :: Int -> PageSize [getPageSize] :: PageSize -> Int -- | Type representing a JSON-API resource object. -- -- A Resource supplies standardized data and metadata about a resource. -- -- Specification: -- http://jsonapi.org/format/#document-resource-objects data Resource a Resource :: Identifier -> a -> Maybe Links -> Maybe Relationships -> Resource a [getIdentifier] :: Resource a -> Identifier [getResource] :: Resource a -> a [getLinks] :: Resource a -> Maybe Links [getRelationships] :: Resource a -> Maybe Relationships newtype ResourceCount ResourceCount :: Int -> ResourceCount [getResourceCount] :: ResourceCount -> Int data Relationships -- | A typeclass for decorating an entity with JSON API properties class (ToJSON a, FromJSON a) => ResourcefulEntity a resourceIdentifier :: ResourcefulEntity a => a -> Text resourceType :: ResourcefulEntity a => a -> Text resourceLinks :: ResourcefulEntity a => a -> Maybe Links resourceMetaData :: ResourcefulEntity a => a -> Maybe Meta resourceRelationships :: ResourcefulEntity a => a -> Maybe Relationships fromResource :: ResourcefulEntity a => Resource a -> a toResource :: ResourcefulEntity a => a -> Resource a -- | A type representing the Relationship between 2 entities -- -- A Relationship provides basic information for fetching further -- information about a related resource. -- -- Specification: -- http://jsonapi.org/format/#document-resource-object-relationships data Relationship -- | Helper function to beuild relative links for a collection of resources -- of type ResourceEntity. -- -- This helper function assumes that the first page is always page 0. indexLinks :: ResourcefulEntity e => e -> Maybe Text -> PageSize -> PageNum -> ResourceCount -> Links -- | Constructor function for creating a Relationship record -- -- A relationship must contain either an Identifier or a Links record mkRelationship :: Maybe Identifier -> Maybe Links -> Maybe Relationship mkRelationships :: Relationship -> Relationships -- | Helper function to build relative links for a single resource of type -- ResourceEntity showLink :: ResourcefulEntity e => e -> Links instance GHC.Show.Show Network.JSONApi.Resource.ResourceCount instance GHC.Show.Show Network.JSONApi.Resource.PageNum instance GHC.Show.Show Network.JSONApi.Resource.PageSize instance GHC.Generics.Generic (Network.JSONApi.Resource.Resource a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Network.JSONApi.Resource.Resource a) instance GHC.Show.Show a => GHC.Show.Show (Network.JSONApi.Resource.Resource a) instance GHC.Generics.Generic Network.JSONApi.Resource.Relationships instance GHC.Classes.Eq Network.JSONApi.Resource.Relationships instance GHC.Show.Show Network.JSONApi.Resource.Relationships instance GHC.Generics.Generic Network.JSONApi.Resource.Relationship instance GHC.Classes.Eq Network.JSONApi.Resource.Relationship instance GHC.Show.Show Network.JSONApi.Resource.Relationship instance Data.Aeson.Types.ToJSON.ToJSON a => Data.Aeson.Types.ToJSON.ToJSON (Network.JSONApi.Resource.Resource a) instance Data.Aeson.Types.FromJSON.FromJSON a => Data.Aeson.Types.FromJSON.FromJSON (Network.JSONApi.Resource.Resource a) instance Network.JSONApi.Identifier.HasIdentifier (Network.JSONApi.Resource.Resource a) instance Data.Aeson.Types.ToJSON.ToJSON Network.JSONApi.Resource.Relationships instance Data.Aeson.Types.FromJSON.FromJSON Network.JSONApi.Resource.Relationships instance Data.Aeson.Types.ToJSON.ToJSON Network.JSONApi.Resource.Relationship instance Data.Aeson.Types.FromJSON.FromJSON Network.JSONApi.Resource.Relationship -- | Contains representations of the top-level JSON-API document structure. module Network.JSONApi.Document -- | The Document type represents the top-level JSON-API -- requirement. -- -- data attribute - the resulting JSON may be either a singleton -- resource or a list of resources. See Resource for the -- construction. -- -- For more information see: -- http://jsonapi.org/format/#document-top-level data Document a -- | The Resource type encapsulates the underlying Resource -- -- Included in the top-level Document, the Resource may be -- either a singleton resource or a list. -- -- For more information see: -- http://jsonapi.org/format/#document-top-level data ResourceData a Singleton :: Resource a -> ResourceData a List :: [Resource a] -> ResourceData a -- | The ErrorDocument type represents the alternative form of the -- top-level JSON-API requirement. -- -- error attribute - a descriptive object encapsulating -- application-specific error detail. -- -- For more information see: http://jsonapi.org/format/#errors data ErrorDocument a ErrorDocument :: Error a -> Maybe Links -> Maybe Meta -> ErrorDocument a [_error] :: ErrorDocument a -> Error a [_errorLinks] :: ErrorDocument a -> Maybe Links [_errorMeta] :: ErrorDocument a -> Maybe Meta -- | The Included type is an abstraction used to constrain the -- included section of the Document to JSON serializable -- Resource objects while enabling a heterogeneous list of Resource -- types. -- -- No data constructors for this type are exported as we need to -- constrain the Value to a heterogeneous list of Resource types. -- See mkIncludedResource for creating Included types. data Included -- | Constructor function for the Document data type. -- -- See mkCompoundDocument for constructing compound Document -- including 'side-loaded' resources mkDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> Document a mkDocument' :: ResourceData a -> Maybe Links -> Maybe Meta -> Document a singleton :: ResourcefulEntity a => a -> ResourceData a list :: ResourcefulEntity a => [a] -> ResourceData a -- | Constructor function for the Document data type. See -- mkIncludedResource for constructing the Included type. -- -- Supports building compound documents -- http://jsonapi.org/format/#document-compound-documents mkCompoundDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> Included -> Document a mkCompoundDocument' :: ResourceData a -> Maybe Links -> Maybe Meta -> Included -> Document a -- | Constructor function for the Document data type. -- -- Supports building compound documents -- http://jsonapi.org/format/#document-compound-documents mkIncludedResource :: ResourcefulEntity a => a -> Included instance GHC.Generics.Generic (Network.JSONApi.Document.ErrorDocument a) instance GHC.Classes.Eq (Network.JSONApi.Document.ErrorDocument a) instance GHC.Show.Show (Network.JSONApi.Document.ErrorDocument a) instance GHC.Generics.Generic (Network.JSONApi.Document.Document a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Network.JSONApi.Document.Document a) instance GHC.Show.Show a => GHC.Show.Show (Network.JSONApi.Document.Document a) instance GHC.Generics.Generic (Network.JSONApi.Document.ResourceData a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Network.JSONApi.Document.ResourceData a) instance GHC.Show.Show a => GHC.Show.Show (Network.JSONApi.Document.ResourceData a) instance GHC.Show.Show Network.JSONApi.Document.Included instance Data.Aeson.Types.ToJSON.ToJSON a => Data.Aeson.Types.ToJSON.ToJSON (Network.JSONApi.Document.ErrorDocument a) instance Data.Aeson.Types.FromJSON.FromJSON a => Data.Aeson.Types.FromJSON.FromJSON (Network.JSONApi.Document.ErrorDocument a) instance Data.Aeson.Types.ToJSON.ToJSON a => Data.Aeson.Types.ToJSON.ToJSON (Network.JSONApi.Document.Document a) instance Data.Aeson.Types.FromJSON.FromJSON a => Data.Aeson.Types.FromJSON.FromJSON (Network.JSONApi.Document.Document a) instance Data.Aeson.Types.ToJSON.ToJSON a => Data.Aeson.Types.ToJSON.ToJSON (Network.JSONApi.Document.ResourceData a) instance Data.Aeson.Types.FromJSON.FromJSON a => Data.Aeson.Types.FromJSON.FromJSON (Network.JSONApi.Document.ResourceData a) -- | Entry-point module for this package. module Network.JSONApi -- | The Document type represents the top-level JSON-API -- requirement. -- -- data attribute - the resulting JSON may be either a singleton -- resource or a list of resources. See Resource for the -- construction. -- -- For more information see: -- http://jsonapi.org/format/#document-top-level data Document a -- | The Resource type encapsulates the underlying Resource -- -- Included in the top-level Document, the Resource may be -- either a singleton resource or a list. -- -- For more information see: -- http://jsonapi.org/format/#document-top-level data ResourceData a Singleton :: Resource a -> ResourceData a List :: [Resource a] -> ResourceData a -- | The ErrorDocument type represents the alternative form of the -- top-level JSON-API requirement. -- -- error attribute - a descriptive object encapsulating -- application-specific error detail. -- -- For more information see: http://jsonapi.org/format/#errors data ErrorDocument a ErrorDocument :: Error a -> Maybe Links -> Maybe Meta -> ErrorDocument a [_error] :: ErrorDocument a -> Error a [_errorLinks] :: ErrorDocument a -> Maybe Links [_errorMeta] :: ErrorDocument a -> Maybe Meta -- | The Included type is an abstraction used to constrain the -- included section of the Document to JSON serializable -- Resource objects while enabling a heterogeneous list of Resource -- types. -- -- No data constructors for this type are exported as we need to -- constrain the Value to a heterogeneous list of Resource types. -- See mkIncludedResource for creating Included types. data Included -- | Type for providing application-specific detail to unsuccessful API -- responses. -- -- Specification: http://jsonapi.org/format/#error-objects data Error a Error :: Maybe Text -> Maybe Links -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Meta -> Error a [id] :: Error a -> Maybe Text [links] :: Error a -> Maybe Links [status] :: Error a -> Maybe Text [code] :: Error a -> Maybe Text [title] :: Error a -> Maybe Text [detail] :: Error a -> Maybe Text [meta] :: Error a -> Maybe Meta newtype PageNum PageNum :: Int -> PageNum [getPageNum] :: PageNum -> Int -- | We can specify limits on the number of rows we would like back from -- the database newtype PageSize PageSize :: Int -> PageSize [getPageSize] :: PageSize -> Int -- | A type representing the Relationship between 2 entities -- -- A Relationship provides basic information for fetching further -- information about a related resource. -- -- Specification: -- http://jsonapi.org/format/#document-resource-object-relationships data Relationship -- | Type representing a JSON-API resource object. -- -- A Resource supplies standardized data and metadata about a resource. -- -- Specification: -- http://jsonapi.org/format/#document-resource-objects data Resource a Resource :: Identifier -> a -> Maybe Links -> Maybe Relationships -> Resource a [getIdentifier] :: Resource a -> Identifier [getResource] :: Resource a -> a [getLinks] :: Resource a -> Maybe Links [getRelationships] :: Resource a -> Maybe Relationships newtype ResourceCount ResourceCount :: Int -> ResourceCount [getResourceCount] :: ResourceCount -> Int data Relationships -- | A typeclass for decorating an entity with JSON API properties class (ToJSON a, FromJSON a) => ResourcefulEntity a resourceIdentifier :: ResourcefulEntity a => a -> Text resourceType :: ResourcefulEntity a => a -> Text resourceLinks :: ResourcefulEntity a => a -> Maybe Links resourceMetaData :: ResourcefulEntity a => a -> Maybe Meta resourceRelationships :: ResourcefulEntity a => a -> Maybe Relationships fromResource :: ResourcefulEntity a => Resource a -> a toResource :: ResourcefulEntity a => a -> Resource a -- | Typeclass indicating how to access an Identifier for a given -- datatype class HasIdentifier a identifier :: HasIdentifier a => a -> Identifier -- | Identifiers are used to encapsulate the minimum amount of information -- to uniquely identify a resource. -- -- This object will be found at multiple levels of the JSON-API structure -- -- Specification: -- http://jsonapi.org/format/#document-resource-identifier-objects data Identifier Identifier :: Text -> Text -> Maybe Meta -> Identifier [_ident] :: Identifier -> Text [_datatype] :: Identifier -> Text [_metadata] :: Identifier -> Maybe Meta -- | Type representing a JSON-API link object. -- -- Links are an abstraction around an underlying Map consisting of -- relevance identifiers as keys and URIs as values. -- -- Example JSON: "links": { "self": -- "http://example.com/posts/1" } -- -- Specification: http://jsonapi.org/format/#document-links data Links -- | Type representing a JSON-API meta object. -- -- Meta is an abstraction around an underlying Map consisting of -- resource-specific metadata. -- -- Example JSON: "meta": { "copyright": "Copyright 2015 Example -- Corp.", "authors": [ "Andre Dawson", "Kirby Puckett", "Don Mattingly", -- "Ozzie Guillen" ] } -- -- Specification: http://jsonapi.org/format/#document-meta data Meta -- | Convienience class for constructing a Meta type -- -- Example usage: @ data Pagination = Pagination { currentPage :: Int , -- totalPages :: Int } deriving (Show, Generic) -- -- instance ToJSON Pagination instance MetaObject Pagination where -- typeName _ = "pagination" @ class (ToJSON a) => MetaObject a typeName :: MetaObject a => a -> Text -- | Pagination is arguably a meta object not covered by the Spec. The spec -- instead opts for links which are supported by this library. However if -- you would like to throw a generic Pagination meta object into your -- response payload this type may be used. data Pagination Pagination :: Maybe Int -> Maybe Int -> Maybe Int -> Pagination [pageSize] :: Pagination -> Maybe Int [currentPage] :: Pagination -> Maybe Int [totalDocuments] :: Pagination -> Maybe Int -- | Constructor function for building Links mkLinks :: [(Rel, Text)] -> Links -- | Helper function to beuild relative links for a collection of resources -- of type ResourceEntity. -- -- This helper function assumes that the first page is always page 0. indexLinks :: ResourcefulEntity e => e -> Maybe Text -> PageSize -> PageNum -> ResourceCount -> Links -- | Constructor function for creating a Relationship record -- -- A relationship must contain either an Identifier or a Links record mkRelationship :: Maybe Identifier -> Maybe Links -> Maybe Relationship mkRelationships :: Relationship -> Relationships -- | Helper function to build relative links for a single resource of type -- ResourceEntity showLink :: ResourcefulEntity e => e -> Links -- | Constructor function for the Document data type. -- -- See mkCompoundDocument for constructing compound Document -- including 'side-loaded' resources mkDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> Document a mkDocument' :: ResourceData a -> Maybe Links -> Maybe Meta -> Document a singleton :: ResourcefulEntity a => a -> ResourceData a list :: ResourcefulEntity a => [a] -> ResourceData a -- | Constructor function for the Document data type. See -- mkIncludedResource for constructing the Included type. -- -- Supports building compound documents -- http://jsonapi.org/format/#document-compound-documents mkCompoundDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> Included -> Document a mkCompoundDocument' :: ResourceData a -> Maybe Links -> Maybe Meta -> Included -> Document a -- | Constructor function for the Document data type. -- -- Supports building compound documents -- http://jsonapi.org/format/#document-compound-documents mkIncludedResource :: ResourcefulEntity a => a -> Included -- | Convienience constructor function for the Meta type -- -- Useful on its own or in combination with Meta's monoid instance -- -- Example usage: See MetaSpec.hs for an example mkMeta :: MetaObject a => a -> Meta