Safe Haskell | None |
---|---|
Language | Haskell98 |
This library allows you to apply a json-patch document (rfc6902) directly to a haskell datatype. It's based on the Data.Aeson.Diff module.
- patch :: JsonPatch a => Patch -> a -> Result a
- applyOperation :: JsonPatch a => Operation -> a -> Result a
- class (Eq s, ToJSON s, FromJSON s, Typeable s) => JsonPatch s where
- getDynamic :: Typeable a => Dynamic -> Result a
- getValueAtPointer :: JsonPatch s => Pointer -> s -> Result Value
- getDataAtPointer :: (JsonPatch s, Typeable a) => Pointer -> s -> Result a
- data GetSet s = JsonPatch v => GetSet v (v -> Result s)
- class (Eq s, ToJSON s, FromJSON s, Typeable s) => FieldLens s where
patch operations
applyOperation :: JsonPatch a => Operation -> a -> Result a Source #
Apply a single operation to the data.
class (Eq s, ToJSON s, FromJSON s, Typeable s) => JsonPatch s where Source #
This class defines all operations necessary for applying patches.
Instances can be written by hand, however it's easier to use the
fieldLens
class instead, or to derive it automatically using the
template haskell functions from the Data.Aeson.Diff.Generic.TH
module. The default implementation is based on fieldLens
, which
matches a string to a existentially quantified getter and setter
(the GetSet
datatype). The Instances can be found in the
Data.Aeson.Diff.Generic.Instances module, which this module
exports.
getAtPointer :: Pointer -> s -> (forall v. JsonPatch v => v -> r) -> Result r Source #
Retrieve the value at the pointer. To get back a json Value
use toJSON
as the helper function, to get back a Dynamic
use
toDyn
.
getAtPointer :: FieldLens s => Pointer -> s -> (forall v. JsonPatch v => v -> r) -> Result r Source #
Retrieve the value at the pointer. To get back a json Value
use toJSON
as the helper function, to get back a Dynamic
use
toDyn
.
deleteAtPointer :: Pointer -> s -> (forall v. JsonPatch v => v -> r) -> Result (r, s) Source #
Remove the value at pointer from the data. The original
value is returned. To get back a json Value
use toJSON
as
the helper function, to get back a Dynamic
use toDyn
.
deleteAtPointer :: FieldLens s => Pointer -> s -> (forall v. JsonPatch v => v -> r) -> Result (r, s) Source #
Remove the value at pointer from the data. The original
value is returned. To get back a json Value
use toJSON
as
the helper function, to get back a Dynamic
use toDyn
.
addAtPointer :: Pointer -> s -> r -> (forall v. JsonPatch v => r -> Result v) -> Result s Source #
Add a value at the pointer. To insert a json Value
, use
fromJSON
as the helper function, to insert a Dynamic
use getDynamic
.
addAtPointer :: FieldLens s => Pointer -> s -> r -> (forall v. JsonPatch v => r -> Result v) -> Result s Source #
Add a value at the pointer. To insert a json Value
, use
fromJSON
as the helper function, to insert a Dynamic
use getDynamic
.
copyPath :: Pointer -> Pointer -> s -> Result s Source #
copyPath src
dst
s. Copy the value at src to dest in s.
If the types don't match an error is returned
copyPath :: FieldLens s => Pointer -> Pointer -> s -> Result s Source #
copyPath src
dst
s. Copy the value at src to dest in s.
If the types don't match an error is returned
movePath :: Pointer -> Pointer -> s -> Result s Source #
movePath src
dst
s. Move the value from src to dest in
s. If the types don't match an error is returned
movePath :: FieldLens s => Pointer -> Pointer -> s -> Result s Source #
movePath src
dst
s. Move the value from src to dest in
s. If the types don't match an error is returned
replaceAtPointer :: Pointer -> s -> r -> (forall v. JsonPatch v => r -> Result v) -> Result s Source #
Replace the value at the pointer with the new value. To replace
using a json Value
, use fromJSON
as the helper function, to
insert a Dynamic
use getDynamic
.
replaceAtPointer :: FieldLens s => Pointer -> s -> r -> (forall v. JsonPatch v => r -> Result v) -> Result s Source #
Replace the value at the pointer with the new value. To replace
using a json Value
, use fromJSON
as the helper function, to
insert a Dynamic
use getDynamic
.
testAtPointer :: Pointer -> s -> r -> (forall v. JsonPatch v => r -> Result v) -> Result s Source #
Test if the value at the pointer matches the given value (after conversion). Return the data if they match, give an error otherwise.
testAtPointer :: FieldLens s => Pointer -> s -> r -> (forall v. JsonPatch v => r -> Result v) -> Result s Source #
Test if the value at the pointer matches the given value (after conversion). Return the data if they match, give an error otherwise.
getValueAtPointer :: JsonPatch s => Pointer -> s -> Result Value Source #
Get the json value at the pointer. Gives an error if the destination doesn't exist.
getDataAtPointer :: (JsonPatch s, Typeable a) => Pointer -> s -> Result a Source #
Get the value at the pointer. Gives and error If the types don't match or if the destination doesn't exist.
the fieldLens class
An existentially quantified getter and setter. The data inside
is manipulated using json conversion functions (toJSON
,
fromJSON
), or Data.Dynamic (getDynamic
, toDyn
, etc...).
class (Eq s, ToJSON s, FromJSON s, Typeable s) => FieldLens s where Source #
fieldLens :: Key -> s -> Result (GetSet s) Source #
Map a key to a getter and setter on the given data.
deleteAt :: Key -> s -> (forall v. JsonPatch v => v -> r) -> Result (r, s) Source #
Delete and return the data at the given key. The helper
function determines which value to return: toJSON
to return an
aeson Value
, toDyn
to return a Dynamic
.
insertAt :: Key -> s -> r -> (forall v. JsonPatch v => r -> Result v) -> Result s Source #
Insert a value at the given key. The helper function
determines how to convert the value: fromJSON
to convert from
an aeson Value
, getDynamic
to convert from a Dynamic
.