mirror of
https://github.com/ilyakooo0/purescript-indexedDB.git
synced 2024-09-11 06:55:48 +03:00
change reference from Key to Foreign for FFI functions
This commit is contained in:
parent
3705bbc48a
commit
808de4f3c3
@ -18,7 +18,7 @@ import Database.IndexedDB.Core
|
||||
-- INTERFACE
|
||||
--
|
||||
-- Type alias for binding listeners to an initial open action.
|
||||
type OpenRequest e =
|
||||
type Callbacks e =
|
||||
{ onBlocked :: Maybe (Eff (| e) Unit)
|
||||
, onUpgradeNeeded :: Maybe (Database -> Transaction -> Eff (| e) Unit)
|
||||
}
|
||||
@ -55,7 +55,7 @@ open
|
||||
:: forall e e'
|
||||
. DatabaseName
|
||||
-> Maybe Version
|
||||
-> OpenRequest e'
|
||||
-> Callbacks e'
|
||||
-> Aff (idb :: IDB | e) Database
|
||||
open name mver req =
|
||||
Fn.runFn4 _open fromMaybe name mver req
|
||||
@ -72,4 +72,4 @@ foreign import _deleteDatabase
|
||||
|
||||
foreign import _open
|
||||
:: forall a e e'
|
||||
. Fn4 (a -> Maybe a -> a) String (Maybe Int) (OpenRequest e') (Aff (idb :: IDB | e) Database)
|
||||
. Fn4 (a -> Maybe a -> a) String (Maybe Int) (Callbacks e') (Aff (idb :: IDB | e) Database)
|
||||
|
@ -4,17 +4,17 @@ module Database.IndexedDB.IDBIndex.Internal where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Control.Monad.Eff.Exception (Error)
|
||||
import Data.Foreign (Foreign, unsafeFromForeign)
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried (Fn2, Fn3, Fn4)
|
||||
import Data.Maybe (Maybe)
|
||||
import Data.Nullable (Nullable, toMaybe, toNullable)
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Control.Monad.Eff.Exception (Error)
|
||||
import Data.Foreign (Foreign, unsafeFromForeign)
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried (Fn2, Fn3, Fn4)
|
||||
import Data.Maybe (Maybe)
|
||||
import Data.Nullable (Nullable, toMaybe, toNullable)
|
||||
|
||||
import Database.IndexedDB.Core (IDB, CursorDirection, Index, Key, KeyCursor, KeyRange,
|
||||
KeyPath, ObjectStore, ValueCursor)
|
||||
import Database.IndexedDB.Core (IDB, CursorDirection, Index, Key, KeyCursor, KeyRange, KeyPath, ObjectStore, ValueCursor)
|
||||
import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key(..))
|
||||
|
||||
|
||||
--------------------
|
||||
@ -166,10 +166,10 @@ instance idbIndexIndex :: IDBIndex Index where
|
||||
(toMaybe >>> map unsafeFromForeign) <$> Fn.runFn2 _get index range
|
||||
|
||||
getAllKeys index range count =
|
||||
Fn.runFn3 _getAllKeys index (toNullable range) (toNullable count)
|
||||
map Key <$> Fn.runFn3 _getAllKeys index (toNullable range) (toNullable count)
|
||||
|
||||
getKey index range =
|
||||
toMaybe <$> Fn.runFn2 _getKey index range
|
||||
(toMaybe >>> map Key) <$> Fn.runFn2 _getKey index range
|
||||
|
||||
openCursor index range dir cb =
|
||||
Fn.runFn4 _openCursor index (toNullable range) (show dir) cb
|
||||
@ -186,10 +186,10 @@ instance idbIndexObjectStore :: IDBIndex ObjectStore where
|
||||
(toMaybe >>> map unsafeFromForeign) <$> Fn.runFn2 _get store range
|
||||
|
||||
getAllKeys store range count =
|
||||
Fn.runFn3 _getAllKeys store (toNullable range) (toNullable count)
|
||||
map Key <$> Fn.runFn3 _getAllKeys store (toNullable range) (toNullable count)
|
||||
|
||||
getKey store range =
|
||||
toMaybe <$> Fn.runFn2 _getKey store range
|
||||
(toMaybe >>> map Key) <$> Fn.runFn2 _getKey store range
|
||||
|
||||
openCursor store range dir cb =
|
||||
Fn.runFn4 _openCursor store (toNullable range) (show dir) cb
|
||||
@ -238,12 +238,12 @@ foreign import _get
|
||||
|
||||
foreign import _getAllKeys
|
||||
:: forall index e
|
||||
. Fn3 index (Nullable KeyRange) (Nullable Int) (Aff (idb :: IDB | e) (Array Key))
|
||||
. Fn3 index (Nullable KeyRange) (Nullable Int) (Aff (idb :: IDB | e) (Array Foreign))
|
||||
|
||||
|
||||
foreign import _getKey
|
||||
:: forall index e
|
||||
. Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Key))
|
||||
. Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Foreign))
|
||||
|
||||
|
||||
foreign import _openCursor
|
||||
|
@ -29,8 +29,7 @@ import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key(..), toKey, extract
|
||||
-- | 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
|
||||
|
||||
includes :: forall k. (IDBKey k) => range -> k -> Boolean
|
||||
|
||||
-- | Type alias for open
|
||||
type Open = Boolean
|
||||
@ -121,34 +120,49 @@ upperOpen =
|
||||
--
|
||||
instance idbKeyRangeKeyRange :: IDBKeyRange KeyRange where
|
||||
includes range =
|
||||
extractForeign >>> Fn.runFn2 _includes range
|
||||
toKey >>> extractForeign >>> Fn.runFn2 _includes range
|
||||
|
||||
|
||||
--------------------
|
||||
-- FFI
|
||||
--
|
||||
foreign import _bound :: Fn4 Foreign Foreign Boolean Boolean (Nullable KeyRange)
|
||||
foreign import _bound
|
||||
:: Fn4 Foreign Foreign Boolean Boolean (Nullable KeyRange)
|
||||
|
||||
|
||||
foreign import _includes :: forall range. Fn2 range Foreign Boolean
|
||||
foreign import _includes
|
||||
:: forall range
|
||||
. Fn2 range Foreign Boolean
|
||||
|
||||
|
||||
foreign import _lower :: KeyRange -> Nullable Foreign
|
||||
foreign import _lower
|
||||
:: KeyRange
|
||||
-> Nullable Foreign
|
||||
|
||||
|
||||
foreign import _lowerBound :: Fn2 Foreign Boolean KeyRange
|
||||
foreign import _lowerBound
|
||||
:: Fn2 Foreign Boolean KeyRange
|
||||
|
||||
|
||||
foreign import _lowerOpen :: KeyRange -> Boolean
|
||||
foreign import _lowerOpen
|
||||
:: KeyRange
|
||||
-> Boolean
|
||||
|
||||
|
||||
foreign import _only :: Foreign -> KeyRange
|
||||
foreign import _only
|
||||
:: Foreign
|
||||
-> KeyRange
|
||||
|
||||
|
||||
foreign import _upper :: KeyRange -> Nullable Foreign
|
||||
foreign import _upper
|
||||
:: KeyRange
|
||||
-> Nullable Foreign
|
||||
|
||||
|
||||
foreign import _upperBound :: Fn2 Foreign Boolean KeyRange
|
||||
foreign import _upperBound
|
||||
:: Fn2 Foreign Boolean KeyRange
|
||||
|
||||
|
||||
foreign import _upperOpen :: KeyRange -> Boolean
|
||||
foreign import _upperOpen
|
||||
:: KeyRange
|
||||
-> Boolean
|
||||
|
Loading…
Reference in New Issue
Block a user