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