git.iko.soy/purescript-indexed-DB
on master help sign in
remove EXCEPTION effects from Aff effects and rename eff -> e
commitbd0306927e137bdee56d22353e0904801c8f1b23 authorKtorZ <matthias.benkort@gmail.com> dateFri 30 Jun 2017, 14:12 (9 years ago) parentfdbbd17
7 files changed+74−64
src/Database/IndexedDB/Core.purs+9−5 src/Database/IndexedDB/IDBCursor.purs+10−10 src/Database/IndexedDB/IDBDatabase.purs+15−8 src/Database/IndexedDB/IDBFactory.purs+7−7 src/Database/IndexedDB/IDBIndex/Internal.purs+13−14 src/Database/IndexedDB/IDBObjectStore.purs+15−15 src/Database/IndexedDB/IDBTransaction.purs+5−5
src/Database/IndexedDB/Core.purs+9−5
@@ -1,6 +1,7 @@
11module Database.IndexedDB.Core
22 ( class FromString, parse
33 , INDEXED_DB
4+ , IDB
45 , CursorDirection(..)
56 , CursorSource(..)
67 , Database
@@ -23,8 +24,10 @@ import Data.Maybe (Maybe(..))
2324import Database.IndexedDB.IDBKey
2425
2526
26−class FromString a where
27− parse :: String -> Maybe a
27+foreign import data INDEXED_DB :: Effect
28+
29+
30+foreign import data IDB :: Effect
2831
2932
3033data CursorDirection = Next | NextUnique | Prev | PrevUnique
@@ -39,9 +42,6 @@ data TransactionMode = ReadOnly | ReadWrite | VersionChange
3942type KeyPath = Array String
4043
4144
42−foreign import data INDEXED_DB :: Effect
43−
44−
4545foreign import data Database :: Type
4646
4747
@@ -63,6 +63,10 @@ foreign import data Transaction :: Type
6363foreign import data ValueCursor :: Type
6464
6565
66+class FromString a where
67+ parse :: String -> Maybe a
68+
69+
6670foreign import _showCursor :: forall cursor. cursor -> String
6771instance showKeyCursor :: Show KeyCursor where
6872 show = _showCursor
src/Database/IndexedDB/IDBCursor.purs+10−10
@@ -29,11 +29,11 @@ import Database.IndexedDB.Core
2929-- INTERFACES
3030--
3131class IDBCursor cursor where
32− advance :: forall eff. cursor -> Int -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
33− continue :: forall eff. cursor -> Maybe Key -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
34− continuePrimaryKey :: forall eff. cursor -> Key -> Key -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
35− delete :: forall eff. cursor -> Aff (idb ::INDEXED_DB, exception :: EXCEPTION | eff) Unit
36− update :: forall val eff. cursor -> val -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Key
32+ advance :: forall e. cursor -> Int -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
33+ continue :: forall e. cursor -> Maybe Key -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
34+ continuePrimaryKey :: forall e. cursor -> Key -> Key -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
35+ delete :: forall e. cursor -> Aff (idb ::IDB, exception :: EXCEPTION | e) Unit
36+ update :: forall val e. cursor -> val -> Aff (idb :: IDB, exception :: EXCEPTION | e) Key
3737
3838
3939--------------------
@@ -110,16 +110,16 @@ instance valueCursorKeyCursor :: IDBCursor ValueCursor where
110110--------------------
111111-- FFI
112112--
113−foreign import _advance :: forall cursor eff. Fn2 cursor Int (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit)
113+foreign import _advance :: forall cursor e. Fn2 cursor Int (Eff (idb :: IDB, exception :: EXCEPTION | e) Unit)
114114
115115
116−foreign import _continue :: forall cursor eff. Fn2 cursor (Nullable Key) (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit)
116+foreign import _continue :: forall cursor e. Fn2 cursor (Nullable Key) (Eff (idb :: IDB, exception :: EXCEPTION | e) Unit)
117117
118118
119−foreign import _continuePrimaryKey :: forall cursor eff. Fn3 cursor Key Key (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit)
119+foreign import _continuePrimaryKey :: forall cursor e. Fn3 cursor Key Key (Eff (idb :: IDB, exception :: EXCEPTION | e) Unit)
120120
121121
122−foreign import _delete :: forall cursor eff. cursor -> (Aff (idb ::INDEXED_DB, exception :: EXCEPTION | eff) Unit)
122+foreign import _delete :: forall cursor e. cursor -> (Aff (idb ::IDB, exception :: EXCEPTION | e) Unit)
123123
124124
125125foreign import _direction :: forall cursor. Fn2 (String -> Nullable CursorDirection) cursor CursorDirection
@@ -134,7 +134,7 @@ foreign import _primaryKey :: forall cursor. cursor -> Key
134134foreign import _source :: forall cursor. Fn3 (ObjectStore -> CursorSource) (Index -> CursorSource) cursor CursorSource
135135
136136
137−foreign import _update :: forall cursor eff. Fn2 cursor Foreign (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Key)
137+foreign import _update :: forall cursor e. Fn2 cursor Foreign (Aff (idb :: IDB, exception :: EXCEPTION | e) Key)
138138
139139
140140foreign import _value :: forall cursor val. cursor -> val
src/Database/IndexedDB/IDBDatabase.purs+15−8
@@ -21,10 +21,10 @@ import Database.IndexedDB.IDBObjectStore (IDBObjectStoreParameters)
2121-- INTERFACE
2222--
2323class IDBDatabase db where
24− close :: forall eff. db -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
25− createObjectStore :: forall eff. db -> StoreName -> IDBObjectStoreParameters -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) ObjectStore
26− deleteObjectStore :: forall eff . db -> StoreName -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) ObjectStore
27− transaction :: forall eff. db -> KeyPath -> TransactionMode -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Transaction
24+ close :: forall e. db -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
25+ createObjectStore :: forall e. db -> StoreName -> IDBObjectStoreParameters -> Eff (idb :: IDB, exception :: EXCEPTION | e) ObjectStore
26+ deleteObjectStore :: forall e. db -> StoreName -> Eff (idb :: IDB, exception :: EXCEPTION | e) ObjectStore
27+ transaction :: forall e. db -> KeyPath -> TransactionMode -> Eff (idb :: IDB, exception :: EXCEPTION | e) Transaction
2828
2929
3030type StoreName = String
@@ -48,6 +48,13 @@ version =
4848 _version
4949
5050
51+--------------------
52+-- EVENT HANDLERS
53+--
54+-- onAbort :: forall e. Database -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
55+
56+
57+
5158--------------------
5259-- INSTANCES
5360--
@@ -68,13 +75,13 @@ instance idbDatabaseDatabase :: IDBDatabase Database where
6875--------------------
6976-- FFI
7077--
71−foreign import _close :: forall db eff. db -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
78+foreign import _close :: forall db e. db -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
7279
7380
74−foreign import _createObjectStore :: forall db eff. Fn3 db String { keyPath :: Array String, autoIncrement :: Boolean } (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) ObjectStore)
81+foreign import _createObjectStore :: forall db e. Fn3 db String { keyPath :: Array String, autoIncrement :: Boolean } (Eff (idb :: IDB, exception :: EXCEPTION | e) ObjectStore)
7582
7683
77−foreign import _deleteObjectStore :: forall db eff. Fn2 db String (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) ObjectStore)
84+foreign import _deleteObjectStore :: forall db e. Fn2 db String (Eff (idb :: IDB, exception :: EXCEPTION | e) ObjectStore)
7885
7986
8087foreign import _name :: Database -> String
@@ -83,7 +90,7 @@ foreign import _name :: Database -> String
8390foreign import _objectStoreNames :: Database -> Array String
8491
8592
86−foreign import _transaction :: forall db eff. Fn4 (db -> String) db (Array String) TransactionMode (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Transaction)
93+foreign import _transaction :: forall db e. Fn4 (db -> String) db (Array String) TransactionMode (Eff (idb :: IDB, exception :: EXCEPTION | e) Transaction)
8794
8895
8996foreign import _version :: Database -> Int
src/Database/IndexedDB/IDBFactory.purs+7−7
@@ -14,18 +14,18 @@ import Database.IndexedDB.Core
1414--------------------
1515-- INTERFACE
1616--
17−type OpenRequest eff =
18− { onBlocked :: Maybe (Eff (idb :: INDEXED_DB | eff) Unit)
19− , onUpgradeNeeded :: Maybe (Database -> Eff (idb :: INDEXED_DB | eff) Unit)
17+type OpenRequest e =
18+ { onBlocked :: Maybe (Eff (idb :: IDB | e) Unit)
19+ , onUpgradeNeeded :: Maybe (Database -> Eff (idb :: IDB | e) Unit)
2020 }
2121
2222
23−deleteDatabase :: forall eff. String -> Aff (idb :: INDEXED_DB | eff) Int
23+deleteDatabase :: forall e. String -> Aff (idb :: IDB | e) Int
2424deleteDatabase =
2525 _deleteDatabase
2626
2727
28−open :: forall eff . String -> Maybe Int -> OpenRequest eff -> Aff (idb :: INDEXED_DB | eff) Database
28+open :: forall e. String -> Maybe Int -> OpenRequest e -> Aff (idb :: IDB | e) Database
2929open name mver req =
3030 Fn.runFn4 _open fromMaybe name mver req
3131
@@ -33,7 +33,7 @@ open name mver req =
3333--------------------
3434-- FFI
3535--
36−foreign import _deleteDatabase :: forall eff. String -> Aff (idb :: INDEXED_DB | eff) Int
36+foreign import _deleteDatabase :: forall e. String -> Aff (idb :: IDB | e) Int
3737
3838
39−foreign import _open :: forall a eff. Fn4 (a -> Maybe a -> a) String (Maybe Int) (OpenRequest eff) (Aff (idb :: INDEXED_DB | eff) Database)
39+foreign import _open :: forall a e. Fn4 (a -> Maybe a -> a) String (Maybe Int) (OpenRequest e) (Aff (idb :: IDB | e) Database)
src/Database/IndexedDB/IDBIndex/Internal.purs+13−14
@@ -3,14 +3,13 @@ module Database.IndexedDB.IDBIndex.Internal where
33import Prelude
44
55import Control.Monad.Aff (Aff)
6−import Control.Monad.Eff.Exception (EXCEPTION)
76import Data.Foreign (Foreign, unsafeFromForeign)
87import Data.Function.Uncurried as Fn
98import Data.Function.Uncurried (Fn2, Fn3)
109import Data.Maybe (Maybe)
1110import Data.Nullable (Nullable, toMaybe, toNullable)
1211
13−import Database.IndexedDB.Core (INDEXED_DB, CursorDirection, Index, Key, KeyCursor, KeyRange,
12+import Database.IndexedDB.Core (IDB, CursorDirection, Index, Key, KeyCursor, KeyRange,
1413 KeyPath, ObjectStore, ValueCursor)
1514
1615
@@ -18,12 +17,12 @@ import Database.IndexedDB.Core (INDEXED_DB, CursorDirection, Index, Key, Key
1817-- INTERFACES
1918--
2019class IDBIndex index where
21− count :: forall eff. index -> Maybe KeyRange -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Int
22− get :: forall a eff. index -> KeyRange -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) (Maybe a)
23− getAllKeys :: forall eff. index -> Maybe KeyRange -> Maybe Int -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) (Array Key)
24− getKey :: forall eff. index -> KeyRange -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) (Maybe Key)
25− openCursor :: forall eff. index -> Maybe KeyRange -> CursorDirection -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) ValueCursor
26− openKeyCursor :: forall eff. index -> Maybe KeyRange -> CursorDirection -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) KeyCursor
20+ count :: forall e. index -> Maybe KeyRange -> Aff (idb :: IDB | e) Int
21+ get :: forall a e. index -> KeyRange -> Aff (idb :: IDB | e) (Maybe a)
22+ getAllKeys :: forall e. index -> Maybe KeyRange -> Maybe Int -> Aff (idb :: IDB | e) (Array Key)
23+ getKey :: forall e. index -> KeyRange -> Aff (idb :: IDB | e) (Maybe Key)
24+ openCursor :: forall e. index -> Maybe KeyRange -> CursorDirection -> Aff (idb :: IDB | e) ValueCursor
25+ openKeyCursor :: forall e. index -> Maybe KeyRange -> CursorDirection -> Aff (idb :: IDB | e) KeyCursor
2726
2827
2928type IDBIndexParameters =
@@ -128,19 +127,19 @@ foreign import _objectStore :: Index -> ObjectStore
128127foreign import _unique :: Index -> Boolean
129128
130129
131−foreign import _count :: forall index eff. Fn2 index (Nullable KeyRange) (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Int)
130+foreign import _count :: forall index e. Fn2 index (Nullable KeyRange) (Aff (idb :: IDB | e) Int)
132131
133132
134−foreign import _get :: forall index eff. Fn2 index KeyRange (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) (Nullable Foreign))
133+foreign import _get :: forall index e. Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Foreign))
135134
136135
137−foreign import _getAllKeys :: forall index eff. Fn3 index (Nullable KeyRange) (Nullable Int) (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) (Array Key))
136+foreign import _getAllKeys :: forall index e. Fn3 index (Nullable KeyRange) (Nullable Int) (Aff (idb :: IDB | e) (Array Key))
138137
139138
140−foreign import _getKey :: forall index eff. Fn2 index KeyRange (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) (Nullable Key))
139+foreign import _getKey :: forall index e. Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Key))
141140
142141
143−foreign import _openCursor :: forall index eff. Fn3 index (Nullable KeyRange) String (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) ValueCursor)
142+foreign import _openCursor :: forall index e. Fn3 index (Nullable KeyRange) String (Aff (idb :: IDB | e) ValueCursor)
144143
145144
146−foreign import _openKeyCursor :: forall index eff. Fn3 index (Nullable KeyRange) String (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) KeyCursor)
145+foreign import _openKeyCursor :: forall index e. Fn3 index (Nullable KeyRange) String (Aff (idb :: IDB | e) KeyCursor)
src/Database/IndexedDB/IDBObjectStore.purs+15−15
@@ -21,7 +21,7 @@ import Data.Function.Uncurried (Fn2, Fn3, Fn4)
2121import Data.Maybe (Maybe)
2222import Data.Nullable (Nullable, toNullable)
2323
24−import Database.IndexedDB.Core (INDEXED_DB, Index, KeyRange, KeyPath, ObjectStore)
24+import Database.IndexedDB.Core (IDB, Index, KeyRange, KeyPath, ObjectStore)
2525import Database.IndexedDB.IDBIndex.Internal (class IDBIndex, IDBIndexParameters, count, get, getAllKeys, getKey, openCursor, openKeyCursor)
2626import Database.IndexedDB.IDBKey.Internal (Key(Key), extractForeign)
2727
@@ -30,13 +30,13 @@ import Database.IndexedDB.IDBKey.Internal (Key(Key), extractForeign)
3030-- INTERFACES
3131--
3232class IDBObjectStore store where
33− add :: forall value eff. store -> value -> Maybe Key -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Key
34− clear :: forall eff. store -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
35− createIndex :: forall eff. store -> IndexName -> KeyPath -> IDBIndexParameters -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Index
36− delete :: forall eff. store -> KeyRange -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
37− deleteIndex :: forall eff. store -> IndexName -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
38− index :: forall eff. store -> IndexName -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Index
39− put :: forall value eff. store -> value -> Maybe Key -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Key
33+ add :: forall value e. store -> value -> Maybe Key -> Aff (idb :: IDB | e) Key
34+ clear :: forall e. store -> Aff (idb :: IDB | e) Unit
35+ createIndex :: forall e. store -> IndexName -> KeyPath -> IDBIndexParameters -> Eff (idb :: IDB, exception :: EXCEPTION | e) Index
36+ delete :: forall e. store -> KeyRange -> Aff (idb :: IDB | e) Unit
37+ deleteIndex :: forall e. store -> IndexName -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
38+ index :: forall e. store -> IndexName -> Eff (idb :: IDB, exception :: EXCEPTION | e) Index
39+ put :: forall value e. store -> value -> Maybe Key -> Aff (idb :: IDB | e) Key
4040
4141
4242type IndexName = String
@@ -107,25 +107,25 @@ defaultParameters =
107107--------------------
108108-- FFI
109109--
110−foreign import _add :: forall value eff. Fn3 ObjectStore value (Nullable Foreign) (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Foreign)
110+foreign import _add :: forall value e. Fn3 ObjectStore value (Nullable Foreign) (Aff (idb :: IDB | e) Foreign)
111111
112112
113113foreign import _autoIncrement :: ObjectStore -> Boolean
114114
115115
116−foreign import _clear :: forall eff. ObjectStore -> Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
116+foreign import _clear :: forall e. ObjectStore -> Aff (idb :: IDB | e) Unit
117117
118118
119−foreign import _createIndex :: forall eff. Fn4 ObjectStore String (Array String) { unique :: Boolean, multiEntry :: Boolean } (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Index)
119+foreign import _createIndex :: forall e. Fn4 ObjectStore String (Array String) { unique :: Boolean, multiEntry :: Boolean } (Eff (idb :: IDB | e) Index)
120120
121121
122−foreign import _delete :: forall eff. Fn2 ObjectStore KeyRange (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit)
122+foreign import _delete :: forall e. Fn2 ObjectStore KeyRange (Aff (idb :: IDB | e) Unit)
123123
124124
125−foreign import _deleteIndex :: forall eff. Fn2 ObjectStore String (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit)
125+foreign import _deleteIndex :: forall e. Fn2 ObjectStore String (Eff (idb :: IDB | e) Unit)
126126
127127
128−foreign import _index :: forall eff. Fn2 ObjectStore String (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Index)
128+foreign import _index :: forall e. Fn2 ObjectStore String (Eff (idb :: IDB | e) Index)
129129
130130
131131foreign import _indexNames :: ObjectStore -> Array String
@@ -137,4 +137,4 @@ foreign import _keyPath :: ObjectStore -> Array String
137137foreign import _name :: ObjectStore -> String
138138
139139
140−foreign import _put :: forall value eff. Fn3 ObjectStore value (Nullable Foreign) (Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Foreign)
140+foreign import _put :: forall value e. Fn3 ObjectStore value (Nullable Foreign) (Aff (idb :: IDB | e) Foreign)
src/Database/IndexedDB/IDBTransaction.purs+5−5
@@ -13,15 +13,15 @@ import Data.Function.Uncurried (Fn2, Fn4)
1313import Data.Maybe (Maybe)
1414import Data.Nullable (Nullable, toMaybe)
1515
16−import Database.IndexedDB.Core (INDEXED_DB, ObjectStore, Transaction, TransactionMode(..))
16+import Database.IndexedDB.Core (IDB, ObjectStore, Transaction, TransactionMode(..))
1717
1818
1919--------------------
2020-- INTERFACES
2121--
2222class IDBTransaction tx where
23− abort :: forall eff. tx -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
24− objectStore :: forall eff. tx -> String -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) ObjectStore
23+ abort :: forall e. tx -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
24+ objectStore :: forall e. tx -> String -> Eff (idb :: IDB, exception :: EXCEPTION | e) ObjectStore
2525
2626
2727--------------------
@@ -51,7 +51,7 @@ instance idbTransactionTransaction :: IDBTransaction Transaction where
5151--------------------
5252-- FFI
5353--
54−foreign import _abort :: forall tx eff. tx -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
54+foreign import _abort :: forall tx e. tx -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
5555
5656
5757foreign import _error :: Transaction -> (Nullable Error)
@@ -60,4 +60,4 @@ foreign import _error :: Transaction -> (Nullable Error)
6060foreign import _mode :: Fn4 TransactionMode TransactionMode TransactionMode Transaction TransactionMode
6161
6262
63−foreign import _objectStore :: forall tx eff. Fn2 tx String (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) ObjectStore)
63+foreign import _objectStore :: forall tx e. Fn2 tx String (Eff (idb :: IDB, exception :: EXCEPTION | e) ObjectStore)