mirror of
https://github.com/ilyakooo0/purescript-indexedDB.git
synced 2024-09-11 06:55:48 +03:00
add documentation to IDBKeyRange
This commit is contained in:
parent
3461bebbce
commit
02acc707ee
@ -1,3 +1,4 @@
|
||||
-- | A key has an associated type which is one of: number, date, string, binary, or array.
|
||||
module Database.IndexedDB.IDBKeyRange
|
||||
( class IDBKeyRange, includes
|
||||
, only
|
||||
@ -25,25 +26,56 @@ import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key(..), toKey, extract
|
||||
--------------------
|
||||
-- INTERFACES
|
||||
--
|
||||
-- | The IDBKeyRange interface represents a key range.
|
||||
class IDBKeyRange range where
|
||||
-- | Returns true if key is included in the range, and false otherwise.
|
||||
includes :: range -> Key -> Boolean
|
||||
|
||||
|
||||
only :: forall a. (IDBKey a) => a -> KeyRange
|
||||
-- | Type alias for open
|
||||
type Open = Boolean
|
||||
|
||||
|
||||
-- | Returns a new IDBKeyRange spanning only key.
|
||||
only
|
||||
:: forall a. (IDBKey a)
|
||||
=> a
|
||||
-> KeyRange
|
||||
only key =
|
||||
_only (extractForeign $ toKey key)
|
||||
|
||||
|
||||
lowerBound :: forall a. (IDBKey a) => a -> Boolean -> KeyRange
|
||||
-- | Returns a new IDBKeyRange starting at key with no upper bound.
|
||||
-- | If `Open` is `true`, key is not included in the range.
|
||||
lowerBound
|
||||
:: forall a. (IDBKey a)
|
||||
=> a
|
||||
-> Open
|
||||
-> KeyRange
|
||||
lowerBound key open =
|
||||
Fn.runFn2 _lowerBound (extractForeign $ toKey key) open
|
||||
|
||||
|
||||
upperBound :: forall a. (IDBKey a) => a -> Boolean -> KeyRange
|
||||
-- | Returns a new IDBKeyRange with no lower bound and ending at key.
|
||||
-- | If `Open` is `true`, key is not included in the range.
|
||||
upperBound
|
||||
:: forall a. (IDBKey a)
|
||||
=> a
|
||||
-> Open
|
||||
-> KeyRange
|
||||
upperBound key open =
|
||||
Fn.runFn2 _upperBound (extractForeign $ toKey key) open
|
||||
|
||||
bound :: forall a. (IDBKey a) => { lower :: a, upper :: a, lowerOpen :: Boolean, upperOpen :: Boolean } -> Maybe KeyRange
|
||||
|
||||
-- | Returns a new IDBKeyRange spanning from `lower` to `upper`.
|
||||
-- | If `lowerOpen` is `true`, `lower` is not included in the range.
|
||||
-- | If `upperOpen` is `true`, `upper` is not included in the range.
|
||||
-- |
|
||||
-- | It throws a `DataError` if the bound is invalid.
|
||||
bound
|
||||
:: forall a. (IDBKey a)
|
||||
=> { lower :: a, upper :: a, lowerOpen :: Boolean, upperOpen :: Boolean }
|
||||
-> Maybe KeyRange
|
||||
bound { lower: key1, upper: key2, lowerOpen: open1, upperOpen: open2 } =
|
||||
toMaybe
|
||||
$ Fn.runFn4 _bound (extractForeign $ toKey key1) (extractForeign $ toKey key2) open1 open2
|
||||
@ -52,22 +84,34 @@ bound { lower: key1, upper: key2, lowerOpen: open1, upperOpen: open2 } =
|
||||
--------------------
|
||||
-- ATTRIBUTES
|
||||
--
|
||||
lower :: KeyRange -> Maybe Key
|
||||
-- | Returns lower bound if any.
|
||||
lower
|
||||
:: KeyRange
|
||||
-> Maybe Key
|
||||
lower =
|
||||
_lower >>> toMaybe >>> map Key
|
||||
|
||||
|
||||
upper :: KeyRange -> Maybe Key
|
||||
-- | Returns upper bound if any.
|
||||
upper
|
||||
:: KeyRange
|
||||
-> Maybe Key
|
||||
upper =
|
||||
_upper >>> toMaybe >>> map Key
|
||||
|
||||
|
||||
lowerOpen :: KeyRange -> Boolean
|
||||
-- | Returns true if the lower open flag is set, false otherwise.
|
||||
lowerOpen
|
||||
:: KeyRange
|
||||
-> Boolean
|
||||
lowerOpen =
|
||||
_lowerOpen
|
||||
|
||||
|
||||
upperOpen :: KeyRange -> Boolean
|
||||
-- | Returns true if the upper open flag is set, false otherwise.
|
||||
upperOpen
|
||||
:: KeyRange
|
||||
-> Boolean
|
||||
upperOpen =
|
||||
_upperOpen
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user