mirror of
https://github.com/ilyakooo0/purescript-indexedDB.git
synced 2024-09-11 06:55:48 +03:00
Merge branch 'purescript-aff-upgrade'
This commit is contained in:
commit
ef6b6498c3
27
README.md
27
README.md
@ -14,8 +14,27 @@ menaingful namespace (e.g `IDBIndex.get`, `IDBObjectStore.openCursor` ...)
|
||||
|
||||
Here's a quick example of what it look likes.
|
||||
```purescript
|
||||
module Main where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Aff (Aff, launchAff_)
|
||||
import Control.Monad.Aff.Console (CONSOLE, log)
|
||||
import Control.Monad.Eff.Exception (EXCEPTION)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Data.Maybe (Maybe(..), maybe)
|
||||
|
||||
import Database.IndexedDB.Core
|
||||
import Database.IndexedDB.IDBFactory as IDBFactory
|
||||
import Database.IndexedDB.IDBDatabase as IDBDatabase
|
||||
import Database.IndexedDB.IDBObjectStore as IDBObjectStore
|
||||
import Database.IndexedDB.IDBIndex as IDBIndex
|
||||
import Database.IndexedDB.IDBTransaction as IDBTransaction
|
||||
import Database.IndexedDB.IDBKeyRange as IDBKeyRange
|
||||
|
||||
|
||||
main :: Eff (idb :: IDB, exception :: EXCEPTION, console :: CONSOLE) Unit
|
||||
main = launchAff' do
|
||||
main = launchAff_ do
|
||||
db <- IDBFactory.open "db" Nothing { onBlocked : Nothing
|
||||
, onUpgradeNeeded : Just onUpgradeNeeded
|
||||
}
|
||||
@ -27,11 +46,11 @@ main = launchAff' do
|
||||
|
||||
|
||||
onUpgradeNeeded :: forall e. Database -> Transaction -> { oldVersion :: Int } -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
|
||||
onUpgradeNeeded db _ _ = launchAff' do
|
||||
store <- IDBDatabase.createObjectStore db "store" IDBObjectStore.defaultParameters
|
||||
onUpgradeNeeded db _ _ = launchAff_ do
|
||||
store <- IDBDatabase.createObjectStore db "store" IDBDatabase.defaultParameters
|
||||
_ <- IDBObjectStore.add store "patate" (Just 1)
|
||||
_ <- IDBObjectStore.add store { property: 42 } (Just 2)
|
||||
_ <- IDBObjectStore.createIndex store "index" ["property"] IDBIndex.defaultParameters
|
||||
_ <- IDBObjectStore.createIndex store "index" ["property"] IDBObjectStore.defaultParameters
|
||||
pure unit
|
||||
```
|
||||
|
||||
|
16
bower.json
16
bower.json
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "purescript-indexeddb",
|
||||
"description": "An API wrapper around IndexedDB",
|
||||
"version": "3.0.0",
|
||||
"version": "4.0.0",
|
||||
"authors": [
|
||||
"Matthias Benkort <matthias.benkort@truqu.com>"
|
||||
"Matthias Benkort <matthias.benkort@gmail.com>"
|
||||
],
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
@ -25,18 +25,20 @@
|
||||
"url": "git://github.com/truqu/purescript-indexedDB.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"purescript-aff": "^3.1.0",
|
||||
"purescript-aff": "^4.0.2",
|
||||
"purescript-datetime": "^3.2.0",
|
||||
"purescript-eff": "^3.1.0",
|
||||
"purescript-exceptions": "^3.1.0",
|
||||
"purescript-exceptions": "^3.0.0",
|
||||
"purescript-foreign": "^4.0.1",
|
||||
"purescript-maybe": "^3.0.0",
|
||||
"purescript-nullable": "^3.0.0",
|
||||
"purescript-prelude": "^3.1.0",
|
||||
"purescript-read": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"purescript-spec": "^1.0.0",
|
||||
"purescript-psci-support": "^3.0.0",
|
||||
"purescript-now": "^3.0.0",
|
||||
"purescript-spec-mocha": "https://github.com/truqu/purescript-spec-mocha.git#0.5.0"
|
||||
"purescript-psci-support": "^3.0.0",
|
||||
"purescript-spec": "^2.0.0",
|
||||
"purescript-spec-mocha": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ module.exports = config => {
|
||||
config.set({
|
||||
autoWatch: true,
|
||||
singleRun: true,
|
||||
browsers: ["Chrome"],
|
||||
browsers: ["Chrome", "Firefox"],
|
||||
files: [
|
||||
"dist/karma/index.js",
|
||||
],
|
||||
|
@ -11,40 +11,52 @@ const successHandler = function successHandler(cb) {
|
||||
};
|
||||
|
||||
exports._advance = function _advance(cursor, count) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
cursor.advance(count);
|
||||
success();
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._continue = function _continue(cursor, key) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
cursor.continue(key || undefined);
|
||||
success();
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._continuePrimaryKey = function _continuePrimaryKey(cursor, key, primaryKey) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
cursor.continuePrimaryKey(key, primaryKey);
|
||||
success();
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._delete = function _delete(cursor) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = cursor.delete();
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -52,6 +64,10 @@ exports._delete = function _delete(cursor) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -60,22 +76,30 @@ exports._direction = function _direction(fromString, cursor) {
|
||||
};
|
||||
|
||||
exports._key = function _key(cursor) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
success(cursor.key);
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._primaryKey = function _primaryKey(cursor) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
success(cursor.primaryKey);
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -100,7 +124,7 @@ exports._source = function _source(IDBObjectStore, IDBIndex, cursor) {
|
||||
};
|
||||
|
||||
exports._update = function _update(cursor, value) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = cursor.update(value);
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -108,6 +132,10 @@ exports._update = function _update(cursor, value) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -16,9 +16,10 @@ module Database.IndexedDB.IDBCursor
|
||||
, value
|
||||
) where
|
||||
|
||||
import Prelude (Unit, ($), (>>>), map)
|
||||
import Prelude (Unit, ($), (>>>), (<<<), map)
|
||||
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Aff.Compat (fromEffFnAff, EffFnAff)
|
||||
import Data.Foreign (Foreign, toForeign, unsafeFromForeign)
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried (Fn2, Fn3)
|
||||
@ -40,8 +41,8 @@ advance
|
||||
=> cursor
|
||||
-> Int
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
advance =
|
||||
Fn.runFn2 _advance
|
||||
advance c =
|
||||
fromEffFnAff <<< Fn.runFn2 _advance c
|
||||
|
||||
|
||||
-- | Advances the cursor to the next record in range matching or after key.
|
||||
@ -51,7 +52,7 @@ continue
|
||||
-> Maybe k
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
continue c mk =
|
||||
Fn.runFn2 _continue c (toNullable $ map (toKey >>> unsafeFromKey) mk)
|
||||
fromEffFnAff $ Fn.runFn2 _continue c (toNullable $ map (toKey >>> unsafeFromKey) mk)
|
||||
|
||||
|
||||
-- | Advances the cursor to the next record in range matching or after key and primaryKey. Throws an "InvalidAccessError" DOMException if the source is not an index.
|
||||
@ -62,7 +63,7 @@ continuePrimaryKey
|
||||
-> k
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
continuePrimaryKey c k1 k2 =
|
||||
Fn.runFn3 _continuePrimaryKey c (unsafeFromKey $ toKey k1) (unsafeFromKey $ toKey k2)
|
||||
fromEffFnAff $ Fn.runFn3 _continuePrimaryKey c (unsafeFromKey $ toKey k1) (unsafeFromKey $ toKey k2)
|
||||
|
||||
|
||||
-- | Delete the record pointed at by the cursor with a new value.
|
||||
@ -71,7 +72,7 @@ delete
|
||||
=> cursor
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
delete =
|
||||
_delete
|
||||
fromEffFnAff <<< _delete
|
||||
|
||||
|
||||
-- | Update the record pointed at by the cursor with a new value.
|
||||
@ -84,7 +85,7 @@ update
|
||||
-> val
|
||||
-> Aff (idb :: IDB | e) Key
|
||||
update c =
|
||||
toForeign >>> Fn.runFn2 _update c >>> map toKey
|
||||
map toKey <<< fromEffFnAff <<< Fn.runFn2 _update c <<< toForeign
|
||||
|
||||
|
||||
--------------------
|
||||
@ -107,7 +108,7 @@ key
|
||||
=> cursor
|
||||
-> Aff (idb :: IDB | e) Key
|
||||
key =
|
||||
_key >>> map toKey
|
||||
map toKey <<< fromEffFnAff <<< _key
|
||||
|
||||
|
||||
-- | Returns the effective key of the cursor. Throws a "InvalidStateError" DOMException
|
||||
@ -117,7 +118,7 @@ primaryKey
|
||||
=> cursor
|
||||
-> Aff (idb :: IDB | e) Key
|
||||
primaryKey =
|
||||
_primaryKey >>> map toKey
|
||||
map toKey <<< fromEffFnAff <<< _primaryKey
|
||||
|
||||
|
||||
-- | Returns the IDBObjectStore or IDBIndex the cursor was opened from.
|
||||
@ -143,23 +144,23 @@ value =
|
||||
|
||||
foreign import _advance
|
||||
:: forall cursor e
|
||||
. Fn2 cursor Int (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 cursor Int (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _continue
|
||||
:: forall cursor e
|
||||
. Fn2 cursor (Nullable Foreign) (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 cursor (Nullable Foreign) (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _continuePrimaryKey
|
||||
:: forall cursor e
|
||||
. Fn3 cursor Foreign Foreign (Aff (idb :: IDB | e) Unit)
|
||||
. Fn3 cursor Foreign Foreign (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _delete
|
||||
:: forall cursor e
|
||||
. cursor
|
||||
-> (Aff (idb :: IDB | e) Unit)
|
||||
-> (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _direction
|
||||
@ -170,13 +171,13 @@ foreign import _direction
|
||||
foreign import _key
|
||||
:: forall cursor e
|
||||
. cursor
|
||||
-> Aff (idb :: IDB | e) Key
|
||||
-> EffFnAff (idb :: IDB | e) Key
|
||||
|
||||
|
||||
foreign import _primaryKey
|
||||
:: forall cursor e
|
||||
. cursor
|
||||
-> Aff (idb :: IDB | e) Key
|
||||
-> EffFnAff (idb :: IDB | e) Key
|
||||
|
||||
|
||||
foreign import _source
|
||||
@ -186,7 +187,7 @@ foreign import _source
|
||||
|
||||
foreign import _update
|
||||
:: forall cursor e
|
||||
. Fn2 cursor Foreign (Aff (idb :: IDB | e) Foreign)
|
||||
. Fn2 cursor Foreign (EffFnAff (idb :: IDB | e) Foreign)
|
||||
|
||||
|
||||
foreign import _value
|
||||
|
@ -4,18 +4,22 @@ const toArray = function toArray(xs) {
|
||||
|
||||
|
||||
exports._close = function _close(db) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
db.close();
|
||||
success();
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._createObjectStore = function _createObjectStore(db, name, opts) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
var keyPath;
|
||||
|
||||
try {
|
||||
@ -41,17 +45,25 @@ exports._createObjectStore = function _createObjectStore(db, name, opts) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._deleteObjectStore = function _deleteObjectStore(db, name) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
db.deleteObjectStore(name);
|
||||
success();
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -64,49 +76,71 @@ exports._objectStoreNames = function _objectStoreNames(db) {
|
||||
};
|
||||
|
||||
exports._onAbort = function _onAbort(db, f) {
|
||||
return function aff(success) {
|
||||
return function aff(error, success) {
|
||||
db.onabort = function onabort() {
|
||||
f();
|
||||
};
|
||||
success();
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._onClose = function _onClose(db, f) {
|
||||
return function aff(success) {
|
||||
return function aff(error, success) {
|
||||
db.onclose = function onclose() {
|
||||
f();
|
||||
};
|
||||
success();
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._onError = function _onError(db, f) {
|
||||
return function aff(success) {
|
||||
return function aff(error, success) {
|
||||
db.onerror = function onerror(e) {
|
||||
f(e.target.error)();
|
||||
};
|
||||
success();
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._onVersionChange = function _onVersionChange(db, f) {
|
||||
return function aff(success) {
|
||||
return function aff(error, success) {
|
||||
db.onversionchange = function onversionchange(e) {
|
||||
f({ oldVersion: e.oldVersion, newVersion: e.newVersion })();
|
||||
};
|
||||
success();
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._transaction = function _transaction(db, stores, mode) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
var transaction;
|
||||
try {
|
||||
const transaction = db.transaction(stores, mode);
|
||||
transaction = db.transaction(stores, mode);
|
||||
success(transaction);
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError, cancelerSuccess) {
|
||||
transaction.abort();
|
||||
cancelerSuccess();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -24,9 +24,10 @@ module Database.IndexedDB.IDBDatabase
|
||||
, onVersionChange
|
||||
) where
|
||||
|
||||
import Prelude (Unit, show)
|
||||
import Prelude (Unit, show, (<<<), ($))
|
||||
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Aff.Compat (fromEffFnAff, EffFnAff)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Control.Monad.Eff.Exception (Error)
|
||||
import Data.Function.Uncurried as Fn
|
||||
@ -67,7 +68,7 @@ close
|
||||
=> db
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
close =
|
||||
_close
|
||||
fromEffFnAff <<< _close
|
||||
|
||||
|
||||
-- | Creates a new object store with the given name and options and returns a new IDBObjectStore.
|
||||
@ -80,7 +81,7 @@ createObjectStore
|
||||
-> ObjectStoreParameters
|
||||
-> Aff (idb :: IDB | e) ObjectStore
|
||||
createObjectStore db name' opts =
|
||||
Fn.runFn3 _createObjectStore db name' opts
|
||||
fromEffFnAff $ Fn.runFn3 _createObjectStore db name' opts
|
||||
|
||||
|
||||
-- | Deletes the object store with the given name.
|
||||
@ -92,7 +93,7 @@ deleteObjectStore
|
||||
-> StoreName
|
||||
-> Aff (idb :: IDB | e) ObjectStore
|
||||
deleteObjectStore db name' =
|
||||
Fn.runFn2 _deleteObjectStore db name'
|
||||
fromEffFnAff $ Fn.runFn2 _deleteObjectStore db name'
|
||||
|
||||
|
||||
-- | Returns a new transaction with the given mode (ReadOnly|ReadWrite)
|
||||
@ -104,7 +105,7 @@ transaction
|
||||
-> TransactionMode
|
||||
-> Aff (idb :: IDB | e) Transaction
|
||||
transaction db stores mode' =
|
||||
Fn.runFn3 _transaction db stores (show mode')
|
||||
fromEffFnAff $ Fn.runFn3 _transaction db stores (show mode')
|
||||
|
||||
|
||||
--------------------
|
||||
@ -145,7 +146,7 @@ onAbort
|
||||
-> Eff ( | e') Unit
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
onAbort db f =
|
||||
Fn.runFn2 _onAbort db f
|
||||
fromEffFnAff $ Fn.runFn2 _onAbort db f
|
||||
|
||||
|
||||
-- | Event handler for the `close` event.
|
||||
@ -155,7 +156,7 @@ onClose
|
||||
-> Eff ( | e') Unit
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
onClose db f =
|
||||
Fn.runFn2 _onClose db f
|
||||
fromEffFnAff $ Fn.runFn2 _onClose db f
|
||||
|
||||
|
||||
-- | Event handler for the `error` event.
|
||||
@ -165,7 +166,7 @@ onError
|
||||
-> (Error -> Eff ( | e') Unit)
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
onError db f =
|
||||
Fn.runFn2 _onError db f
|
||||
fromEffFnAff $ Fn.runFn2 _onError db f
|
||||
|
||||
|
||||
-- | Event handler for the `versionchange` event.
|
||||
@ -176,7 +177,7 @@ onVersionChange
|
||||
-> Eff ( | e') Unit)
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
onVersionChange db f =
|
||||
Fn.runFn2 _onVersionChange db f
|
||||
fromEffFnAff $ Fn.runFn2 _onVersionChange db f
|
||||
|
||||
|
||||
--------------------
|
||||
@ -186,17 +187,17 @@ onVersionChange db f =
|
||||
foreign import _close
|
||||
:: forall db e
|
||||
. db
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
-> EffFnAff (idb :: IDB | e) Unit
|
||||
|
||||
|
||||
foreign import _createObjectStore
|
||||
:: forall db e
|
||||
. Fn3 db String { keyPath :: Array String, autoIncrement :: Boolean } (Aff (idb :: IDB | e) ObjectStore)
|
||||
. Fn3 db String { keyPath :: Array String, autoIncrement :: Boolean } (EffFnAff (idb :: IDB | e) ObjectStore)
|
||||
|
||||
|
||||
foreign import _deleteObjectStore
|
||||
:: forall db e
|
||||
. Fn2 db String (Aff (idb :: IDB | e) ObjectStore)
|
||||
. Fn2 db String (EffFnAff (idb :: IDB | e) ObjectStore)
|
||||
|
||||
|
||||
foreign import _name
|
||||
@ -211,27 +212,27 @@ foreign import _objectStoreNames
|
||||
|
||||
foreign import _onAbort
|
||||
:: forall db e e'
|
||||
. Fn2 db (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 db (Eff ( | e') Unit) (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _onClose
|
||||
:: forall db e e'
|
||||
. Fn2 db (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 db (Eff ( | e') Unit) (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _onError
|
||||
:: forall db e e'
|
||||
. Fn2 db (Error -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 db (Error -> Eff ( | e') Unit) (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _onVersionChange
|
||||
:: forall db e e'
|
||||
. Fn2 db ({ oldVersion :: Int, newVersion :: Int } -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 db ({ oldVersion :: Int, newVersion :: Int } -> Eff ( | e') Unit) (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _transaction
|
||||
:: forall db e
|
||||
. Fn3 db (Array String) String (Aff (idb :: IDB | e) Transaction)
|
||||
. Fn3 db (Array String) String (EffFnAff (idb :: IDB | e) Transaction)
|
||||
|
||||
|
||||
foreign import _version
|
||||
|
@ -19,7 +19,7 @@ const noOp3 = function noOp3() {
|
||||
};
|
||||
|
||||
exports._deleteDatabase = function _deleteDatabase(name) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = indexedDB.deleteDatabase(name);
|
||||
|
||||
@ -31,13 +31,17 @@ exports._deleteDatabase = function _deleteDatabase(name) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._open = function _open(fromMaybe, name, mver, req) {
|
||||
const ver = fromMaybe(undefined)(mver);
|
||||
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = indexedDB.open(name, ver);
|
||||
request.onsuccess = function onSuccess(e) {
|
||||
@ -50,6 +54,7 @@ exports._open = function _open(fromMaybe, name, mver, req) {
|
||||
|
||||
request.onupgradeneeded = function onUpgradeNeeded(e) {
|
||||
const meta = { oldVersion: e.oldVersion };
|
||||
// eslint-disable-next-line max-len
|
||||
fromMaybe(noOp3)(req.onUpgradeNeeded)(e.target.result)(e.target.transaction)(meta)();
|
||||
};
|
||||
|
||||
@ -57,5 +62,9 @@ exports._open = function _open(fromMaybe, name, mver, req) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -12,13 +12,14 @@ module Database.IndexedDB.IDBFactory
|
||||
, open
|
||||
) where
|
||||
|
||||
import Prelude (Unit)
|
||||
import Prelude (Unit, ($), (<<<))
|
||||
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried (Fn4)
|
||||
import Data.Maybe (Maybe, fromMaybe)
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Aff.Compat (fromEffFnAff, EffFnAff)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried (Fn4)
|
||||
import Data.Maybe (Maybe, fromMaybe)
|
||||
|
||||
import Database.IndexedDB.Core
|
||||
|
||||
@ -54,7 +55,7 @@ deleteDatabase
|
||||
. DatabaseName
|
||||
-> Aff (idb :: IDB | e) Int
|
||||
deleteDatabase =
|
||||
_deleteDatabase
|
||||
fromEffFnAff <<< _deleteDatabase
|
||||
|
||||
|
||||
-- | Attempts to open a connection to the named database with the specified version.
|
||||
@ -72,7 +73,7 @@ open
|
||||
-> Callbacks e'
|
||||
-> Aff (idb :: IDB | e) Database
|
||||
open name mver req =
|
||||
Fn.runFn4 _open fromMaybe name mver req
|
||||
fromEffFnAff $ Fn.runFn4 _open fromMaybe name mver req
|
||||
|
||||
|
||||
--------------------
|
||||
@ -81,9 +82,9 @@ open name mver req =
|
||||
foreign import _deleteDatabase
|
||||
:: forall e
|
||||
. String
|
||||
-> Aff (idb :: IDB | e) Int
|
||||
-> EffFnAff (idb :: IDB | e) Int
|
||||
|
||||
|
||||
foreign import _open
|
||||
:: forall a e e'
|
||||
. Fn4 (a -> Maybe a -> a) String (Maybe Int) (Callbacks e') (Aff (idb :: IDB | e) Database)
|
||||
. Fn4 (a -> Maybe a -> a) String (Maybe Int) (Callbacks e') (EffFnAff (idb :: IDB | e) Database)
|
||||
|
@ -42,7 +42,7 @@ exports._unique = function _unique(index) {
|
||||
};
|
||||
|
||||
exports._count = function _count(index, query) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = index.count(query);
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -50,11 +50,15 @@ exports._count = function _count(index, query) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._get = function _get(index, range) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = index.get(range);
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -62,6 +66,10 @@ exports._get = function _get(index, range) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -72,7 +80,7 @@ exports._get = function _get(index, range) {
|
||||
* However, it may be doable to convert the result to some key / value structure with values of
|
||||
* different types.
|
||||
exports._getAll = function _getAll(index, query, count) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
const request = index.getAll(query, count);
|
||||
request.onsuccess = successHandler(success);
|
||||
request.onerror = errorHandler(error);
|
||||
@ -81,7 +89,7 @@ exports._getAll = function _getAll(index, query, count) {
|
||||
*/
|
||||
|
||||
exports._getAllKeys = function _getAllKeys(index, range, count) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = index.getAllKeys(range, count || undefined);
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -89,11 +97,15 @@ exports._getAllKeys = function _getAllKeys(index, range, count) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._getKey = function _getKey(index, range) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = index.getKey(range);
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -101,11 +113,15 @@ exports._getKey = function _getKey(index, range) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._openCursor = function _openCursor(index, query, dir, cb) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = index.openCursor(query, dir);
|
||||
request.onsuccess = function onSuccess(e) {
|
||||
@ -122,11 +138,15 @@ exports._openCursor = function _openCursor(index, query, dir, cb) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._openKeyCursor = function _openKeyCursor(index, query, dir, cb) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = index.openKeyCursor(query, dir);
|
||||
request.onsuccess = function onSuccess(e) {
|
||||
@ -143,5 +163,9 @@ exports._openKeyCursor = function _openKeyCursor(index, query, dir, cb) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -20,9 +20,10 @@ module Database.IndexedDB.IDBIndex
|
||||
, unique
|
||||
) where
|
||||
|
||||
import Prelude (Unit, map, show, (<$>), (>>>))
|
||||
import Prelude (Unit, map, show, (<$>), (>>>), ($))
|
||||
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Aff.Compat (EffFnAff, fromEffFnAff)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Control.Monad.Eff.Exception (Error)
|
||||
import Data.Foreign (Foreign, unsafeFromForeign)
|
||||
@ -58,7 +59,7 @@ count
|
||||
-> Maybe KeyRange
|
||||
-> Aff (idb :: IDB | e) Int
|
||||
count index range =
|
||||
Fn.runFn2 _count index (toNullable range)
|
||||
fromEffFnAff $ Fn.runFn2 _count index (toNullable range)
|
||||
|
||||
|
||||
-- | Retrieves the value of the first record matching the given key range in query.
|
||||
@ -71,7 +72,7 @@ get
|
||||
-> KeyRange
|
||||
-> Aff (idb :: IDB | e) (Maybe a)
|
||||
get index range =
|
||||
(toMaybe >>> map unsafeFromForeign) <$> Fn.runFn2 _get index range
|
||||
map (toMaybe >>> map unsafeFromForeign) $ fromEffFnAff $ Fn.runFn2 _get index range
|
||||
|
||||
|
||||
-- | Retrieves the keys of records matching the given key range in query
|
||||
@ -83,7 +84,7 @@ getAllKeys
|
||||
-> Maybe Int
|
||||
-> Aff (idb :: IDB | e) (Array Key)
|
||||
getAllKeys index range n =
|
||||
map toKey <$> Fn.runFn3 _getAllKeys index (toNullable range) (toNullable n)
|
||||
map (map toKey) $ fromEffFnAff $ Fn.runFn3 _getAllKeys index (toNullable range) (toNullable n)
|
||||
|
||||
|
||||
-- | Retrieves the key of the first record matching the given key or key range in query.
|
||||
@ -93,7 +94,7 @@ getKey
|
||||
-> KeyRange
|
||||
-> Aff (idb :: IDB | e) (Maybe Key)
|
||||
getKey index range =
|
||||
(toMaybe >>> map toKey) <$> Fn.runFn2 _getKey index range
|
||||
map (toMaybe >>> map toKey) $ fromEffFnAff $ Fn.runFn2 _getKey index range
|
||||
|
||||
|
||||
-- | Opens a ValueCursor over the records matching query, ordered by direction.
|
||||
@ -106,7 +107,7 @@ openCursor
|
||||
-> Callbacks ValueCursor e'
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
openCursor index range dir cb =
|
||||
Fn.runFn4 _openCursor index (toNullable range) (show dir) cb
|
||||
fromEffFnAff $ Fn.runFn4 _openCursor index (toNullable range) (show dir) cb
|
||||
|
||||
|
||||
-- | Opens a KeyCursor over the records matching query, ordered by direction.
|
||||
@ -119,7 +120,7 @@ openKeyCursor
|
||||
-> Callbacks KeyCursor e'
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
openKeyCursor index range dir cb =
|
||||
Fn.runFn4 _openKeyCursor index (toNullable range) (show dir) cb
|
||||
fromEffFnAff $ Fn.runFn4 _openKeyCursor index (toNullable range) (show dir) cb
|
||||
|
||||
|
||||
--------------------
|
||||
@ -195,29 +196,29 @@ foreign import _unique
|
||||
|
||||
foreign import _count
|
||||
:: forall index e
|
||||
. Fn2 index (Nullable KeyRange) (Aff (idb :: IDB | e) Int)
|
||||
. Fn2 index (Nullable KeyRange) (EffFnAff (idb :: IDB | e) Int)
|
||||
|
||||
|
||||
foreign import _get
|
||||
:: forall index e
|
||||
. Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Foreign))
|
||||
. Fn2 index KeyRange (EffFnAff (idb :: IDB | e) (Nullable Foreign))
|
||||
|
||||
|
||||
foreign import _getAllKeys
|
||||
:: forall index e
|
||||
. Fn3 index (Nullable KeyRange) (Nullable Int) (Aff (idb :: IDB | e) (Array Foreign))
|
||||
. Fn3 index (Nullable KeyRange) (Nullable Int) (EffFnAff (idb :: IDB | e) (Array Foreign))
|
||||
|
||||
|
||||
foreign import _getKey
|
||||
:: forall index e
|
||||
. Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Foreign))
|
||||
. Fn2 index KeyRange (EffFnAff (idb :: IDB | e) (Nullable Foreign))
|
||||
|
||||
|
||||
foreign import _openCursor
|
||||
:: forall index e e'
|
||||
. Fn4 index (Nullable KeyRange) String (Callbacks ValueCursor e') (Aff (idb :: IDB | e) Unit)
|
||||
. Fn4 index (Nullable KeyRange) String (Callbacks ValueCursor e') (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _openKeyCursor
|
||||
:: forall index e e'
|
||||
. Fn4 index (Nullable KeyRange) String (Callbacks KeyCursor e') (Aff (idb :: IDB | e) Unit)
|
||||
. Fn4 index (Nullable KeyRange) String (Callbacks KeyCursor e') (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
@ -16,7 +16,7 @@ const toArray = function toArray(xs) {
|
||||
|
||||
|
||||
exports._add = function _add(store, value, key) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = store.add(value, key || undefined);
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -24,6 +24,10 @@ exports._add = function _add(store, value, key) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -32,7 +36,7 @@ exports._autoIncrement = function _autoIncrement(store) {
|
||||
};
|
||||
|
||||
exports._clear = function _clear(store) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = store.clear();
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -40,11 +44,15 @@ exports._clear = function _clear(store) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._createIndex = function _createIndex(store, name, path, params) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
var keyPath;
|
||||
|
||||
try {
|
||||
@ -66,22 +74,30 @@ exports._createIndex = function _createIndex(store, name, path, params) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._deleteIndex = function _deleteIndex(store, name) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
store.deleteIndex(name);
|
||||
success();
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._delete = function _delete(store, query) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = store.delete(query);
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -89,17 +105,25 @@ exports._delete = function _delete(store, query) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._index = function _index(store, name) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const index = store.index(name);
|
||||
success(index);
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -126,7 +150,7 @@ exports._name = function _name(store) {
|
||||
};
|
||||
|
||||
exports._put = function _put(store, value, key) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const request = store.put(value, key || undefined);
|
||||
request.onsuccess = successHandler(success);
|
||||
@ -134,6 +158,10 @@ exports._put = function _put(store, value, key) {
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -25,9 +25,10 @@ module Database.IndexedDB.IDBObjectStore
|
||||
, module Database.IndexedDB.IDBIndex
|
||||
) where
|
||||
|
||||
import Prelude (Unit, ($), (<$>), (>>>))
|
||||
import Prelude (Unit, map, ($), (<$>), (>>>), (<<<))
|
||||
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Aff.Compat (EffFnAff, fromEffFnAff)
|
||||
import Data.Foreign (Foreign)
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried (Fn2, Fn3, Fn4)
|
||||
@ -90,7 +91,7 @@ add
|
||||
-> Maybe key
|
||||
-> Aff (idb :: IDB | e) Key
|
||||
add store value key =
|
||||
toKey <$> Fn.runFn3 _add store value (toNullable $ (toKey >>> unsafeFromKey) <$> key)
|
||||
map toKey $ fromEffFnAff $ Fn.runFn3 _add store value (toNullable $ (toKey >>> unsafeFromKey) <$> key)
|
||||
|
||||
|
||||
-- | Deletes all records in store.
|
||||
@ -99,7 +100,7 @@ clear
|
||||
=> store
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
clear =
|
||||
_clear
|
||||
fromEffFnAff <<< _clear
|
||||
|
||||
|
||||
-- | Creates a new index in store with the given name, keyPath and options and
|
||||
@ -116,7 +117,7 @@ createIndex
|
||||
-> IndexParameters
|
||||
-> Aff (idb :: IDB | e) Index
|
||||
createIndex store name' path params =
|
||||
Fn.runFn4 _createIndex store name' path params
|
||||
fromEffFnAff $ Fn.runFn4 _createIndex store name' path params
|
||||
|
||||
|
||||
-- | Deletes records in store with the given key or in the given key range in query.
|
||||
@ -126,7 +127,7 @@ delete
|
||||
-> KeyRange
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
delete store range =
|
||||
Fn.runFn2 _delete store range
|
||||
fromEffFnAff $ Fn.runFn2 _delete store range
|
||||
|
||||
|
||||
-- | Deletes the index in store with the given name.
|
||||
@ -138,7 +139,7 @@ deleteIndex
|
||||
-> IndexName
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
deleteIndex store name' =
|
||||
Fn.runFn2 _deleteIndex store name'
|
||||
fromEffFnAff $ Fn.runFn2 _deleteIndex store name'
|
||||
|
||||
|
||||
-- | Returns an IDBIndex for the index named name in store.
|
||||
@ -148,7 +149,7 @@ index
|
||||
-> IndexName
|
||||
-> Aff (idb :: IDB | e) Index
|
||||
index store name' =
|
||||
Fn.runFn2 _index store name'
|
||||
fromEffFnAff $ Fn.runFn2 _index store name'
|
||||
|
||||
|
||||
-- | Adds or updates a record in store with the given value and key.
|
||||
@ -164,7 +165,7 @@ put
|
||||
-> Maybe key
|
||||
-> Aff (idb :: IDB | e) Key
|
||||
put store value key =
|
||||
toKey <$> Fn.runFn3 _put store value (toNullable $ (toKey >>> unsafeFromKey) <$> key)
|
||||
map toKey $ fromEffFnAff $ Fn.runFn3 _put store value (toNullable $ (toKey >>> unsafeFromKey) <$> key)
|
||||
|
||||
|
||||
--------------------
|
||||
@ -215,7 +216,7 @@ transaction =
|
||||
--
|
||||
foreign import _add
|
||||
:: forall e val store
|
||||
. Fn3 store val (Nullable Foreign) (Aff (idb :: IDB | e) Foreign)
|
||||
. Fn3 store val (Nullable Foreign) (EffFnAff (idb :: IDB | e) Foreign)
|
||||
|
||||
|
||||
foreign import _autoIncrement
|
||||
@ -226,27 +227,27 @@ foreign import _autoIncrement
|
||||
foreign import _clear
|
||||
:: forall e store
|
||||
. store
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
-> EffFnAff (idb :: IDB | e) Unit
|
||||
|
||||
|
||||
foreign import _createIndex
|
||||
:: forall e store
|
||||
. Fn4 store String (Array String) { unique :: Boolean, multiEntry :: Boolean } (Aff (idb :: IDB | e) Index)
|
||||
. Fn4 store String (Array String) { unique :: Boolean, multiEntry :: Boolean } (EffFnAff (idb :: IDB | e) Index)
|
||||
|
||||
|
||||
foreign import _delete
|
||||
:: forall e store
|
||||
. Fn2 store KeyRange (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 store KeyRange (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _deleteIndex
|
||||
:: forall e store
|
||||
. Fn2 store String (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 store String (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _index
|
||||
:: forall e store
|
||||
. Fn2 store String (Aff (idb :: IDB | e) Index)
|
||||
. Fn2 store String (EffFnAff (idb :: IDB | e) Index)
|
||||
|
||||
|
||||
foreign import _indexNames
|
||||
@ -266,7 +267,7 @@ foreign import _name
|
||||
|
||||
foreign import _put
|
||||
:: forall e val store
|
||||
. Fn3 store val (Nullable Foreign) (Aff (idb :: IDB | e) Foreign)
|
||||
. Fn3 store val (Nullable Foreign) (EffFnAff (idb :: IDB | e) Foreign)
|
||||
|
||||
|
||||
foreign import _transaction
|
||||
|
@ -1,11 +1,15 @@
|
||||
exports._abort = function _abort(tx) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
tx.abort();
|
||||
success();
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -30,13 +34,17 @@ exports._mode = function _mode(ReadOnly, ReadWrite, VersionChange, tx) {
|
||||
};
|
||||
|
||||
exports._objectStore = function _objectStore(tx, name) {
|
||||
return function aff(success, error) {
|
||||
return function aff(error, success) {
|
||||
try {
|
||||
const store = tx.objectStore(name);
|
||||
success(store);
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -45,28 +53,40 @@ exports._objectStoreNames = function _objectStoreNames(tx) {
|
||||
};
|
||||
|
||||
exports._onAbort = function _onAbort(tx, f) {
|
||||
return function aff(success) {
|
||||
return function aff(error, success) {
|
||||
tx.onabort = function onabort() {
|
||||
f();
|
||||
};
|
||||
success();
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._onComplete = function _onComplete(tx, f) {
|
||||
return function aff(success) {
|
||||
return function aff(error, success) {
|
||||
tx.oncomplete = function oncomplete() {
|
||||
f();
|
||||
};
|
||||
success();
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports._onError = function _onError(tx, f) {
|
||||
return function aff(success) {
|
||||
return function aff(error, success) {
|
||||
tx.onerror = function onerror(e) {
|
||||
f(e.target.error)();
|
||||
};
|
||||
success();
|
||||
|
||||
return function canceler(_, cancelerError) {
|
||||
cancelerError(new Error("Can't cancel IDB Effects"));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -14,9 +14,10 @@ module Database.IndexedDB.IDBTransaction
|
||||
, onError
|
||||
) where
|
||||
|
||||
import Prelude (Unit, (>>>))
|
||||
import Prelude (Unit, ($), (<<<), (>>>))
|
||||
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Control.Monad.Aff.Compat (EffFnAff, fromEffFnAff)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Control.Monad.Eff.Exception (Error)
|
||||
import Data.Function.Uncurried as Fn
|
||||
@ -38,8 +39,7 @@ abort
|
||||
=> tx
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
abort =
|
||||
_abort
|
||||
|
||||
fromEffFnAff <<< _abort
|
||||
|
||||
-- | Returns an IDBObjectStore in the transaction's scope.
|
||||
objectStore
|
||||
@ -48,7 +48,7 @@ objectStore
|
||||
-> String
|
||||
-> Aff (idb :: IDB | e) ObjectStore
|
||||
objectStore tx name =
|
||||
Fn.runFn2 _objectStore tx name
|
||||
fromEffFnAff $ Fn.runFn2 _objectStore tx name
|
||||
|
||||
|
||||
--------------------
|
||||
@ -100,7 +100,7 @@ onAbort
|
||||
-> Eff ( | e') Unit
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
onAbort db' f =
|
||||
Fn.runFn2 _onAbort db' f
|
||||
fromEffFnAff $ Fn.runFn2 _onAbort db' f
|
||||
|
||||
|
||||
-- | Event handler for the `complete` event.
|
||||
@ -110,7 +110,7 @@ onComplete
|
||||
-> Eff ( | e') Unit
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
onComplete db' f =
|
||||
Fn.runFn2 _onComplete db' f
|
||||
fromEffFnAff $ Fn.runFn2 _onComplete db' f
|
||||
|
||||
|
||||
-- | Event handler for the `error` event.
|
||||
@ -120,7 +120,7 @@ onError
|
||||
-> (Error -> Eff ( | e') Unit)
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
onError db' f =
|
||||
Fn.runFn2 _onError db' f
|
||||
fromEffFnAff $ Fn.runFn2 _onError db' f
|
||||
|
||||
|
||||
--------------------
|
||||
@ -130,7 +130,7 @@ onError db' f =
|
||||
foreign import _abort
|
||||
:: forall tx e
|
||||
. tx
|
||||
-> Aff (idb :: IDB | e) Unit
|
||||
-> EffFnAff (idb :: IDB | e) Unit
|
||||
|
||||
|
||||
foreign import _db
|
||||
@ -154,19 +154,19 @@ foreign import _objectStoreNames
|
||||
|
||||
foreign import _objectStore
|
||||
:: forall tx e
|
||||
. Fn2 tx String (Aff (idb :: IDB | e) ObjectStore)
|
||||
. Fn2 tx String (EffFnAff (idb :: IDB | e) ObjectStore)
|
||||
|
||||
|
||||
foreign import _onAbort
|
||||
:: forall tx e e'
|
||||
. Fn2 tx (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 tx (Eff ( | e') Unit) (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _onComplete
|
||||
:: forall tx e e'
|
||||
. Fn2 tx (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 tx (Eff ( | e') Unit) (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
||||
|
||||
foreign import _onError
|
||||
:: forall tx e e'
|
||||
. Fn2 tx (Error -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
|
||||
. Fn2 tx (Error -> Eff ( | e') Unit) (EffFnAff (idb :: IDB | e) Unit)
|
||||
|
149
test/Main.purs
149
test/Main.purs
@ -2,8 +2,8 @@ module Test.Main where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Aff (Aff, launchAff, forkAff, delay, attempt)
|
||||
import Control.Monad.Aff.AVar (AVAR, makeVar, makeVar', modifyVar, peekVar, putVar, takeVar)
|
||||
import Control.Monad.Aff (Aff, launchAff, launchAff_, forkAff, delay, attempt)
|
||||
import Control.Monad.Aff.AVar (AVAR, AVar, makeVar, makeEmptyVar, readVar, putVar, takeVar)
|
||||
import Control.Monad.Aff.Console (log)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Control.Monad.Eff.Class (liftEff)
|
||||
@ -37,9 +37,16 @@ import Database.IndexedDB.IDBTransaction as IDBTransaction
|
||||
|
||||
infixr 7 Tuple as :+:
|
||||
|
||||
launchAff' :: forall a e. Aff e a -> Eff (exception :: EXCEPTION | e) Unit
|
||||
launchAff' aff =
|
||||
pure unit <* (launchAff aff)
|
||||
launchAff' :: forall a e. Aff e a -> Eff e Unit
|
||||
launchAff' =
|
||||
launchAff_
|
||||
|
||||
|
||||
modifyVar :: forall eff a. (a -> a) -> AVar a -> Aff (avar :: AVAR | eff) Unit
|
||||
modifyVar fn v = do
|
||||
val <- takeVar v
|
||||
putVar (fn val) v
|
||||
|
||||
|
||||
-- main :: forall eff. Eff (now :: NOW, mocha :: MOCHA, idb :: IDB, exception :: EXCEPTION, avar :: AVAR | eff) Unit
|
||||
main = runMocha do
|
||||
@ -75,17 +82,17 @@ main = runMocha do
|
||||
it "open specific version -> close -> open latest" do
|
||||
let name = "db-latest"
|
||||
version = 14
|
||||
db <- IDBFactory.open name (Just version)
|
||||
db01 <- IDBFactory.open name (Just version)
|
||||
{ onUpgradeNeeded : Nothing
|
||||
, onBlocked : Nothing
|
||||
}
|
||||
IDBDatabase.name db `shouldEqual` name
|
||||
IDBDatabase.close db
|
||||
db <- IDBFactory.open name Nothing
|
||||
IDBDatabase.name db01 `shouldEqual` name
|
||||
IDBDatabase.close db01
|
||||
db02 <- IDBFactory.open name Nothing
|
||||
{ onUpgradeNeeded : Nothing
|
||||
, onBlocked : Nothing
|
||||
}
|
||||
tearDown name version db
|
||||
tearDown name version db02
|
||||
|
||||
it "open + onUpgradeNeed" do
|
||||
let name = "db-upgrade-needed"
|
||||
@ -94,14 +101,14 @@ main = runMocha do
|
||||
_ <- launchAff $ modifyVar (const $ IDBDatabase.name db) varName
|
||||
_ <- launchAff $ modifyVar (const $ oldVersion) varVersion
|
||||
pure unit
|
||||
varName <- makeVar' "-"
|
||||
varVersion <- makeVar' (-1)
|
||||
varName <- makeVar "-"
|
||||
varVersion <- makeVar (-1)
|
||||
db <- IDBFactory.open name Nothing
|
||||
{ onUpgradeNeeded : Just (callback (Tuple varName varVersion))
|
||||
, onBlocked : Nothing
|
||||
}
|
||||
name' <- peekVar varName
|
||||
version' <- peekVar varVersion
|
||||
name' <- readVar varName
|
||||
version' <- readVar varVersion
|
||||
name' `shouldEqual` name
|
||||
version' `shouldEqual` 0
|
||||
tearDown name version db
|
||||
@ -113,7 +120,7 @@ main = runMocha do
|
||||
_ <- launchAff $ modifyVar (const $ "db-blocked") var
|
||||
pure unit
|
||||
|
||||
var <- makeVar' "-"
|
||||
var <- makeVar "-"
|
||||
db01 <- IDBFactory.open name Nothing
|
||||
{ onUpgradeNeeded : Nothing
|
||||
, onBlocked : Nothing
|
||||
@ -126,7 +133,7 @@ main = runMocha do
|
||||
{ onUpgradeNeeded : Nothing
|
||||
, onBlocked : Just (callback var)
|
||||
}
|
||||
name' <- peekVar var
|
||||
name' <- readVar var
|
||||
name' `shouldEqual` name
|
||||
tearDown name version db02
|
||||
|
||||
@ -293,10 +300,10 @@ main = runMocha do
|
||||
setup storeParams = do
|
||||
let onUpgradeNeeded var db _ _ = launchAff' do
|
||||
store <- IDBDatabase.createObjectStore db "store" storeParams
|
||||
_ <- putVar var { db, store }
|
||||
_ <- putVar { db, store } var
|
||||
pure unit
|
||||
|
||||
var <- makeVar
|
||||
var <- makeEmptyVar
|
||||
db <- IDBFactory.open "db" Nothing
|
||||
{ onUpgradeNeeded : Just (onUpgradeNeeded var)
|
||||
, onBlocked : Nothing
|
||||
@ -331,17 +338,17 @@ main = runMocha do
|
||||
it "deleteObjectStore" do
|
||||
let onUpgradeNeeded var db _ _ = launchAff' do
|
||||
_ <- IDBDatabase.deleteObjectStore db "store"
|
||||
putVar var true
|
||||
putVar true var
|
||||
|
||||
var <- makeVar
|
||||
var <- makeEmptyVar
|
||||
{ db, store } <- setup IDBDatabase.defaultParameters
|
||||
IDBDatabase.close db
|
||||
db <- IDBFactory.open "db" (Just 999) { onUpgradeNeeded : Just (onUpgradeNeeded var)
|
||||
db' <- IDBFactory.open "db" (Just 999) { onUpgradeNeeded : Just (onUpgradeNeeded var)
|
||||
, onBlocked : Nothing
|
||||
}
|
||||
deleted <- takeVar var
|
||||
deleted `shouldEqual` true
|
||||
tearDown db
|
||||
tearDown db'
|
||||
|
||||
|
||||
describe "IDBObjectStore" do
|
||||
@ -355,9 +362,9 @@ main = runMocha do
|
||||
let onUpgradeNeeded' var db _ _ = launchAff' do
|
||||
store <- IDBDatabase.createObjectStore db "store" storeParams
|
||||
liftEff $ maybe (pure unit) id (onUpgradeNeeded <*> pure db <*> pure store)
|
||||
putVar var { db, store }
|
||||
putVar { db, store } var
|
||||
|
||||
var <- makeVar
|
||||
var <- makeEmptyVar
|
||||
db <- IDBFactory.open "db" Nothing
|
||||
{ onUpgradeNeeded : Just (onUpgradeNeeded' var)
|
||||
, onBlocked : Nothing
|
||||
@ -375,24 +382,24 @@ main = runMocha do
|
||||
(toKey 1) `shouldEqual` key
|
||||
|
||||
-- int key
|
||||
key <- IDBObjectStore.add store "patate" (Just 14)
|
||||
(toKey 14) `shouldEqual` key
|
||||
key' <- IDBObjectStore.add store "patate" (Just 14)
|
||||
(toKey 14) `shouldEqual` key'
|
||||
|
||||
-- number key
|
||||
key <- IDBObjectStore.add store "patate" (Just 14.42)
|
||||
(toKey 14.42) `shouldEqual` key
|
||||
key'' <- IDBObjectStore.add store "patate" (Just 14.42)
|
||||
(toKey 14.42) `shouldEqual` key''
|
||||
|
||||
-- string key
|
||||
key <- IDBObjectStore.add store "patate" (Just "key")
|
||||
(toKey "key") `shouldEqual` key
|
||||
key''' <- IDBObjectStore.add store "patate" (Just "key")
|
||||
(toKey "key") `shouldEqual` key'''
|
||||
|
||||
-- date key
|
||||
key <- IDBObjectStore.add store "patate" (Just date)
|
||||
(toKey date) `shouldEqual` key
|
||||
key'''' <- IDBObjectStore.add store "patate" (Just date)
|
||||
(toKey date) `shouldEqual` key''''
|
||||
|
||||
-- array key
|
||||
key <- IDBObjectStore.add store "patate" (Just $ toKey [14, 42])
|
||||
(toKey [14, 42]) `shouldEqual` key
|
||||
key''''' <- IDBObjectStore.add store "patate" (Just $ toKey [14, 42])
|
||||
(toKey [14, 42]) `shouldEqual` key'''''
|
||||
}
|
||||
tearDown db
|
||||
|
||||
@ -411,8 +418,8 @@ main = runMocha do
|
||||
{ db } <- setup
|
||||
{ storeParams: IDBDatabase.defaultParameters
|
||||
, onUpgradeNeeded: Just $ \_ store -> launchAff' do
|
||||
key <- IDBObjectStore.add store "patate" (Just 14)
|
||||
key <- IDBObjectStore.add store "autruche" (Just 42)
|
||||
_ <- IDBObjectStore.add store "patate" (Just 14)
|
||||
_ <- IDBObjectStore.add store "autruche" (Just 42)
|
||||
n <- IDBObjectStore.count store Nothing
|
||||
n `shouldEqual` 2
|
||||
}
|
||||
@ -426,8 +433,8 @@ main = runMocha do
|
||||
mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 14)
|
||||
mkey `shouldEqual` (Just key)
|
||||
|
||||
mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 42)
|
||||
mkey `shouldEqual` none
|
||||
mkey' <- IDBObjectStore.getKey store (IDBKeyRange.only 42)
|
||||
mkey' `shouldEqual` none
|
||||
}
|
||||
tearDown db
|
||||
|
||||
@ -444,16 +451,16 @@ main = runMocha do
|
||||
keys `shouldEqual` [key1, key2, key3]
|
||||
|
||||
-- lower bound
|
||||
keys <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 14 true) Nothing
|
||||
keys `shouldEqual` [key2, key3]
|
||||
keys' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 14 true) Nothing
|
||||
keys' `shouldEqual` [key2, key3]
|
||||
|
||||
-- upper bound
|
||||
keys <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.upperBound 42 false) Nothing
|
||||
keys `shouldEqual` [key1, key2]
|
||||
keys'' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.upperBound 42 false) Nothing
|
||||
keys'' `shouldEqual` [key1, key2]
|
||||
|
||||
-- count
|
||||
keys <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 1 true) (Just 2)
|
||||
keys `shouldEqual` [key1, key2]
|
||||
keys''' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 1 true) (Just 2)
|
||||
keys''' `shouldEqual` [key1, key2]
|
||||
}
|
||||
tearDown db
|
||||
|
||||
@ -513,9 +520,9 @@ main = runMocha do
|
||||
_ <- traverse (uncurry (IDBObjectStore.add store)) values
|
||||
index <- IDBObjectStore.createIndex store "index" keyPath indexParams
|
||||
liftEff $ maybe (pure unit) id (onUpgradeNeeded <*> pure db <*> pure tx <*> pure index)
|
||||
putVar var { db, index, store }
|
||||
putVar { db, index, store } var
|
||||
|
||||
var <- makeVar
|
||||
var <- makeEmptyVar
|
||||
db <- IDBFactory.open "db" Nothing
|
||||
{ onUpgradeNeeded : Just (onUpgradeNeeded' var)
|
||||
, onBlocked : Nothing
|
||||
@ -538,9 +545,9 @@ main = runMocha do
|
||||
tearDown db
|
||||
|
||||
it "attempt to create an index that requires unique values on an object store already contains duplicates" do
|
||||
let onAbort var = launchAff' (putVar var true)
|
||||
txVar <- makeVar
|
||||
dbVar <- makeVar
|
||||
let onAbort var = launchAff' (putVar true var)
|
||||
txVar <- makeEmptyVar
|
||||
dbVar <- makeEmptyVar
|
||||
res <- attempt $ setup
|
||||
{ storeParams : IDBDatabase.defaultParameters
|
||||
, indexParams : { unique : true
|
||||
@ -802,11 +809,11 @@ main = runMocha do
|
||||
key <- IDBIndex.getKey index (IDBKeyRange.only "patate")
|
||||
key `shouldEqual` (Just $ toKey 1)
|
||||
|
||||
key <- IDBIndex.getKey index (IDBKeyRange.only "autruche")
|
||||
key `shouldEqual` (Just $ toKey 1)
|
||||
key' <- IDBIndex.getKey index (IDBKeyRange.only "autruche")
|
||||
key' `shouldEqual` (Just $ toKey 1)
|
||||
|
||||
key <- IDBIndex.getKey index (IDBKeyRange.only "bob")
|
||||
key `shouldEqual` (Just $ toKey 2)
|
||||
key'' <- IDBIndex.getKey index (IDBKeyRange.only "bob")
|
||||
key'' `shouldEqual` (Just $ toKey 2)
|
||||
}
|
||||
tearDown db
|
||||
|
||||
@ -851,9 +858,9 @@ main = runMocha do
|
||||
_ <- traverse (uncurry (IDBObjectStore.add store)) values
|
||||
index <- IDBObjectStore.createIndex store "index" keyPath indexParams
|
||||
liftEff $ maybe (pure unit) id (onUpgradeNeeded <*> pure db <*> pure tx <*> pure index)
|
||||
putVar var { db, index, store }
|
||||
putVar { db, index, store } var
|
||||
|
||||
var <- makeVar
|
||||
var <- makeEmptyVar
|
||||
db <- IDBFactory.open "db" Nothing
|
||||
{ onUpgradeNeeded : Just (onUpgradeNeeded' var)
|
||||
, onBlocked : Nothing
|
||||
@ -874,7 +881,7 @@ main = runMocha do
|
||||
}
|
||||
let cb vdone vvals =
|
||||
{ onComplete: launchAff' do
|
||||
putVar vdone unit
|
||||
putVar unit vdone
|
||||
|
||||
, onError: \error -> launchAff' do
|
||||
fail $ "unexpected error: " <> show error
|
||||
@ -883,11 +890,11 @@ main = runMocha do
|
||||
vals <- takeVar vvals
|
||||
pure (IDBCursor.value cursor) >>= shouldEqual (maybe "" _.v $ head vals)
|
||||
IDBCursor.primaryKey cursor >>= shouldEqual (maybe (toKey 0) _.k $ head vals)
|
||||
putVar vvals (drop 1 vals)
|
||||
putVar (drop 1 vals) vvals
|
||||
IDBCursor.continue cursor none
|
||||
}
|
||||
vdone <- makeVar
|
||||
vvals <- makeVar'
|
||||
vdone <- makeEmptyVar
|
||||
vvals <- makeVar
|
||||
[ { v: "pie" , k: toKey 1 }
|
||||
, { v: "pancake", k: toKey 2 }
|
||||
, { v: "pie" , k: toKey 3 }
|
||||
@ -923,11 +930,11 @@ main = runMocha do
|
||||
case res of
|
||||
Left err -> do
|
||||
name err `shouldEqual` "DataError"
|
||||
putVar vdone unit
|
||||
putVar unit vdone
|
||||
Right _ -> do
|
||||
fail "expected continue to fail"
|
||||
}
|
||||
vdone <- makeVar
|
||||
vdone <- makeEmptyVar
|
||||
tx <- IDBDatabase.transaction db ["store"] ReadOnly
|
||||
store <- IDBTransaction.objectStore tx "store"
|
||||
IDBObjectStore.openCursor store Nothing Next (cb vdone)
|
||||
@ -949,7 +956,7 @@ main = runMocha do
|
||||
}
|
||||
let cb vdone vjump =
|
||||
{ onComplete: launchAff' do
|
||||
putVar vdone unit
|
||||
putVar unit vdone
|
||||
|
||||
, onError: \error -> launchAff' do
|
||||
fail $ "unexpected error: " <> show error
|
||||
@ -964,10 +971,10 @@ main = runMocha do
|
||||
value.pKey `shouldEqual` "pkey_3"
|
||||
value.iKey `shouldEqual` "ikey_3"
|
||||
IDBCursor.continue cursor none
|
||||
putVar vjump false
|
||||
putVar false vjump
|
||||
}
|
||||
vdone <- makeVar
|
||||
vjump <- makeVar' true
|
||||
vdone <- makeEmptyVar
|
||||
vjump <- makeVar true
|
||||
tx <- IDBDatabase.transaction db ["store"] ReadOnly
|
||||
store <- IDBTransaction.objectStore tx "store"
|
||||
IDBObjectStore.openCursor store Nothing Next (cb vdone vjump)
|
||||
@ -990,7 +997,7 @@ main = runMocha do
|
||||
{ onComplete: launchAff' do
|
||||
mval <- map _.pKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
|
||||
mval `shouldEqual` (Nothing :: Maybe String)
|
||||
putVar vdone unit
|
||||
putVar unit vdone
|
||||
|
||||
, onError: \error -> launchAff' do
|
||||
fail $ "unexpected error: " <> show error
|
||||
@ -1001,7 +1008,7 @@ main = runMocha do
|
||||
IDBCursor.delete cursor
|
||||
IDBCursor.advance cursor 4
|
||||
}
|
||||
vdone <- makeVar
|
||||
vdone <- makeEmptyVar
|
||||
tx <- IDBDatabase.transaction db ["store"] ReadWrite
|
||||
store <- IDBTransaction.objectStore tx "store"
|
||||
IDBObjectStore.openCursor store Nothing Next (cb vdone store)
|
||||
@ -1021,7 +1028,7 @@ main = runMocha do
|
||||
{ onComplete: launchAff' do
|
||||
mval <- map _.iKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
|
||||
mval `shouldEqual` (Just "patate")
|
||||
putVar vdone unit
|
||||
putVar unit vdone
|
||||
|
||||
, onError: \error -> launchAff' do
|
||||
fail $ "unexpected error: " <> show error
|
||||
@ -1033,7 +1040,7 @@ main = runMocha do
|
||||
key `shouldEqual` toKey "pkey_0"
|
||||
IDBCursor.advance cursor 4
|
||||
}
|
||||
vdone <- makeVar
|
||||
vdone <- makeEmptyVar
|
||||
tx <- IDBDatabase.transaction db ["store"] ReadWrite
|
||||
store <- IDBTransaction.objectStore tx "store"
|
||||
IDBObjectStore.openCursor store Nothing Next (cb vdone store)
|
||||
@ -1061,11 +1068,11 @@ main = runMocha do
|
||||
case res of
|
||||
Left err -> do
|
||||
name err `shouldEqual` "ReadOnlyError"
|
||||
putVar vdone unit
|
||||
putVar unit vdone
|
||||
Right _ ->
|
||||
fail $ "expected ReadOnlyError"
|
||||
}
|
||||
vdone <- makeVar
|
||||
vdone <- makeEmptyVar
|
||||
tx <- IDBDatabase.transaction db ["store"] ReadOnly
|
||||
store <- IDBTransaction.objectStore tx "store"
|
||||
IDBObjectStore.openCursor store Nothing Next (cb vdone)
|
||||
|
Loading…
Reference in New Issue
Block a user