Safe Haskell | None |
---|---|
Language | Haskell2010 |
Turn your jordan parsers into query-string parsers.
This module should be considered internal. Import Jordan.Servant.Query instead.
Synopsis
- data QueryKeyComponent
- newtype QueryKey = QueryKey {}
- labelParser :: Parser i a -> String -> Parser i a
- escapedBrace :: Parser ByteString
- afterBrace :: Parser ByteString
- escapedBraceEnding :: Parser ByteString
- unbracedValueInner :: Parser ByteString
- unbracedValue :: Parser Text
- bracedValue :: Parser Text
- emptyBraces :: Parser ByteString QueryKeyComponent
- queryComponent :: Parser QueryKeyComponent
- parseQueryKey :: Parser QueryKey
- newtype QueryParser a = QueryParser {
- runQueryParser :: (QueryKey -> Maybe QueryKey) -> [(QueryKey, Maybe ByteString)] -> Either String (a, [(QueryKey, Maybe ByteString)])
- peekTransformedKeyHead :: QueryParser QueryKey
- readBracketKey :: QueryKey -> QueryParser (Text, QueryKeyComponent)
- modifyTransformed :: (QueryKey -> Maybe QueryKey) -> QueryParser a -> QueryParser a
- droppingItem :: QueryKeyComponent -> QueryParser a -> QueryParser a
- droppingFirst :: QueryParser a -> QueryParser a
- asTuple :: QueryParser a -> QueryParser (Text, a)
- getTransform :: QueryParser (QueryKey -> Maybe QueryKey)
- failParse :: String -> QueryParser a
- takeValue :: QueryParser (Maybe ByteString)
- takeElement :: QueryParser ByteString
- takeNull :: QueryParser ()
- orParseError :: Show err => QueryParser (Either err a) -> QueryParser a
- ensureConsumes :: QueryParser a -> QueryParser a
- newtype JordanQueryParser a = JordanQueryParser {}
- newtype JordanQueryObjectParser a = JordanQueryObjectParser {}
- addArrayBrackets :: QueryParser q -> QueryParser q
- addJSONKey :: Text -> QueryParser q -> QueryParser q
- toBool :: ByteString -> Either JSONError Bool
- takeText :: QueryParser Text
- parseQueryToKeys :: Query -> [(QueryKey, Maybe ByteString)]
- filterToStarting :: Text -> [(QueryKey, Maybe ByteString)] -> [(QueryKey, Maybe ByteString)]
- transformToKey :: Text -> Query -> [(QueryKey, Maybe ByteString)]
- parseQueryAtKeyWith :: (forall jsonParser. JSONParser jsonParser => jsonParser a) -> Text -> Query -> Either String a
- hasQueryAtKey :: Text -> Query -> Bool
- parseQueryAtKey :: FromJSON a => Text -> Query -> Either String a
Documentation
data QueryKeyComponent Source #
Instances
Instances
Eq QueryKey Source # | |
Ord QueryKey Source # | |
Defined in Jordan.Servant.Query.Parse | |
Read QueryKey Source # | |
Show QueryKey Source # | |
Generic QueryKey Source # | |
type Rep QueryKey Source # | |
Defined in Jordan.Servant.Query.Parse type Rep QueryKey = D1 ('MetaData "QueryKey" "Jordan.Servant.Query.Parse" "jordan-servant-0.1.0.0-4pWi47ZOJ6bHDVnhgja79c" 'True) (C1 ('MetaCons "QueryKey" 'PrefixI 'True) (S1 ('MetaSel ('Just "queryKeyComponents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [QueryKeyComponent]))) |
bracedValue :: Parser Text Source #
newtype QueryParser a Source #
QueryParser | |
|
Instances
modifyTransformed :: (QueryKey -> Maybe QueryKey) -> QueryParser a -> QueryParser a Source #
droppingItem :: QueryKeyComponent -> QueryParser a -> QueryParser a Source #
droppingFirst :: QueryParser a -> QueryParser a Source #
asTuple :: QueryParser a -> QueryParser (Text, a) Source #
getTransform :: QueryParser (QueryKey -> Maybe QueryKey) Source #
failParse :: String -> QueryParser a Source #
takeValue :: QueryParser (Maybe ByteString) Source #
Take the value at the head, ensuring along the way that the entire query matches.
takeNull :: QueryParser () Source #
orParseError :: Show err => QueryParser (Either err a) -> QueryParser a Source #
ensureConsumes :: QueryParser a -> QueryParser a Source #
newtype JordanQueryParser a Source #
Instances
newtype JordanQueryObjectParser a Source #
Instances
addArrayBrackets :: QueryParser q -> QueryParser q Source #
addJSONKey :: Text -> QueryParser q -> QueryParser q Source #
parseQueryToKeys :: Query -> [(QueryKey, Maybe ByteString)] Source #
filterToStarting :: Text -> [(QueryKey, Maybe ByteString)] -> [(QueryKey, Maybe ByteString)] Source #
transformToKey :: Text -> Query -> [(QueryKey, Maybe ByteString)] Source #
:: (forall jsonParser. JSONParser jsonParser => jsonParser a) | JSON parser to use. Note the rank-N type. |
-> Text | Base key to use in the query string. |
-> Query | Query string |
-> Either String a | Either a value, or a brief (not super helpful) description of what went wrong. |
Use Jordan to parse a query at a given "base" key.
We need a base key in case the JSON type is "just an int" or something.
hasQueryAtKey :: Text -> Query -> Bool Source #
Determine if there are any query keys that match this base key.
>>>
hasQueryAtKey "foo" (parseQuery "foo[bar][baz]=true")
True
>>>
hasQueryAtKey "foo" (parseQuery "bar[baz]=true&bar[foo]=true&foo=true")
True
>>>
hasQueryAtKey "foo" (parseQuery "bar[baz]=true&bar[foo]=true")
False
parseQueryAtKey :: FromJSON a => Text -> Query -> Either String a Source #
Like parseQueryAtKeyWith
, but uses the FromJSON
instance, which is what you want 90% of the time.