git.iko.soy/purescript-indexed-DB
on 24fa04a help sign in
.gitignore−2
since splitsnapshots
unifiedsplit
@@ -77,5 +77,3 @@ releases
77.purs*
77.purs*
78.psa*
78.psa*
79dist
79dist
80−.spago
81−test.js
README.md+9−41
@@ -14,27 +14,8 @@ menaingful namespace (e.g `IDBIndex.get`, `IDBObjectStore.openCursor` ...)
14
14
15Here's a quick example of what it look likes.
15Here's a quick example of what it look likes.
16```purescript
16```purescript
17−module Main where
18−
19−import Prelude
20−
21−import Control.Monad.Aff (Aff, launchAff_)
22−import Control.Monad.Aff.Console (CONSOLE, log)
23−import Control.Monad.Eff.Exception (EXCEPTION)
24−import Control.Monad.Eff (Eff)
25−import Data.Maybe (Maybe(..), maybe)
26−
27−import Database.IndexedDB.Core
28−import Database.IndexedDB.IDBFactory as IDBFactory
29−import Database.IndexedDB.IDBDatabase as IDBDatabase
30−import Database.IndexedDB.IDBObjectStore as IDBObjectStore
31−import Database.IndexedDB.IDBIndex as IDBIndex
32−import Database.IndexedDB.IDBTransaction as IDBTransaction
33−import Database.IndexedDB.IDBKeyRange as IDBKeyRange
34−
35−
36main :: Eff (idb :: IDB, exception :: EXCEPTION, console :: CONSOLE) Unit
17main :: Eff (idb :: IDB, exception :: EXCEPTION, console :: CONSOLE) Unit
37−main = launchAff_ do
18+main = launchAff' do
38 db <- IDBFactory.open "db" Nothing { onBlocked : Nothing
19 db <- IDBFactory.open "db" Nothing { onBlocked : Nothing
39 , onUpgradeNeeded : Just onUpgradeNeeded
20 , onUpgradeNeeded : Just onUpgradeNeeded
40 }
21 }
@@ -45,21 +26,22 @@ main = launchAff_ do
45 log $ maybe "not found" id val
26 log $ maybe "not found" id val
46
27
47
28
48−onUpgradeNeeded :: forall e. Database -> Transaction -> { oldVersion :: Int } -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
29+onUpgradeNeeded :: forall e. Database -> Transaction -> Eff (idb :: IDB, exception :: EXCEPTION | e) Unit
49−onUpgradeNeeded db _ _ = launchAff_ do
30+onUpgradeNeeded db _ = launchAff' do
50− store <- IDBDatabase.createObjectStore db "store" IDBDatabase.defaultParameters
31+ store <- IDBDatabase.createObjectStore db "store" IDBObjectStore.defaultParameters
51 _ <- IDBObjectStore.add store "patate" (Just 1)
32 _ <- IDBObjectStore.add store "patate" (Just 1)
52 _ <- IDBObjectStore.add store { property: 42 } (Just 2)
33 _ <- IDBObjectStore.add store { property: 42 } (Just 2)
53− _ <- IDBObjectStore.createIndex store "index" ["property"] IDBObjectStore.defaultParameters
34+ _ <- IDBObjectStore.createIndex store "index" ["property"] IDBIndex.defaultParameters
54 pure unit
35 pure unit
55```
36```
56
37
57## Notes
38## Notes
58
39
59### Errors
40### Errors
60−Errors normally thrown by the IDB\* interfaces are wrapped in the `Aff` Monad as `Error` where
41+Errors normally thrown by the IDB\* interfaces are wrapped in the `Aff` Monad as `Error`
61−the `name` corresponds to the error's name (e.g. "InvalidStateError"). Pattern matching can
42+where the `message` corresponds to the error's name (e.g. "InvalidStateError").
62−therefore be done on any error to handle specific errors thrown by the API.
43+Pattern matching can therefore be done on any error message to handle specific errors thrown
44+by the API.
63
45
64### Examples
46### Examples
65The `test` folder contains a great amount of examples showing practical usage of the IDB\*
47The `test` folder contains a great amount of examples showing practical usage of the IDB\*
@@ -70,20 +52,6 @@ one.
70
52
71## Changelog
53## Changelog
72
54
73−#### v3.0.0
74−
75−- callback to `onUpgradeNeeded` event now provide a record with the database old version.
76−
77−#### v2.0.0
78−
79−- review interface implementation (use of opaque classes to improve readability without compromising
80− the reusability). The API doesn't really change from a user perspective though.
81−
82−- make the Key more opaque (by having an IDBKey instance for Foreign types)
83−
84−- Upgrade purescript-exceptions to 3.1.0 and leverage the new `name` accessor
85−
86−
87#### v1.0.0
55#### v1.0.0
88
56
89- [Indexed Database API 2.0](https://w3c.github.io/IndexedDB/) totally covered apart from
57- [Indexed Database API 2.0](https://w3c.github.io/IndexedDB/) totally covered apart from
bower.jsonnew file+42
@@ -0,0 +1,42 @@
1+{
2+ "name": "purescript-indexeddb",
3+ "description": "An API wrapper around IndexedDB",
4+ "version": "1.0.2",
5+ "authors": [
6+ "Matthias Benkort <matthias.benkort@truqu.com>"
7+ ],
8+ "ignore": [
9+ "**/.*",
10+ "node_modules",
11+ "bower_components",
12+ "output",
13+ "test",
14+ "dist",
15+ "releases",
16+ "package.json",
17+ "karma.conf.js",
18+ "karma.browserstack.conf.js",
19+ "deploy.sh"
20+ ],
21+ "license": "MIT",
22+ "homepage": "https://github.com/truqu/purescript-indexedDB",
23+ "repository": {
24+ "type": "git",
25+ "url": "git://github.com/truqu/purescript-indexedDB.git"
26+ },
27+ "dependencies": {
28+ "purescript-aff": "^3.1.0",
29+ "purescript-datetime": "^3.2.0",
30+ "purescript-eff": "^3.1.0",
31+ "purescript-exceptions": "https://github.com/truqu/purescript-exceptions.git#3.1.0",
32+ "purescript-maybe": "^3.0.0",
33+ "purescript-prelude": "^3.1.0",
34+ "purescript-read": "^1.0.0"
35+ },
36+ "devDependencies": {
37+ "purescript-spec": "^1.0.0",
38+ "purescript-psci-support": "^3.0.0",
39+ "purescript-now": "^3.0.0",
40+ "purescript-spec-mocha": "https://github.com/truqu/purescript-spec-mocha.git#0.5.0"
41+ }
42+}
deploy.shnew file+6
@@ -0,0 +1,6 @@
1+#!/bin/sh
2+
3+git stash save
4+git clean -df
5+yes | pulp publish --no-push
6+git stash pop
index.jsdeleted−4
@@ -1,4 +0,0 @@
1−import "fake-indexeddb/auto";
2−import * as Main from './output/Test.Main/index.js';
3−
4−Main.main();
karma.browserstack.conf.jsnew file+91
@@ -0,0 +1,91 @@
1+module.exports = (config) => {
2+ config.set({
3+ browsers: [
4+ 'FirefoxMAC',
5+ 'ChromeMAC',
6+ // 'SafariMAC',
7+ 'OperaMAC',
8+
9+ 'FirefoxWIN',
10+ 'ChromeWIN',
11+ 'OperaWIN',
12+ ],
13+ files: [
14+ 'dist/karma/index.js',
15+ ],
16+ frameworks: [
17+ 'mocha',
18+ ],
19+ plugins: [
20+ 'karma-browserstack-launcher',
21+ 'karma-mocha',
22+ ],
23+ reporters: [
24+ 'dots',
25+ 'BrowserStack',
26+ ],
27+ singleRun: true,
28+ client: {
29+ mocha: {
30+ timeout: 10000,
31+ },
32+ },
33+ browserStack: {
34+ username: process.env.BROWSERSTACK_USERNAME,
35+ accessKey: process.env.BROWSERSTACK_ACCESSKEY,
36+ timeout: 1500,
37+ captureTimeout: 500,
38+ },
39+ customLaunchers: {
40+ FirefoxMAC: {
41+ base: 'BrowserStack',
42+ browser: 'Firefox',
43+ browser_version: '51',
44+ os: 'OS X',
45+ os_version: 'Sierra',
46+ },
47+ ChromeMAC: {
48+ base: 'BrowserStack',
49+ browser: 'Chrome',
50+ browser_version: '58',
51+ os: 'OS X',
52+ os_version: 'Sierra',
53+ },
54+ SafariMAC: {
55+ base: 'BrowserStack',
56+ browser: 'Safari',
57+ browser_version: '10.1',
58+ os: 'OS X',
59+ os_version: 'Sierra',
60+ },
61+ OperaMAC: {
62+ base: 'BrowserStack',
63+ browser: 'Opera',
64+ browser_version: '46',
65+ os: 'OS X',
66+ os_version: 'Sierra',
67+ },
68+ FirefoxWIN: {
69+ base: 'BrowserStack',
70+ browser: 'Firefox',
71+ browser_version: '51',
72+ os: 'WINDOWS',
73+ os_version: '10',
74+ },
75+ ChromeWIN: {
76+ base: 'BrowserStack',
77+ browser: 'Chrome',
78+ browser_version: '58',
79+ os: 'WINDOWS',
80+ os_version: '10',
81+ },
82+ OperaWIN: {
83+ base: 'BrowserStack',
84+ browser: 'Opera',
85+ browser_version: '46',
86+ os: 'WINDOWS',
87+ os_version: '10',
88+ },
89+ },
90+ });
91+};
karma.conf.jsnew file+25
@@ -0,0 +1,25 @@
1+module.exports = config => {
2+ config.set({
3+ autoWatch: true,
4+ singleRun: true,
5+ browsers: ["Chrome"],
6+ files: [
7+ "dist/karma/index.js",
8+ ],
9+ frameworks: [
10+ "mocha",
11+ ],
12+ plugins: [
13+ "karma-chrome-launcher",
14+ "karma-firefox-launcher",
15+ "karma-spec-reporter",
16+ "karma-mocha",
17+ ],
18+ reporters: ["spec"],
19+ client: {
20+ mocha: {
21+ timeout: 10000
22+ }
23+ }
24+ });
25+};
package.json+36−9
@@ -1,15 +1,42 @@
1{
1{
2− "name": "purescript-indexed-DB",
2+ "name": "purescript-indexeddb",
3 "version": "1.0.0",
3 "version": "1.0.0",
4− "main": "index.js",
4+ "description": "A wrapper around the IndexedDB API",
5− "repository": "https://github.com/ilyakooo0/purescript-indexed-DB.git",
6− "author": "iko <mail@iko.soy>",
7− "license": "MIT",
8 "scripts": {
5 "scripts": {
9− "test": "spago build && node index.js"
6+ "prepare:release": "mkdir -p releases/github && cp -r README.md LICENSE src bower.json releases/github",
7+ "test:build": "mkdir -p dist/karma && pulp browserify -j 4 --main \"Test.Main\" -I test --to dist/karma/index.js",
8+ "test:run": "karma start karma.conf.js",
9+ "test:run:browserstack": "karma start karma.browserstack.conf.js",
10+ "test:browserstack": "npm run test:build && npm run test:run:browserstack",
11+ "test": "npm run test:build && npm run test:run",
12+ "start": "find . -type f -regex '.*\\(src\\|test\\).*' ! -regex '.*bower_components.*\\|.*node_modules.*|.*\\.sw.*' | entr -s 'npm run test -s'"
13+ },
14+ "dependencies": {},
15+ "devDependencies": {
16+ "bower": "1.8.0",
17+ "eslint": "3.19.0",
18+ "eslint-config-airbnb": "15.0.1",
19+ "eslint-plugin-import": "2.5.0",
20+ "eslint-plugin-jsx-a11y": "5.0.3",
21+ "eslint-plugin-react": "7.1.0",
22+ "karma": "1.7.0",
23+ "karma-browserstack-launcher": "1.3.0",
24+ "karma-chrome-launcher": "2.1.1",
25+ "karma-firefox-launcher": "1.0.1",
26+ "karma-mocha": "1.3.0",
27+ "karma-spec-reporter": "0.0.31",
28+ "mocha": "3.4.2",
29+ "pulp": "11.0.0",
30+ "purescript": "0.11.5"
10 },
31 },
11− "dependencies": {
32+ "repository": {
12− "fake-indexeddb": "^4.0.1"
33+ "type": "git",
34+ "url": "git+https://github.com/Truqu/purescript-indexeddb.git"
35+ },
36+ "author": "Matthias Benkort <matthias.benkort@truqu.com>",
37+ "license": "MIT",
38+ "bugs": {
39+ "url": "https://github.com/Truqu/purescript-indexeddb/issues"
13 },
40 },
14− "type": "module"
41+ "homepage": "https://github.com/Truqu/purescript-indexeddb#readme"
15}
42}
packages.dhalldeleted−105
@@ -1,105 +0,0 @@
1−{-
2−Welcome to your new Dhall package-set!
3−
4−Below are instructions for how to edit this file for most use
5−cases, so that you don't need to know Dhall to use it.
6−
7−## Use Cases
8−
9−Most will want to do one or both of these options:
10−1. Override/Patch a package's dependency
11−2. Add a package not already in the default package set
12−
13−This file will continue to work whether you use one or both options.
14−Instructions for each option are explained below.
15−
16−### Overriding/Patching a package
17−
18−Purpose:
19−- Change a package's dependency to a newer/older release than the
20− default package set's release
21−- Use your own modified version of some dependency that may
22− include new API, changed API, removed API by
23− using your custom git repo of the library rather than
24− the package set's repo
25−
26−Syntax:
27−where `entityName` is one of the following:
28−- dependencies
29−- repo
30−- version
31−-------------------------------
32−let upstream = --
33−in upstream
34− with packageName.entityName = "new value"
35−-------------------------------
36−
37−Example:
38−-------------------------------
39−let upstream = --
40−in upstream
41− with halogen.version = "master"
42− with halogen.repo = "https://example.com/path/to/git/repo.git"
43−
44− with halogen-vdom.version = "v4.0.0"
45− with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies
46−-------------------------------
47−
48−### Additions
49−
50−Purpose:
51−- Add packages that aren't already included in the default package set
52−
53−Syntax:
54−where `<version>` is:
55−- a tag (i.e. "v4.0.0")
56−- a branch (i.e. "master")
57−- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977")
58−-------------------------------
59−let upstream = --
60−in upstream
61− with new-package-name =
62− { dependencies =
63− [ "dependency1"
64− , "dependency2"
65− ]
66− , repo =
67− "https://example.com/path/to/git/repo.git"
68− , version =
69− "<version>"
70− }
71−-------------------------------
72−
73−Example:
74−-------------------------------
75−let upstream = --
76−in upstream
77− with benchotron =
78− { dependencies =
79− [ "arrays"
80− , "exists"
81− , "profunctor"
82− , "strings"
83− , "quickcheck"
84− , "lcg"
85− , "transformers"
86− , "foldable-traversable"
87− , "exceptions"
88− , "node-fs"
89− , "node-buffer"
90− , "node-readline"
91− , "datetime"
92− , "now"
93− ]
94− , repo =
95− "https://github.com/hdgarrood/purescript-benchotron.git"
96− , version =
97− "v7.0.0"
98− }
99−-------------------------------
100−-}
101−
102−let upstream =
103− https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221124/packages.dhall
104− sha256:792255bbd8e2141468d967325f3e78246cb7e500bf3ab6d76d5b22dffbb09d49
105−in upstream
spago.dhalldeleted−42
@@ -1,42 +0,0 @@
1−{-
2−Welcome to a Spago project!
3−You can edit this file as you like.
4−
5−Need help? See the following resources:
6−- Spago documentation: https://github.com/purescript/spago
7−- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html
8−
9−When creating a new Spago project, you can use
10−`spago init --no-comments` or `spago init -C`
11−to generate this file without the comments in this block.
12−-}
13−{ name = "indexed-db"
14−, dependencies =
15− [ "aff"
16− , "arrays"
17− , "avar"
18− , "console"
19− , "control"
20− , "datetime"
21− , "effect"
22− , "either"
23− , "enums"
24− , "exceptions"
25− , "foldable-traversable"
26− , "foreign"
27− , "functions"
28− , "identity"
29− , "lists"
30− , "maybe"
31− , "nonempty"
32− , "now"
33− , "nullable"
34− , "prelude"
35− , "read"
36− , "spec"
37− , "transformers"
38− , "tuples"
39− ]
40−, packages = ./packages.dhall
41−, sources = [ "src/**/*.purs", "test/**/*.purs" ]
42−}
src/Database/IndexedDB/Core.js+6−6
@@ -3,7 +3,7 @@ const toArray = function toArray(xs) {
3};
3};
4
4
5
5
6−export function _showCursor(cursor) {
6+exports._showCursor = function _showCursor(cursor) {
7 return '(IDBCursor ' +
7 return '(IDBCursor ' +
8 '{ direction: ' + cursor.direction +
8 '{ direction: ' + cursor.direction +
9 ', key: ' + cursor.key +
9 ', key: ' + cursor.key +
@@ -11,7 +11,7 @@ export function _showCursor(cursor) {
11 ' })';
11 ' })';
12};
12};
13
13
14−export function _showDatabase(db) {
14+exports._showDatabase = function _showDatabase(db) {
15 return '(IDBDatabase ' +
15 return '(IDBDatabase ' +
16 '{ name: ' + db.name +
16 '{ name: ' + db.name +
17 ', objectStoreNames: [' + toArray(db.objectStoreNames).join(', ') + ']' +
17 ', objectStoreNames: [' + toArray(db.objectStoreNames).join(', ') + ']' +
@@ -19,7 +19,7 @@ export function _showDatabase(db) {
19 ' })';
19 ' })';
20};
20};
21
21
22−export function _showIndex(index) {
22+exports._showIndex = function _showIndex(index) {
23 return '(IDBIndex ' +
23 return '(IDBIndex ' +
24 '{ name: ' + index.name +
24 '{ name: ' + index.name +
25 ', keyPath: ' + index.keyPath +
25 ', keyPath: ' + index.keyPath +
@@ -28,7 +28,7 @@ export function _showIndex(index) {
28 ' })';
28 ' })';
29};
29};
30
30
31−export function _showKeyRange(range) {
31+exports._showKeyRange = function _showKeyRange(range) {
32 return '(IDBKeyRange ' +
32 return '(IDBKeyRange ' +
33 '{ lower: ' + range.lower +
33 '{ lower: ' + range.lower +
34 ', upper: ' + range.upper +
34 ', upper: ' + range.upper +
@@ -37,7 +37,7 @@ export function _showKeyRange(range) {
37 ' })';
37 ' })';
38};
38};
39
39
40−export function _showObjectStore(store) {
40+exports._showObjectStore = function _showObjectStore(store) {
41 return '(IDBObjectStore ' +
41 return '(IDBObjectStore ' +
42 '{ autoIncrement: ' + store.autoIncrement +
42 '{ autoIncrement: ' + store.autoIncrement +
43 ', indexNames: [' + toArray(store.indexNames).join(', ') + ']' +
43 ', indexNames: [' + toArray(store.indexNames).join(', ') + ']' +
@@ -46,7 +46,7 @@ export function _showObjectStore(store) {
46 ' })';
46 ' })';
47};
47};
48
48
49−export function _showTransaction(tx) {
49+exports._showTransaction = function _showTransaction(tx) {
50 return '(IDBTransaction ' +
50 return '(IDBTransaction ' +
51 '{ error: ' + tx.error +
51 '{ error: ' + tx.error +
52 ', mode: ' + tx.mode +
52 ', mode: ' + tx.mode +
src/Database/IndexedDB/Core.purs+81−21
@@ -1,12 +1,18 @@
1-- | The Core module gathers types used across the library and provides basic Show instances for
1-- | The Core module gathers types used across the library and provides basic Show instances for
2-- | those types.
2-- | those types.
3+-- |
4+-- | NOTE:
5+-- | Errors normally thrown by the IDB* interfaces are wrapped in the `Aff` Monad as `Error`
6+-- | where the `message` corresponds to the error's name (e.g. "InvalidStateError").
7+-- | Pattern matching can therefore be done on any error message to handle specific errors thrown
8+-- | by the API.
9+
3module Database.IndexedDB.Core
10module Database.IndexedDB.Core
4 -- * Effects
11 -- * Effects
5− (
6− -- IDB
12+ ( IDB
7
13
8− -- * Types
14+ -- * Types
9− Database
15+ , Database
10 , Index
16 , Index
11 , KeyCursor
17 , KeyCursor
12 , KeyRange
18 , KeyRange
@@ -31,13 +37,23 @@ module Database.IndexedDB.Core
31 , module Database.IndexedDB.IDBKey
37 , module Database.IndexedDB.IDBKey
32 ) where
38 ) where
33
39
34−import Prelude (class Show)
40+import Prelude (class Show)
35
41
42+import Control.Monad.Eff (kind Effect)
36−import Data.Maybe (Maybe(..))
43+import Data.Maybe (Maybe(..))
37−import Data.String.Read (class Read)
44+import Data.String.Read (class Read)
38
45
39import Database.IndexedDB.IDBKey
46import Database.IndexedDB.IDBKey
40
47
48+
49+--------------------
50+-- Effects
51+--
52+
53+-- | IDB Effects, manifestation that something happened with the IndexedDB
54+foreign import data IDB :: Effect
55+
56+
41--------------------
57--------------------
42-- TYPES
58-- TYPES
43--
59--
@@ -46,28 +62,35 @@ import Database.IndexedDB.IDBKey
46-- | stores which hold the data stored in the database.
62-- | stores which hold the data stored in the database.
47foreign import data Database :: Type
63foreign import data Database :: Type
48
64
65+
49-- | An index allows looking up records in an object store using properties of the values
66-- | An index allows looking up records in an object store using properties of the values
50-- | in the object stores records.
67-- | in the object stores records.
51foreign import data Index :: Type
68foreign import data Index :: Type
52
69
70+
53-- | A key range is a continuous interval over some data type used for keys.
71-- | A key range is a continuous interval over some data type used for keys.
54foreign import data KeyRange :: Type
72foreign import data KeyRange :: Type
55
73
74+
56-- | A cursor is used to iterate over a range of records in an index or an object store
75-- | A cursor is used to iterate over a range of records in an index or an object store
57-- | in a specific direction. A KeyCursor doesn't hold any value.
76-- | in a specific direction. A KeyCursor doesn't hold any value.
58foreign import data KeyCursor :: Type
77foreign import data KeyCursor :: Type
59
78
79+
60-- | A Transaction is used to interact with the data in a database.
80-- | A Transaction is used to interact with the data in a database.
61-- | Whenever data is read or written to the database it is done by using a transaction.
81-- | Whenever data is read or written to the database it is done by using a transaction.
62foreign import data Transaction :: Type
82foreign import data Transaction :: Type
63
83
84+
64-- | An object store is the primary storage mechanism for storing data in a database.
85-- | An object store is the primary storage mechanism for storing data in a database.
65foreign import data ObjectStore :: Type
86foreign import data ObjectStore :: Type
66
87
88+
67-- | A cursor is used to iterate over a range of records in an index or an object store
89-- | A cursor is used to iterate over a range of records in an index or an object store
68-- | in a specific direction. A ValueCursor also holds the value corresponding to matching key.
90-- | in a specific direction. A ValueCursor also holds the value corresponding to matching key.
69foreign import data ValueCursor :: Type
91foreign import data ValueCursor :: Type
70
92
93+
71-- | A cursor has a direction that determines whether it moves in monotonically
94-- | A cursor has a direction that determines whether it moves in monotonically
72-- | increasing or decreasing order of the record keys when iterated, and if it
95-- | increasing or decreasing order of the record keys when iterated, and if it
73-- | skips duplicated values when iterating indexes.
96-- | skips duplicated values when iterating indexes.
@@ -79,6 +102,7 @@ data CursorDirection
79 | Prev
102 | Prev
80 | PrevUnique
103 | PrevUnique
81
104
105+
82-- | If the source of a cursor is an object store, the effective object store of
106-- | If the source of a cursor is an object store, the effective object store of
83-- | the cursor is that object store and the effective key of the cursor is the
107-- | the cursor is that object store and the effective key of the cursor is the
84-- | cursor’s position. If the source of a cursor is an index, the effective object
108-- | cursor’s position. If the source of a cursor is an index, the effective object
@@ -88,6 +112,7 @@ data CursorSource
88 = ObjectStore ObjectStore
112 = ObjectStore ObjectStore
89 | Index Index
113 | Index Index
90
114
115+
91-- | A key path is a list of strings that defines how to extract a key from a value.
116-- | A key path is a list of strings that defines how to extract a key from a value.
92-- | A valid key path is one of:
117-- | A valid key path is one of:
93-- |
118-- |
@@ -97,13 +122,15 @@ data CursorSource
97-- | - A non-empty list containing only strings conforming to the above requirements.
122-- | - A non-empty list containing only strings conforming to the above requirements.
98type KeyPath = Array String
123type KeyPath = Array String
99
124
125+
100-- | A transaction has a mode that determines which types of interactions can be performed
126-- | A transaction has a mode that determines which types of interactions can be performed
101-- | upon that transaction. The mode is set when the transaction is created and remains
127-- | upon that transaction. The mode is set when the transaction is created and remains
102-- | fixed for the life of the transaction.
128-- | fixed for the life of the transaction.
103data TransactionMode
129data TransactionMode
104− = ReadOnly -- ^ The transaction is only allowed to read data.
130+ = ReadOnly -- ^ The transaction is only allowed to read data.
105− | ReadWrite -- ^ The transaction is allowed to read, modify and delete data from existing object stores
131+ | ReadWrite -- ^ The transaction is allowed to read, modify and delete data from existing object stores
106− | VersionChange -- ^ The transaction is allowed to read, modify and delete data from existing object stores, and can also create and remove object stores and indexes.
132+ | VersionChange -- ^ The transaction is allowed to read, modify and delete data from existing object stores, and can also create and remove object stores and indexes.
133+
107
134
108--------------------
135--------------------
109-- Classes
136-- Classes
@@ -113,104 +140,132 @@ data TransactionMode
113-- | specific attributes (see KeyCursor or CursorWithValue).
140-- | specific attributes (see KeyCursor or CursorWithValue).
114class (IDBCursor cursor) <= IDBConcreteCursor cursor
141class (IDBCursor cursor) <= IDBConcreteCursor cursor
115
142
143+
116-- | Cursor objects implement the IDBCursor interface.
144-- | Cursor objects implement the IDBCursor interface.
117-- | There is only ever one IDBCursor instance representing a given cursor.
145-- | There is only ever one IDBCursor instance representing a given cursor.
118-- | There is no limit on how many cursors can be used at the same time.
146-- | There is no limit on how many cursors can be used at the same time.
119class IDBCursor cursor
147class IDBCursor cursor
120
148
149+
121-- | The IDBDatabase interface represents a connection to a database.
150-- | The IDBDatabase interface represents a connection to a database.
122class IDBDatabase db
151class IDBDatabase db
123
152
153+
124-- | The IDBIndex interface represents an index handle.
154-- | The IDBIndex interface represents an index handle.
125-- | Any of these methods throw an "TransactionInactiveError" DOMException
155-- | Any of these methods throw an "TransactionInactiveError" DOMException
126-- | if called when the transaction is not active.
156-- | if called when the transaction is not active.
127class IDBIndex index
157class IDBIndex index
128
158
159+
129-- | The IDBKeyRange interface represents a key range.
160-- | The IDBKeyRange interface represents a key range.
130class IDBKeyRange range
161class IDBKeyRange range
131
162
163+
132-- | The IDBtransaction interface.
164-- | The IDBtransaction interface.
133class IDBTransaction tx
165class IDBTransaction tx
134
166
167+
135-- | The IDBObjectStore interface represents an object store handle.
168-- | The IDBObjectStore interface represents an object store handle.
136class IDBObjectStore store
169class IDBObjectStore store
137
170
171+
138--------------------
172--------------------
139-- INSTANCES
173-- INSTANCES
140--
174--
141
175
142instance idbCursorKeyCursor :: IDBCursor KeyCursor
176instance idbCursorKeyCursor :: IDBCursor KeyCursor
143
177
178+
144instance idbCursorValueCursor :: IDBCursor ValueCursor
179instance idbCursorValueCursor :: IDBCursor ValueCursor
145
180
181+
146instance idbConcreteCursorKeyCursor :: IDBConcreteCursor KeyCursor
182instance idbConcreteCursorKeyCursor :: IDBConcreteCursor KeyCursor
147
183
184+
148instance idbConcreteCursorValueCursor :: IDBConcreteCursor ValueCursor
185instance idbConcreteCursorValueCursor :: IDBConcreteCursor ValueCursor
149
186
187+
150instance idbDatabaseDatabase :: IDBDatabase Database
188instance idbDatabaseDatabase :: IDBDatabase Database
151
189
190+
152instance idbIndexIndex :: IDBIndex Index
191instance idbIndexIndex :: IDBIndex Index
153
192
193+
154instance idbIndexObjectStore :: IDBIndex ObjectStore
194instance idbIndexObjectStore :: IDBIndex ObjectStore
155
195
196+
156instance idbKeyRangeKeyRange :: IDBKeyRange KeyRange
197instance idbKeyRangeKeyRange :: IDBKeyRange KeyRange
157
198
199+
158instance idbObjectStoreObjectStore :: IDBObjectStore ObjectStore
200instance idbObjectStoreObjectStore :: IDBObjectStore ObjectStore
159
201
202+
160instance idbTransactionTransaction :: IDBTransaction Transaction
203instance idbTransactionTransaction :: IDBTransaction Transaction
161
204
205+
162instance showKeyCursor :: Show KeyCursor where
206instance showKeyCursor :: Show KeyCursor where
163 show = _showCursor
207 show = _showCursor
164
208
209+
165instance showValueCursor :: Show ValueCursor where
210instance showValueCursor :: Show ValueCursor where
166 show = _showCursor
211 show = _showCursor
167
212
213+
168instance showIndex :: Show Index where
214instance showIndex :: Show Index where
169 show = _showIndex
215 show = _showIndex
170
216
217+
171instance showKeyRange :: Show KeyRange where
218instance showKeyRange :: Show KeyRange where
172 show = _showKeyRange
219 show = _showKeyRange
173
220
221+
174instance showObjectStore :: Show ObjectStore where
222instance showObjectStore :: Show ObjectStore where
175 show = _showObjectStore
223 show = _showObjectStore
176
224
225+
177instance showTransaction :: Show Transaction where
226instance showTransaction :: Show Transaction where
178 show = _showTransaction
227 show = _showTransaction
179
228
229+
180instance showDatabase :: Show Database where
230instance showDatabase :: Show Database where
181 show = _showDatabase
231 show = _showDatabase
182
232
233+
183instance showCursorDirection :: Show CursorDirection where
234instance showCursorDirection :: Show CursorDirection where
184 show x =
235 show x =
185 case x of
236 case x of
186− Next -> "next"
237+ Next -> "next"
187 NextUnique -> "nextunique"
238 NextUnique -> "nextunique"
188− Prev -> "prev"
239+ Prev -> "prev"
189 PrevUnique -> "prevunique"
240 PrevUnique -> "prevunique"
190
241
242+
191instance showTransactionMode :: Show TransactionMode where
243instance showTransactionMode :: Show TransactionMode where
192 show x =
244 show x =
193 case x of
245 case x of
194− ReadOnly -> "readonly"
246+ ReadOnly -> "readonly"
195− ReadWrite -> "readwrite"
247+ ReadWrite -> "readwrite"
196 VersionChange -> "versionchange"
248 VersionChange -> "versionchange"
197
249
250+
198instance readCursorDirection :: Read CursorDirection where
251instance readCursorDirection :: Read CursorDirection where
199 read s =
252 read s =
200 case s of
253 case s of
201− "next" -> Just Next
254+ "next" -> Just Next
202 "nextunique" -> Just NextUnique
255 "nextunique" -> Just NextUnique
203− "prev" -> Just Prev
256+ "prev" -> Just Prev
204 "prevunique" -> Just PrevUnique
257 "prevunique" -> Just PrevUnique
205− _ -> Nothing
258+ _ -> Nothing
259+
206
260
207instance readTransactionMode :: Read TransactionMode where
261instance readTransactionMode :: Read TransactionMode where
208 read s =
262 read s =
209 case s of
263 case s of
210− "readonly" -> Just ReadOnly
264+ "readonly" -> Just ReadOnly
211− "readwrite" -> Just ReadWrite
265+ "readwrite" -> Just ReadWrite
212 "versionchange" -> Just VersionChange
266 "versionchange" -> Just VersionChange
213− _ -> Nothing
267+ _ -> Nothing
268+
214
269
215--------------------
270--------------------
216-- FFI
271-- FFI
@@ -218,25 +273,30 @@ instance readTransactionMode :: Read TransactionMode where
218
273
219foreign import _showCursor
274foreign import _showCursor
220 :: forall cursor
275 :: forall cursor
221− . cursor
276+ . cursor
222 -> String
277 -> String
223
278
279+
224foreign import _showDatabase
280foreign import _showDatabase
225 :: Database
281 :: Database
226 -> String
282 -> String
227
283
284+
228foreign import _showIndex
285foreign import _showIndex
229 :: Index
286 :: Index
230 -> String
287 -> String
231
288
289+
232foreign import _showKeyRange
290foreign import _showKeyRange
233 :: KeyRange
291 :: KeyRange
234 -> String
292 -> String
235
293
294+
236foreign import _showObjectStore
295foreign import _showObjectStore
237 :: ObjectStore
296 :: ObjectStore
238 -> String
297 -> String
239
298
299+
240foreign import _showTransaction
300foreign import _showTransaction
241 :: Transaction
301 :: Transaction
242 -> String
302 -> String
src/Database/IndexedDB/IDBCursor.js+26−63
@@ -1,6 +1,6 @@
1const errorHandler = function errorHandler(cb) {
1const errorHandler = function errorHandler(cb) {
2 return function _handler(e) {
2 return function _handler(e) {
3− cb(e.target.error);
3+ cb(new Error(e.target.error.name));
4 };
4 };
5};
5};
6
6
@@ -10,135 +10,98 @@ const successHandler = function successHandler(cb) {
10 };
10 };
11};
11};
12
12
13−export function _advance(cursor, count) {
13+exports._advance = function _advance(cursor, count) {
14− return function aff(error, success) {
14+ return function aff(success, error) {
15 try {
15 try {
16 cursor.advance(count);
16 cursor.advance(count);
17 success();
17 success();
18 } catch (e) {
18 } catch (e) {
19− error(e);
19+ error(new Error(e.name));
20 }
20 }
21−
22− return function canceler(_, cancelerError) {
23− cancelerError(new Error("Can't cancel IDB Effects"));
24− };
25 };
21 };
26};
22};
27
23
28−export function _continue(cursor, key) {
24+exports._continue = function _continue(cursor, key) {
29− return function aff(error, success) {
25+ return function aff(success, error) {
30 try {
26 try {
31 cursor.continue(key || undefined);
27 cursor.continue(key || undefined);
32 success();
28 success();
33 } catch (e) {
29 } catch (e) {
34− error(e);
30+ error(new Error(e.name));
35 }
31 }
36−
37− return function canceler(_, cancelerError) {
38− cancelerError(new Error("Can't cancel IDB Effects"));
39− };
40 };
32 };
41};
33};
42
34
43−export function _continuePrimaryKey(cursor, key, primaryKey) {
35+exports._continuePrimaryKey = function _continuePrimaryKey(cursor, key, primaryKey) {
44− return function aff(error, success) {
36+ return function aff(success, error) {
45 try {
37 try {
46 cursor.continuePrimaryKey(key, primaryKey);
38 cursor.continuePrimaryKey(key, primaryKey);
47 success();
39 success();
48 } catch (e) {
40 } catch (e) {
49− error(e);
41+ error(new Error(e.name));
50 }
42 }
51−
52− return function canceler(_, cancelerError) {
53− cancelerError(new Error("Can't cancel IDB Effects"));
54− };
55 };
43 };
56};
44};
57
45
58−export function _delete(cursor) {
46+exports._delete = function _delete(cursor) {
59− return function aff(error, success) {
47+ return function aff(success, error) {
60 try {
48 try {
61 const request = cursor.delete();
49 const request = cursor.delete();
62 request.onsuccess = successHandler(success);
50 request.onsuccess = successHandler(success);
63 request.onerror = errorHandler(error);
51 request.onerror = errorHandler(error);
64 } catch (e) {
52 } catch (e) {
65− error(e);
53+ error(new Error(e.name));
66 }
54 }
67−
68− return function canceler(_, cancelerError) {
69− cancelerError(new Error("Can't cancel IDB Effects"));
70− };
71 };
55 };
72};
56};
73
57
74−export function _direction(fromString, cursor) {
58+exports._direction = function _direction(fromString, cursor) {
75 return fromString(cursor.direction);
59 return fromString(cursor.direction);
76};
60};
77
61
78−export function _key(cursor) {
62+exports._key = function _key(cursor) {
79− return function aff(error, success) {
63+ return function aff(success, error) {
80 try {
64 try {
81 success(cursor.key);
65 success(cursor.key);
82 } catch (e) {
66 } catch (e) {
83− error(e);
67+ error(new Error(e.name));
84 }
68 }
85−
86− return function canceler(_, cancelerError) {
87− cancelerError(new Error("Can't cancel IDB Effects"));
88− };
89 };
69 };
90};
70};
91
71
92−export function _primaryKey(cursor) {
72+exports._primaryKey = function _primaryKey(cursor) {
93− return function aff(error, success) {
73+ return function aff(success, error) {
94 try {
74 try {
95 success(cursor.primaryKey);
75 success(cursor.primaryKey);
96 } catch (e) {
76 } catch (e) {
97− error(e);
77+ error(new Error(e.name));
98 }
78 }
99−
100− return function canceler(_, cancelerError) {
101− cancelerError(new Error("Can't cancel IDB Effects"));
102− };
103 };
79 };
104};
80};
105
81
106−export function _source(IDBObjectStore, IDBIndex, cursor) {
82+exports._source = function _source(IDBObjectStore, IDBIndex, cursor) {
107 switch (cursor.source.constructor.name) {
83 switch (cursor.source.constructor.name) {
108 case 'IDBIndex':
84 case 'IDBIndex':
109 return IDBIndex(cursor.source);
85 return IDBIndex(cursor.source);
110 case 'IDBObjectStore':
86 case 'IDBObjectStore':
111 return IDBObjectStore(cursor.source);
87 return IDBObjectStore(cursor.source);
112 default:
88 default:
113− throw Object.create(Error.prototype, {
114− message: {
115− enumerable: true,
116− value: 'Unable to retrieve the cursor\'s source constructor.',
117− },
118− name: {
119− enumerable: true,
120− value: 'UnexpectedCursorSource',
89+ throw new Error('UnexpectedCursorSource');
121− },
122− });
123 }
90 }
124};
91};
125
92
126−export function _update(cursor, value) {
93+exports._update = function _update(cursor, value) {
127− return function aff(error, success) {
94+ return function aff(success, error) {
128 try {
95 try {
129 const request = cursor.update(value);
96 const request = cursor.update(value);
130 request.onsuccess = successHandler(success);
97 request.onsuccess = successHandler(success);
131 request.onerror = errorHandler(error);
98 request.onerror = errorHandler(error);
132 } catch (e) {
99 } catch (e) {
133− error(e);
100+ error(new Error(e.name));
134 }
101 }
135−
136− return function canceler(_, cancelerError) {
137− cancelerError(new Error("Can't cancel IDB Effects"));
138− };
139 };
102 };
140};
103};
141
104
142−export function _value(cursor) {
105+exports._value = function _value(cursor) {
143 return cursor.value;
106 return cursor.value;
144};
107};
src/Database/IndexedDB/IDBCursor.purs+86−76
@@ -16,18 +16,20 @@ module Database.IndexedDB.IDBCursor
16 , value
16 , value
17 ) where
17 ) where
18
18
19−import Database.IndexedDB.Core
19+import Prelude (Unit, ($), (>>>), map)
20+
21+import Control.Monad.Aff (Aff)
22+import Data.Foreign (Foreign, toForeign, unsafeFromForeign)
23+import Data.Function.Uncurried as Fn
24+import Data.Function.Uncurried (Fn2, Fn3)
25+import Data.Maybe (Maybe)
26+import Data.Nullable (Nullable, toNullable)
27+import Data.String.Read (read)
20
28
21−import Data.Function.Uncurried (Fn2, Fn3)
29+import Database.IndexedDB.Core
22−import Data.Function.Uncurried as Fn
23−import Data.Maybe (Maybe)
24−import Data.Nullable (Nullable, toNullable)
25−import Data.String.Read (read)
26import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key, toKey, unsafeFromKey)
30import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key, toKey, unsafeFromKey)
27−import Effect.Aff (Aff)
31+import Database.IndexedDB.IDBKey.Internal as IDBKey
28−import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
32+
29−import Foreign (Foreign, unsafeFromForeign, unsafeToForeign)
30−import Prelude (Unit, ($), (>>>), (<<<), map)
31
33
32--------------------
34--------------------
33-- INTERFACES
35-- INTERFACES
@@ -35,58 +37,56 @@ import Prelude (Unit, ($), (>>>), (<<<), map)
35
37
36-- | Advances the cursor through the next count records in range.
38-- | Advances the cursor through the next count records in range.
37advance
39advance
38− :: forall cursor
39− . (IDBCursor cursor)
40+ :: forall e cursor. (IDBCursor cursor)
40− => cursor
41+ => cursor
41− -> Int
42+ -> Int
42− -> Aff Unit
43+ -> Aff (idb :: IDB | e) Unit
43−advance c =
44+advance =
44− fromEffectFnAff <<< Fn.runFn2 _advance c
45+ Fn.runFn2 _advance
46+
45
47
46-- | Advances the cursor to the next record in range matching or after key.
48-- | Advances the cursor to the next record in range matching or after key.
47continue
49continue
48− :: forall k cursor
49− . (IDBKey k)
50− => (IDBCursor cursor)
50+ :: forall e k cursor. (IDBKey k) => (IDBCursor cursor)
51− => cursor
51+ => cursor
52− -> Maybe k
52+ -> Maybe k
53− -> Aff Unit
53+ -> Aff (idb :: IDB | e) Unit
54continue c mk =
54continue c mk =
55− fromEffectFnAff $ Fn.runFn2 _continue c (toNullable $ map (toKey >>> unsafeFromKey) mk)
55+ Fn.runFn2 _continue c (toNullable $ map (toKey >>> unsafeFromKey) mk)
56+
56
57
57-- | 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.
58-- | 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.
58continuePrimaryKey
59continuePrimaryKey
59− :: forall k cursor
60− . (IDBKey k)
61− => (IDBCursor cursor)
60+ :: forall e k cursor. (IDBKey k) => (IDBCursor cursor)
62− => cursor
61+ => cursor
63− -> k
62+ -> k
64− -> k
63+ -> k
65− -> Aff Unit
64+ -> Aff (idb :: IDB | e) Unit
66continuePrimaryKey c k1 k2 =
65continuePrimaryKey c k1 k2 =
67− fromEffectFnAff $ Fn.runFn3 _continuePrimaryKey c (unsafeFromKey $ toKey k1) (unsafeFromKey $ toKey k2)
66+ Fn.runFn3 _continuePrimaryKey c (unsafeFromKey $ toKey k1) (unsafeFromKey $ toKey k2)
67+
68
68
69-- | Delete the record pointed at by the cursor with a new value.
69-- | Delete the record pointed at by the cursor with a new value.
70delete
70delete
71− :: forall cursor
72− . (IDBCursor cursor)
71+ :: forall e cursor. (IDBCursor cursor)
73− => cursor
72+ => cursor
74− -> Aff Unit
73+ -> Aff (idb :: IDB | e) Unit
75delete =
74delete =
76− fromEffectFnAff <<< _delete
75+ _delete
76+
77
77
78-- | Update the record pointed at by the cursor with a new value.
78-- | Update the record pointed at by the cursor with a new value.
79-- |
79-- |
80-- | Throws a "DataError" DOMException if the effective object store uses
80-- | Throws a "DataError" DOMException if the effective object store uses
81-- | in-line keys and the key would have changed.
81-- | in-line keys and the key would have changed.
82update
82update
83− :: forall val cursor
83+ :: forall val e cursor. (IDBCursor cursor)
84− . (IDBCursor cursor)
85− => cursor
84+ => cursor
86− -> val
85+ -> val
87− -> Aff Key
86+ -> Aff (idb :: IDB | e) Key
88update c =
87update c =
89− map toKey <<< fromEffectFnAff <<< Fn.runFn2 _update c <<< unsafeToForeign
88+ toForeign >>> Fn.runFn2 _update c >>> map toKey
89+
90
90
91--------------------
91--------------------
92-- ATTRIBUTES
92-- ATTRIBUTES
@@ -94,93 +94,103 @@ update c =
94
94
95-- | Returns the direction (Next|NextUnique|Prev|PrevUnique) of the cursor.
95-- | Returns the direction (Next|NextUnique|Prev|PrevUnique) of the cursor.
96direction
96direction
97− :: forall cursor
98− . (IDBConcreteCursor cursor)
97+ :: forall cursor. (IDBConcreteCursor cursor)
99 => cursor
98 => cursor
100 -> CursorDirection
99 -> CursorDirection
101direction =
100direction =
102 Fn.runFn2 _direction (read >>> toNullable)
101 Fn.runFn2 _direction (read >>> toNullable)
103
102
103+
104-- | Returns the key of the cursor. Throws a "InvalidStateError" DOMException
104-- | Returns the key of the cursor. Throws a "InvalidStateError" DOMException
105-- | if the cursor is advancing or is finished.
105-- | if the cursor is advancing or is finished.
106key
106key
107− :: forall cursor
108− . (IDBConcreteCursor cursor)
107+ :: forall e cursor. (IDBConcreteCursor cursor)
109 => cursor
108 => cursor
110− -> Aff Key
109+ -> Aff (idb :: IDB | e) Key
111key =
110key =
112− map toKey <<< fromEffectFnAff <<< _key
111+ _key >>> map toKey
112+
113
113
114-- | Returns the effective key of the cursor. Throws a "InvalidStateError" DOMException
114-- | Returns the effective key of the cursor. Throws a "InvalidStateError" DOMException
115-- | if the cursor is advancing or is finished.
115-- | if the cursor is advancing or is finished.
116primaryKey
116primaryKey
117− :: forall cursor
118− . (IDBConcreteCursor cursor)
117+ :: forall e cursor. (IDBConcreteCursor cursor)
119 => cursor
118 => cursor
120− -> Aff Key
119+ -> Aff (idb :: IDB | e) Key
121primaryKey =
120primaryKey =
122− map toKey <<< fromEffectFnAff <<< _primaryKey
121+ _primaryKey >>> map toKey
122+
123
123
124-- | Returns the IDBObjectStore or IDBIndex the cursor was opened from.
124-- | Returns the IDBObjectStore or IDBIndex the cursor was opened from.
125source
125source
126− :: forall cursor
127− . (IDBConcreteCursor cursor)
126+ :: forall cursor. (IDBConcreteCursor cursor)
128 => cursor
127 => cursor
129 -> CursorSource
128 -> CursorSource
130source =
129source =
131 Fn.runFn3 _source ObjectStore Index
130 Fn.runFn3 _source ObjectStore Index
132
131
132+
133value
133value
134 :: forall val
134 :: forall val
135− . ValueCursor
135+ . ValueCursor
136 -> val
136 -> val
137value =
137value =
138 _value >>> unsafeFromForeign
138 _value >>> unsafeFromForeign
139
139
140+
140--------------------
141--------------------
141-- FFI
142-- FFI
142--
143--
143
144
144foreign import _advance
145foreign import _advance
145− :: forall cursor
146+ :: forall cursor e
146− . Fn2 cursor Int (EffectFnAff Unit)
147+ . Fn2 cursor Int (Aff (idb :: IDB | e) Unit)
148+
147
149
148foreign import _continue
150foreign import _continue
149− :: forall cursor
151+ :: forall cursor e
150− . Fn2 cursor (Nullable Foreign) (EffectFnAff Unit)
152+ . Fn2 cursor (Nullable Foreign) (Aff (idb :: IDB | e) Unit)
153+
151
154
152foreign import _continuePrimaryKey
155foreign import _continuePrimaryKey
153− :: forall cursor
156+ :: forall cursor e
154− . Fn3 cursor Foreign Foreign (EffectFnAff Unit)
157+ . Fn3 cursor Foreign Foreign (Aff (idb :: IDB | e) Unit)
158+
155
159
156foreign import _delete
160foreign import _delete
157− :: forall cursor
161+ :: forall cursor e
158− . cursor
162+ . cursor
159− -> (EffectFnAff Unit)
163+ -> (Aff (idb :: IDB | e) Unit)
164+
160
165
161foreign import _direction
166foreign import _direction
162 :: forall cursor
167 :: forall cursor
163− . Fn2 (String -> Nullable CursorDirection) cursor CursorDirection
168+ . Fn2 (String -> Nullable CursorDirection) cursor CursorDirection
169+
164
170
165foreign import _key
171foreign import _key
166− :: forall cursor
172+ :: forall cursor e
167− . cursor
173+ . cursor
168− -> EffectFnAff Key
174+ -> Aff (idb :: IDB | e) Key
175+
169
176
170foreign import _primaryKey
177foreign import _primaryKey
171− :: forall cursor
178+ :: forall cursor e
172− . cursor
179+ . cursor
173− -> EffectFnAff Key
180+ -> Aff (idb :: IDB | e) Key
181+
174
182
175foreign import _source
183foreign import _source
176 :: forall cursor
184 :: forall cursor
177− . Fn3 (ObjectStore -> CursorSource) (Index -> CursorSource) cursor CursorSource
185+ . Fn3 (ObjectStore -> CursorSource) (Index -> CursorSource) cursor CursorSource
186+
178
187
179foreign import _update
188foreign import _update
180− :: forall cursor
189+ :: forall cursor e
181− . Fn2 cursor Foreign (EffectFnAff Foreign)
190+ . Fn2 cursor Foreign (Aff (idb :: IDB | e) Foreign)
191+
182
192
183foreign import _value
193foreign import _value
184 :: forall cursor val
194 :: forall cursor val
185− . cursor
195+ . cursor
186 -> val
196 -> val
src/Database/IndexedDB/IDBDatabase.js+33−59
@@ -3,23 +3,27 @@ const toArray = function toArray(xs) {
3};
3};
4
4
5
5
6+exports._showDatabase = function _showDatabase(db) {
7+ return '(IDBDatabase ' +
8+ '{ name: ' + db.name +
9+ ', objectStoreNames: [' + toArray(db.objectStoreNames).join(', ') + ']' +
10+ ', version: ' + db.version +
11+ ' })';
12+};
13+
6−export function _close(db) {
14+exports._close = function _close(db) {
7− return function aff(error, success) {
15+ return function aff(success, error) {
8 try {
16 try {
9 db.close();
17 db.close();
10 success();
18 success();
11 } catch (e) {
19 } catch (e) {
12− error(e);
20+ error(new Error(e.name));
13 }
21 }
14−
15− return function canceler(_, cancelerError) {
16− cancelerError(new Error("Can't cancel IDB Effects"));
17− };
18 };
22 };
19};
23};
20
24
21−export function _createObjectStore(db, name, opts) {
25+exports._createObjectStore = function _createObjectStore(db, name, opts) {
22− return function aff(error, success) {
26+ return function aff(success, error) {
23 var keyPath;
27 var keyPath;
24
28
25 try {
29 try {
@@ -43,107 +47,77 @@ export function _createObjectStore(db, name, opts) {
43 });
47 });
44 success(store);
48 success(store);
45 } catch (e) {
49 } catch (e) {
46− error(e);
50+ error(new Error(e.name));
47 }
51 }
48−
49− return function canceler(_, cancelerError) {
50− cancelerError(new Error("Can't cancel IDB Effects"));
51− };
52 };
52 };
53};
53};
54
54
55−export function _deleteObjectStore(db, name) {
55+exports._deleteObjectStore = function _deleteObjectStore(db, name) {
56− return function aff(error, success) {
56+ return function aff(success, error) {
57 try {
57 try {
58 db.deleteObjectStore(name);
58 db.deleteObjectStore(name);
59 success();
59 success();
60 } catch (e) {
60 } catch (e) {
61− error(e);
61+ error(new Error(e.name));
62 }
62 }
63−
64− return function canceler(_, cancelerError) {
65− cancelerError(new Error("Can't cancel IDB Effects"));
66− };
67 };
63 };
68};
64};
69
65
70−export function _name(db) {
66+exports._name = function _name(db) {
71 return db.name;
67 return db.name;
72};
68};
73
69
74−export function _objectStoreNames(db) {
70+exports._objectStoreNames = function _objectStoreNames(db) {
75 return toArray(db.objectStoreNames);
71 return toArray(db.objectStoreNames);
76};
72};
77
73
78−export function _onAbort(db, f) {
74+exports._onAbort = function _onAbort(db, f) {
79− return function aff(error, success) {
75+ return function aff(success) {
80 db.onabort = function onabort() {
76 db.onabort = function onabort() {
81 f();
77 f();
82 };
78 };
83 success();
79 success();
84−
85− return function canceler(_, cancelerError) {
86− cancelerError(new Error("Can't cancel IDB Effects"));
87− };
88 };
80 };
89};
81};
90
82
91−export function _onClose(db, f) {
83+exports._onClose = function _onClose(db, f) {
92− return function aff(error, success) {
84+ return function aff(success) {
93 db.onclose = function onclose() {
85 db.onclose = function onclose() {
94 f();
86 f();
95 };
87 };
96 success();
88 success();
97−
98− return function canceler(_, cancelerError) {
99− cancelerError(new Error("Can't cancel IDB Effects"));
100− };
101 };
89 };
102};
90};
103
91
104−export function _onError(db, f) {
92+exports._onError = function _onError(db, f) {
105− return function aff(error, success) {
93+ return function aff(success) {
106 db.onerror = function onerror(e) {
94 db.onerror = function onerror(e) {
107− f(e.target.error)();
95+ f(new Error(e.target.error.name))();
108 };
96 };
109 success();
97 success();
110−
111− return function canceler(_, cancelerError) {
112− cancelerError(new Error("Can't cancel IDB Effects"));
113− };
114 };
98 };
115};
99};
116
100
117−export function _onVersionChange(db, f) {
101+exports._onVersionChange = function _onVersionChange(db, f) {
118− return function aff(error, success) {
102+ return function aff(success) {
119 db.onversionchange = function onversionchange(e) {
103 db.onversionchange = function onversionchange(e) {
120 f({ oldVersion: e.oldVersion, newVersion: e.newVersion })();
104 f({ oldVersion: e.oldVersion, newVersion: e.newVersion })();
121 };
105 };
122 success();
106 success();
123−
124− return function canceler(_, cancelerError) {
125− cancelerError(new Error("Can't cancel IDB Effects"));
126− };
127 };
107 };
128};
108};
129
109
130−export function _transaction(db, stores, mode) {
110+exports._transaction = function _transaction(db, stores, mode) {
131− return function aff(error, success) {
111+ return function aff(success, error) {
132− var transaction;
133 try {
112 try {
134− transaction = db.transaction(stores, mode);
113+ const transaction = db.transaction(stores, mode);
135 success(transaction);
114 success(transaction);
136 } catch (e) {
115 } catch (e) {
137− error(e);
116+ error(new Error(e.name));
138 }
117 }
139−
140− return function canceler(_, cancelerError, cancelerSuccess) {
141− transaction.abort();
142− cancelerSuccess();
143− };
144 };
118 };
145};
119};
146
120
147−export function _version(db) {
121+exports._version = function _version(db) {
148 return db.version;
122 return db.version;
149};
123};
src/Database/IndexedDB/IDBDatabase.purs+97−73
@@ -24,15 +24,16 @@ module Database.IndexedDB.IDBDatabase
24 , onVersionChange
24 , onVersionChange
25 ) where
25 ) where
26
26
27+import Prelude (Unit, show)
28+
29+import Control.Monad.Aff (Aff)
30+import Control.Monad.Eff (Eff)
31+import Control.Monad.Eff.Exception (Error)
32+import Data.Function.Uncurried as Fn
33+import Data.Function.Uncurried (Fn2, Fn3)
34+
27import Database.IndexedDB.Core
35import Database.IndexedDB.Core
28
36
29−import Data.Function.Uncurried (Fn2, Fn3)
30−import Data.Function.Uncurried as Fn
31−import Effect (Effect)
32−import Effect.Aff (Aff)
33−import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
34−import Effect.Exception (Error)
35−import Prelude (Unit, show, (<<<), ($))
36
37
37--------------------
38--------------------
38-- TYPES
39-- TYPES
@@ -41,67 +42,70 @@ import Prelude (Unit, show, (<<<), ($))
41-- | Type alias for StoreName
42-- | Type alias for StoreName
42type StoreName = String
43type StoreName = String
43
44
45+
44-- | Options provided when creating an object store.
46-- | Options provided when creating an object store.
45type ObjectStoreParameters =
47type ObjectStoreParameters =
46− { keyPath :: KeyPath
48+ { keyPath :: KeyPath
47 , autoIncrement :: Boolean
49 , autoIncrement :: Boolean
48 }
50 }
49
51
52+
50defaultParameters :: ObjectStoreParameters
53defaultParameters :: ObjectStoreParameters
51defaultParameters =
54defaultParameters =
52− { keyPath: []
55+ { keyPath : []
53− , autoIncrement: false
56+ , autoIncrement : false
54 }
57 }
55
58
59+
56--------------------
60--------------------
57-- INTERFACE
61-- INTERFACE
58--
62--
59
63
60-- | Closes the connection once all running transactions have finished.
64-- | Closes the connection once all running transactions have finished.
61close
65close
62− :: forall db
63− . (IDBDatabase db)
66+ :: forall e db. (IDBDatabase db)
64 => db
67 => db
65− -> Aff Unit
68+ -> Aff (idb :: IDB | e) Unit
66close =
69close =
67− fromEffectFnAff <<< _close
70+ _close
71+
68
72
69-- | Creates a new object store with the given name and options and returns a new IDBObjectStore.
73-- | Creates a new object store with the given name and options and returns a new IDBObjectStore.
70-- |
74-- |
71-- | Throws a "InvalidStateError" DOMException if not called within an upgrade transaction
75-- | Throws a "InvalidStateError" DOMException if not called within an upgrade transaction
72createObjectStore
76createObjectStore
73− :: forall db
74− . (IDBDatabase db)
77+ :: forall e db. (IDBDatabase db)
75 => db
78 => db
76 -> StoreName
79 -> StoreName
77 -> ObjectStoreParameters
80 -> ObjectStoreParameters
78− -> Aff ObjectStore
81+ -> Aff (idb :: IDB | e) ObjectStore
79createObjectStore db name' opts =
82createObjectStore db name' opts =
80− fromEffectFnAff $ Fn.runFn3 _createObjectStore db name' opts
83+ Fn.runFn3 _createObjectStore db name' opts
84+
81
85
82-- | Deletes the object store with the given name.
86-- | Deletes the object store with the given name.
83-- |
87-- |
84-- | Throws a "InvalidStateError" DOMException if not called within an upgrade transaction.
88-- | Throws a "InvalidStateError" DOMException if not called within an upgrade transaction.
85deleteObjectStore
89deleteObjectStore
86− :: forall db
87− . (IDBDatabase db)
90+ :: forall e db. (IDBDatabase db)
88 => db
91 => db
89 -> StoreName
92 -> StoreName
90− -> Aff ObjectStore
93+ -> Aff (idb :: IDB | e) ObjectStore
91deleteObjectStore db name' =
94deleteObjectStore db name' =
92− fromEffectFnAff $ Fn.runFn2 _deleteObjectStore db name'
95+ Fn.runFn2 _deleteObjectStore db name'
96+
93
97
94-- | Returns a new transaction with the given mode (ReadOnly|ReadWrite)
98-- | Returns a new transaction with the given mode (ReadOnly|ReadWrite)
95-- | and scope which in the form of an array of object store names.
99-- | and scope which in the form of an array of object store names.
96transaction
100transaction
97− :: forall db
98− . (IDBDatabase db)
101+ :: forall e db. (IDBDatabase db)
99 => db
102 => db
100 -> Array StoreName
103 -> Array StoreName
101 -> TransactionMode
104 -> TransactionMode
102− -> Aff Transaction
105+ -> Aff (idb :: IDB | e) Transaction
103transaction db stores mode' =
106transaction db stores mode' =
104− fromEffectFnAff $ Fn.runFn3 _transaction db stores (show mode')
107+ Fn.runFn3 _transaction db stores (show mode')
108+
105
109
106--------------------
110--------------------
107-- ATTRIBUTES
111-- ATTRIBUTES
@@ -109,107 +113,127 @@ transaction db stores mode' =
109
113
110-- | Returns the name of the database.
114-- | Returns the name of the database.
111name
115name
112− :: Database
116+ :: Database
113− -> String
117+ -> String
114name =
118name =
115 _name
119 _name
116
120
121+
117-- | Returns a list of the names of object stores in the database.
122-- | Returns a list of the names of object stores in the database.
118objectStoreNames
123objectStoreNames
119− :: Database
124+ :: Database
120− -> Array String
125+ -> Array String
121objectStoreNames =
126objectStoreNames =
122 _objectStoreNames
127 _objectStoreNames
123
128
129+
124-- | Returns the version of the database.
130-- | Returns the version of the database.
125version
131version
126− :: Database
132+ :: Database
127− -> Int
133+ -> Int
128version =
134version =
129 _version
135 _version
130
136
137+
131--------------------
138--------------------
132-- EVENT HANDLERS
139-- EVENT HANDLERS
133--
140--
134-- | Event handler for the `abort` event.
141-- | Event handler for the `abort` event.
135onAbort
142onAbort
143+ :: forall e e'
136− :: Database
144+ . Database
137− -> Effect Unit
145+ -> Eff ( | e') Unit
138− -> Aff Unit
146+ -> Aff (idb :: IDB | e) Unit
139onAbort db f =
147onAbort db f =
140− fromEffectFnAff $ Fn.runFn2 _onAbort db f
148+ Fn.runFn2 _onAbort db f
149+
141
150
142-- | Event handler for the `close` event.
151-- | Event handler for the `close` event.
143onClose
152onClose
153+ :: forall e e'
144− :: Database
154+ . Database
145− -> Effect Unit
155+ -> Eff ( | e') Unit
146− -> Aff Unit
156+ -> Aff (idb :: IDB | e) Unit
147onClose db f =
157onClose db f =
148− fromEffectFnAff $ Fn.runFn2 _onClose db f
158+ Fn.runFn2 _onClose db f
159+
149
160
150-- | Event handler for the `error` event.
161-- | Event handler for the `error` event.
151onError
162onError
163+ :: forall e e'
152− :: Database
164+ . Database
153− -> (Error -> Effect Unit)
165+ -> (Error -> Eff ( | e') Unit)
154− -> Aff Unit
166+ -> Aff (idb :: IDB | e) Unit
155onError db f =
167onError db f =
156− fromEffectFnAff $ Fn.runFn2 _onError db f
168+ Fn.runFn2 _onError db f
169+
157
170
158-- | Event handler for the `versionchange` event.
171-- | Event handler for the `versionchange` event.
159onVersionChange
172onVersionChange
173+ :: forall e e'
160− :: Database
174+ . Database
161− -> ( { oldVersion :: Int, newVersion :: Int }
175+ -> ({ oldVersion :: Int, newVersion :: Int }
162− -> Effect Unit
176+ -> Eff ( | e') Unit)
163− )
164− -> Aff Unit
177+ -> Aff (idb :: IDB | e) Unit
165onVersionChange db f =
178onVersionChange db f =
166− fromEffectFnAff $ Fn.runFn2 _onVersionChange db f
179+ Fn.runFn2 _onVersionChange db f
180+
167
181
168--------------------
182--------------------
169-- FFI
183-- FFI
170--
184--
171
185
172foreign import _close
186foreign import _close
173− :: forall db
187+ :: forall db e
174− . db
188+ . db
175− -> EffectFnAff Unit
189+ -> Aff (idb :: IDB | e) Unit
190+
176
191
177foreign import _createObjectStore
192foreign import _createObjectStore
178− :: forall db
193+ :: forall db e
179− . Fn3 db String { keyPath :: Array String, autoIncrement :: Boolean } (EffectFnAff ObjectStore)
194+ . Fn3 db String { keyPath :: Array String, autoIncrement :: Boolean } (Aff (idb :: IDB | e) ObjectStore)
195+
180
196
181foreign import _deleteObjectStore
197foreign import _deleteObjectStore
182− :: forall db
198+ :: forall db e
183− . Fn2 db String (EffectFnAff ObjectStore)
199+ . Fn2 db String (Aff (idb :: IDB | e) ObjectStore)
200+
184
201
185foreign import _name
202foreign import _name
186− :: Database
203+ :: Database
187− -> String
204+ -> String
205+
188
206
189foreign import _objectStoreNames
207foreign import _objectStoreNames
190− :: Database
208+ :: Database
191− -> Array String
209+ -> Array String
210+
192
211
193foreign import _onAbort
212foreign import _onAbort
194− :: forall db
213+ :: forall db e e'
195− . Fn2 db (Effect Unit) (EffectFnAff Unit)
214+ . Fn2 db (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
215+
196
216
197foreign import _onClose
217foreign import _onClose
198− :: forall db
218+ :: forall db e e'
199− . Fn2 db (Effect Unit) (EffectFnAff Unit)
219+ . Fn2 db (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
220+
200
221
201foreign import _onError
222foreign import _onError
202− :: forall db
223+ :: forall db e e'
203− . Fn2 db (Error -> Effect Unit) (EffectFnAff Unit)
224+ . Fn2 db (Error -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
225+
204
226
205foreign import _onVersionChange
227foreign import _onVersionChange
206− :: forall db
228+ :: forall db e e'
207− . Fn2 db ({ oldVersion :: Int, newVersion :: Int } -> Effect Unit) (EffectFnAff Unit)
229+ . Fn2 db ({ oldVersion :: Int, newVersion :: Int } -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
230+
208
231
209foreign import _transaction
232foreign import _transaction
210− :: forall db
233+ :: forall db e
211− . Fn3 db (Array String) String (EffectFnAff Transaction)
234+ . Fn3 db (Array String) String (Aff (idb :: IDB | e) Transaction)
235+
212
236
213foreign import _version
237foreign import _version
214− :: Database
238+ :: Database
215− -> Int
239+ -> Int
src/Database/IndexedDB/IDBFactory.js+8−21
@@ -1,6 +1,6 @@
1const errorHandler = function errorHandler(cb) {
1const errorHandler = function errorHandler(cb) {
2 return function _handler(e) {
2 return function _handler(e) {
3− cb(e.target.error);
3+ cb(new Error(e.target.error.name));
4 };
4 };
5};
5};
6
6
@@ -14,12 +14,9 @@ const noOp2 = function noOp2() {
14 return noOp;
14 return noOp;
15};
15};
16
16
17−const noOp3 = function noOp3() {
18− return noOp2;
19−};
20
17
21−export function _deleteDatabase(name) {
18+exports._deleteDatabase = function _deleteDatabase(name) {
22− return function aff(error, success) {
19+ return function aff(success, error) {
23 try {
20 try {
24 const request = indexedDB.deleteDatabase(name);
21 const request = indexedDB.deleteDatabase(name);
25
22
@@ -29,19 +26,15 @@ export function _deleteDatabase(name) {
29
26
30 request.onerror = errorHandler(error);
27 request.onerror = errorHandler(error);
31 } catch (e) {
28 } catch (e) {
32− error(e);
29+ error(new Error(e.name));
33 }
30 }
34−
35− return function canceler(_, cancelerError) {
36− cancelerError(new Error("Can't cancel IDB Effects"));
37− };
38 };
31 };
39};
32};
40
33
41−export function _open(fromMaybe, name, mver, req) {
34+exports._open = function _open(fromMaybe, name, mver, req) {
42 const ver = fromMaybe(undefined)(mver);
35 const ver = fromMaybe(undefined)(mver);
43
36
44− return function aff(error, success) {
37+ return function aff(success, error) {
45 try {
38 try {
46 const request = indexedDB.open(name, ver);
39 const request = indexedDB.open(name, ver);
47 request.onsuccess = function onSuccess(e) {
40 request.onsuccess = function onSuccess(e) {
@@ -53,18 +46,12 @@ export function _open(fromMaybe, name, mver, req) {
53 };
46 };
54
47
55 request.onupgradeneeded = function onUpgradeNeeded(e) {
48 request.onupgradeneeded = function onUpgradeNeeded(e) {
56− const meta = { oldVersion: e.oldVersion };
57− // eslint-disable-next-line max-len
58− fromMaybe(noOp3)(req.onUpgradeNeeded)(e.target.result)(e.target.transaction)(meta)();
49+ fromMaybe(noOp2)(req.onUpgradeNeeded)(e.target.result)(e.target.transaction)();
59 };
50 };
60
51
61 request.onerror = errorHandler(error);
52 request.onerror = errorHandler(error);
62 } catch (e) {
53 } catch (e) {
63− error(e);
54+ error(new Error(e.name));
64 }
55 }
65−
66− return function canceler(_, cancelerError) {
67− cancelerError(new Error("Can't cancel IDB Effects"));
68− };
69 };
56 };
70};
57};
src/Database/IndexedDB/IDBFactory.purs+32−22
@@ -12,32 +12,36 @@ module Database.IndexedDB.IDBFactory
12 , open
12 , open
13 ) where
13 ) where
14
14
15−import Database.IndexedDB.Core
15+import Prelude (Unit)
16
16
17+import Control.Monad.Aff (Aff)
18+import Control.Monad.Eff (Eff)
19+import Data.Function.Uncurried as Fn
17import Data.Function.Uncurried (Fn4)
20import Data.Function.Uncurried (Fn4)
18−import Data.Function.Uncurried as Fn
19−import Data.Maybe (Maybe, fromMaybe)
21+import Data.Maybe (Maybe, fromMaybe)
20−import Effect (Effect)
22+
21−import Effect.Aff (Aff)
23+import Database.IndexedDB.Core
22−import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
24+
23−import Prelude (Unit, ($), (<<<))
24
25
25--------------------
26--------------------
26-- TYPES
27-- TYPES
27--
28--
28
29
29-- Type alias for binding listeners to an initial open action.
30-- Type alias for binding listeners to an initial open action.
30−type Callbacks =
31+type Callbacks e =
31− { onBlocked :: Maybe (Effect Unit)
32+ { onBlocked :: Maybe (Eff (| e) Unit)
32− , onUpgradeNeeded :: Maybe (Database -> Transaction -> { oldVersion :: Int } -> Effect Unit)
33+ , onUpgradeNeeded :: Maybe (Database -> Transaction -> Eff (| e) Unit)
33 }
34 }
34
35
36+
35-- | Type alias for DatabaseName.
37-- | Type alias for DatabaseName.
36type DatabaseName = String
38type DatabaseName = String
37
39
40+
38-- | Type alias for Version.
41-- | Type alias for Version.
39type Version = Int
42type Version = Int
40
43
44+
41--------------------
45--------------------
42-- INTERFACE
46-- INTERFACE
43--
47--
@@ -46,10 +50,12 @@ type Version = Int
46-- | and there are open connections that don’t close in response to a
50-- | and there are open connections that don’t close in response to a
47-- | `versionchange` event, the request will be blocked until all they close.
51-- | `versionchange` event, the request will be blocked until all they close.
48deleteDatabase
52deleteDatabase
53+ :: forall e
49− :: DatabaseName
54+ . DatabaseName
50− -> Aff Int
55+ -> Aff (idb :: IDB | e) Int
51deleteDatabase =
56deleteDatabase =
52− fromEffectFnAff <<< _deleteDatabase
57+ _deleteDatabase
58+
53
59
54-- | Attempts to open a connection to the named database with the specified version.
60-- | Attempts to open a connection to the named database with the specified version.
55-- | If the database already exists with a lower version and there are open connections
61-- | If the database already exists with a lower version and there are open connections
@@ -60,20 +66,24 @@ deleteDatabase =
60-- | When the version isn't provided (`Nothing`), attempts to open a connection to the
66-- | When the version isn't provided (`Nothing`), attempts to open a connection to the
61-- | named database with the current version, or 1 if it does not already exist.
67-- | named database with the current version, or 1 if it does not already exist.
62open
68open
69+ :: forall e e'
63− :: DatabaseName
70+ . DatabaseName
64− -> Maybe Version
71+ -> Maybe Version
65− -> Callbacks
72+ -> Callbacks e'
66− -> Aff Database
73+ -> Aff (idb :: IDB | e) Database
67open name mver req =
74open name mver req =
68− fromEffectFnAff $ Fn.runFn4 _open fromMaybe name mver req
75+ Fn.runFn4 _open fromMaybe name mver req
76+
69
77
70--------------------
78--------------------
71-- FFI
79-- FFI
72--
80--
73foreign import _deleteDatabase
81foreign import _deleteDatabase
82+ :: forall e
74− :: String
83+ . String
75− -> EffectFnAff Int
84+ -> Aff (idb :: IDB | e) Int
85+
76
86
77foreign import _open
87foreign import _open
78− :: forall a
88+ :: forall a e e'
79− . Fn4 (a -> Maybe a -> a) String (Maybe Int) (Callbacks) (EffectFnAff Database)
89+ . Fn4 (a -> Maybe a -> a) String (Maybe Int) (Callbacks e') (Aff (idb :: IDB | e) Database)
src/Database/IndexedDB/IDBIndex.js+28−52
@@ -1,6 +1,6 @@
1const errorHandler = function errorHandler(cb) {
1const errorHandler = function errorHandler(cb) {
2 return function _handler(e) {
2 return function _handler(e) {
3− cb(e.target.error);
3+ cb(new Error(e.target.error.name));
4 };
4 };
5};
5};
6
6
@@ -11,7 +11,7 @@ const successHandler = function successHandler(cb) {
11};
11};
12
12
13
13
14−export function _keyPath(index) {
14+exports._keyPath = function _keyPath(index) {
15 const path = index.keyPath;
15 const path = index.keyPath;
16
16
17 if (Array.isArray(path)) {
17 if (Array.isArray(path)) {
@@ -25,51 +25,43 @@ export function _keyPath(index) {
25 return [];
25 return [];
26};
26};
27
27
28−export function _multiEntry(index) {
28+exports._multiEntry = function _multiEntry(index) {
29 return index.multiEntry;
29 return index.multiEntry;
30};
30};
31
31
32−export function _name(index) {
32+exports._name = function _name(index) {
33 return index.name;
33 return index.name;
34};
34};
35
35
36−export function _objectStore(index) {
36+exports._objectStore = function _objectStore(index) {
37 return index.obectStore;
37 return index.obectStore;
38};
38};
39
39
40−export function _unique(index) {
40+exports._unique = function _unique(index) {
41 return index.unique;
41 return index.unique;
42};
42};
43
43
44−export function _count(index, query) {
44+exports._count = function _count(index, query) {
45− return function aff(error, success) {
45+ return function aff(success, error) {
46 try {
46 try {
47 const request = index.count(query);
47 const request = index.count(query);
48 request.onsuccess = successHandler(success);
48 request.onsuccess = successHandler(success);
49 request.onerror = errorHandler(error);
49 request.onerror = errorHandler(error);
50 } catch (e) {
50 } catch (e) {
51− error(e);
51+ error(new Error(e.name));
52 }
52 }
53−
54− return function canceler(_, cancelerError) {
55− cancelerError(new Error("Can't cancel IDB Effects"));
56− };
57 };
53 };
58};
54};
59
55
60−export function _get(index, range) {
56+exports._get = function _get(index, range) {
61− return function aff(error, success) {
57+ return function aff(success, error) {
62 try {
58 try {
63 const request = index.get(range);
59 const request = index.get(range);
64 request.onsuccess = successHandler(success);
60 request.onsuccess = successHandler(success);
65 request.onerror = errorHandler(error);
61 request.onerror = errorHandler(error);
66 } catch (e) {
62 } catch (e) {
67− error(e);
63+ error(new Error(e.name));
68 }
64 }
69−
70− return function canceler(_, cancelerError) {
71− cancelerError(new Error("Can't cancel IDB Effects"));
72− };
73 };
65 };
74};
66};
75
67
@@ -79,8 +71,8 @@ export function _get(index, range) {
79 *
71 *
80 * However, it may be doable to convert the result to some key / value structure with values of
72 * However, it may be doable to convert the result to some key / value structure with values of
81 * different types.
73 * different types.
82−export function _getAll(index, query, count) {
74+exports._getAll = function _getAll(index, query, count) {
83− return function aff(error, success) {
75+ return function aff(success, error) {
84 const request = index.getAll(query, count);
76 const request = index.getAll(query, count);
85 request.onsuccess = successHandler(success);
77 request.onsuccess = successHandler(success);
86 request.onerror = errorHandler(error);
78 request.onerror = errorHandler(error);
@@ -88,40 +80,32 @@ export function _getAll(index, query, count) {
88};
80};
89*/
81*/
90
82
91−export function _getAllKeys(index, range, count) {
83+exports._getAllKeys = function _getAllKeys(index, range, count) {
92− return function aff(error, success) {
84+ return function aff(success, error) {
93 try {
85 try {
94 const request = index.getAllKeys(range, count || undefined);
86 const request = index.getAllKeys(range, count || undefined);
95 request.onsuccess = successHandler(success);
87 request.onsuccess = successHandler(success);
96 request.onerror = errorHandler(error);
88 request.onerror = errorHandler(error);
97 } catch (e) {
89 } catch (e) {
98− error(e);
90+ error(new Error(e.name));
99 }
91 }
100−
101− return function canceler(_, cancelerError) {
102− cancelerError(new Error("Can't cancel IDB Effects"));
103− };
104 };
92 };
105};
93};
106
94
107−export function _getKey(index, range) {
95+exports._getKey = function _getKey(index, range) {
108− return function aff(error, success) {
96+ return function aff(success, error) {
109 try {
97 try {
110 const request = index.getKey(range);
98 const request = index.getKey(range);
111 request.onsuccess = successHandler(success);
99 request.onsuccess = successHandler(success);
112 request.onerror = errorHandler(error);
100 request.onerror = errorHandler(error);
113 } catch (e) {
101 } catch (e) {
114− error(e);
102+ error(new Error(e.name));
115 }
103 }
116−
117− return function canceler(_, cancelerError) {
118− cancelerError(new Error("Can't cancel IDB Effects"));
119− };
120 };
104 };
121};
105};
122
106
123−export function _openCursor(index, query, dir, cb) {
107+exports._openCursor = function _openCursor(index, query, dir, cb) {
124− return function aff(error, success) {
108+ return function aff(success, error) {
125 try {
109 try {
126 const request = index.openCursor(query, dir);
110 const request = index.openCursor(query, dir);
127 request.onsuccess = function onSuccess(e) {
111 request.onsuccess = function onSuccess(e) {
@@ -132,21 +116,17 @@ export function _openCursor(index, query, dir, cb) {
132 }
116 }
133 };
117 };
134 request.onerror = function onError(e) {
118 request.onerror = function onError(e) {
135− cb.onError(e.target.error);
119+ cb.onError(new Error(e.target.error.name));
136 };
120 };
137 success();
121 success();
138 } catch (e) {
122 } catch (e) {
139− error(e);
123+ error(new Error(e.name));
140 }
124 }
141−
142− return function canceler(_, cancelerError) {
143− cancelerError(new Error("Can't cancel IDB Effects"));
144− };
145 };
125 };
146};
126};
147
127
148−export function _openKeyCursor(index, query, dir, cb) {
128+exports._openKeyCursor = function _openKeyCursor(index, query, dir, cb) {
149− return function aff(error, success) {
129+ return function aff(success, error) {
150 try {
130 try {
151 const request = index.openKeyCursor(query, dir);
131 const request = index.openKeyCursor(query, dir);
152 request.onsuccess = function onSuccess(e) {
132 request.onsuccess = function onSuccess(e) {
@@ -157,15 +137,11 @@ export function _openKeyCursor(index, query, dir, cb) {
157 }
137 }
158 };
138 };
159 request.onerror = function onError(e) {
139 request.onerror = function onError(e) {
160− cb.onError(e.target.error);
140+ cb.onError(new Error(e.target.error.name));
161 };
141 };
162 success();
142 success();
163 } catch (e) {
143 } catch (e) {
164− error(e);
144+ error(new Error(e.name));
165 }
145 }
166−
167− return function canceler(_, cancelerError) {
168− cancelerError(new Error("Can't cancel IDB Effects"));
169− };
170 };
146 };
171};
147};
src/Database/IndexedDB/IDBIndex.purs+95−78
@@ -20,187 +20,204 @@ module Database.IndexedDB.IDBIndex
20 , unique
20 , unique
21 ) where
21 ) where
22
22
23−import Database.IndexedDB.Core
23+import Prelude (Unit, map, show, (<$>), (>>>))
24+
25+import Control.Monad.Aff (Aff)
26+import Control.Monad.Eff (Eff)
27+import Control.Monad.Eff.Exception (Error)
28+import Data.Foreign (Foreign, unsafeFromForeign)
29+import Data.Function.Uncurried as Fn
30+import Data.Function.Uncurried (Fn2, Fn3, Fn4)
31+import Data.Maybe (Maybe)
32+import Data.Nullable (Nullable, toMaybe, toNullable)
24
33
25−import Data.Function.Uncurried (Fn2, Fn3, Fn4)
34+import Database.IndexedDB.Core
26−import Data.Function.Uncurried as Fn
27−import Data.Maybe (Maybe)
28−import Data.Nullable (Nullable, toMaybe, toNullable)
29import Database.IndexedDB.IDBKey.Internal (Key, toKey)
35import Database.IndexedDB.IDBKey.Internal (Key, toKey)
30−import Effect (Effect)
36+
31−import Effect.Aff (Aff)
32−import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
33−import Effect.Exception (Error)
34−import Foreign (Foreign, unsafeFromForeign)
35−import Prelude (Unit, map, show, ($), (>>>))
36
37
37--------------------
38--------------------
38-- TYPES
39-- TYPES
39--
40--
40
41
41-- | Callbacks to manipulate a cursor from an Open*Cursor call
42-- | Callbacks to manipulate a cursor from an Open*Cursor call
42−type Callbacks cursor =
43+type Callbacks cursor e =
43− { onSuccess :: cursor -> Effect Unit
44+ { onSuccess :: cursor -> Eff ( | e) Unit
44− , onError :: Error -> Effect Unit
45+ , onError :: Error -> Eff ( | e) Unit
45− , onComplete :: Effect Unit
46+ , onComplete :: Eff ( | e) Unit
46 }
47 }
47
48
49+
48--------------------
50--------------------
49-- INTERFACES
51-- INTERFACES
50--
52--
51
53
52-- | Retrieves the number of records matching the key range in query.
54-- | Retrieves the number of records matching the key range in query.
53count
55count
54− :: forall index
55− . (IDBIndex index)
56+ :: forall e index. (IDBIndex index)
56− => index
57+ => index
57 -> Maybe KeyRange
58 -> Maybe KeyRange
58− -> Aff Int
59+ -> Aff (idb :: IDB | e) Int
59count index range =
60count index range =
60− fromEffectFnAff $ Fn.runFn2 _count index (toNullable range)
61+ Fn.runFn2 _count index (toNullable range)
62+
61
63
62-- | Retrieves the value of the first record matching the given key range in query.
64-- | Retrieves the value of the first record matching the given key range in query.
63-- |
65-- |
64-- | NOTE
66-- | NOTE
65-- | The coercion from `a` to any type is unsafe and might throw a runtime error if incorrect.
67-- | The coercion from `a` to any type is unsafe and might throw a runtime error if incorrect.
66get
68get
67− :: forall a index
68− . (IDBIndex index)
69+ :: forall a e index. (IDBIndex index)
69 => index
70 => index
70 -> KeyRange
71 -> KeyRange
71− -> Aff (Maybe a)
72+ -> Aff (idb :: IDB | e) (Maybe a)
72get index range =
73get index range =
73− map (toMaybe >>> map unsafeFromForeign) $ fromEffectFnAff $ Fn.runFn2 _get index range
74+ (toMaybe >>> map unsafeFromForeign) <$> Fn.runFn2 _get index range
75+
74
76
75-- | Retrieves the keys of records matching the given key range in query
77-- | Retrieves the keys of records matching the given key range in query
76-- | (up to the number given if given).
78-- | (up to the number given if given).
77getAllKeys
79getAllKeys
78− :: forall index
79− . (IDBIndex index)
80+ :: forall e index. (IDBIndex index)
80 => index
81 => index
81 -> Maybe KeyRange
82 -> Maybe KeyRange
82 -> Maybe Int
83 -> Maybe Int
83− -> Aff (Array Key)
84+ -> Aff (idb :: IDB | e) (Array Key)
84getAllKeys index range n =
85getAllKeys index range n =
85− map (map toKey) $ fromEffectFnAff $ Fn.runFn3 _getAllKeys index (toNullable range) (toNullable n)
86+ map toKey <$> Fn.runFn3 _getAllKeys index (toNullable range) (toNullable n)
87+
86
88
87-- | Retrieves the key of the first record matching the given key or key range in query.
89-- | Retrieves the key of the first record matching the given key or key range in query.
88getKey
90getKey
89− :: forall index
90− . (IDBIndex index)
91+ :: forall e index. (IDBIndex index)
91 => index
92 => index
92 -> KeyRange
93 -> KeyRange
93− -> Aff (Maybe Key)
94+ -> Aff (idb :: IDB | e) (Maybe Key)
94getKey index range =
95getKey index range =
95− map (toMaybe >>> map toKey) $ fromEffectFnAff $ Fn.runFn2 _getKey index range
96+ (toMaybe >>> map toKey) <$> Fn.runFn2 _getKey index range
97+
96
98
97-- | Opens a ValueCursor over the records matching query, ordered by direction.
99-- | Opens a ValueCursor over the records matching query, ordered by direction.
98-- | If query is `Nothing`, all records in index are matched.
100-- | If query is `Nothing`, all records in index are matched.
99openCursor
101openCursor
100− :: forall index
101− . (IDBIndex index)
102+ :: forall e e' index. (IDBIndex index)
102− => index
103+ => index
103 -> Maybe KeyRange
104 -> Maybe KeyRange
104 -> CursorDirection
105 -> CursorDirection
105− -> Callbacks ValueCursor
106+ -> Callbacks ValueCursor e'
106− -> Aff Unit
107+ -> Aff (idb :: IDB | e) Unit
107openCursor index range dir cb =
108openCursor index range dir cb =
108− fromEffectFnAff $ Fn.runFn4 _openCursor index (toNullable range) (show dir) cb
109+ Fn.runFn4 _openCursor index (toNullable range) (show dir) cb
110+
109
111
110-- | Opens a KeyCursor over the records matching query, ordered by direction.
112-- | Opens a KeyCursor over the records matching query, ordered by direction.
111-- | If query is `Nothing`, all records in index are matched.
113-- | If query is `Nothing`, all records in index are matched.
112openKeyCursor
114openKeyCursor
113− :: forall index
114− . (IDBIndex index)
115+ :: forall e e' index. (IDBIndex index)
115− => index
116+ => index
116− -> Maybe KeyRange
117+ -> Maybe KeyRange
117− -> CursorDirection
118+ -> CursorDirection
118− -> Callbacks KeyCursor
119+ -> Callbacks KeyCursor e'
119− -> Aff Unit
120+ -> Aff (idb :: IDB | e) Unit
120openKeyCursor index range dir cb =
121openKeyCursor index range dir cb =
121− fromEffectFnAff $ Fn.runFn4 _openKeyCursor index (toNullable range) (show dir) cb
122+ Fn.runFn4 _openKeyCursor index (toNullable range) (show dir) cb
123+
122
124
123--------------------
125--------------------
124-- ATTRIBUTES
126-- ATTRIBUTES
125--
127--
126-- | Returns the key path of the index.
128-- | Returns the key path of the index.
127keyPath
129keyPath
128− :: Index
130+ :: Index
129− -> KeyPath
131+ -> KeyPath
130keyPath =
132keyPath =
131 _keyPath
133 _keyPath
132
134
135+
133-- | Returns true if the index's multiEntry flag is set.
136-- | Returns true if the index's multiEntry flag is set.
134multiEntry
137multiEntry
135− :: Index
138+ :: Index
136− -> Boolean
139+ -> Boolean
137multiEntry =
140multiEntry =
138 _multiEntry
141 _multiEntry
139
142
143+
140-- | Returns the name of the index.
144-- | Returns the name of the index.
141name
145name
142− :: Index
146+ :: Index
143− -> String
147+ -> String
144name =
148name =
145 _name
149 _name
146
150
151+
147-- | Returns the IDBObjectStore the index belongs to.
152-- | Returns the IDBObjectStore the index belongs to.
148objectStore
153objectStore
149− :: Index
154+ :: Index
150− -> ObjectStore
155+ -> ObjectStore
151objectStore =
156objectStore =
152 _objectStore
157 _objectStore
153
158
159+
154-- | Returns true if the index's unique flag is set.
160-- | Returns true if the index's unique flag is set.
155unique
161unique
156− :: Index
162+ :: Index
157− -> Boolean
163+ -> Boolean
158unique =
164unique =
159 _unique
165 _unique
160
166
167+
161--------------------
168--------------------
162-- FFI
169-- FFI
163--
170--
164foreign import _keyPath
171foreign import _keyPath
165− :: Index
172+ :: Index
166− -> Array String
173+ -> Array String
174+
167
175
168foreign import _multiEntry
176foreign import _multiEntry
169− :: Index
177+ :: Index
170− -> Boolean
178+ -> Boolean
179+
171
180
172foreign import _name
181foreign import _name
173− :: Index
182+ :: Index
174− -> String
183+ -> String
184+
175
185
176foreign import _objectStore
186foreign import _objectStore
177− :: Index
187+ :: Index
178− -> ObjectStore
188+ -> ObjectStore
189+
179
190
180foreign import _unique
191foreign import _unique
181− :: Index
192+ :: Index
182− -> Boolean
193+ -> Boolean
194+
183
195
184foreign import _count
196foreign import _count
185− :: forall index
197+ :: forall index e
186− . Fn2 index (Nullable KeyRange) (EffectFnAff Int)
198+ . Fn2 index (Nullable KeyRange) (Aff (idb :: IDB | e) Int)
199+
187
200
188foreign import _get
201foreign import _get
189− :: forall index
202+ :: forall index e
190− . Fn2 index KeyRange (EffectFnAff (Nullable Foreign))
203+ . Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Foreign))
204+
191
205
192foreign import _getAllKeys
206foreign import _getAllKeys
193− :: forall index
207+ :: forall index e
194− . Fn3 index (Nullable KeyRange) (Nullable Int) (EffectFnAff (Array Foreign))
208+ . Fn3 index (Nullable KeyRange) (Nullable Int) (Aff (idb :: IDB | e) (Array Foreign))
209+
195
210
196foreign import _getKey
211foreign import _getKey
197− :: forall index
212+ :: forall index e
198− . Fn2 index KeyRange (EffectFnAff (Nullable Foreign))
213+ . Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Foreign))
214+
199
215
200foreign import _openCursor
216foreign import _openCursor
201− :: forall index
217+ :: forall index e e'
202− . Fn4 index (Nullable KeyRange) String (Callbacks ValueCursor) (EffectFnAff Unit)
218+ . Fn4 index (Nullable KeyRange) String (Callbacks ValueCursor e') (Aff (idb :: IDB | e) Unit)
219+
203
220
204foreign import _openKeyCursor
221foreign import _openKeyCursor
205− :: forall index
222+ :: forall index e e'
206− . Fn4 index (Nullable KeyRange) String (Callbacks KeyCursor) (EffectFnAff Unit)
223+ . Fn4 index (Nullable KeyRange) String (Callbacks KeyCursor e') (Aff (idb :: IDB | e) Unit)
src/Database/IndexedDB/IDBKey/Internal.js+3−3
@@ -1,8 +1,8 @@
1−export function _dateTimeToForeign(y, m, d, h, mi, s, ms) {
1+exports._dateTimeToForeign = function _dateTimeToForeign(y, m, d, h, mi, s, ms) {
2 return new Date(y, m, d, h, mi, s, ms);
2 return new Date(y, m, d, h, mi, s, ms);
3};
3};
4
4
5−export function _readDateTime(parse, right, left, date) {
5+exports._readDateTime = function _readDateTime(parse, right, left, date) {
6 if (Object.getPrototypeOf(date) !== Date.prototype) {
6 if (Object.getPrototypeOf(date) !== Date.prototype) {
7 return left(typeof date);
7 return left(typeof date);
8 }
8 }
@@ -24,7 +24,7 @@ export function _readDateTime(parse, right, left, date) {
24 return right(mdate);
24 return right(mdate);
25};
25};
26
26
27−export function _unsafeReadDateTime(parse, date) {
27+exports._unsafeReadDateTime = function _unsafeReadDateTime(parse, date) {
28 const y = date.getFullYear();
28 const y = date.getFullYear();
29 const m = date.getMonth() + 1;
29 const m = date.getMonth() + 1;
30 const d = date.getDate();
30 const d = date.getDate();
src/Database/IndexedDB/IDBKey/Internal.purs+106−90
@@ -3,36 +3,35 @@
3-- | NOTE: Binary keys aren't supported yet.
3-- | NOTE: Binary keys aren't supported yet.
4module Database.IndexedDB.IDBKey.Internal
4module Database.IndexedDB.IDBKey.Internal
5 ( Key
5 ( Key
6− , class IDBKey
7− , toKey
8− , fromKey
9− , unsafeFromKey
6+ , class IDBKey, toKey , fromKey , unsafeFromKey
10 , none
7 , none
11 ) where
8 ) where
12
9
13import Prelude
10import Prelude
14
11
15−import Control.Alt ((<|>))
12+import Control.Alt ((<|>))
16−import Control.Monad.Except (ExceptT(..), runExceptT)
13+import Control.Monad.Except (ExceptT(..), runExceptT)
17−import Data.Date as Date
14+import Data.Date as Date
18−import Data.DateTime (DateTime(..), Time(..))
15+import Data.DateTime (DateTime(..), Time(..))
19−import Data.Either (Either(..), either, isRight)
16+import Data.Either (Either(..), either, isRight)
20−import Data.Enum (fromEnum, toEnum)
17+import Data.Enum (fromEnum, toEnum)
21−import Foreign as Foreign
18+import Data.Foreign as Foreign
22−import Foreign (Foreign, F)
19+import Data.Foreign (Foreign, F)
23−import Data.Function.Uncurried as Fn
20+import Data.Function.Uncurried as Fn
24import Data.Function.Uncurried (Fn2, Fn4, Fn7)
21import Data.Function.Uncurried (Fn2, Fn4, Fn7)
25−import Data.Identity (Identity(..))
22+import Data.Identity (Identity(..))
26−import Data.List.NonEmpty (NonEmptyList(..))
23+import Data.List.NonEmpty (NonEmptyList(..))
27−import Data.List.Types (List(..))
24+import Data.List.Types (List(..))
28−import Data.Maybe (Maybe(..))
25+import Data.Maybe (Maybe(..))
29−import Data.NonEmpty (NonEmpty(..))
26+import Data.NonEmpty (NonEmpty(..))
30−import Data.Nullable (Nullable, toNullable)
27+import Data.Nullable (Nullable, toNullable)
31−import Data.Time as Time
28+import Data.Time as Time
32−import Data.Traversable (traverse)
29+import Data.Traversable (traverse)
30+
33
31
34newtype Key = Key Foreign
32newtype Key = Key Foreign
35
33
34+
36--------------------
35--------------------
37-- INTERFACES
36-- INTERFACES
38--
37--
@@ -40,90 +39,100 @@ newtype Key = Key Foreign
40-- | to a known type (e.g if you only strings as keys, or perfectly knows the
39-- | to a known type (e.g if you only strings as keys, or perfectly knows the
41-- | type of a given key).
40-- | type of a given key).
42class IDBKey a where
41class IDBKey a where
43− toKey :: a -> Key
42+ toKey :: a -> Key
44− fromKey :: Key -> F a
43+ fromKey :: Key -> F a
45 unsafeFromKey :: Key -> a
44 unsafeFromKey :: Key -> a
46
45
46+
47none :: Maybe Key
47none :: Maybe Key
48none =
48none =
49 Nothing
49 Nothing
50
50
51+
51--------------------
52--------------------
52-- INSTANCES
53-- INSTANCES
53--
54--
54instance eqKey :: Eq Key where
55instance eqKey :: Eq Key where
55 eq a b = (runExceptT >>> runIdentity >>> isRight) $
56 eq a b = (runExceptT >>> runIdentity >>> isRight) $
56− eq <$> ((fromKey a) :: F Int) <*> fromKey b
57+ eq <$> ((fromKey a) :: F Int) <*> fromKey b
57− <|>
58+ <|>
58− eq <$> ((fromKey a) :: F Number) <*> fromKey b
59+ eq <$> ((fromKey a) :: F Number) <*> fromKey b
59− <|>
60+ <|>
60− eq <$> ((fromKey a) :: F String) <*> fromKey b
61+ eq <$> ((fromKey a) :: F String) <*> fromKey b
61− <|>
62+ <|>
62− eq <$> ((fromKey a) :: F DateTime) <*> fromKey b
63+ eq <$> ((fromKey a) :: F DateTime) <*> fromKey b
63− <|>
64+ <|>
64− eq <$> ((fromKey a) :: F (Array Key)) <*> fromKey b
65+ eq <$> ((fromKey a) :: F (Array Key)) <*> fromKey b
65 where
66 where
66− runIdentity :: forall a. Identity a -> a
67+ runIdentity :: forall a. Identity a -> a
67− runIdentity (Identity x) = x
68+ runIdentity (Identity x) = x
69+
68
70
69instance ordKey :: Ord Key where
71instance ordKey :: Ord Key where
70− compare a b = (runExceptT >>> runIdentity >>> either (const LT) identity) $
72+ compare a b = (runExceptT >>> runIdentity >>> either (const LT) id) $
71− compare <$> ((fromKey a) :: F Int) <*> fromKey b
73+ compare <$> ((fromKey a) :: F Int) <*> fromKey b
72− <|>
74+ <|>
73− compare <$> ((fromKey a) :: F Number) <*> fromKey b
75+ compare <$> ((fromKey a) :: F Number) <*> fromKey b
74− <|>
76+ <|>
75− compare <$> ((fromKey a) :: F String) <*> fromKey b
77+ compare <$> ((fromKey a) :: F String) <*> fromKey b
76− <|>
78+ <|>
77− compare <$> ((fromKey a) :: F DateTime) <*> fromKey b
79+ compare <$> ((fromKey a) :: F DateTime) <*> fromKey b
78− <|>
80+ <|>
79− compare <$> ((fromKey a) :: F (Array Key)) <*> fromKey b
81+ compare <$> ((fromKey a) :: F (Array Key)) <*> fromKey b
80 where
82 where
81− runIdentity :: forall a. Identity a -> a
83+ runIdentity :: forall a. Identity a -> a
82− runIdentity (Identity x) = x
84+ runIdentity (Identity x) = x
85+
83
86
84instance showKey :: Show Key where
87instance showKey :: Show Key where
85 show a = (runExceptT >>> format) $
88 show a = (runExceptT >>> format) $
86− (show <$> (fromKey a :: F Int))
89+ (show <$> (fromKey a :: F Int))
87− <|>
90+ <|>
88− (show <$> (fromKey a :: F Number))
91+ (show <$> (fromKey a :: F Number))
89− <|>
92+ <|>
90− (show <$> (fromKey a :: F String))
93+ (show <$> (fromKey a :: F String))
91− <|>
94+ <|>
92− (show <$> (fromKey a :: F DateTime))
95+ (show <$> (fromKey a :: F DateTime))
93− <|>
96+ <|>
94− (show <$> (fromKey a :: F (Array Key)))
97+ (show <$> (fromKey a :: F (Array Key)))
95 where
98 where
96− format :: forall a. Identity (Either a String) -> String
99+ format :: forall a. Identity (Either a String) -> String
97− format (Identity x) =
100+ format (Identity x) =
98− either (const "(Key)") (\s -> "(Key " <> s <> ")") x
101+ either (const "(Key)") (\s -> "(Key " <> s <> ")") x
102+
99
103
100instance idbKeyKey :: IDBKey Key where
104instance idbKeyKey :: IDBKey Key where
101− toKey = identity
105+ toKey = id
102− fromKey = pure
106+ fromKey = pure
103− unsafeFromKey = identity
107+ unsafeFromKey = id
108+
104
109
105instance idbKeyForeign :: IDBKey Foreign where
110instance idbKeyForeign :: IDBKey Foreign where
106− toKey = Key
111+ toKey = Key
107− fromKey (Key f) = pure f
112+ fromKey (Key f) = pure f
108 unsafeFromKey (Key f) = f
113 unsafeFromKey (Key f) = f
109
114
115+
110instance idbKeyInt :: IDBKey Int where
116instance idbKeyInt :: IDBKey Int where
111− toKey = Foreign.unsafeToForeign >>> Key
117+ toKey = Foreign.toForeign >>> Key
112− fromKey (Key f) = Foreign.readInt f
118+ fromKey (Key f) = Foreign.readInt f
113 unsafeFromKey (Key f) = Foreign.unsafeFromForeign f
119 unsafeFromKey (Key f) = Foreign.unsafeFromForeign f
114
120
121+
115instance idbKeyNumber :: IDBKey Number where
122instance idbKeyNumber :: IDBKey Number where
116− toKey = Foreign.unsafeToForeign >>> Key
123+ toKey = Foreign.toForeign >>> Key
117− fromKey (Key f) = Foreign.readNumber f
124+ fromKey (Key f) = Foreign.readNumber f
118 unsafeFromKey (Key f) = Foreign.unsafeFromForeign f
125 unsafeFromKey (Key f) = Foreign.unsafeFromForeign f
119
126
127+
120instance idbKeyString :: IDBKey String where
128instance idbKeyString :: IDBKey String where
121− toKey = Foreign.unsafeToForeign >>> Key
129+ toKey = Foreign.toForeign >>> Key
122− fromKey (Key f) = Foreign.readString f
130+ fromKey (Key f) = Foreign.readString f
123 unsafeFromKey (Key f) = Foreign.unsafeFromForeign f
131 unsafeFromKey (Key f) = Foreign.unsafeFromForeign f
124
132
133+
125instance idbKeyDate :: IDBKey DateTime where
134instance idbKeyDate :: IDBKey DateTime where
126− toKey (DateTime d t) = Key $ Fn.runFn7 _dateTimeToForeign
135+ toKey (DateTime d t) = Key $ Fn.runFn7 _dateTimeToForeign
127 (fromEnum $ Date.year d)
136 (fromEnum $ Date.year d)
128 (fromEnum $ Date.month d)
137 (fromEnum $ Date.month d)
129 (fromEnum $ Date.day d)
138 (fromEnum $ Date.day d)
@@ -131,51 +140,58 @@ instance idbKeyDate :: IDBKey DateTime where
131 (fromEnum $ Time.minute t)
140 (fromEnum $ Time.minute t)
132 (fromEnum $ Time.second t)
141 (fromEnum $ Time.second t)
133 (fromEnum $ Time.millisecond t)
142 (fromEnum $ Time.millisecond t)
134− fromKey (Key f) = Fn.runFn4 _readDateTime dateTime dateTimeF dateTimeE f
143+ fromKey (Key f) = Fn.runFn4 _readDateTime dateTime dateTimeF dateTimeE f
135 unsafeFromKey (Key f) = Fn.runFn2 _unsafeReadDateTime dateTime f
144 unsafeFromKey (Key f) = Fn.runFn2 _unsafeReadDateTime dateTime f
136
145
146+
137instance idbKeyArray :: IDBKey a => IDBKey (Array a) where
147instance idbKeyArray :: IDBKey a => IDBKey (Array a) where
138− toKey = Foreign.unsafeToForeign >>> Key
148+ toKey = Foreign.toForeign >>> Key
139− fromKey (Key f) = Foreign.readArray f >>= traverse (Key >>> fromKey)
149+ fromKey (Key f) = Foreign.readArray f >>= traverse (Key >>> fromKey)
140 unsafeFromKey (Key f) = map unsafeFromKey (Foreign.unsafeFromForeign f)
150 unsafeFromKey (Key f) = map unsafeFromKey (Foreign.unsafeFromForeign f)
141
151
152+
142-- FFI constructor to build a DateTime from years, months, days, hours, minutes, seconds and millis
153-- FFI constructor to build a DateTime from years, months, days, hours, minutes, seconds and millis
143dateTime
154dateTime
144− :: Int -- ^ years
155+ :: Int -- ^ years
145− -> Int -- ^ months
156+ -> Int -- ^ months
146− -> Int -- ^ days
157+ -> Int -- ^ days
147− -> Int -- ^ hours
158+ -> Int -- ^ hours
148− -> Int -- ^ minutes
159+ -> Int -- ^ minutes
149− -> Int -- ^ seconds
160+ -> Int -- ^ seconds
150− -> Int -- ^ milliseconds
161+ -> Int -- ^ milliseconds
151− -> Nullable DateTime
162+ -> Nullable DateTime
152dateTime y m d h mi s ms =
163dateTime y m d h mi s ms =
153 toNullable $ DateTime
164 toNullable $ DateTime
154− <$> (Date.canonicalDate <$> toEnum y <*> toEnum m <*> toEnum d)
165+ <$> (Date.canonicalDate <$> toEnum y <*> toEnum m <*> toEnum d)
155− <*> (Time <$> toEnum h <*> toEnum mi <*> toEnum s <*> toEnum ms)
166+ <*> (Time <$> toEnum h <*> toEnum mi <*> toEnum s <*> toEnum ms)
167+
156
168
157-- FFI constructor to convert a JS `Date` into a successful `F DateTime`
169-- FFI constructor to convert a JS `Date` into a successful `F DateTime`
158dateTimeF
170dateTimeF
159− :: DateTime
171+ :: DateTime
160− -> F DateTime
172+ -> F DateTime
161dateTimeF =
173dateTimeF =
162 Right >>> Identity >>> ExceptT
174 Right >>> Identity >>> ExceptT
163
175
176+
164-- FFI constructor to convert a string into an errored `F DateTime`
177-- FFI constructor to convert a string into an errored `F DateTime`
165dateTimeE
178dateTimeE
166− :: String
179+ :: String
167− -> F DateTime
180+ -> F DateTime
168dateTimeE =
181dateTimeE =
169 Foreign.TypeMismatch "Date" >>> flip NonEmpty Nil >>> NonEmptyList >>> Left >>> Identity >>> ExceptT
182 Foreign.TypeMismatch "Date" >>> flip NonEmpty Nil >>> NonEmptyList >>> Left >>> Identity >>> ExceptT
170
183
184+
171--------------------
185--------------------
172-- FFI
186-- FFI
173--
187--
174foreign import _dateTimeToForeign
188foreign import _dateTimeToForeign
175− :: Fn7 Int Int Int Int Int Int Int Foreign
189+ :: Fn7 Int Int Int Int Int Int Int Foreign
190+
176
191
177foreign import _readDateTime
192foreign import _readDateTime
178− :: Fn4 (Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime) (DateTime -> F DateTime) (String -> F DateTime) Foreign (F DateTime)
193+ :: Fn4 (Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime) (DateTime -> F DateTime) (String -> F DateTime) Foreign (F DateTime)
194+
179
195
180foreign import _unsafeReadDateTime
196foreign import _unsafeReadDateTime
181− :: Fn2 (Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime) Foreign DateTime
197+ :: Fn2 (Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime) Foreign DateTime
src/Database/IndexedDB/IDBKeyRange.js+9−9
@@ -1,4 +1,4 @@
1−export function _bound(lower, upper, lowerOpen, upperOpen) {
1+exports._bound = function _bound(lower, upper, lowerOpen, upperOpen) {
2 try {
2 try {
3 return IDBKeyRange.bound(lower, upper, lowerOpen, upperOpen);
3 return IDBKeyRange.bound(lower, upper, lowerOpen, upperOpen);
4 } catch (e) {
4 } catch (e) {
@@ -6,34 +6,34 @@ export function _bound(lower, upper, lowerOpen, upperOpen) {
6 }
6 }
7};
7};
8
8
9−export function _includes(range, key) {
9+exports._includes = function _includes(range, key) {
10 return range.includes(key);
10 return range.includes(key);
11};
11};
12
12
13−export function _lower(range) {
13+exports._lower = function _lower(range) {
14 return range.lower;
14 return range.lower;
15};
15};
16
16
17−export function _lowerBound(lower, open) {
17+exports._lowerBound = function _lowerBound(lower, open) {
18 return IDBKeyRange.lowerBound(lower, open);
18 return IDBKeyRange.lowerBound(lower, open);
19};
19};
20
20
21−export function _lowerOpen(range) {
21+exports._lowerOpen = function _lowerOpen(range) {
22 return range.lowerOpen;
22 return range.lowerOpen;
23};
23};
24
24
25−export function _only(key) {
25+exports._only = function _only(key) {
26 return IDBKeyRange.only(key);
26 return IDBKeyRange.only(key);
27};
27};
28
28
29−export function _upper(range) {
29+exports._upper = function _upper(range) {
30 return range.upper;
30 return range.upper;
31};
31};
32
32
33−export function _upperBound(upper, open) {
33+exports._upperBound = function _upperBound(upper, open) {
34 return IDBKeyRange.upperBound(upper, open);
34 return IDBKeyRange.upperBound(upper, open);
35};
35};
36
36
37−export function _upperOpen(range) {
37+exports._upperOpen = function _upperOpen(range) {
38 return range.upperOpen;
38 return range.upperOpen;
39};
39};
src/Database/IndexedDB/IDBKeyRange.purs+42−30
@@ -19,17 +19,18 @@ module Database.IndexedDB.IDBKeyRange
19 , upperOpen
19 , upperOpen
20 ) where
20 ) where
21
21
22−import Prelude (($), (>>>), map)
22+import Prelude (($), (>>>), map)
23
23
24−import Foreign (Foreign)
24+import Data.Foreign (Foreign)
25−import Data.Function.Uncurried as Fn
25+import Data.Function.Uncurried as Fn
26−import Data.Function.Uncurried (Fn2, Fn4)
26+import Data.Function.Uncurried (Fn2, Fn4)
27−import Data.Maybe (Maybe)
27+import Data.Maybe (Maybe)
28−import Data.Nullable (Nullable, toMaybe)
28+import Data.Nullable (Nullable, toMaybe)
29
29
30−import Database.IndexedDB.Core (class IDBKeyRange, KeyRange)
30+import Database.IndexedDB.Core (class IDBKeyRange, KeyRange)
31import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key, toKey, unsafeFromKey)
31import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key, toKey, unsafeFromKey)
32
32
33+
33--------------------
34--------------------
34-- TYPES
35-- TYPES
35--
36--
@@ -37,54 +38,55 @@ import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key, toKey, unsafeFromK
37-- | Type alias for open
38-- | Type alias for open
38type Open = Boolean
39type Open = Boolean
39
40
41+
40--------------------
42--------------------
41-- CONSTRUCTORS
43-- CONSTRUCTORS
42--
44--
43
45
44-- | Returns a new IDBKeyRange spanning only key.
46-- | Returns a new IDBKeyRange spanning only key.
45only
47only
46− :: forall a
48+ :: forall a. (IDBKey a)
47− . (IDBKey a)
48− => a
49+ => a
49− -> KeyRange
50+ -> KeyRange
50only key =
51only key =
51 _only (unsafeFromKey $ toKey key)
52 _only (unsafeFromKey $ toKey key)
52
53
54+
53-- | Returns a new IDBKeyRange starting at key with no upper bound.
55-- | Returns a new IDBKeyRange starting at key with no upper bound.
54-- | If `Open` is `true`, key is not included in the range.
56-- | If `Open` is `true`, key is not included in the range.
55lowerBound
57lowerBound
56− :: forall a
58+ :: forall a. (IDBKey a)
57− . (IDBKey a)
58− => a
59+ => a
59− -> Open
60+ -> Open
60− -> KeyRange
61+ -> KeyRange
61lowerBound key open =
62lowerBound key open =
62 Fn.runFn2 _lowerBound (unsafeFromKey $ toKey key) open
63 Fn.runFn2 _lowerBound (unsafeFromKey $ toKey key) open
63
64
65+
64-- | Returns a new IDBKeyRange with no lower bound and ending at key.
66-- | Returns a new IDBKeyRange with no lower bound and ending at key.
65-- | If `Open` is `true`, key is not included in the range.
67-- | If `Open` is `true`, key is not included in the range.
66upperBound
68upperBound
67− :: forall a
69+ :: forall a. (IDBKey a)
68− . (IDBKey a)
69− => a
70+ => a
70− -> Open
71+ -> Open
71− -> KeyRange
72+ -> KeyRange
72upperBound key open =
73upperBound key open =
73 Fn.runFn2 _upperBound (unsafeFromKey $ toKey key) open
74 Fn.runFn2 _upperBound (unsafeFromKey $ toKey key) open
74
75
76+
75-- | Returns a new IDBKeyRange spanning from `lower` to `upper`.
77-- | Returns a new IDBKeyRange spanning from `lower` to `upper`.
76-- | If `lowerOpen` is `true`, `lower` is not included in the range.
78-- | If `lowerOpen` is `true`, `lower` is not included in the range.
77-- | If `upperOpen` is `true`, `upper` is not included in the range.
79-- | If `upperOpen` is `true`, `upper` is not included in the range.
78-- |
80-- |
79-- | It throws a `DataError` if the bound is invalid.
81-- | It throws a `DataError` if the bound is invalid.
80bound
82bound
81− :: forall key
83+ :: forall key. (IDBKey key)
82− . (IDBKey key)
83− => { lower :: key, upper :: key, lowerOpen :: Boolean, upperOpen :: Boolean }
84+ => { lower :: key, upper :: key, lowerOpen :: Boolean, upperOpen :: Boolean }
84− -> Maybe KeyRange
85+ -> Maybe KeyRange
85bound { lower: key1, upper: key2, lowerOpen: open1, upperOpen: open2 } =
86bound { lower: key1, upper: key2, lowerOpen: open1, upperOpen: open2 } =
86 toMaybe
87 toMaybe
87− $ Fn.runFn4 _bound (unsafeFromKey $ toKey key1) (unsafeFromKey $ toKey key2) open1 open2
88+ $ Fn.runFn4 _bound (unsafeFromKey $ toKey key1) (unsafeFromKey $ toKey key2) open1 open2
89+
88
90
89--------------------
91--------------------
90-- INTERFACE
92-- INTERFACE
@@ -92,15 +94,14 @@ bound { lower: key1, upper: key2, lowerOpen: open1, upperOpen: open2 } =
92
94
93-- | Returns true if key is included in the range, and false otherwise.
95-- | Returns true if key is included in the range, and false otherwise.
94includes
96includes
95− :: forall key range
96− . (IDBKey key)
97− => (IDBKeyRange range)
97+ :: forall key range. (IDBKey key) => (IDBKeyRange range)
98 => range
98 => range
99 -> key
99 -> key
100 -> Boolean
100 -> Boolean
101includes range =
101includes range =
102 toKey >>> unsafeFromKey >>> Fn.runFn2 _includes range
102 toKey >>> unsafeFromKey >>> Fn.runFn2 _includes range
103
103
104+
104--------------------
105--------------------
105-- ATTRIBUTES
106-- ATTRIBUTES
106--
107--
@@ -111,6 +112,7 @@ lower
111lower =
112lower =
112 _lower >>> toMaybe >>> map toKey
113 _lower >>> toMaybe >>> map toKey
113
114
115+
114-- | Returns upper bound if any.
116-- | Returns upper bound if any.
115upper
117upper
116 :: KeyRange
118 :: KeyRange
@@ -118,6 +120,7 @@ upper
118upper =
120upper =
119 _upper >>> toMaybe >>> map toKey
121 _upper >>> toMaybe >>> map toKey
120
122
123+
121-- | Returns true if the lower open flag is set, false otherwise.
124-- | Returns true if the lower open flag is set, false otherwise.
122lowerOpen
125lowerOpen
123 :: KeyRange
126 :: KeyRange
@@ -125,6 +128,7 @@ lowerOpen
125lowerOpen =
128lowerOpen =
126 _lowerOpen
129 _lowerOpen
127
130
131+
128-- | Returns true if the upper open flag is set, false otherwise.
132-- | Returns true if the upper open flag is set, false otherwise.
129upperOpen
133upperOpen
130 :: KeyRange
134 :: KeyRange
@@ -132,6 +136,7 @@ upperOpen
132upperOpen =
136upperOpen =
133 _upperOpen
137 _upperOpen
134
138
139+
135--------------------
140--------------------
136-- FFI
141-- FFI
137--
142--
@@ -143,28 +148,35 @@ foreign import _only
143foreign import _lowerBound
148foreign import _lowerBound
144 :: Fn2 Foreign Boolean KeyRange
149 :: Fn2 Foreign Boolean KeyRange
145
150
151+
146foreign import _upperBound
152foreign import _upperBound
147 :: Fn2 Foreign Boolean KeyRange
153 :: Fn2 Foreign Boolean KeyRange
148
154
155+
149foreign import _bound
156foreign import _bound
150 :: Fn4 Foreign Foreign Boolean Boolean (Nullable KeyRange)
157 :: Fn4 Foreign Foreign Boolean Boolean (Nullable KeyRange)
151
158
159+
152foreign import _includes
160foreign import _includes
153 :: forall range
161 :: forall range
154− . Fn2 range Foreign Boolean
162+ . Fn2 range Foreign Boolean
163+
155
164
156foreign import _lower
165foreign import _lower
157 :: KeyRange
166 :: KeyRange
158 -> Nullable Foreign
167 -> Nullable Foreign
159
168
169+
160foreign import _upper
170foreign import _upper
161 :: KeyRange
171 :: KeyRange
162 -> Nullable Foreign
172 -> Nullable Foreign
163
173
174+
164foreign import _lowerOpen
175foreign import _lowerOpen
165 :: KeyRange
176 :: KeyRange
166 -> Boolean
177 -> Boolean
167
178
179+
168foreign import _upperOpen
180foreign import _upperOpen
169 :: KeyRange
181 :: KeyRange
170 -> Boolean
182 -> Boolean
src/Database/IndexedDB/IDBObjectStore.js+27−55
@@ -1,6 +1,6 @@
1const errorHandler = function errorHandler(cb) {
1const errorHandler = function errorHandler(cb) {
2 return function _handler(e) {
2 return function _handler(e) {
3− cb(e.target.error);
3+ cb(new Error(e.target.error.name));
4 };
4 };
5};
5};
6
6
@@ -15,44 +15,36 @@ const toArray = function toArray(xs) {
15};
15};
16
16
17
17
18−export function _add(store, value, key) {
18+exports._add = function _add(store, value, key) {
19− return function aff(error, success) {
19+ return function aff(success, error) {
20 try {
20 try {
21 const request = store.add(value, key || undefined);
21 const request = store.add(value, key || undefined);
22 request.onsuccess = successHandler(success);
22 request.onsuccess = successHandler(success);
23 request.onerror = errorHandler(error);
23 request.onerror = errorHandler(error);
24 } catch (e) {
24 } catch (e) {
25− error(e);
25+ error(new Error(e.name));
26 }
26 }
27−
28− return function canceler(_, cancelerError) {
29− cancelerError(new Error("Can't cancel IDB Effects"));
30− };
31 };
27 };
32};
28};
33
29
34−export function _autoIncrement(store) {
30+exports._autoIncrement = function _autoIncrement(store) {
35 return store.autoIncrement;
31 return store.autoIncrement;
36};
32};
37
33
38−export function _clear(store) {
34+exports._clear = function _clear(store) {
39− return function aff(error, success) {
35+ return function aff(success, error) {
40 try {
36 try {
41 const request = store.clear();
37 const request = store.clear();
42 request.onsuccess = successHandler(success);
38 request.onsuccess = successHandler(success);
43 request.onerror = errorHandler(error);
39 request.onerror = errorHandler(error);
44 } catch (e) {
40 } catch (e) {
45− error(e);
41+ error(new Error(e.name));
46 }
42 }
47−
48− return function canceler(_, cancelerError) {
49− cancelerError(new Error("Can't cancel IDB Effects"));
50− };
51 };
43 };
52};
44};
53
45
54−export function _createIndex(store, name, path, params) {
46+exports._createIndex = function _createIndex(store, name, path, params) {
55− return function aff(error, success) {
47+ return function aff(success, error) {
56 var keyPath;
48 var keyPath;
57
49
58 try {
50 try {
@@ -72,66 +64,50 @@ export function _createIndex(store, name, path, params) {
72 const index = store.createIndex(name, keyPath, params);
64 const index = store.createIndex(name, keyPath, params);
73 success(index);
65 success(index);
74 } catch (e) {
66 } catch (e) {
75− error(e);
67+ error(new Error(e.name));
76 }
68 }
77−
78− return function canceler(_, cancelerError) {
79− cancelerError(new Error("Can't cancel IDB Effects"));
80− };
81 };
69 };
82};
70};
83
71
84−export function _deleteIndex(store, name) {
72+exports._deleteIndex = function _deleteIndex(store, name) {
85− return function aff(error, success) {
73+ return function aff(success, error) {
86 try {
74 try {
87 store.deleteIndex(name);
75 store.deleteIndex(name);
88 success();
76 success();
89 } catch (e) {
77 } catch (e) {
90− error(e);
78+ error(new Error(e.name));
91 }
79 }
92−
93− return function canceler(_, cancelerError) {
94− cancelerError(new Error("Can't cancel IDB Effects"));
95− };
96 };
80 };
97};
81};
98
82
99−export function _delete(store, query) {
83+exports._delete = function _delete(store, query) {
100− return function aff(error, success) {
84+ return function aff(success, error) {
101 try {
85 try {
102 const request = store.delete(query);
86 const request = store.delete(query);
103 request.onsuccess = successHandler(success);
87 request.onsuccess = successHandler(success);
104 request.onerror = errorHandler(error);
88 request.onerror = errorHandler(error);
105 } catch (e) {
89 } catch (e) {
106− error(e);
90+ error(new Error(e.name));
107 }
91 }
108−
109− return function canceler(_, cancelerError) {
110− cancelerError(new Error("Can't cancel IDB Effects"));
111− };
112 };
92 };
113};
93};
114
94
115−export function _index(store, name) {
95+exports._index = function _index(store, name) {
116− return function aff(error, success) {
96+ return function aff(success, error) {
117 try {
97 try {
118 const index = store.index(name);
98 const index = store.index(name);
119 success(index);
99 success(index);
120 } catch (e) {
100 } catch (e) {
121− error(e);
101+ error(new Error(e.name));
122 }
102 }
123−
124− return function canceler(_, cancelerError) {
125− cancelerError(new Error("Can't cancel IDB Effects"));
126− };
127 };
103 };
128};
104};
129
105
130−export function _indexNames(store) {
106+exports._indexNames = function _indexNames(store) {
131 return toArray(store.indexNames);
107 return toArray(store.indexNames);
132};
108};
133
109
134−export function _keyPath(store) {
110+exports._keyPath = function _keyPath(store) {
135 const path = store.keyPath;
111 const path = store.keyPath;
136
112
137 if (Array.isArray(path)) {
113 if (Array.isArray(path)) {
@@ -145,26 +121,22 @@ export function _keyPath(store) {
145 return [];
121 return [];
146};
122};
147
123
148−export function _name(store) {
124+exports._name = function _name(store) {
149 return store.name;
125 return store.name;
150};
126};
151
127
152−export function _put(store, value, key) {
128+exports._put = function _put(store, value, key) {
153− return function aff(error, success) {
129+ return function aff(success, error) {
154 try {
130 try {
155 const request = store.put(value, key || undefined);
131 const request = store.put(value, key || undefined);
156 request.onsuccess = successHandler(success);
132 request.onsuccess = successHandler(success);
157 request.onerror = errorHandler(error);
133 request.onerror = errorHandler(error);
158 } catch (e) {
134 } catch (e) {
159− error(e);
135+ error(new Error(e.name));
160 }
136 }
161−
162− return function canceler(_, cancelerError) {
163− cancelerError(new Error("Can't cancel IDB Effects"));
164− };
165 };
137 };
166};
138};
167
139
168−export function _transaction(store) {
140+exports._transaction = function _transaction(store) {
169 return store.transaction;
141 return store.transaction;
170};
142};
src/Database/IndexedDB/IDBObjectStore.purs+75−58
@@ -25,18 +25,18 @@ module Database.IndexedDB.IDBObjectStore
25 , module Database.IndexedDB.IDBIndex
25 , module Database.IndexedDB.IDBIndex
26 ) where
26 ) where
27
27
28−import Database.IndexedDB.Core
28+import Prelude (Unit, ($), (<$>), (>>>))
29+
30+import Control.Monad.Aff (Aff)
31+import Data.Foreign (Foreign)
32+import Data.Function.Uncurried as Fn
33+import Data.Function.Uncurried (Fn2, Fn3, Fn4)
34+import Data.Maybe (Maybe)
35+import Data.Nullable (Nullable, toNullable)
29
36
30−import Data.Function.Uncurried (Fn2, Fn3, Fn4)
37+import Database.IndexedDB.Core
31−import Data.Function.Uncurried as Fn
32−import Data.Maybe (Maybe)
33−import Data.Nullable (Nullable, toNullable)
34−import Database.IndexedDB.IDBIndex (count, get, getAllKeys, getKey, openCursor, openKeyCursor)
38+import Database.IndexedDB.IDBIndex (count, get, getAllKeys, getKey, openCursor, openKeyCursor)
35import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key, unsafeFromKey, toKey)
39import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key, unsafeFromKey, toKey)
36−import Effect.Aff (Aff)
37−import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
38−import Foreign (Foreign)
39−import Prelude (Unit, map, ($), (<$>), (>>>), (<<<))
40
40
41--------------------
41--------------------
42-- TYPES
42-- TYPES
@@ -45,6 +45,7 @@ import Prelude (Unit, map, ($), (<$>), (>>>), (<<<))
45-- | Type alias for IndexName
45-- | Type alias for IndexName
46type IndexName = String
46type IndexName = String
47
47
48+
48-- | Flags to set on the index.
49-- | Flags to set on the index.
49-- |
50-- |
50-- | An index has a `unique` flag. When this flag is set, the index enforces that no
51-- | An index has a `unique` flag. When this flag is set, the index enforces that no
@@ -59,16 +60,18 @@ type IndexName = String
59-- | If the `multiEntry` flag is true, then the one record is added to the index for each
60-- | If the `multiEntry` flag is true, then the one record is added to the index for each
60-- | of the subkeys.
61-- | of the subkeys.
61type IndexParameters =
62type IndexParameters =
62− { unique :: Boolean
63+ { unique :: Boolean
63 , multiEntry :: Boolean
64 , multiEntry :: Boolean
64 }
65 }
65
66
67+
66defaultParameters :: IndexParameters
68defaultParameters :: IndexParameters
67defaultParameters =
69defaultParameters =
68− { unique: false
70+ { unique : false
69− , multiEntry: false
71+ , multiEntry : false
70 }
72 }
71
73
74+
72--------------------
75--------------------
73-- INTERFACES
76-- INTERFACES
74--
77--
@@ -81,24 +84,23 @@ defaultParameters =
81-- | If add() is used, and if a record with the key already exists the request will fail,
84-- | If add() is used, and if a record with the key already exists the request will fail,
82-- | with a "ConstraintError" DOMException.
85-- | with a "ConstraintError" DOMException.
83add
86add
84− :: forall key val store
85− . (IDBKey key)
86− => (IDBObjectStore store)
87+ :: forall e key val store. (IDBKey key) => (IDBObjectStore store)
87 => store
88 => store
88 -> val
89 -> val
89 -> Maybe key
90 -> Maybe key
90− -> Aff Key
91+ -> Aff (idb :: IDB | e) Key
91add store value key =
92add store value key =
92− map toKey $ fromEffectFnAff $ Fn.runFn3 _add store value (toNullable $ (toKey >>> unsafeFromKey) <$> key)
93+ toKey <$> Fn.runFn3 _add store value (toNullable $ (toKey >>> unsafeFromKey) <$> key)
94+
93
95
94-- | Deletes all records in store.
96-- | Deletes all records in store.
95clear
97clear
96− :: forall store
97− . (IDBObjectStore store)
98+ :: forall e store. (IDBObjectStore store)
98 => store
99 => store
99− -> Aff Unit
100+ -> Aff (idb :: IDB | e) Unit
100clear =
101clear =
101− fromEffectFnAff <<< _clear
102+ _clear
103+
102
104
103-- | Creates a new index in store with the given name, keyPath and options and
105-- | Creates a new index in store with the given name, keyPath and options and
104-- | returns a new IDBIndex. If the keyPath and options define constraints that
106-- | returns a new IDBIndex. If the keyPath and options define constraints that
@@ -107,47 +109,47 @@ clear =
107-- |
109-- |
108-- | Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.
110-- | Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.
109createIndex
111createIndex
110− :: forall store
111− . (IDBObjectStore store)
112+ :: forall e store. (IDBObjectStore store)
112 => store
113 => store
113 -> IndexName
114 -> IndexName
114 -> KeyPath
115 -> KeyPath
115 -> IndexParameters
116 -> IndexParameters
116− -> Aff Index
117+ -> Aff (idb :: IDB | e) Index
117createIndex store name' path params =
118createIndex store name' path params =
118− fromEffectFnAff $ Fn.runFn4 _createIndex store name' path params
119+ Fn.runFn4 _createIndex store name' path params
120+
119
121
120-- | Deletes records in store with the given key or in the given key range in query.
122-- | Deletes records in store with the given key or in the given key range in query.
121delete
123delete
122− :: forall store
123− . (IDBObjectStore store)
124+ :: forall e store. (IDBObjectStore store)
124 => store
125 => store
125 -> KeyRange
126 -> KeyRange
126− -> Aff Unit
127+ -> Aff (idb :: IDB | e) Unit
127delete store range =
128delete store range =
128− fromEffectFnAff $ Fn.runFn2 _delete store range
129+ Fn.runFn2 _delete store range
130+
129
131
130-- | Deletes the index in store with the given name.
132-- | Deletes the index in store with the given name.
131-- |
133-- |
132-- | Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.
134-- | Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.
133deleteIndex
135deleteIndex
134− :: forall store
135− . (IDBObjectStore store)
136+ :: forall e store. (IDBObjectStore store)
136 => store
137 => store
137 -> IndexName
138 -> IndexName
138− -> Aff Unit
139+ -> Aff (idb :: IDB | e) Unit
139deleteIndex store name' =
140deleteIndex store name' =
140− fromEffectFnAff $ Fn.runFn2 _deleteIndex store name'
141+ Fn.runFn2 _deleteIndex store name'
142+
141
143
142-- | Returns an IDBIndex for the index named name in store.
144-- | Returns an IDBIndex for the index named name in store.
143index
145index
144− :: forall store
145− . (IDBObjectStore store)
146+ :: forall e store. (IDBObjectStore store)
146 => store
147 => store
147 -> IndexName
148 -> IndexName
148− -> Aff Index
149+ -> Aff (idb :: IDB | e) Index
149index store name' =
150index store name' =
150− fromEffectFnAff $ Fn.runFn2 _index store name'
151+ Fn.runFn2 _index store name'
152+
151
153
152-- | Adds or updates a record in store with the given value and key.
154-- | Adds or updates a record in store with the given value and key.
153-- |
155-- |
@@ -156,15 +158,14 @@ index store name' =
156-- |
158-- |
157-- | If put() is used, any existing record with the key will be replaced.
159-- | If put() is used, any existing record with the key will be replaced.
158put
160put
159− :: forall val key store
160− . (IDBKey key)
161− => (IDBObjectStore store)
161+ :: forall e val key store. (IDBKey key) => (IDBObjectStore store)
162 => store
162 => store
163 -> val
163 -> val
164 -> Maybe key
164 -> Maybe key
165− -> Aff Key
165+ -> Aff (idb :: IDB | e) Key
166put store value key =
166put store value key =
167− map toKey $ fromEffectFnAff $ Fn.runFn3 _put store value (toNullable $ (toKey >>> unsafeFromKey) <$> key)
167+ toKey <$> Fn.runFn3 _put store value (toNullable $ (toKey >>> unsafeFromKey) <$> key)
168+
168
169
169--------------------
170--------------------
170-- ATTRIBUTES
171-- ATTRIBUTES
@@ -176,6 +177,7 @@ autoIncrement
176autoIncrement =
177autoIncrement =
177 _autoIncrement
178 _autoIncrement
178
179
180+
179--| Returns a list of the names of indexes in the store.
181--| Returns a list of the names of indexes in the store.
180indexNames
182indexNames
181 :: ObjectStore
183 :: ObjectStore
@@ -183,6 +185,7 @@ indexNames
183indexNames =
185indexNames =
184 _indexNames
186 _indexNames
185
187
188+
186-- | Returns the key path of the store, or empty array if none
189-- | Returns the key path of the store, or empty array if none
187keyPath
190keyPath
188 :: ObjectStore
191 :: ObjectStore
@@ -190,6 +193,7 @@ keyPath
190keyPath =
193keyPath =
191 _keyPath
194 _keyPath
192
195
196+
193-- | Returns the name of the store.
197-- | Returns the name of the store.
194name
198name
195 :: ObjectStore
199 :: ObjectStore
@@ -197,6 +201,7 @@ name
197name =
201name =
198 _name
202 _name
199
203
204+
200-- | Returns the associated transaction.
205-- | Returns the associated transaction.
201transaction
206transaction
202 :: ObjectStore
207 :: ObjectStore
@@ -204,53 +209,65 @@ transaction
204transaction =
209transaction =
205 _transaction
210 _transaction
206
211
212+
207--------------------
213--------------------
208-- FFI
214-- FFI
209--
215--
210foreign import _add
216foreign import _add
211− :: forall val store
217+ :: forall e val store
212− . Fn3 store val (Nullable Foreign) (EffectFnAff Foreign)
218+ . Fn3 store val (Nullable Foreign) (Aff (idb :: IDB | e) Foreign)
219+
213
220
214foreign import _autoIncrement
221foreign import _autoIncrement
215 :: ObjectStore
222 :: ObjectStore
216 -> Boolean
223 -> Boolean
217
224
225+
218foreign import _clear
226foreign import _clear
219− :: forall store
227+ :: forall e store
220− . store
228+ . store
221− -> EffectFnAff Unit
229+ -> Aff (idb :: IDB | e) Unit
230+
222
231
223foreign import _createIndex
232foreign import _createIndex
224− :: forall store
233+ :: forall e store
225− . Fn4 store String (Array String) { unique :: Boolean, multiEntry :: Boolean } (EffectFnAff Index)
234+ . Fn4 store String (Array String) { unique :: Boolean, multiEntry :: Boolean } (Aff (idb :: IDB | e) Index)
235+
226
236
227foreign import _delete
237foreign import _delete
228− :: forall store
238+ :: forall e store
229− . Fn2 store KeyRange (EffectFnAff Unit)
239+ . Fn2 store KeyRange (Aff (idb :: IDB | e) Unit)
240+
230
241
231foreign import _deleteIndex
242foreign import _deleteIndex
232− :: forall store
243+ :: forall e store
233− . Fn2 store String (EffectFnAff Unit)
244+ . Fn2 store String (Aff (idb :: IDB | e) Unit)
245+
234
246
235foreign import _index
247foreign import _index
236− :: forall store
248+ :: forall e store
237− . Fn2 store String (EffectFnAff Index)
249+ . Fn2 store String (Aff (idb :: IDB | e) Index)
250+
238
251
239foreign import _indexNames
252foreign import _indexNames
240 :: ObjectStore
253 :: ObjectStore
241 -> Array String
254 -> Array String
242
255
256+
243foreign import _keyPath
257foreign import _keyPath
244 :: ObjectStore
258 :: ObjectStore
245 -> Array String
259 -> Array String
246
260
261+
247foreign import _name
262foreign import _name
248 :: ObjectStore
263 :: ObjectStore
249 -> String
264 -> String
250
265
266+
251foreign import _put
267foreign import _put
252− :: forall val store
268+ :: forall e val store
253− . Fn3 store val (Nullable Foreign) (EffectFnAff Foreign)
269+ . Fn3 store val (Nullable Foreign) (Aff (idb :: IDB | e) Foreign)
270+
254
271
255foreign import _transaction
272foreign import _transaction
256 :: ObjectStore
273 :: ObjectStore
src/Database/IndexedDB/IDBTransaction.js+18−38
@@ -1,29 +1,25 @@
1−export function _abort(tx) {
1+exports._abort = function _abort(tx) {
2− return function aff(error, success) {
2+ return function aff(success, error) {
3 try {
3 try {
4 tx.abort();
4 tx.abort();
5 success();
5 success();
6 } catch (e) {
6 } catch (e) {
7− error(e);
7+ error(new Error(e.name));
8 }
8 }
9−
10− return function canceler(_, cancelerError) {
11− cancelerError(new Error("Can't cancel IDB Effects"));
12− };
13 };
9 };
14};
10};
15
11
16−export function _db(tx) {
12+exports._db = function _db(tx) {
17 return tx.db;
13 return tx.db;
18};
14};
19
15
20−export function _error(tx) {
16+exports._error = function _error(tx) {
21 return tx.error == null
17 return tx.error == null
22 ? null
18 ? null
23− : tx.error;
19+ : new Error(tx.error.name);
24};
20};
25
21
26−export function _mode(ReadOnly, ReadWrite, VersionChange, tx) {
22+exports._mode = function _mode(ReadOnly, ReadWrite, VersionChange, tx) {
27 if (tx.mode === 'readwrite') {
23 if (tx.mode === 'readwrite') {
28 return ReadWrite;
24 return ReadWrite;
29 } else if (tx.mode === 'versionchange') {
25 } else if (tx.mode === 'versionchange') {
@@ -33,60 +29,44 @@ export function _mode(ReadOnly, ReadWrite, VersionChange, tx) {
33 return ReadOnly;
29 return ReadOnly;
34};
30};
35
31
36−export function _objectStore(tx, name) {
32+exports._objectStore = function _objectStore(tx, name) {
37− return function aff(error, success) {
33+ return function aff(success, error) {
38 try {
34 try {
39 const store = tx.objectStore(name);
35 const store = tx.objectStore(name);
40 success(store);
36 success(store);
41 } catch (e) {
37 } catch (e) {
42− error(e);
38+ error(new Error(e.name));
43 }
39 }
44−
45− return function canceler(_, cancelerError) {
46− cancelerError(new Error("Can't cancel IDB Effects"));
47− };
48 };
40 };
49};
41};
50
42
51−export function _objectStoreNames(tx) {
43+exports._objectStoreNames = function _objectStoreNames(tx) {
52 return tx.objectStoreNames;
44 return tx.objectStoreNames;
53};
45};
54
46
55−export function _onAbort(tx, f) {
47+exports._onAbort = function _onAbort(tx, f) {
56− return function aff(error, success) {
48+ return function aff(success) {
57 tx.onabort = function onabort() {
49 tx.onabort = function onabort() {
58 f();
50 f();
59 };
51 };
60 success();
52 success();
61−
62− return function canceler(_, cancelerError) {
63− cancelerError(new Error("Can't cancel IDB Effects"));
64− };
65 };
53 };
66};
54};
67
55
68−export function _onComplete(tx, f) {
56+exports._onComplete = function _onComplete(tx, f) {
69− return function aff(error, success) {
57+ return function aff(success) {
70 tx.oncomplete = function oncomplete() {
58 tx.oncomplete = function oncomplete() {
71 f();
59 f();
72 };
60 };
73 success();
61 success();
74−
75− return function canceler(_, cancelerError) {
76− cancelerError(new Error("Can't cancel IDB Effects"));
77− };
78 };
62 };
79};
63};
80
64
81−export function _onError(tx, f) {
65+exports._onError = function _onError(tx, f) {
82− return function aff(error, success) {
66+ return function aff(success) {
83 tx.onerror = function onerror(e) {
67 tx.onerror = function onerror(e) {
84− f(e.target.error)();
68+ f(new Error(e.target.error.name))();
85 };
69 };
86 success();
70 success();
87−
88− return function canceler(_, cancelerError) {
89− cancelerError(new Error("Can't cancel IDB Effects"));
90− };
91 };
71 };
92};
72};
src/Database/IndexedDB/IDBTransaction.purs+59−40
@@ -14,17 +14,18 @@ module Database.IndexedDB.IDBTransaction
14 , onError
14 , onError
15 ) where
15 ) where
16
16
17+import Prelude (Unit, (>>>))
18+
19+import Control.Monad.Aff (Aff)
20+import Control.Monad.Eff (Eff)
21+import Control.Monad.Eff.Exception (Error)
22+import Data.Function.Uncurried as Fn
23+import Data.Function.Uncurried (Fn2, Fn4)
24+import Data.Maybe (Maybe)
25+import Data.Nullable (Nullable, toMaybe)
26+
17import Database.IndexedDB.Core
27import Database.IndexedDB.Core
18
28
19−import Data.Function.Uncurried (Fn2, Fn4)
20−import Data.Function.Uncurried as Fn
21−import Data.Maybe (Maybe)
22−import Data.Nullable (Nullable, toMaybe)
23−import Effect (Effect)
24−import Effect.Aff (Aff)
25−import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
26−import Effect.Exception (Error)
27−import Prelude (Unit, ($), (<<<), (>>>))
28
29
29--------------------
30--------------------
30-- INTERFACES
31-- INTERFACES
@@ -33,22 +34,22 @@ import Prelude (Unit, ($), (<<<), (>>>))
33-- | Aborts the transaction. All pending requests will fail with a "AbortError"
34-- | Aborts the transaction. All pending requests will fail with a "AbortError"
34-- | DOMException and all changes made to the database will be reverted.
35-- | DOMException and all changes made to the database will be reverted.
35abort
36abort
36− :: forall tx
37− . (IDBTransaction tx)
37+ :: forall e tx. (IDBTransaction tx)
38 => tx
38 => tx
39− -> Aff Unit
39+ -> Aff (idb :: IDB | e) Unit
40abort =
40abort =
41− fromEffectFnAff <<< _abort
41+ _abort
42+
42
43
43-- | Returns an IDBObjectStore in the transaction's scope.
44-- | Returns an IDBObjectStore in the transaction's scope.
44objectStore
45objectStore
45− :: forall tx
46− . (IDBTransaction tx)
46+ :: forall e tx. (IDBTransaction tx)
47 => tx
47 => tx
48 -> String
48 -> String
49− -> Aff ObjectStore
49+ -> Aff (idb :: IDB | e) ObjectStore
50objectStore tx name =
50objectStore tx name =
51− fromEffectFnAff $ Fn.runFn2 _objectStore tx name
51+ Fn.runFn2 _objectStore tx name
52+
52
53
53--------------------
54--------------------
54-- ATTRIBUTES
55-- ATTRIBUTES
@@ -61,6 +62,7 @@ db
61db =
62db =
62 _db
63 _db
63
64
65+
64-- | If the transaction was aborted, returns the error (a DOMException) providing the reason.
66-- | If the transaction was aborted, returns the error (a DOMException) providing the reason.
65error
67error
66 :: Transaction
68 :: Transaction
@@ -68,6 +70,7 @@ error
68error =
70error =
69 _error >>> toMaybe
71 _error >>> toMaybe
70
72
73+
71-- | Returns the mode the transaction was created with (`ReadOnly|ReadWrite`)
74-- | Returns the mode the transaction was created with (`ReadOnly|ReadWrite`)
72-- | , or `VersionChange` for an upgrade transaction.
75-- | , or `VersionChange` for an upgrade transaction.
73mode
76mode
@@ -76,6 +79,7 @@ mode
76mode =
79mode =
77 Fn.runFn4 _mode ReadOnly ReadWrite VersionChange
80 Fn.runFn4 _mode ReadOnly ReadWrite VersionChange
78
81
82+
79-- | Returns a list of the names of object stores in the transaction’s scope.
83-- | Returns a list of the names of object stores in the transaction’s scope.
80-- | For an upgrade transaction this is all object stores in the database.
84-- | For an upgrade transaction this is all object stores in the database.
81objectStoreNames
85objectStoreNames
@@ -84,70 +88,85 @@ objectStoreNames
84objectStoreNames =
88objectStoreNames =
85 _objectStoreNames
89 _objectStoreNames
86
90
91+
87--------------------
92--------------------
88-- EVENT HANDLERS
93-- EVENT HANDLERS
89--
94--
90
95
91-- | Event handler for the `abort` event.
96-- | Event handler for the `abort` event.
92onAbort
97onAbort
98+ :: forall e e'
93− :: Transaction
99+ . Transaction
94− -> Effect Unit
100+ -> Eff ( | e') Unit
95− -> Aff Unit
101+ -> Aff (idb :: IDB | e) Unit
96onAbort db' f =
102onAbort db' f =
97− fromEffectFnAff $ Fn.runFn2 _onAbort db' f
103+ Fn.runFn2 _onAbort db' f
104+
98
105
99-- | Event handler for the `complete` event.
106-- | Event handler for the `complete` event.
100onComplete
107onComplete
108+ :: forall e e'
101− :: Transaction
109+ . Transaction
102− -> Effect Unit
110+ -> Eff ( | e') Unit
103− -> Aff Unit
111+ -> Aff (idb :: IDB | e) Unit
104onComplete db' f =
112onComplete db' f =
105− fromEffectFnAff $ Fn.runFn2 _onComplete db' f
113+ Fn.runFn2 _onComplete db' f
114+
106
115
107-- | Event handler for the `error` event.
116-- | Event handler for the `error` event.
108onError
117onError
118+ :: forall e e'
109− :: Transaction
119+ . Transaction
110− -> (Error -> Effect Unit)
120+ -> (Error -> Eff ( | e') Unit)
111− -> Aff Unit
121+ -> Aff (idb :: IDB | e) Unit
112onError db' f =
122onError db' f =
113− fromEffectFnAff $ Fn.runFn2 _onError db' f
123+ Fn.runFn2 _onError db' f
124+
114
125
115--------------------
126--------------------
116-- FFI
127-- FFI
117--
128--
118
129
119foreign import _abort
130foreign import _abort
120− :: forall tx
131+ :: forall tx e
121− . tx
132+ . tx
122− -> EffectFnAff Unit
133+ -> Aff (idb :: IDB | e) Unit
134+
123
135
124foreign import _db
136foreign import _db
125 :: Transaction
137 :: Transaction
126 -> Database
138 -> Database
127
139
140+
128foreign import _error
141foreign import _error
129 :: Transaction
142 :: Transaction
130 -> (Nullable Error)
143 -> (Nullable Error)
131
144
145+
132foreign import _mode
146foreign import _mode
133 :: Fn4 TransactionMode TransactionMode TransactionMode Transaction TransactionMode
147 :: Fn4 TransactionMode TransactionMode TransactionMode Transaction TransactionMode
134
148
149+
135foreign import _objectStoreNames
150foreign import _objectStoreNames
136 :: Transaction
151 :: Transaction
137 -> Array String
152 -> Array String
138
153
154+
139foreign import _objectStore
155foreign import _objectStore
140− :: forall tx
156+ :: forall tx e
141− . Fn2 tx String (EffectFnAff ObjectStore)
157+ . Fn2 tx String (Aff (idb :: IDB | e) ObjectStore)
158+
142
159
143foreign import _onAbort
160foreign import _onAbort
144− :: forall tx
161+ :: forall tx e e'
145− . Fn2 tx (Effect Unit) (EffectFnAff Unit)
162+ . Fn2 tx (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
163+
146
164
147foreign import _onComplete
165foreign import _onComplete
148− :: forall tx
166+ :: forall tx e e'
149− . Fn2 tx (Effect Unit) (EffectFnAff Unit)
167+ . Fn2 tx (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
168+
150
169
151foreign import _onError
170foreign import _onError
152− :: forall tx
171+ :: forall tx e e'
153− . Fn2 tx (Error -> Effect Unit) (EffectFnAff Unit)
172+ . Fn2 tx (Error -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
test/Main.purs+904−974
@@ -2,1060 +2,995 @@ module Test.Main where
2
2
3import Prelude
3import Prelude
4
4
5−import Data.Array (head, drop)
5+import Control.Monad.Aff (Aff, launchAff, forkAff, delay, attempt)
6+import Control.Monad.Aff.AVar (AVAR, makeVar, makeVar', modifyVar, peekVar, putVar, takeVar)
7+import Control.Monad.Aff.Console (log)
8+import Control.Monad.Eff (Eff)
9+import Control.Monad.Eff.Class (liftEff)
10+import Control.Monad.Eff.Exception (EXCEPTION, message)
11+import Control.Monad.Eff.Now (NOW, now)
6−import Data.Date as Date
12+import Data.Date as Date
7−import Data.DateTime (DateTime(..), Time(..))
13+import Data.DateTime as DateTime
14+import Data.DateTime (DateTime(..), Time(..))
8−import Data.DateTime.Instant (toDateTime)
15+import Data.DateTime.Instant (toDateTime)
9−import Data.Either (Either(..))
16+import Data.Either (Either(..))
10−import Data.Enum (toEnum)
17+import Data.Enum (toEnum)
11−import Data.Maybe (Maybe(..), isNothing, maybe)
18+import Data.Maybe (Maybe(..), isNothing, maybe)
19+import Data.Array (head, drop)
12−import Data.Time.Duration (Milliseconds(..))
20+import Data.Time.Duration (Milliseconds(..))
13−import Data.Traversable (traverse)
21+import Data.Traversable (traverse)
14−import Data.Tuple (Tuple(..), uncurry)
22+import Data.Tuple (Tuple(..), uncurry)
15−import Database.IndexedDB.Core (CursorDirection(..), Database, Index, ObjectStore, Transaction, TransactionMode(..))
16−import Database.IndexedDB.IDBCursor as IDBCursor
17−import Database.IndexedDB.IDBDatabase as IDBDatabase
18−import Database.IndexedDB.IDBFactory as IDBFactory
19−import Database.IndexedDB.IDBIndex as IDBIndex
20−import Database.IndexedDB.IDBKey (Key, none, toKey)
21−import Database.IndexedDB.IDBKeyRange as IDBKeyRange
22−import Database.IndexedDB.IDBObjectStore as IDBObjectStore
23−import Database.IndexedDB.IDBTransaction as IDBTransaction
24−import Effect (Effect)
25−import Effect.Aff (Aff, attempt, delay, forkAff, launchAff, launchAff_)
26−import Effect.Aff.AVar (AVar)
27−import Effect.Aff.AVar as AVar
28−import Effect.Class (liftEffect)
29−import Effect.Console (log)
30−import Effect.Exception (name)
31−import Effect.Now (now)
32−import Test.Spec (describe, it)
23+import Test.Spec (describe, describeOnly, it)
33−import Test.Spec.Assertions (shouldEqual, fail)
24+import Test.Spec.Assertions (shouldEqual, fail)
34−import Test.Spec.Reporter (consoleReporter)
25+import Test.Spec.Mocha (MOCHA, runMocha)
35−import Test.Spec.Runner (runSpec)
26+
27+import Database.IndexedDB.Core
28+import Database.IndexedDB.IDBKey
29+import Database.IndexedDB.IDBCursor as IDBCursor
30+import Database.IndexedDB.IDBDatabase as IDBDatabase
31+import Database.IndexedDB.IDBFactory as IDBFactory
32+import Database.IndexedDB.IDBIndex as IDBIndex
33+import Database.IndexedDB.IDBKeyRange as IDBKeyRange
34+import Database.IndexedDB.IDBObjectStore as IDBObjectStore
35+import Database.IndexedDB.IDBTransaction as IDBTransaction
36
36
37−infixr 7 Tuple as :+:
38
37
39−launchAff' :: forall a. Aff a -> Effect Unit
38+infixr 7 Tuple as :+:
40−launchAff' =
41− launchAff_ <<< void
42
39
43−modifyAVar :: forall a. (a -> a) -> AVar a -> Aff Unit
40+launchAff' :: forall a e. Aff e a -> Eff (exception :: EXCEPTION | e) Unit
44−modifyAVar fn v = do
41+launchAff' aff =
45− val <- AVar.take v
42+ pure unit <* (launchAff aff)
46− AVar.put (fn val) v
47
43
48−main :: Effect Unit
44+-- main :: forall eff. Eff (now :: NOW, mocha :: MOCHA, idb :: IDB, exception :: EXCEPTION, avar :: AVAR | eff) Unit
49−main = do
45+main = runMocha do
50− launchAff_ $ runSpec [ consoleReporter ] $ do
51− describe "IDBFactory" do
46+ describe "IDBFactory" do
52− let
47+ let
53 tearDown name version db = do
48 tearDown name version db = do
54 IDBDatabase.close db
49 IDBDatabase.close db
55 version' <- IDBFactory.deleteDatabase name
50 version' <- IDBFactory.deleteDatabase name
56− liftEffect $ log $ show version'
57 version' `shouldEqual` version
51 version' `shouldEqual` version
58
52
59− it "open default" do
53+ it "open default" do
60− let
61− name = "db-default"
54+ let name = "db-default"
62 version = 1
55 version = 1
63− db <- IDBFactory.open name Nothing
56+ db <- IDBFactory.open name Nothing
64− { onUpgradeNeeded: Nothing
57+ { onUpgradeNeeded : Nothing
65− , onBlocked: Nothing
58+ , onBlocked : Nothing
66− }
59+ }
67− IDBDatabase.name db `shouldEqual` name
60+ IDBDatabase.name db `shouldEqual` name
68− tearDown name version db
61+ tearDown name version db
69
62
70− it "open specific version" do
71− let
72− name = "db-specific"
73− version = 14
74− db <- IDBFactory.open name (Just version)
75− { onUpgradeNeeded: Nothing
76− , onBlocked: Nothing
77− }
78− IDBDatabase.name db `shouldEqual` name
79− tearDown name version db
80
63
81− it "open specific version -> close -> open latest" do
64+ it "open specific version" do
82− let
83− name = "db-latest"
65+ let name = "db-specific"
84 version = 14
66 version = 14
85− db01 <- IDBFactory.open name (Just version)
67+ db <- IDBFactory.open name (Just version)
86− { onUpgradeNeeded: Nothing
68+ { onUpgradeNeeded : Nothing
87− , onBlocked: Nothing
69+ , onBlocked : Nothing
88− }
70+ }
89− IDBDatabase.name db01 `shouldEqual` name
71+ IDBDatabase.name db `shouldEqual` name
90− IDBDatabase.close db01
91− db02 <- IDBFactory.open name Nothing
92− { onUpgradeNeeded: Nothing
93− , onBlocked: Nothing
94− }
95− tearDown name version db02
72+ tearDown name version db
96
73
74+
75+ it "open specific version -> close -> open latest" do
76+ let name = "db-latest"
77+ version = 14
78+ db <- IDBFactory.open name (Just version)
79+ { onUpgradeNeeded : Nothing
80+ , onBlocked : Nothing
81+ }
82+ IDBDatabase.name db `shouldEqual` name
83+ IDBDatabase.close db
84+ db <- IDBFactory.open name Nothing
85+ { onUpgradeNeeded : Nothing
86+ , onBlocked : Nothing
87+ }
88+ tearDown name version db
89+
90+
97− it "open + onUpgradeNeed" do
91+ it "open + onUpgradeNeed" do
98− let
99− name = "db-upgrade-needed"
92+ let name = "db-upgrade-needed"
100 version = 1
93 version = 1
101− callback (Tuple varName varVersion) db _ { oldVersion } = do
94+ callback var db _ = do
102− _ <- launchAff $ modifyAVar (const $ IDBDatabase.name db) varName
95+ _ <- launchAff $ modifyVar (const $ IDBDatabase.name db) var
103− _ <- launchAff $ modifyAVar (const $ oldVersion) varVersion
104 pure unit
96 pure unit
105− varName <- AVar.new "-"
97+ var <- makeVar' "-"
106− varVersion <- AVar.new (-1)
107− db <- IDBFactory.open name Nothing
98+ db <- IDBFactory.open name Nothing
108− { onUpgradeNeeded: Just (callback (Tuple varName varVersion))
99+ { onUpgradeNeeded : Just (callback var)
109− , onBlocked: Nothing
100+ , onBlocked : Nothing
110− }
101+ }
111− name' <- AVar.read varName
102+ name <- peekVar var
112− version' <- AVar.read varVersion
113− name' `shouldEqual` name
103+ name `shouldEqual` name
114− version' `shouldEqual` 0
115− tearDown name version db
104+ tearDown name version db
116−
105+
106+
117− it "open + onBlocked" do
107+ it "open + onBlocked" do
118− let
119− name = "db-blocked"
108+ let name = "db-blocked"
120 version = 14
109 version = 14
121 callback var = do
110 callback var = do
122− _ <- launchAff $ modifyAVar (const $ "db-blocked") var
111+ _ <- launchAff $ modifyVar (const $ "db-blocked") var
123 pure unit
112 pure unit
124
113
125− var <- AVar.new "-"
114+ var <- makeVar' "-"
126− db01 <- IDBFactory.open name Nothing
115+ db01 <- IDBFactory.open name Nothing
127− { onUpgradeNeeded: Nothing
116+ { onUpgradeNeeded : Nothing
128− , onBlocked: Nothing
117+ , onBlocked : Nothing
129− }
118+ }
130− _ <- forkAff do
119+ _ <- forkAff do
131− delay (Milliseconds 100.0)
120+ delay (Milliseconds 100.0)
132− IDBDatabase.close db01
121+ IDBDatabase.close db01
133
122
134− db02 <- IDBFactory.open name (Just version)
123+ db02 <- IDBFactory.open name (Just version)
135− { onUpgradeNeeded: Nothing
124+ { onUpgradeNeeded : Nothing
136− , onBlocked: Just (callback var)
125+ , onBlocked : Just (callback var)
137− }
126+ }
138− name' <- AVar.read var
127+ name <- peekVar var
139− name' `shouldEqual` name
128+ name `shouldEqual` name
140− tearDown name version db02
129+ tearDown name version db02
141−
130+
142− describe "IDBKeyRange" do
131+ describe "IDBKeyRange" do
143− it "only(int)" do
132+ it "only(int)" do
144− let
145− key = 14
133+ let key = 14
146 range = IDBKeyRange.only key
134 range = IDBKeyRange.only key
147− IDBKeyRange.includes range (toKey key) `shouldEqual` true
135+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
148
136
149− it "only(string)" do
137+ it "only(string)" do
150− let
151− key = "patate"
138+ let key = "patate"
152 range = IDBKeyRange.only key
139 range = IDBKeyRange.only key
153− IDBKeyRange.includes range (toKey key) `shouldEqual` true
140+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
154
141
155− it "only(float)" do
142+ it "only(float)" do
156− let
157− key = 14.42
143+ let key = 14.42
158 range = IDBKeyRange.only key
144 range = IDBKeyRange.only key
159− IDBKeyRange.includes range (toKey key) `shouldEqual` true
145+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
160
146
161− it "only(date)" do
147+ it "only(date)" do
162− let
163− mkey = DateTime
148+ let mkey = DateTime
164 <$> (Date.canonicalDate <$> toEnum 2017 <*> toEnum 6 <*> toEnum 23)
149 <$> (Date.canonicalDate <$> toEnum 2017 <*> toEnum 6 <*> toEnum 23)
165 <*> (Time <$> toEnum 17 <*> toEnum 59 <*> toEnum 34 <*> toEnum 42)
150 <*> (Time <$> toEnum 17 <*> toEnum 59 <*> toEnum 34 <*> toEnum 42)
166
151
167− case mkey of
152+ case mkey of
168− Nothing ->
153+ Nothing ->
169− fail "unable to create datetime"
154+ fail "unable to create datetime"
170− Just key -> do
155+ Just key -> do
171− let range = IDBKeyRange.only key
156+ let range = IDBKeyRange.only key
172− IDBKeyRange.includes range (toKey key) `shouldEqual` true
157+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
173
158
174− it "only([int])" do
159+ it "only([int])" do
175− let
176− key = [ 14, 42 ]
160+ let key = [14, 42]
177 range = IDBKeyRange.only key
161 range = IDBKeyRange.only key
178− IDBKeyRange.includes range (toKey key) `shouldEqual` true
162+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
179
163
180− it "only([string])" do
164+ it "only([string])" do
181− let
182− key = [ "patate", "autruche" ]
165+ let key = ["patate", "autruche"]
183 range = IDBKeyRange.only key
166 range = IDBKeyRange.only key
184− IDBKeyRange.includes range (toKey key) `shouldEqual` true
167+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
185
168
186− it "lowerBound(14, open)" do
169+ it "lowerBound(14, open)" do
187− let
188− key = 14
170+ let key = 14
189− open = true
171+ open = true
190 range = IDBKeyRange.lowerBound key open
172 range = IDBKeyRange.lowerBound key open
191− IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` true
173+ IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` true
192− IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
174+ IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
193− IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` false
175+ IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` false
194−
176+
195− it "lowerBound(14, close)" do
177+ it "lowerBound(14, close)" do
196− let
197− key = 14
178+ let key = 14
198− open = false
179+ open = false
199 range = IDBKeyRange.lowerBound key open
180 range = IDBKeyRange.lowerBound key open
200− IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` true
181+ IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` true
201− IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
182+ IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
202− IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` false
183+ IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` false
203−
184+
204− it "upperBound(14, open)" do
185+ it "upperBound(14, open)" do
205− let
206− key = 14
186+ let key = 14
207− open = true
187+ open = true
208 range = IDBKeyRange.upperBound key open
188 range = IDBKeyRange.upperBound key open
209− IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` false
189+ IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` false
210− IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
190+ IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
211− IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` true
191+ IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` true
212−
192+
213− it "upperBound(14, close)" do
193+ it "upperBound(14, close)" do
214− let
215− key = 14
194+ let key = 14
216− open = false
195+ open = false
217 range = IDBKeyRange.upperBound key open
196 range = IDBKeyRange.upperBound key open
218− IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` false
197+ IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` false
219− IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
198+ IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
220− IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` true
199+ IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` true
221−
200+
222− it "bound(42, 14, open, open) => Nothing" do
201+ it "bound(42, 14, open, open) => Nothing" do
223− let
224− lower = 42
202+ let lower = 42
225− upper = 14
203+ upper = 14
226 lowerOpen = true
204 lowerOpen = true
227 upperOpen = true
205 upperOpen = true
228− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
206+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
229− isNothing mrange `shouldEqual` true
207+ isNothing mrange `shouldEqual` true
230
208
231− it "bound(14, 42, open, open)" do
209+ it "bound(14, 42, open, open)" do
232− let
233− lower = 14
210+ let lower = 14
234− upper = 42
211+ upper = 42
235 lowerOpen = true
212 lowerOpen = true
236 upperOpen = true
213 upperOpen = true
237− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
214+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
238− case mrange of
215+ case mrange of
239− Nothing ->
216+ Nothing ->
240− fail "invalid range provided"
217+ fail "invalid range provided"
241− Just range -> do
218+ Just range -> do
242− IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
219+ IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
243− IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
220+ IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
244− IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
221+ IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
245− IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
222+ IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
246− IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
223+ IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
247− IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
224+ IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
248−
225+
249− it "bound(14, 42, open, close)" do
226+ it "bound(14, 42, open, close)" do
250− let
251− lower = 14
227+ let lower = 14
252− upper = 42
228+ upper = 42
253 lowerOpen = true
229 lowerOpen = true
254 upperOpen = false
230 upperOpen = false
255− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
231+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
256− case mrange of
232+ case mrange of
257− Nothing ->
233+ Nothing ->
258− fail "invalid range provided"
234+ fail "invalid range provided"
259− Just range -> do
235+ Just range -> do
260− IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
236+ IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
261− IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
237+ IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
262− IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
238+ IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
263− IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
239+ IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
264− IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
240+ IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
265− IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
241+ IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
266−
242+
267− it "bound(14, 42, close, open)" do
243+ it "bound(14, 42, close, open)" do
268− let
269− lower = 14
244+ let lower = 14
270− upper = 42
245+ upper = 42
271 lowerOpen = false
246 lowerOpen = false
272 upperOpen = true
247 upperOpen = true
273− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
248+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
274− case mrange of
249+ case mrange of
275− Nothing ->
250+ Nothing ->
276− fail "invalid range provided"
251+ fail "invalid range provided"
277− Just range -> do
252+ Just range -> do
278− IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
253+ IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
279− IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
254+ IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
280− IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
255+ IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
281− IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
256+ IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
282− IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
257+ IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
283− IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
258+ IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
284−
259+
285− it "bound(14, 42, close, close)" do
260+ it "bound(14, 42, close, close)" do
286− let
287− lower = 14
261+ let lower = 14
288− upper = 42
262+ upper = 42
289 lowerOpen = false
263 lowerOpen = false
290 upperOpen = false
264 upperOpen = false
291− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
265+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
292− case mrange of
266+ case mrange of
293− Nothing ->
267+ Nothing ->
294− fail "invalid range provided"
268+ fail "invalid range provided"
295− Just range -> do
269+ Just range -> do
296− IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
270+ IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
297− IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
271+ IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
298− IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
272+ IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
299− IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
273+ IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
300− IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
274+ IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
301− IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
275+ IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
302−
276+
303− it "can access attributes of a range" do
277+ it "can access attributes of a range" do
304− let range = IDBKeyRange.lowerBound 14 false
278+ let range = IDBKeyRange.lowerBound 14 false
305− IDBKeyRange.lower range `shouldEqual` (Just $ toKey 14)
279+ IDBKeyRange.lower range `shouldEqual` (Just $ toKey 14)
306− IDBKeyRange.upper range `shouldEqual` none
280+ IDBKeyRange.upper range `shouldEqual` none
307− IDBKeyRange.lowerOpen range `shouldEqual` false
281+ IDBKeyRange.lowerOpen range `shouldEqual` false
308− IDBKeyRange.upperOpen range `shouldEqual` true
282+ IDBKeyRange.upperOpen range `shouldEqual` true
309−
283+
310− describe "IDBDatabase" do
284+ describe "IDBDatabase" do
311− let
285+ let
312 tearDown db = do
286 tearDown db = do
313 IDBDatabase.close db
287 IDBDatabase.close db
314 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
288 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
315 pure unit
289 pure unit
316
290
317 setup storeParams = do
291 setup storeParams = do
318− let
319− onUpgradeNeeded var db _ _ = launchAff' do
292+ let onUpgradeNeeded var db _ = launchAff' do
320− store <- IDBDatabase.createObjectStore db "store" storeParams
293+ store <- IDBDatabase.createObjectStore db "store" storeParams
321− _ <- AVar.put { db, store } var
294+ _ <- putVar var { db, store }
322− pure unit
295+ pure unit
323−
296+
324− var <- AVar.empty
297+ var <- makeVar
325− _ <- IDBFactory.open "db" Nothing
298+ db <- IDBFactory.open "db" Nothing
326− { onUpgradeNeeded: Just (onUpgradeNeeded var)
299+ { onUpgradeNeeded : Just (onUpgradeNeeded var)
327− , onBlocked: Nothing
300+ , onBlocked : Nothing
328 }
301 }
329
302
330− AVar.take var
303+ takeVar var
331−
304+
332− it "createObjectStore (keyPath: [], autoIncrement: true)" do
305+ it "createObjectStore (keyPath: [], autoIncrement: true)" do
333− { db, store } <- setup { keyPath: [], autoIncrement: true }
306+ { db, store } <- setup { keyPath: [], autoIncrement: true }
334− IDBObjectStore.name store `shouldEqual` "store"
307+ IDBObjectStore.name store `shouldEqual` "store"
335− IDBObjectStore.keyPath store `shouldEqual` []
308+ IDBObjectStore.keyPath store `shouldEqual` []
336− IDBObjectStore.autoIncrement store `shouldEqual` true
309+ IDBObjectStore.autoIncrement store `shouldEqual` true
337− IDBObjectStore.indexNames store `shouldEqual` []
310+ IDBObjectStore.indexNames store `shouldEqual` []
338− tearDown db
311+ tearDown db
339−
312+
340− it "createObjectStore (keyPath: [\"patate\"], autoIncrement: true)" do
313+ it "createObjectStore (keyPath: [\"patate\"], autoIncrement: true)" do
341− { db, store } <- setup { keyPath: [ "patate" ], autoIncrement: true }
314+ { db, store } <- setup { keyPath: ["patate"], autoIncrement: true }
342− IDBObjectStore.name store `shouldEqual` "store"
315+ IDBObjectStore.name store `shouldEqual` "store"
343− IDBObjectStore.keyPath store `shouldEqual` [ "patate" ]
316+ IDBObjectStore.keyPath store `shouldEqual` ["patate"]
344− IDBObjectStore.autoIncrement store `shouldEqual` true
317+ IDBObjectStore.autoIncrement store `shouldEqual` true
345− IDBObjectStore.indexNames store `shouldEqual` []
318+ IDBObjectStore.indexNames store `shouldEqual` []
346− tearDown db
319+ tearDown db
347−
320+
348− it "createObjectStore (keyPath: [\"a\", \"b\"], autoIncrement: false)" do
321+ it "createObjectStore (keyPath: [\"a\", \"b\"], autoIncrement: false)" do
349− { db, store } <- setup { keyPath: [ "patate", "autruche" ], autoIncrement: false }
322+ { db, store } <- setup { keyPath: ["patate", "autruche"], autoIncrement: false }
350− IDBObjectStore.name store `shouldEqual` "store"
323+ IDBObjectStore.name store `shouldEqual` "store"
351− IDBObjectStore.keyPath store `shouldEqual` [ "patate", "autruche" ]
324+ IDBObjectStore.keyPath store `shouldEqual` ["patate", "autruche"]
352− IDBObjectStore.autoIncrement store `shouldEqual` false
325+ IDBObjectStore.autoIncrement store `shouldEqual` false
353− IDBObjectStore.indexNames store `shouldEqual` []
326+ IDBObjectStore.indexNames store `shouldEqual` []
354− tearDown db
327+ tearDown db
355−
328+
356− it "deleteObjectStore" do
329+ it "deleteObjectStore" do
357− let
358− onUpgradeNeeded var db _ _ = launchAff' do
330+ let onUpgradeNeeded var db _ = launchAff' do
359 _ <- IDBDatabase.deleteObjectStore db "store"
331 _ <- IDBDatabase.deleteObjectStore db "store"
360− AVar.put true var
332+ putVar var true
361−
333+
362− var <- AVar.empty
334+ var <- makeVar
363− { db } <- setup IDBDatabase.defaultParameters
335+ { db, store } <- setup IDBDatabase.defaultParameters
364− IDBDatabase.close db
336+ IDBDatabase.close db
365− db' <- IDBFactory.open "db" (Just 999)
366− { onUpgradeNeeded: Just (onUpgradeNeeded var)
337+ db <- IDBFactory.open "db" (Just 999) { onUpgradeNeeded : Just (onUpgradeNeeded var)
367− , onBlocked: Nothing
338+ , onBlocked : Nothing
368− }
339+ }
369− deleted <- AVar.take var
340+ deleted <- takeVar var
370− deleted `shouldEqual` true
341+ deleted `shouldEqual` true
371− tearDown db'
342+ tearDown db
372
343
344+
373− describe "IDBObjectStore" do
345+ describe "IDBObjectStore" do
374− let
346+ let
375 tearDown db = do
347 tearDown db = do
376 IDBDatabase.close db
348 IDBDatabase.close db
377 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
349 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
378 pure unit
350 pure unit
379
351
380 setup { storeParams, onUpgradeNeeded } = do
352 setup { storeParams, onUpgradeNeeded } = do
381− let
382− onUpgradeNeeded' var db _ _ = launchAff' do
353+ let onUpgradeNeeded' var db _ = launchAff' do
383− store <- IDBDatabase.createObjectStore db "store" storeParams
354+ store <- IDBDatabase.createObjectStore db "store" storeParams
384− liftEffect $ maybe (pure unit) identity (onUpgradeNeeded <*> pure db <*> pure store)
355+ liftEff $ maybe (pure unit) id (onUpgradeNeeded <*> pure db <*> pure store)
385− AVar.put { db, store } var
356+ putVar var { db, store }
386−
357+
387− var <- AVar.empty
358+ var <- makeVar
388− _ <- IDBFactory.open "db" Nothing
359+ db <- IDBFactory.open "db" Nothing
389− { onUpgradeNeeded: Just (onUpgradeNeeded' var)
360+ { onUpgradeNeeded : Just (onUpgradeNeeded' var)
390− , onBlocked: Nothing
361+ , onBlocked : Nothing
391 }
362 }
392
363
393− AVar.take var
364+ takeVar var
394−
365+
395− it "add()" do
366+ it "add()" do
396− date <- liftEffect $ toDateTime <$> now
367+ date <- liftEff $ toDateTime <$> now
397− { db } <- setup
368+ { db } <- setup
398− { storeParams: { autoIncrement: true, keyPath: [] }
369+ { storeParams: { autoIncrement: true, keyPath: [] }
399− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
370+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
400− -- no key
371+ -- no key
401− key <- IDBObjectStore.add store "patate" none
372+ key <- IDBObjectStore.add store "patate" none
402− (toKey 1) `shouldEqual` key
373+ (toKey 1) `shouldEqual` key
403−
374+
404− -- int key
375+ -- int key
405− key' <- IDBObjectStore.add store "patate" (Just 14)
376+ key <- IDBObjectStore.add store "patate" (Just 14)
406− (toKey 14) `shouldEqual` key'
377+ (toKey 14) `shouldEqual` key
407−
378+
408− -- number key
379+ -- number key
409− key'' <- IDBObjectStore.add store "patate" (Just 14.42)
380+ key <- IDBObjectStore.add store "patate" (Just 14.42)
410− (toKey 14.42) `shouldEqual` key''
381+ (toKey 14.42) `shouldEqual` key
411−
382+
412− -- string key
383+ -- string key
413− key''' <- IDBObjectStore.add store "patate" (Just "key")
384+ key <- IDBObjectStore.add store "patate" (Just "key")
414− (toKey "key") `shouldEqual` key'''
385+ (toKey "key") `shouldEqual` key
415−
386+
416− -- date key
387+ -- date key
417− key'''' <- IDBObjectStore.add store "patate" (Just date)
388+ key <- IDBObjectStore.add store "patate" (Just date)
418− (toKey date) `shouldEqual` key''''
389+ (toKey date) `shouldEqual` key
419−
390+
420− -- array key
391+ -- array key
421− key''''' <- IDBObjectStore.add store "patate" (Just $ toKey [ 14, 42 ])
392+ key <- IDBObjectStore.add store "patate" (Just $ toKey [14, 42])
422− (toKey [ 14, 42 ]) `shouldEqual` key'''''
393+ (toKey [14, 42]) `shouldEqual` key
423− }
394+ }
424− tearDown db
395+ tearDown db
425−
396+
426− it "clear()" do
397+ it "clear()" do
427− { db } <- setup
398+ { db } <- setup
428− { storeParams: IDBDatabase.defaultParameters
399+ { storeParams: IDBDatabase.defaultParameters
429− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
400+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
430− key <- IDBObjectStore.add store "patate" (Just 14)
401+ key <- IDBObjectStore.add store "patate" (Just 14)
431− _ <- IDBObjectStore.clear store
402+ _ <- IDBObjectStore.clear store
432− val <- IDBObjectStore.get store (IDBKeyRange.only key)
403+ val <- IDBObjectStore.get store (IDBKeyRange.only key)
433− val `shouldEqual` (Nothing :: Maybe String)
404+ val `shouldEqual` (Nothing :: Maybe String)
405+ }
406+ tearDown db
407+
408+ it "count()" do
409+ { db } <- setup
410+ { storeParams: IDBDatabase.defaultParameters
411+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
412+ key <- IDBObjectStore.add store "patate" (Just 14)
413+ key <- IDBObjectStore.add store "autruche" (Just 42)
414+ n <- IDBObjectStore.count store Nothing
415+ n `shouldEqual` 2
416+ }
417+ tearDown db
418+
419+ it "getKey()" do
420+ { db } <- setup
421+ { storeParams: IDBDatabase.defaultParameters
422+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
423+ key <- IDBObjectStore.add store "patate" (Just 14)
424+ mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 14)
425+ mkey `shouldEqual` (Just key)
426+
427+ mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 42)
428+ mkey `shouldEqual` none
434 }
429 }
435− tearDown db
436−
437− it "count()" do
438− { db } <- setup
439− { storeParams: IDBDatabase.defaultParameters
440− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
441− _ <- IDBObjectStore.add store "patate" (Just 14)
442− _ <- IDBObjectStore.add store "autruche" (Just 42)
443− n <- IDBObjectStore.count store Nothing
444− n `shouldEqual` 2
445− }
446− tearDown db
430+ tearDown db
447−
431+
448− it "getKey()" do
432+ it "getAllKeys()" do
449− { db } <- setup
433+ { db } <- setup
450− { storeParams: IDBDatabase.defaultParameters
434+ { storeParams: IDBDatabase.defaultParameters
451− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
452− key <- IDBObjectStore.add store "patate" (Just 14)
453− mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 14)
454− mkey `shouldEqual` (Just key)
455−
456− mkey' <- IDBObjectStore.getKey store (IDBKeyRange.only 42)
457− mkey' `shouldEqual` none
458− }
459− tearDown db
460−
461− it "getAllKeys()" do
462− { db } <- setup
463− { storeParams: IDBDatabase.defaultParameters
464− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
435+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
465− key1 <- IDBObjectStore.add store "patate" (Just 14)
436+ key1 <- IDBObjectStore.add store "patate" (Just 14)
466− key2 <- IDBObjectStore.add store "autruche" (Just 42)
437+ key2 <- IDBObjectStore.add store "autruche" (Just 42)
467− key3 <- IDBObjectStore.add store 14 (Just 1337)
438+ key3 <- IDBObjectStore.add store 14 (Just 1337)
468−
439+
469− -- no bounds
440+ -- no bounds
470− keys <- IDBObjectStore.getAllKeys store Nothing Nothing
441+ keys <- IDBObjectStore.getAllKeys store Nothing Nothing
471− keys `shouldEqual` [ key1, key2, key3 ]
442+ keys `shouldEqual` [key1, key2, key3]
472−
443+
473− -- lower bound
444+ -- lower bound
474− keys' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 14 true) Nothing
445+ keys <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 14 true) Nothing
475− keys' `shouldEqual` [ key2, key3 ]
446+ keys `shouldEqual` [key2, key3]
476−
447+
477− -- upper bound
448+ -- upper bound
478− keys'' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.upperBound 42 false) Nothing
449+ keys <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.upperBound 42 false) Nothing
479− keys'' `shouldEqual` [ key1, key2 ]
450+ keys `shouldEqual` [key1, key2]
480−
451+
481− -- count
452+ -- count
482− keys''' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 1 true) (Just 2)
453+ keys <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 1 true) (Just 2)
483− keys''' `shouldEqual` [ key1, key2 ]
454+ keys `shouldEqual` [key1, key2]
484− }
455+ }
485− tearDown db
456+ tearDown db
486−
457+
487− it "openCursor()" do
458+ it "openCursor()" do
488− let
459+ let cb =
489− cb =
490− { onSuccess: const $ pure unit
460+ { onSuccess : const $ pure unit
491− , onError: show >>> fail >>> launchAff'
461+ , onError : show >>> fail >>> launchAff'
492 , onComplete: pure unit
462 , onComplete: pure unit
493 }
463 }
494− { db } <- setup
464+ { db } <- setup
495− { storeParams: IDBDatabase.defaultParameters
465+ { storeParams: IDBDatabase.defaultParameters
496− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
466+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
497− _ <- IDBObjectStore.openCursor store Nothing Next cb
467+ _ <- IDBObjectStore.openCursor store Nothing Next cb
498− _ <- IDBObjectStore.openCursor store Nothing NextUnique cb
468+ _ <- IDBObjectStore.openCursor store Nothing NextUnique cb
499− _ <- IDBObjectStore.openCursor store Nothing Prev cb
469+ _ <- IDBObjectStore.openCursor store Nothing Prev cb
500− _ <- IDBObjectStore.openCursor store Nothing PrevUnique cb
470+ _ <- IDBObjectStore.openCursor store Nothing PrevUnique cb
501− _ <- IDBObjectStore.openCursor store (Just $ IDBKeyRange.upperBound 1 true) Next cb
471+ _ <- IDBObjectStore.openCursor store (Just $ IDBKeyRange.upperBound 1 true) Next cb
502− pure unit
472+ pure unit
503− }
473+ }
504− tearDown db
474+ tearDown db
505
475
506− it "openKeyCursor()" do
476+ it "openKeyCursor()" do
507− let
477+ let cb =
508− cb =
509− { onSuccess: const $ pure unit
478+ { onSuccess : const $ pure unit
510− , onError: show >>> fail >>> launchAff'
479+ , onError : show >>> fail >>> launchAff'
511 , onComplete: pure unit
480 , onComplete: pure unit
512 }
481 }
513− { db } <- setup
482+ { db } <- setup
514− { storeParams: IDBDatabase.defaultParameters
483+ { storeParams: IDBDatabase.defaultParameters
515− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
484+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
516− _ <- IDBObjectStore.openKeyCursor store Nothing Next cb
485+ _ <- IDBObjectStore.openKeyCursor store Nothing Next cb
517− _ <- IDBObjectStore.openKeyCursor store Nothing NextUnique cb
486+ _ <- IDBObjectStore.openKeyCursor store Nothing NextUnique cb
518− _ <- IDBObjectStore.openKeyCursor store Nothing Prev cb
487+ _ <- IDBObjectStore.openKeyCursor store Nothing Prev cb
519− _ <- IDBObjectStore.openKeyCursor store Nothing PrevUnique cb
488+ _ <- IDBObjectStore.openKeyCursor store Nothing PrevUnique cb
520− _ <- IDBObjectStore.openKeyCursor store (Just $ IDBKeyRange.lowerBound 1 true) Next cb
489+ _ <- IDBObjectStore.openKeyCursor store (Just $ IDBKeyRange.lowerBound 1 true) Next cb
521− pure unit
490+ pure unit
522− }
491+ }
523− tearDown db
492+ tearDown db
524
493
525− describe "IDBIndex" do
494+ describe "IDBIndex" do
526− let
495+ let
527 tearDown db = do
496 tearDown db = do
528 IDBDatabase.close db
497 IDBDatabase.close db
529 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
498 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
530 pure unit
499 pure unit
531
500
532− setup
533− :: forall value
501+ setup :: forall value e e'.
534− . { storeParams :: { keyPath :: Array String, autoIncrement :: Boolean }
502+ { storeParams :: { keyPath :: Array String, autoIncrement :: Boolean }
535− , indexParams :: { unique :: Boolean, multiEntry :: Boolean }
503+ , indexParams :: { unique :: Boolean, multiEntry :: Boolean }
536− , values :: Array (Tuple value (Maybe Key))
504+ , values :: Array (Tuple value (Maybe Key))
537− , keyPath :: Array String
505+ , keyPath :: Array String
538− , onUpgradeNeeded :: Maybe (Database -> Transaction -> Index -> Effect Unit)
506+ , onUpgradeNeeded :: Maybe (Database -> Transaction -> Index -> Eff (idb :: IDB, avar :: AVAR, exception :: EXCEPTION | e') Unit)
539− }
540− -> Aff { db :: Database, index :: Index, store :: ObjectStore }
507+ } -> Aff (idb :: IDB, avar :: AVAR | e) { db :: Database, index :: Index, store :: ObjectStore }
541 setup { storeParams, indexParams, values, keyPath, onUpgradeNeeded } = do
508 setup { storeParams, indexParams, values, keyPath, onUpgradeNeeded } = do
542− let
543− onUpgradeNeeded' var db tx _ = launchAff' do
509+ let onUpgradeNeeded' var db tx = launchAff' do
544− store <- IDBDatabase.createObjectStore db "store" storeParams
510+ store <- IDBDatabase.createObjectStore db "store" storeParams
545− _ <- traverse (uncurry (IDBObjectStore.add store)) values
511+ _ <- traverse (uncurry (IDBObjectStore.add store)) values
546− index <- IDBObjectStore.createIndex store "index" keyPath indexParams
512+ index <- IDBObjectStore.createIndex store "index" keyPath indexParams
547− liftEffect $ maybe (pure unit) identity (onUpgradeNeeded <*> pure db <*> pure tx <*> pure index)
513+ liftEff $ maybe (pure unit) id (onUpgradeNeeded <*> pure db <*> pure tx <*> pure index)
548− AVar.put { db, index, store } var
514+ putVar var { db, index, store }
549−
515+
550− var <- AVar.empty
516+ var <- makeVar
551− _ <- IDBFactory.open "db" Nothing
517+ db <- IDBFactory.open "db" Nothing
552− { onUpgradeNeeded: Just (onUpgradeNeeded' var)
518+ { onUpgradeNeeded : Just (onUpgradeNeeded' var)
553− , onBlocked: Nothing
519+ , onBlocked : Nothing
554 }
520 }
555− AVar.take var
521+ takeVar var
556−
522+
557− it "returns an IDBIndex and the properties are set correctly" do
523+
558− { db, index } <- setup
524+ it "returns an IDBIndex and the properties are set correctly" do
559− { storeParams: IDBDatabase.defaultParameters
525+ { db, index } <- setup
560− , indexParams: IDBObjectStore.defaultParameters
526+ { storeParams : IDBDatabase.defaultParameters
561− , onUpgradeNeeded: Nothing
527+ , indexParams : IDBObjectStore.defaultParameters
562− , keyPath: []
528+ , onUpgradeNeeded : Nothing
563− , values: []
529+ , keyPath : []
564− }
530+ , values : []
565− IDBIndex.name index `shouldEqual` "index"
531+ }
566− IDBIndex.keyPath index `shouldEqual` []
532+ IDBIndex.name index `shouldEqual` "index"
567− IDBIndex.unique index `shouldEqual` IDBObjectStore.defaultParameters.unique
533+ IDBIndex.keyPath index `shouldEqual` []
568− IDBIndex.multiEntry index `shouldEqual` IDBObjectStore.defaultParameters.multiEntry
534+ IDBIndex.unique index `shouldEqual` IDBObjectStore.defaultParameters.unique
569− tearDown db
535+ IDBIndex.multiEntry index `shouldEqual` IDBObjectStore.defaultParameters.multiEntry
570−
536+ tearDown db
571− it "attempt to create an index that requires unique values on an object store already contains duplicates" do
537+
572− let onAbort var = launchAff' (AVar.put true var)
538+ it "attempt to create an index that requires unique values on an object store already contains duplicates" do
573− txVar <- AVar.empty
539+ let onAbort var = launchAff' (putVar var true)
574− dbVar <- AVar.empty
540+ txVar <- makeVar
575− res <- attempt $ setup
541+ dbVar <- makeVar
576− { storeParams: IDBDatabase.defaultParameters
542+ res <- attempt $ setup
577− , indexParams:
543+ { storeParams : IDBDatabase.defaultParameters
578− { unique: true
544+ , indexParams : { unique : true
579− , multiEntry: false
545+ , multiEntry : false
580− }
546+ }
581− , keyPath: [ "indexedProperty" ]
547+ , keyPath : ["indexedProperty"]
582− , values:
548+ , values : [ { indexedProperty: "bar" } :+: (Just $ toKey 1)
583− [ { indexedProperty: "bar" } :+: (Just $ toKey 1)
549+ , { indexedProperty: "bar" } :+: (Just $ toKey 2)
584− , { indexedProperty: "bar" } :+: (Just $ toKey 2)
550+ ]
585− ]
551+ , onUpgradeNeeded : Just $ \db tx _ -> launchAff' do
586− , onUpgradeNeeded: Just $ \db tx _ -> launchAff' do
552+ IDBTransaction.onAbort tx (onAbort txVar)
587− IDBTransaction.onAbort tx (onAbort txVar)
553+ IDBDatabase.onAbort db (onAbort dbVar)
588− IDBDatabase.onAbort db (onAbort dbVar)
554+ }
589− }
555+ case res of
590− case res of
556+ Right _ ->
591− Right _ ->
557+ fail "expected abort"
592− fail "expected abort"
558+ _ -> do
593− _ -> do
559+ shouldEqual true =<< takeVar txVar
594− shouldEqual true =<< AVar.take txVar
560+ shouldEqual true =<< takeVar dbVar
595− shouldEqual true =<< AVar.take dbVar
561+
596−
562+
597− it "the index is usable right after being made" do
563+ it "the index is usable right after being made" do
598− { db } <- setup
564+ { db } <- setup
599− { storeParams:
565+ { storeParams : { keyPath : ["key"]
600− { keyPath: [ "key" ]
566+ , autoIncrement : false
601− , autoIncrement: false
567+ }
602− }
568+ , indexParams : IDBObjectStore.defaultParameters
603− , indexParams: IDBObjectStore.defaultParameters
569+ , keyPath : ["indexedProperty"]
604− , keyPath: [ "indexedProperty" ]
570+ , values : [ { key: "key1", indexedProperty: "indexed_1" } :+: Nothing
605− , values:
571+ , { key: "key2", indexedProperty: "indexed_2" } :+: Nothing
606− [ { key: "key1", indexedProperty: "indexed_1" } :+: Nothing
572+ , { key: "key3", indexedProperty: "indexed_3" } :+: Nothing
607− , { key: "key2", indexedProperty: "indexed_2" } :+: Nothing
573+ ]
608− , { key: "key3", indexedProperty: "indexed_3" } :+: Nothing
574+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
609− ]
575+ val <- IDBIndex.get index (IDBKeyRange.only "indexed_2")
610− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
576+ ((\r -> r.key) <$> val) `shouldEqual` (Just $ toKey "key2")
611− val <- IDBIndex.get index (IDBKeyRange.only "indexed_2")
577+ }
612− ((\r -> r.key) <$> val) `shouldEqual` (Just $ toKey "key2")
578+ tearDown db
613− }
579+
614− tearDown db
580+ it "empty keyPath" do
615−
581+ { db } <- setup
616− it "empty keyPath" do
582+ { storeParams : IDBDatabase.defaultParameters
617− { db } <- setup
583+ , indexParams : IDBObjectStore.defaultParameters
618− { storeParams: IDBDatabase.defaultParameters
584+ , keyPath : []
619− , indexParams: IDBObjectStore.defaultParameters
585+ , values : [ "object_1" :+: (Just $ toKey 1)
620− , keyPath: []
586+ , "object_2" :+: (Just $ toKey 2)
621− , values:
587+ , "object_3" :+: (Just $ toKey 3)
622− [ "object_1" :+: (Just $ toKey 1)
588+ ]
623− , "object_2" :+: (Just $ toKey 2)
589+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
624− , "object_3" :+: (Just $ toKey 3)
590+ val <- IDBIndex.get index (IDBKeyRange.only "object_3")
625− ]
591+ val `shouldEqual` (Just "object_3")
626− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
592+ }
627− val <- IDBIndex.get index (IDBKeyRange.only "object_3")
593+ tearDown db
628− val `shouldEqual` (Just "object_3")
594+
629− }
595+ it "index can be valid keys [date]" do
630− tearDown db
596+ date <- liftEff $ toDateTime <$> now
631−
597+ { db } <- setup
632− it "index can be valid keys [date]" do
598+ { storeParams : { keyPath: ["key"]
633− date <- liftEffect $ toDateTime <$> now
599+ , autoIncrement: false
634− { db } <- setup
600+ }
635− { storeParams:
601+ , indexParams : IDBObjectStore.defaultParameters
636− { keyPath: [ "key" ]
602+ , keyPath : ["i"]
637− , autoIncrement: false
603+ , values : [ { key: "date", i: (toKey date) } :+: Nothing
638− }
604+ ]
639− , indexParams: IDBObjectStore.defaultParameters
605+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
640− , keyPath: [ "i" ]
606+ val <- IDBIndex.get index (IDBKeyRange.only date)
641− , values:
607+ ((\r -> r.key) <$> val) `shouldEqual` (Just "date")
642− [ { key: "date", i: (toKey date) } :+: Nothing
608+ }
643− ]
609+ tearDown db
644− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
610+
645− val <- IDBIndex.get index (IDBKeyRange.only date)
611+ it "index can be valid keys [num]" do
646− ((\r -> r.key) <$> val) `shouldEqual` (Just "date")
612+ let num = 14
647− }
613+ { db } <- setup
648− tearDown db
614+ { storeParams : { keyPath: ["key"]
649−
615+ , autoIncrement: false
650− it "index can be valid keys [num]" do
616+ }
651− let num = 14
617+ , indexParams : IDBObjectStore.defaultParameters
652− { db } <- setup
618+ , keyPath : ["i"]
653− { storeParams:
619+ , values : [ { key: "num", i: (toKey num) } :+: Nothing
654− { keyPath: [ "key" ]
620+ ]
655− , autoIncrement: false
621+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
656− }
622+ val <- IDBIndex.get index (IDBKeyRange.only num)
657− , indexParams: IDBObjectStore.defaultParameters
623+ ((\r -> r.key) <$> val) `shouldEqual` (Just "num")
658− , keyPath: [ "i" ]
624+ }
659− , values:
625+ tearDown db
660− [ { key: "num", i: (toKey num) } :+: Nothing
626+
661− ]
627+ it "index can be valid keys [array]" do
662− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
628+ let array = ["patate", "autruche"]
663− val <- IDBIndex.get index (IDBKeyRange.only num)
629+ { db } <- setup
664− ((\r -> r.key) <$> val) `shouldEqual` (Just "num")
630+ { storeParams : { keyPath: ["key"]
665− }
631+ , autoIncrement: false
666− tearDown db
632+ }
667−
633+ , indexParams : IDBObjectStore.defaultParameters
668− it "index can be valid keys [array]" do
634+ , keyPath : ["i"]
669− let array = [ "patate", "autruche" ]
635+ , values : [ { key: "array", i: (toKey array) } :+: Nothing
670− { db } <- setup
636+ ]
671− { storeParams:
637+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
672− { keyPath: [ "key" ]
638+ val <- IDBIndex.get index (IDBKeyRange.only array)
673− , autoIncrement: false
639+ ((\r -> r.key) <$> val) `shouldEqual` (Just "array")
674− }
640+ }
675− , indexParams: IDBObjectStore.defaultParameters
641+ tearDown db
676− , keyPath: [ "i" ]
642+
677− , values:
643+ it "openKeyCursor() - throw InvalidStateError on index deleted by aborted upgrade" do
678− [ { key: "array", i: (toKey array) } :+: Nothing
644+ res <- attempt $ setup
679− ]
645+ { storeParams : { keyPath: ["key"], autoIncrement: false }
680− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
646+ , indexParams : IDBObjectStore.defaultParameters
681− val <- IDBIndex.get index (IDBKeyRange.only array)
647+ , keyPath : ["indexedProperty"]
682− ((\r -> r.key) <$> val) `shouldEqual` (Just "array")
648+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
683− }
649+ ]
684− tearDown db
650+ , onUpgradeNeeded : Just $ \db tx index -> launchAff' do
685−
651+ let cb =
686− it "openKeyCursor() - throw InvalidStateError on index deleted by aborted upgrade" do
652+ { onSuccess : const $ pure unit
687− res <- attempt $ setup
653+ , onError : show >>> fail >>> launchAff'
688− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
689− , indexParams: IDBObjectStore.defaultParameters
690− , keyPath: [ "indexedProperty" ]
691− , values:
692− [ { key: 14, indexedProperty: "patate" } :+: Nothing
693− ]
694− , onUpgradeNeeded: Just $ \db tx index -> launchAff' do
695− let
696− cb =
697− { onSuccess: const $ pure unit
698− , onError: show >>> fail >>> launchAff'
699 , onComplete: pure unit
654 , onComplete: pure unit
700 }
655 }
701− IDBTransaction.onAbort tx (pure unit)
656+ IDBTransaction.onAbort tx (pure unit)
702− IDBDatabase.onAbort db (pure unit)
657+ IDBDatabase.onAbort db (pure unit)
703− IDBTransaction.abort tx
658+ IDBTransaction.abort tx
704− cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
659+ cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
705− case cursor of
660+ case cursor of
706− Right _ -> fail "expected InvalidStateError"
661+ Right _ -> fail "expected InvalidStateError"
707− Left err -> name err `shouldEqual` "InvalidStateError"
662+ Left err -> message err `shouldEqual` "InvalidStateError"
708− }
663+ }
709− case res of
664+ case res of
710− Right _ -> fail "expected InvalidStateError"
665+ Right _ -> fail "expected InvalidStateError"
711− _ -> pure unit
666+ _ -> pure unit
712−
667+
713− it "openKeyCursor() - throw TransactionInactiveError on aborted transaction" do
668+ it "openKeyCursor() - throw TransactionInactiveError on aborted transaction" do
714− { db } <- setup
669+ { db } <- setup
715− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
670+ { storeParams : { keyPath: ["key"], autoIncrement: false }
716− , indexParams: IDBObjectStore.defaultParameters
671+ , indexParams : IDBObjectStore.defaultParameters
717− , keyPath: [ "indexedProperty" ]
672+ , keyPath : ["indexedProperty"]
718− , values:
673+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
719− [ { key: 14, indexedProperty: "patate" } :+: Nothing
674+ ]
720− ]
675+ , onUpgradeNeeded : Nothing
721− , onUpgradeNeeded: Nothing
676+ }
722− }
677+ let cb =
723− let
678+ { onSuccess : const $ pure unit
724− cb =
679+ , onError : show >>> fail >>> launchAff'
725− { onSuccess: const $ pure unit
726− , onError: show >>> fail >>> launchAff'
727 , onComplete: pure unit
680 , onComplete: pure unit
728 }
681 }
729− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
682+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
730− store <- IDBTransaction.objectStore tx "store"
683+ store <- IDBTransaction.objectStore tx "store"
731− index <- IDBObjectStore.index store "index"
684+ index <- IDBObjectStore.index store "index"
732− IDBTransaction.onAbort tx (pure unit)
685+ IDBTransaction.onAbort tx (pure unit)
733− IDBTransaction.abort tx
686+ IDBTransaction.abort tx
734− cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
687+ cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
735− case cursor of
688+ case cursor of
736− Right _ -> fail "expected TransactionInactiveError"
689+ Right _ -> fail "expected TransactionInactiveError"
737− Left err -> name err `shouldEqual` "TransactionInactiveError"
690+ Left err -> message err `shouldEqual` "TransactionInactiveError"
738−
691+
739− tearDown db
692+ tearDown db
740−
693+
741− it "openKeyCursor() - throw InvalidStateError when the index is deleted" do
694+ it "openKeyCursor() - throw InvalidStateError when the index is deleted" do
742− { db } <- setup
695+ { db } <- setup
743− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
696+ { storeParams : { keyPath: ["key"], autoIncrement: false }
744− , indexParams: IDBObjectStore.defaultParameters
697+ , indexParams : IDBObjectStore.defaultParameters
745− , keyPath: [ "indexedProperty" ]
698+ , keyPath : ["indexedProperty"]
746− , values:
699+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
747− [ { key: 14, indexedProperty: "patate" } :+: Nothing
700+ ]
748− ]
701+ , onUpgradeNeeded : Just $ \db tx index -> launchAff' do
749− , onUpgradeNeeded: Just $ \_ tx index -> launchAff' do
702+ let cb =
750− let
703+ { onSuccess : const $ pure unit
751− cb =
704+ , onError : show >>> fail >>> launchAff'
752− { onSuccess: const $ pure unit
753− , onError: show >>> fail >>> launchAff'
754 , onComplete: pure unit
705 , onComplete: pure unit
755 }
706 }
756− store <- IDBTransaction.objectStore tx "store"
707+ store <- IDBTransaction.objectStore tx "store"
757− IDBObjectStore.deleteIndex store "index"
708+ IDBObjectStore.deleteIndex store "index"
758− cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
709+ cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
759− case cursor of
710+ case cursor of
760− Right _ -> fail "expected InvalidStateError"
711+ Right _ -> fail "expected InvalidStateError"
761− Left err -> name err `shouldEqual` "InvalidStateError"
712+ Left err -> message err `shouldEqual` "InvalidStateError"
762− }
713+ }
763−
714+
764− tearDown db
715+ tearDown db
765−
716+
766− it "openCursor() - throw InvalidStateError on index deleted by aborted upgrade" do
717+ it "openCursor() - throw InvalidStateError on index deleted by aborted upgrade" do
767− res <- attempt $ setup
718+ res <- attempt $ setup
768− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
719+ { storeParams : { keyPath: ["key"], autoIncrement: false }
769− , indexParams: IDBObjectStore.defaultParameters
720+ , indexParams : IDBObjectStore.defaultParameters
770− , keyPath: [ "indexedProperty" ]
721+ , keyPath : ["indexedProperty"]
771− , values:
722+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
772− [ { key: 14, indexedProperty: "patate" } :+: Nothing
723+ ]
773− ]
724+ , onUpgradeNeeded : Just $ \db tx index -> launchAff' do
774− , onUpgradeNeeded: Just $ \db tx index -> launchAff' do
725+ let cb =
775− let
726+ { onSuccess : const $ pure unit
776− cb =
727+ , onError : show >>> fail >>> launchAff'
777− { onSuccess: const $ pure unit
778− , onError: show >>> fail >>> launchAff'
779 , onComplete: pure unit
728 , onComplete: pure unit
780 }
729 }
781− IDBTransaction.onAbort tx (pure unit)
730+ IDBTransaction.onAbort tx (pure unit)
782− IDBDatabase.onAbort db (pure unit)
731+ IDBDatabase.onAbort db (pure unit)
783− IDBTransaction.abort tx
732+ IDBTransaction.abort tx
784− cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
733+ cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
785− case cursor of
734+ case cursor of
786− Right _ -> fail "expected InvalidStateError"
735+ Right _ -> fail "expected InvalidStateError"
787− Left err -> name err `shouldEqual` "InvalidStateError"
736+ Left err -> message err `shouldEqual` "InvalidStateError"
788− }
737+ }
789− case res of
738+ case res of
790− Right _ -> fail "expected InvalidStateError"
739+ Right _ -> fail "expected InvalidStateError"
791− _ -> pure unit
740+ _ -> pure unit
792−
741+
793− it "openCursor() - throw TransactionInactiveError on aborted transaction" do
742+ it "openCursor() - throw TransactionInactiveError on aborted transaction" do
794− { db } <- setup
743+ { db } <- setup
795− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
744+ { storeParams : { keyPath: ["key"], autoIncrement: false }
796− , indexParams: IDBObjectStore.defaultParameters
745+ , indexParams : IDBObjectStore.defaultParameters
797− , keyPath: [ "indexedProperty" ]
746+ , keyPath : ["indexedProperty"]
798− , values:
747+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
799− [ { key: 14, indexedProperty: "patate" } :+: Nothing
748+ ]
800− ]
749+ , onUpgradeNeeded : Nothing
801− , onUpgradeNeeded: Nothing
750+ }
802− }
751+ let cb =
803− let
752+ { onSuccess : const $ pure unit
804− cb =
753+ , onError : show >>> fail >>> launchAff'
805− { onSuccess: const $ pure unit
806− , onError: show >>> fail >>> launchAff'
807 , onComplete: pure unit
754 , onComplete: pure unit
808 }
755 }
809− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
756+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
810− store <- IDBTransaction.objectStore tx "store"
757+ store <- IDBTransaction.objectStore tx "store"
811− index <- IDBObjectStore.index store "index"
758+ index <- IDBObjectStore.index store "index"
812− IDBTransaction.onAbort tx (pure unit)
759+ IDBTransaction.onAbort tx (pure unit)
813− IDBTransaction.abort tx
760+ IDBTransaction.abort tx
814− cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
761+ cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
815− case cursor of
762+ case cursor of
816− Right _ -> fail "expected TransactionInactiveError"
763+ Right _ -> fail "expected TransactionInactiveError"
817− Left err -> name err `shouldEqual` "TransactionInactiveError"
764+ Left err -> message err `shouldEqual` "TransactionInactiveError"
818−
765+
819− tearDown db
766+ tearDown db
820−
767+
821− it "openCursor() - throw InvalidStateError when the index is deleted" do
768+ it "openCursor() - throw InvalidStateError when the index is deleted" do
822− { db } <- setup
769+ { db } <- setup
823− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
770+ { storeParams : { keyPath: ["key"], autoIncrement: false }
824− , indexParams: IDBObjectStore.defaultParameters
771+ , indexParams : IDBObjectStore.defaultParameters
825− , keyPath: [ "indexedProperty" ]
772+ , keyPath : ["indexedProperty"]
826− , values:
773+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
827− [ { key: 14, indexedProperty: "patate" } :+: Nothing
774+ ]
828− ]
775+ , onUpgradeNeeded : Just $ \db tx index -> launchAff' do
829− , onUpgradeNeeded: Just $ \db tx index -> launchAff' do
776+ let cb =
830− let
777+ { onSuccess : const $ pure unit
831− cb =
778+ , onError : show >>> fail >>> launchAff'
832− { onSuccess: const $ pure unit
833− , onError: show >>> fail >>> launchAff'
834 , onComplete: pure unit
779 , onComplete: pure unit
835 }
780 }
836− store <- IDBTransaction.objectStore tx "store"
781+ store <- IDBTransaction.objectStore tx "store"
837− IDBObjectStore.deleteIndex store "index"
782+ IDBObjectStore.deleteIndex store "index"
838− cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
783+ cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
839− case cursor of
784+ case cursor of
840− Right _ -> fail "expected InvalidStateError"
785+ Right _ -> fail "expected InvalidStateError"
841− Left err -> name err `shouldEqual` "InvalidStateError"
786+ Left err -> message err `shouldEqual` "InvalidStateError"
842− }
787+ }
843−
788+
844− tearDown db
789+ tearDown db
845−
790+
846− it "getKey() - multiEntry - adding keys" do
791+ it "getKey() - multiEntry - adding keys" do
847− { db } <- setup
792+ { db } <- setup
848− { storeParams: IDBDatabase.defaultParameters
793+ { storeParams : IDBDatabase.defaultParameters
849− , indexParams: { unique: false, multiEntry: true }
794+ , indexParams : { unique: false, multiEntry: true }
850− , keyPath: [ "name" ]
795+ , keyPath : ["name"]
851− , values:
796+ , values : [ { name: ["patate", "autruche"] } :+: (Just $ toKey 1)
852− [ { name: [ "patate", "autruche" ] } :+: (Just $ toKey 1)
797+ , { name: ["bob"] } :+: (Just $ toKey 2)
853− , { name: [ "bob" ] } :+: (Just $ toKey 2)
798+ ]
854− ]
799+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
855− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
800+ key <- IDBIndex.getKey index (IDBKeyRange.only "patate")
856− key <- IDBIndex.getKey index (IDBKeyRange.only "patate")
801+ key `shouldEqual` (Just $ toKey 1)
857− key `shouldEqual` (Just $ toKey 1)
802+
858−
803+ key <- IDBIndex.getKey index (IDBKeyRange.only "autruche")
859− key' <- IDBIndex.getKey index (IDBKeyRange.only "autruche")
804+ key `shouldEqual` (Just $ toKey 1)
860− key' `shouldEqual` (Just $ toKey 1)
805+
861−
806+ key <- IDBIndex.getKey index (IDBKeyRange.only "bob")
862− key'' <- IDBIndex.getKey index (IDBKeyRange.only "bob")
807+ key `shouldEqual` (Just $ toKey 2)
863− key'' `shouldEqual` (Just $ toKey 2)
808+ }
864− }
809+ tearDown db
865− tearDown db
810+
866−
811+
867− it "get() - returns the record with the first key in the range" do
812+ it "get() - returns the record with the first key in the range" do
868− { db } <- setup
813+ { db } <- setup
869− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
814+ { storeParams : { keyPath: ["key"], autoIncrement: false }
870− , indexParams: IDBObjectStore.defaultParameters
815+ , indexParams : IDBObjectStore.defaultParameters
871− , keyPath: [ "indexedProperty" ]
816+ , keyPath : ["indexedProperty"]
872− , values:
817+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
873− [ { key: 14, indexedProperty: "patate" } :+: Nothing
818+ , { key: 42, indexedProperty: "autruche" } :+: Nothing
874− , { key: 42, indexedProperty: "autruche" } :+: Nothing
819+ , { key: 1337, indexedProperty: "baguette" } :+: Nothing
875− , { key: 1337, indexedProperty: "baguette" } :+: Nothing
820+ ]
876− ]
821+ , onUpgradeNeeded : Nothing
877− , onUpgradeNeeded: Nothing
822+ }
878− }
823+
879−
824+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
880− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
825+ store <- IDBTransaction.objectStore tx "store"
881− store <- IDBTransaction.objectStore tx "store"
826+ index <- IDBObjectStore.index store "index"
882− index <- IDBObjectStore.index store "index"
827+ val <- IDBIndex.get index (IDBKeyRange.lowerBound "autruche" false)
883− val <- IDBIndex.get index (IDBKeyRange.lowerBound "autruche" false)
828+ ((\r -> r.key) <$> val) `shouldEqual` (Just 42)
884− ((\r -> r.key) <$> val) `shouldEqual` (Just 42)
829+
885−
830+ tearDown db
886− tearDown db
831+
887−
832+ describe "IDBCursor" do
888− describe "IDBCursor" do
833+ let
889− let
890 tearDown db = do
834 tearDown db = do
891 IDBDatabase.close db
835 IDBDatabase.close db
892 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
836 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
893 pure unit
837 pure unit
894
838
895− setup
839+ setup :: forall value e e'.
896− :: forall value
840+ { storeParams :: { keyPath :: Array String, autoIncrement :: Boolean }
897− . { storeParams :: { keyPath :: Array String, autoIncrement :: Boolean }
841+ , indexParams :: { unique :: Boolean, multiEntry :: Boolean }
898− , indexParams :: { unique :: Boolean, multiEntry :: Boolean }
842+ , values :: Array (Tuple value (Maybe Key))
899− , values :: Array (Tuple value (Maybe Key))
843+ , keyPath :: Array String
900− , keyPath :: Array String
844+ , onUpgradeNeeded :: Maybe (Database -> Transaction -> Index -> Eff (idb :: IDB, avar :: AVAR, exception :: EXCEPTION | e') Unit)
901− , onUpgradeNeeded :: Maybe (Database -> Transaction -> Index -> Effect Unit)
845+ } -> Aff (idb :: IDB, avar :: AVAR | e) { db :: Database, index :: Index, store :: ObjectStore }
902− }
903− -> Aff { db :: Database, index :: Index, store :: ObjectStore }
904 setup { storeParams, indexParams, values, keyPath, onUpgradeNeeded } = do
846 setup { storeParams, indexParams, values, keyPath, onUpgradeNeeded } = do
905− let
847+ let onUpgradeNeeded' var db tx = launchAff' do
906− onUpgradeNeeded' var db tx _ = launchAff' do
848+ store <- IDBDatabase.createObjectStore db "store" storeParams
907− store <- IDBDatabase.createObjectStore db "store" storeParams
849+ _ <- traverse (uncurry (IDBObjectStore.add store)) values
908− _ <- traverse (uncurry (IDBObjectStore.add store)) values
850+ index <- IDBObjectStore.createIndex store "index" keyPath indexParams
909− index <- IDBObjectStore.createIndex store "index" keyPath indexParams
851+ liftEff $ maybe (pure unit) id (onUpgradeNeeded <*> pure db <*> pure tx <*> pure index)
910− liftEffect $ maybe (pure unit) identity (onUpgradeNeeded <*> pure db <*> pure tx <*> pure index)
852+ putVar var { db, index, store }
911− AVar.put { db, index, store } var
853+
912−
854+ var <- makeVar
913− var <- AVar.empty
855+ db <- IDBFactory.open "db" Nothing
914− db <- IDBFactory.open "db" Nothing
856+ { onUpgradeNeeded : Just (onUpgradeNeeded' var)
915− { onUpgradeNeeded: Just (onUpgradeNeeded' var)
857+ , onBlocked : Nothing
916− , onBlocked: Nothing
917 }
858 }
918− AVar.take var
859+ takeVar var
919−
860+
920− it "continue() - iterate to the next record" do
861+ it "continue() - iterate to the next record" do
921− { db } <- setup
862+ { db } <- setup
922− { storeParams: IDBDatabase.defaultParameters
863+ { storeParams : IDBDatabase.defaultParameters
923− , indexParams: IDBObjectStore.defaultParameters
864+ , indexParams : IDBObjectStore.defaultParameters
924− , keyPath: []
865+ , keyPath : []
925− , values:
866+ , values : [ "cupcake" :+: (Just $ toKey 4)
926− [ "cupcake" :+: (Just $ toKey 4)
867+ , "pancake" :+: (Just $ toKey 2)
927− , "pancake" :+: (Just $ toKey 2)
868+ , "pie" :+: (Just $ toKey 1)
928− , "pie" :+: (Just $ toKey 1)
869+ , "pie" :+: (Just $ toKey 3)
929− , "pie" :+: (Just $ toKey 3)
870+ ]
930− ]
871+ , onUpgradeNeeded: Nothing
931− , onUpgradeNeeded: Nothing
872+ }
932− }
873+ let cb vdone vvals =
933− let
934− cb vdone vvals =
935 { onComplete: launchAff' do
874 { onComplete: launchAff' do
936− AVar.put unit vdone
875+ putVar vdone unit
937
876
938− , onError: \error -> launchAff' do
877+ , onError: \error -> launchAff' do
939 fail $ "unexpected error: " <> show error
878 fail $ "unexpected error: " <> show error
940
879
941 , onSuccess: \cursor -> launchAff' do
880 , onSuccess: \cursor -> launchAff' do
942− vals <- AVar.take vvals
881+ vals <- takeVar vvals
943 pure (IDBCursor.value cursor) >>= shouldEqual (maybe "" _.v $ head vals)
882 pure (IDBCursor.value cursor) >>= shouldEqual (maybe "" _.v $ head vals)
944− IDBCursor.primaryKey cursor >>= shouldEqual (maybe (toKey 0) _.k $ head vals)
883+ IDBCursor.primaryKey cursor >>= shouldEqual (maybe (toKey 0) _.k $ head vals)
945− AVar.put (drop 1 vals) vvals
884+ putVar vvals (drop 1 vals)
946 IDBCursor.continue cursor none
885 IDBCursor.continue cursor none
947 }
886 }
948− vdone <- AVar.empty
887+ vdone <- makeVar
949− vvals <- AVar.new
888+ vvals <- makeVar'
950− [ { v: "pie", k: toKey 1 }
889+ [ { v: "pie" , k: toKey 1 }
951− , { v: "pancake", k: toKey 2 }
890+ , { v: "pancake", k: toKey 2 }
952− , { v: "pie", k: toKey 3 }
891+ , { v: "pie" , k: toKey 3 }
953− , { v: "cupcake", k: toKey 4 }
892+ , { v: "cupcake", k: toKey 4 }
954− ]
893+ ]
955− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
894+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
956− store <- IDBTransaction.objectStore tx "store"
895+ store <- IDBTransaction.objectStore tx "store"
957− IDBObjectStore.openCursor store Nothing Next (cb vdone vvals)
896+ IDBObjectStore.openCursor store Nothing Next (cb vdone vvals)
958− AVar.take vdone
897+ takeVar vdone
959− tearDown db
898+ tearDown db
960−
899+
961− it "continue() - attempt to iterate in the wrong direction" do
900+ it "continue() - attempt to iterate in the wrong direction" do
962− { db } <- setup
901+ { db } <- setup
963− { storeParams: IDBDatabase.defaultParameters
902+ { storeParams : IDBDatabase.defaultParameters
964− , indexParams: IDBObjectStore.defaultParameters
903+ , indexParams : IDBObjectStore.defaultParameters
965− , keyPath: []
904+ , keyPath : []
966− , values:
905+ , values : [ "cupcake" :+: (Just $ toKey 4)
967− [ "cupcake" :+: (Just $ toKey 4)
906+ , "pancake" :+: (Just $ toKey 2)
968− , "pancake" :+: (Just $ toKey 2)
907+ , "pie" :+: (Just $ toKey 1)
969− , "pie" :+: (Just $ toKey 1)
908+ , "pie" :+: (Just $ toKey 3)
970− , "pie" :+: (Just $ toKey 3)
909+ ]
971− ]
910+ , onUpgradeNeeded: Nothing
972− , onUpgradeNeeded: Nothing
911+ }
973− }
912+ let cb vdone =
974− let
975− cb vdone =
976 { onComplete: launchAff' do
913 { onComplete: launchAff' do
977 fail $ "shouldn't complete"
914 fail $ "shouldn't complete"
978
915
979− , onError: \error -> launchAff' do
916+ , onError: \error -> launchAff' do
980 fail $ "unexpected error: " <> show error
917 fail $ "unexpected error: " <> show error
981
918
982 , onSuccess: \cursor -> launchAff' do
919 , onSuccess: \cursor -> launchAff' do
983 res <- attempt $ IDBCursor.continue cursor (Just 1)
920 res <- attempt $ IDBCursor.continue cursor (Just 1)
984 case res of
921 case res of
985− Left err -> do
922+ Left err -> do
986− name err `shouldEqual` "DataError"
923+ message err `shouldEqual` "DataError"
987− AVar.put unit vdone
924+ putVar vdone unit
988 Right _ -> do
925 Right _ -> do
989 fail "expected continue to fail"
926 fail "expected continue to fail"
990 }
927 }
991− vdone <- AVar.empty
928+ vdone <- makeVar
992− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
929+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
993− store <- IDBTransaction.objectStore tx "store"
930+ store <- IDBTransaction.objectStore tx "store"
994− IDBObjectStore.openCursor store Nothing Next (cb vdone)
931+ IDBObjectStore.openCursor store Nothing Next (cb vdone)
995− AVar.take vdone
932+ takeVar vdone
996− tearDown db
933+ tearDown db
997−
934+
998− it "advance() - iterate cursor number of times specified by count" do
935+
999− { db } <- setup
936+ it "advance() - iterate cursor number of times specified by count" do
1000− { storeParams: { keyPath: [ "pKey" ], autoIncrement: false }
937+ { db } <- setup
1001− , indexParams: IDBObjectStore.defaultParameters
938+ { storeParams : { keyPath: ["pKey"], autoIncrement: false }
1002− , keyPath: []
939+ , indexParams : IDBObjectStore.defaultParameters
1003− , values:
940+ , keyPath : []
1004− [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
941+ , values : [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1005− , { pKey: "pkey_1", iKey: "ikey_1" } :+: Nothing
942+ , { pKey: "pkey_1", iKey: "ikey_1" } :+: Nothing
1006− , { pKey: "pkey_2", iKey: "ikey_2" } :+: Nothing
943+ , { pKey: "pkey_2", iKey: "ikey_2" } :+: Nothing
1007− , { pKey: "pkey_3", iKey: "ikey_3" } :+: Nothing
944+ , { pKey: "pkey_3", iKey: "ikey_3" } :+: Nothing
1008− ]
945+ ]
1009− , onUpgradeNeeded: Nothing
946+ , onUpgradeNeeded: Nothing
1010− }
947+ }
1011− let
948+ let cb vdone vjump =
1012− cb vdone vjump =
1013 { onComplete: launchAff' do
949 { onComplete: launchAff' do
1014− AVar.put unit vdone
950+ putVar vdone unit
1015
951
1016− , onError: \error -> launchAff' do
952+ , onError: \error -> launchAff' do
1017 fail $ "unexpected error: " <> show error
953 fail $ "unexpected error: " <> show error
1018
954
1019 , onSuccess: \cursor -> launchAff' do
955 , onSuccess: \cursor -> launchAff' do
1020− jump <- AVar.take vjump
956+ jump <- takeVar vjump
1021− if jump then do
957+ if jump
1022− IDBCursor.advance cursor 3
958+ then do
1023− else do
959+ IDBCursor.advance cursor 3
1024− let value = IDBCursor.value cursor
960+ else do
1025− value.pKey `shouldEqual` "pkey_3"
961+ let value = IDBCursor.value cursor
1026− value.iKey `shouldEqual` "ikey_3"
962+ value.pKey `shouldEqual` "pkey_3"
1027− IDBCursor.continue cursor none
963+ value.iKey `shouldEqual` "ikey_3"
1028− AVar.put false vjump
964+ IDBCursor.continue cursor none
965+ putVar vjump false
1029 }
966 }
1030− vdone <- AVar.empty
967+ vdone <- makeVar
1031− vjump <- AVar.new true
968+ vjump <- makeVar' true
1032− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
969+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
1033− store <- IDBTransaction.objectStore tx "store"
970+ store <- IDBTransaction.objectStore tx "store"
1034− IDBObjectStore.openCursor store Nothing Next (cb vdone vjump)
971+ IDBObjectStore.openCursor store Nothing Next (cb vdone vjump)
1035− AVar.take vdone
972+ takeVar vdone
1036− tearDown db
973+ tearDown db
1037−
974+
1038− it "delete() - remove a record from the object store" do
975+ it "delete() - remove a record from the object store" do
1039− { db } <- setup
976+ { db } <- setup
1040− { storeParams: { keyPath: [ "pKey" ], autoIncrement: false }
977+ { storeParams : { keyPath: ["pKey"], autoIncrement: false }
1041− , indexParams: IDBObjectStore.defaultParameters
978+ , indexParams : IDBObjectStore.defaultParameters
1042− , keyPath: []
979+ , keyPath : []
1043− , values:
980+ , values : [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1044− [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
981+ , { pKey: "pkey_1", iKey: "ikey_1" } :+: Nothing
1045− , { pKey: "pkey_1", iKey: "ikey_1" } :+: Nothing
982+ , { pKey: "pkey_2", iKey: "ikey_2" } :+: Nothing
1046− , { pKey: "pkey_2", iKey: "ikey_2" } :+: Nothing
983+ , { pKey: "pkey_3", iKey: "ikey_3" } :+: Nothing
1047− , { pKey: "pkey_3", iKey: "ikey_3" } :+: Nothing
984+ ]
1048− ]
985+ , onUpgradeNeeded: Nothing
1049− , onUpgradeNeeded: Nothing
986+ }
1050− }
987+ let cb vdone store =
1051− let
1052− cb vdone store =
1053 { onComplete: launchAff' do
988 { onComplete: launchAff' do
1054 mval <- map _.pKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
989 mval <- map _.pKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
1055 mval `shouldEqual` (Nothing :: Maybe String)
990 mval `shouldEqual` (Nothing :: Maybe String)
1056− AVar.put unit vdone
991+ putVar vdone unit
1057
992
1058− , onError: \error -> launchAff' do
993+ , onError: \error -> launchAff' do
1059 fail $ "unexpected error: " <> show error
994 fail $ "unexpected error: " <> show error
1060
995
1061 , onSuccess: \cursor -> launchAff' do
996 , onSuccess: \cursor -> launchAff' do
@@ -1064,31 +999,29 @@ main = do
1064 IDBCursor.delete cursor
999 IDBCursor.delete cursor
1065 IDBCursor.advance cursor 4
1000 IDBCursor.advance cursor 4
1066 }
1001 }
1067− vdone <- AVar.empty
1002+ vdone <- makeVar
1068− tx <- IDBDatabase.transaction db [ "store" ] ReadWrite
1003+ tx <- IDBDatabase.transaction db ["store"] ReadWrite
1069− store <- IDBTransaction.objectStore tx "store"
1004+ store <- IDBTransaction.objectStore tx "store"
1070− IDBObjectStore.openCursor store Nothing Next (cb vdone store)
1005+ IDBObjectStore.openCursor store Nothing Next (cb vdone store)
1071− AVar.take vdone
1006+ takeVar vdone
1072− tearDown db
1007+ tearDown db
1073−
1008+
1074− it "update() - modify a record in the object store" do
1009+ it "update() - modify a record in the object store" do
1075− { db } <- setup
1010+ { db } <- setup
1076− { storeParams: { keyPath: [ "pKey" ], autoIncrement: false }
1011+ { storeParams : { keyPath: ["pKey"], autoIncrement: false }
1077− , indexParams: IDBObjectStore.defaultParameters
1012+ , indexParams : IDBObjectStore.defaultParameters
1078− , keyPath: []
1013+ , keyPath : []
1079− , values:
1014+ , values : [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1080− [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1015+ ]
1081− ]
1016+ , onUpgradeNeeded: Nothing
1082− , onUpgradeNeeded: Nothing
1017+ }
1083− }
1018+ let cb vdone store =
1084− let
1085− cb vdone store =
1086 { onComplete: launchAff' do
1019 { onComplete: launchAff' do
1087 mval <- map _.iKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
1020 mval <- map _.iKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
1088 mval `shouldEqual` (Just "patate")
1021 mval `shouldEqual` (Just "patate")
1089− AVar.put unit vdone
1022+ putVar vdone unit
1090
1023
1091− , onError: \error -> launchAff' do
1024+ , onError: \error -> launchAff' do
1092 fail $ "unexpected error: " <> show error
1025 fail $ "unexpected error: " <> show error
1093
1026
1094 , onSuccess: \cursor -> launchAff' do
1027 , onSuccess: \cursor -> launchAff' do
@@ -1098,44 +1031,41 @@ main = do
1098 key `shouldEqual` toKey "pkey_0"
1031 key `shouldEqual` toKey "pkey_0"
1099 IDBCursor.advance cursor 4
1032 IDBCursor.advance cursor 4
1100 }
1033 }
1101− vdone <- AVar.empty
1034+ vdone <- makeVar
1102− tx <- IDBDatabase.transaction db [ "store" ] ReadWrite
1035+ tx <- IDBDatabase.transaction db ["store"] ReadWrite
1103− store <- IDBTransaction.objectStore tx "store"
1036+ store <- IDBTransaction.objectStore tx "store"
1104− IDBObjectStore.openCursor store Nothing Next (cb vdone store)
1037+ IDBObjectStore.openCursor store Nothing Next (cb vdone store)
1105− AVar.take vdone
1038+ takeVar vdone
1106− tearDown db
1039+ tearDown db
1107−
1040+
1108− it "update() - throw ReadOnlyError after update on ReadOnly transaction" do
1041+ it "update() - throw ReadOnlyError after update on ReadOnly transaction" do
1109− { db } <- setup
1042+ { db } <- setup
1110− { storeParams: { keyPath: [ "pKey" ], autoIncrement: false }
1043+ { storeParams : { keyPath: ["pKey"], autoIncrement: false }
1111− , indexParams: IDBObjectStore.defaultParameters
1044+ , indexParams : IDBObjectStore.defaultParameters
1112− , keyPath: []
1045+ , keyPath : []
1113− , values:
1046+ , values : [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1114− [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1047+ ]
1115− ]
1048+ , onUpgradeNeeded: Nothing
1116− , onUpgradeNeeded: Nothing
1049+ }
1117− }
1050+ let cb vdone =
1118− let
1119− cb vdone =
1120 { onComplete: launchAff' do
1051 { onComplete: launchAff' do
1121 fail $ "shouldn't complete"
1052 fail $ "shouldn't complete"
1122
1053
1123− , onError: \error -> launchAff' do
1054+ , onError: \error -> launchAff' do
1124 fail $ "unexpected error: " <> show error
1055 fail $ "unexpected error: " <> show error
1125
1056
1126 , onSuccess: \cursor -> launchAff' do
1057 , onSuccess: \cursor -> launchAff' do
1127 res <- attempt $ IDBCursor.update cursor "patate"
1058 res <- attempt $ IDBCursor.update cursor "patate"
1128 case res of
1059 case res of
1129 Left err -> do
1060 Left err -> do
1130− name err `shouldEqual` "ReadOnlyError"
1061+ message err `shouldEqual` "ReadOnlyError"
1131− AVar.put unit vdone
1062+ putVar vdone unit
1132 Right _ ->
1063 Right _ ->
1133 fail $ "expected ReadOnlyError"
1064 fail $ "expected ReadOnlyError"
1134 }
1065 }
1135− vdone <- AVar.empty
1066+ vdone <- makeVar
1136− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
1067+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
1137− store <- IDBTransaction.objectStore tx "store"
1068+ store <- IDBTransaction.objectStore tx "store"
1138− IDBObjectStore.openCursor store Nothing Next (cb vdone)
1069+ IDBObjectStore.openCursor store Nothing Next (cb vdone)
1139− AVar.take vdone
1070+ takeVar vdone
1140− tearDown db
1071+ tearDown db
1141−
yarn.lockdeleted−81
@@ -1,81 +0,0 @@
1−# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2−# yarn lockfile v1
3−
4−
5−base64-arraybuffer-es6@^0.7.0:
6− version "0.7.0"
7− resolved "https://registry.yarnpkg.com/base64-arraybuffer-es6/-/base64-arraybuffer-es6-0.7.0.tgz#dbe1e6c87b1bf1ca2875904461a7de40f21abc86"
8− integrity sha512-ESyU/U1CFZDJUdr+neHRhNozeCv72Y7Vm0m1DCbjX3KBjT6eYocvAJlSk6+8+HkVwXlT1FNxhGW6q3UKAlCvvw==
9−
10−domexception@^1.0.1:
11− version "1.0.1"
12− resolved "https://registry.yarnpkg.com/domexception/-/domexception-1.0.1.tgz#937442644ca6a31261ef36e3ec677fe805582c90"
13− integrity sha512-raigMkn7CJNNo6Ihro1fzG7wr3fHuYVytzquZKX5n0yizGsTcYgzdIUwj1X9pK0VvjeihV+XiclP+DjwbsSKug==
14− dependencies:
15− webidl-conversions "^4.0.2"
16−
17−fake-indexeddb@^4.0.1:
18− version "4.0.1"
19− resolved "https://registry.yarnpkg.com/fake-indexeddb/-/fake-indexeddb-4.0.1.tgz#09bb2468e21d0832b2177e894765fb109edac8fb"
20− integrity sha512-hFRyPmvEZILYgdcLBxVdHLik4Tj3gDTu/g7s9ZDOiU3sTNiGx+vEu1ri/AMsFJUZ/1sdRbAVrEcKndh3sViBcA==
21− dependencies:
22− realistic-structured-clone "^3.0.0"
23−
24−lodash@^4.7.0:
25− version "4.17.21"
26− resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
27− integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
28−
29−punycode@^2.1.1:
30− version "2.3.0"
31− resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.0.tgz#f67fa67c94da8f4d0cfff981aee4118064199b8f"
32− integrity sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==
33−
34−realistic-structured-clone@^3.0.0:
35− version "3.0.0"
36− resolved "https://registry.yarnpkg.com/realistic-structured-clone/-/realistic-structured-clone-3.0.0.tgz#7b518049ce2dad41ac32b421cd297075b00e3e35"
37− integrity sha512-rOjh4nuWkAqf9PWu6JVpOWD4ndI+JHfgiZeMmujYcPi+fvILUu7g6l26TC1K5aBIp34nV+jE1cDO75EKOfHC5Q==
38− dependencies:
39− domexception "^1.0.1"
40− typeson "^6.1.0"
41− typeson-registry "^1.0.0-alpha.20"
42−
43−tr46@^2.1.0:
44− version "2.1.0"
45− resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.1.0.tgz#fa87aa81ca5d5941da8cbf1f9b749dc969a4e240"
46− integrity sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==
47− dependencies:
48− punycode "^2.1.1"
49−
50−typeson-registry@^1.0.0-alpha.20:
51− version "1.0.0-alpha.39"
52− resolved "https://registry.yarnpkg.com/typeson-registry/-/typeson-registry-1.0.0-alpha.39.tgz#9e0f5aabd5eebfcffd65a796487541196f4b1211"
53− integrity sha512-NeGDEquhw+yfwNhguLPcZ9Oj0fzbADiX4R0WxvoY8nGhy98IbzQy1sezjoEFWOywOboj/DWehI+/aUlRVrJnnw==
54− dependencies:
55− base64-arraybuffer-es6 "^0.7.0"
56− typeson "^6.0.0"
57− whatwg-url "^8.4.0"
58−
59−typeson@^6.0.0, typeson@^6.1.0:
60− version "6.1.0"
61− resolved "https://registry.yarnpkg.com/typeson/-/typeson-6.1.0.tgz#5b2a53705a5f58ff4d6f82f965917cabd0d7448b"
62− integrity sha512-6FTtyGr8ldU0pfbvW/eOZrEtEkczHRUtduBnA90Jh9kMPCiFNnXIon3vF41N0S4tV1HHQt4Hk1j4srpESziCaA==
63−
64−webidl-conversions@^4.0.2:
65− version "4.0.2"
66− resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
67− integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==
68−
69−webidl-conversions@^6.1.0:
70− version "6.1.0"
71− resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514"
72− integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==
73−
74−whatwg-url@^8.4.0:
75− version "8.7.0"
76− resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.7.0.tgz#656a78e510ff8f3937bc0bcbe9f5c0ac35941b77"
77− integrity sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==
78− dependencies:
79− lodash "^4.7.0"
80− tr46 "^2.1.0"
81− webidl-conversions "^6.1.0"