@@ -2,1060 +2,1004 @@ module Test.Main where
3import Prelude
3import Prelude
5−import Data.Array (head, drop)
5+import Control.Monad.Aff (Aff, launchAff, launchAff_, forkAff, delay, attempt)
6+import Control.Monad.Aff.AVar (AVAR, AVar, makeVar, makeEmptyVar, readVar, 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, name)
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
37infixr 7 Tuple as :+:
38infixr 7 Tuple as :+:
39−launchAff' :: forall a. Aff a -> Effect Unit
40+launchAff' :: forall a e. Aff e a -> Eff e Unit
40launchAff' =
41launchAff' =
41− launchAff_ <<< void
42+ launchAff_
43−modifyAVar :: forall a. (a -> a) -> AVar a -> Aff Unit
45+modifyVar :: forall eff a. (a -> a) -> AVar a -> Aff (avar :: AVAR | eff) Unit
44−modifyAVar fn v = do
46+modifyVar fn v = do
45− val <- AVar.take v
47+ val <- takeVar v
46− AVar.put (fn val) v
48+ putVar (fn val) v
48−main :: Effect Unit
50+
49−main = do
51+-- main :: forall eff. Eff (now :: NOW, mocha :: MOCHA, idb :: IDB, exception :: EXCEPTION, avar :: AVAR | eff) Unit
50− launchAff_ $ runSpec [ consoleReporter ] $ do
52+main = runMocha do
51− describe "IDBFactory" do
53+ describe "IDBFactory" do
53 tearDown name version db = do
55 tearDown name version db = do
54 IDBDatabase.close db
56 IDBDatabase.close db
55 version' <- IDBFactory.deleteDatabase name
57 version' <- IDBFactory.deleteDatabase name
56− liftEffect $ log $ show version'
57 version' `shouldEqual` version
58 version' `shouldEqual` version
59− it "open default" do
60+ it "open default" do
61− name = "db-default"
61+ let name = "db-default"
62 version = 1
62 version = 1
63− db <- IDBFactory.open name Nothing
63+ db <- IDBFactory.open name Nothing
64− { onUpgradeNeeded: Nothing
64+ { onUpgradeNeeded : Nothing
65− , onBlocked: Nothing
65+ , onBlocked : Nothing
67− IDBDatabase.name db `shouldEqual` name
67+ IDBDatabase.name db `shouldEqual` name
68− tearDown name version db
68+ tearDown name version db
70− it "open specific version" do
74− db <- IDBFactory.open name (Just version)
75− { onUpgradeNeeded: Nothing
78− IDBDatabase.name db `shouldEqual` name
79− tearDown name version db
81− it "open specific version -> close -> open latest" do
71+ it "open specific version" do
83− name = "db-latest"
72+ let name = "db-specific"
84 version = 14
73 version = 14
85− db01 <- IDBFactory.open name (Just version)
74+ db <- IDBFactory.open name (Just version)
86− { onUpgradeNeeded: Nothing
75+ { onUpgradeNeeded : Nothing
87− , onBlocked: Nothing
76+ , onBlocked : Nothing
89− IDBDatabase.name db01 `shouldEqual` name
78+ IDBDatabase.name db `shouldEqual` name
90− IDBDatabase.close db01
91− db02 <- IDBFactory.open name Nothing
92− { onUpgradeNeeded: Nothing
95− tearDown name version db02
79+ tearDown name version db
82+ it "open specific version -> close -> open latest" do
83+ let name = "db-latest"
85+ db01 <- IDBFactory.open name (Just version)
86+ { onUpgradeNeeded : Nothing
87+ , onBlocked : Nothing
89+ IDBDatabase.name db01 `shouldEqual` name
90+ IDBDatabase.close db01
91+ db02 <- IDBFactory.open name Nothing
92+ { onUpgradeNeeded : Nothing
93+ , onBlocked : Nothing
95+ tearDown name version db02
97− it "open + onUpgradeNeed" do
97+ it "open + onUpgradeNeed" do
99− name = "db-upgrade-needed"
98+ let name = "db-upgrade-needed"
100 version = 1
99 version = 1
101 callback (Tuple varName varVersion) db _ { oldVersion } = do
100 callback (Tuple varName varVersion) db _ { oldVersion } = do
102− _ <- launchAff $ modifyAVar (const $ IDBDatabase.name db) varName
101+ _ <- launchAff $ modifyVar (const $ IDBDatabase.name db) varName
103− _ <- launchAff $ modifyAVar (const $ oldVersion) varVersion
102+ _ <- launchAff $ modifyVar (const $ oldVersion) varVersion
104 pure unit
103 pure unit
105− varName <- AVar.new "-"
104+ varName <- makeVar "-"
106− varVersion <- AVar.new (-1)
105+ varVersion <- makeVar (-1)
107− db <- IDBFactory.open name Nothing
106+ db <- IDBFactory.open name Nothing
108− { onUpgradeNeeded: Just (callback (Tuple varName varVersion))
107+ { onUpgradeNeeded : Just (callback (Tuple varName varVersion))
109− , onBlocked: Nothing
108+ , onBlocked : Nothing
111− name' <- AVar.read varName
110+ name' <- readVar varName
112− version' <- AVar.read varVersion
111+ version' <- readVar varVersion
113− name' `shouldEqual` name
112+ name' `shouldEqual` name
114− version' `shouldEqual` 0
113+ version' `shouldEqual` 0
115− tearDown name version db
114+ tearDown name version db
117− it "open + onBlocked" do
116+ it "open + onBlocked" do
119− name = "db-blocked"
117+ let name = "db-blocked"
120 version = 14
118 version = 14
121 callback var = do
119 callback var = do
122− _ <- launchAff $ modifyAVar (const $ "db-blocked") var
120+ _ <- launchAff $ modifyVar (const $ "db-blocked") var
123 pure unit
121 pure unit
125− var <- AVar.new "-"
123+ var <- makeVar "-"
126− db01 <- IDBFactory.open name Nothing
124+ db01 <- IDBFactory.open name Nothing
127− { onUpgradeNeeded: Nothing
125+ { onUpgradeNeeded : Nothing
128− , onBlocked: Nothing
126+ , onBlocked : Nothing
130− _ <- forkAff do
128+ _ <- forkAff do
131− delay (Milliseconds 100.0)
129+ delay (Milliseconds 100.0)
132− IDBDatabase.close db01
130+ IDBDatabase.close db01
134− db02 <- IDBFactory.open name (Just version)
132+ db02 <- IDBFactory.open name (Just version)
135− { onUpgradeNeeded: Nothing
133+ { onUpgradeNeeded : Nothing
136− , onBlocked: Just (callback var)
134+ , onBlocked : Just (callback var)
138− name' <- AVar.read var
136+ name' <- readVar var
139− name' `shouldEqual` name
137+ name' `shouldEqual` name
140− tearDown name version db02
138+ tearDown name version db02
142− describe "IDBKeyRange" do
140+ describe "IDBKeyRange" do
143− it "only(int)" do
141+ it "only(int)" do
145− key = 14
142+ let key = 14
146 range = IDBKeyRange.only key
143 range = IDBKeyRange.only key
147− IDBKeyRange.includes range (toKey key) `shouldEqual` true
144+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
149− it "only(string)" do
146+ it "only(string)" do
151− key = "patate"
147+ let key = "patate"
152 range = IDBKeyRange.only key
148 range = IDBKeyRange.only key
153− IDBKeyRange.includes range (toKey key) `shouldEqual` true
149+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
155− it "only(float)" do
151+ it "only(float)" do
157− key = 14.42
152+ let key = 14.42
158 range = IDBKeyRange.only key
153 range = IDBKeyRange.only key
159− IDBKeyRange.includes range (toKey key) `shouldEqual` true
154+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
161− it "only(date)" do
156+ it "only(date)" do
163− mkey = DateTime
157+ let mkey = DateTime
164 <$> (Date.canonicalDate <$> toEnum 2017 <*> toEnum 6 <*> toEnum 23)
158 <$> (Date.canonicalDate <$> toEnum 2017 <*> toEnum 6 <*> toEnum 23)
165 <*> (Time <$> toEnum 17 <*> toEnum 59 <*> toEnum 34 <*> toEnum 42)
159 <*> (Time <$> toEnum 17 <*> toEnum 59 <*> toEnum 34 <*> toEnum 42)
167− case mkey of
161+ case mkey of
168− Nothing ->
162+ Nothing ->
169− fail "unable to create datetime"
163+ fail "unable to create datetime"
170− Just key -> do
164+ Just key -> do
171− let range = IDBKeyRange.only key
165+ let range = IDBKeyRange.only key
172− IDBKeyRange.includes range (toKey key) `shouldEqual` true
166+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
174− it "only([int])" do
168+ it "only([int])" do
176− key = [ 14, 42 ]
169+ let key = [14, 42]
177 range = IDBKeyRange.only key
170 range = IDBKeyRange.only key
178− IDBKeyRange.includes range (toKey key) `shouldEqual` true
171+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
180− it "only([string])" do
173+ it "only([string])" do
182− key = [ "patate", "autruche" ]
174+ let key = ["patate", "autruche"]
183 range = IDBKeyRange.only key
175 range = IDBKeyRange.only key
184− IDBKeyRange.includes range (toKey key) `shouldEqual` true
176+ IDBKeyRange.includes range (toKey key) `shouldEqual` true
186− it "lowerBound(14, open)" do
178+ it "lowerBound(14, open)" do
188− key = 14
179+ let key = 14
189− open = true
180+ open = true
190 range = IDBKeyRange.lowerBound key open
181 range = IDBKeyRange.lowerBound key open
191− IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` true
182+ IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` true
192− IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
183+ IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
193− IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` false
184+ IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` false
195− it "lowerBound(14, close)" do
186+ it "lowerBound(14, close)" do
197− key = 14
187+ let key = 14
198− open = false
188+ open = false
199 range = IDBKeyRange.lowerBound key open
189 range = IDBKeyRange.lowerBound key open
200− IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` true
190+ IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` true
201− IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
191+ IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
202− IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` false
192+ IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` false
204− it "upperBound(14, open)" do
194+ it "upperBound(14, open)" do
206− key = 14
195+ let key = 14
207− open = true
196+ open = true
208 range = IDBKeyRange.upperBound key open
197 range = IDBKeyRange.upperBound key open
209− IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` false
198+ IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` false
210− IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
199+ IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
211− IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` true
200+ IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` true
213− it "upperBound(14, close)" do
202+ it "upperBound(14, close)" do
215− key = 14
203+ let key = 14
216− open = false
204+ open = false
217 range = IDBKeyRange.upperBound key open
205 range = IDBKeyRange.upperBound key open
218− IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` false
206+ IDBKeyRange.includes range (toKey (key + 1)) `shouldEqual` false
219− IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
207+ IDBKeyRange.includes range (toKey key) `shouldEqual` (not open)
220− IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` true
208+ IDBKeyRange.includes range (toKey (key - 1)) `shouldEqual` true
222− it "bound(42, 14, open, open) => Nothing" do
210+ it "bound(42, 14, open, open) => Nothing" do
224− lower = 42
211+ let lower = 42
225− upper = 14
212+ upper = 14
226 lowerOpen = true
213 lowerOpen = true
227 upperOpen = true
214 upperOpen = true
228− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
215+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
229− isNothing mrange `shouldEqual` true
216+ isNothing mrange `shouldEqual` true
231− it "bound(14, 42, open, open)" do
218+ it "bound(14, 42, open, open)" do
233− lower = 14
219+ let lower = 14
234− upper = 42
220+ upper = 42
235 lowerOpen = true
221 lowerOpen = true
236 upperOpen = true
222 upperOpen = true
237− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
223+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
238− case mrange of
224+ case mrange of
239− Nothing ->
225+ Nothing ->
240− fail "invalid range provided"
226+ fail "invalid range provided"
241− Just range -> do
227+ Just range -> do
242− IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
228+ IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
243− IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
229+ IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
244− IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
230+ IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
245− IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
231+ IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
246− IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
232+ IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
247− IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
233+ IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
249− it "bound(14, 42, open, close)" do
235+ it "bound(14, 42, open, close)" do
251− lower = 14
236+ let lower = 14
252− upper = 42
237+ upper = 42
253 lowerOpen = true
238 lowerOpen = true
254 upperOpen = false
239 upperOpen = false
255− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
240+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
256− case mrange of
241+ case mrange of
257− Nothing ->
242+ Nothing ->
258− fail "invalid range provided"
243+ fail "invalid range provided"
259− Just range -> do
244+ Just range -> do
260− IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
245+ IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
261− IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
246+ IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
262− IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
247+ IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
263− IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
248+ IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
264− IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
249+ IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
265− IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
250+ IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
267− it "bound(14, 42, close, open)" do
252+ it "bound(14, 42, close, open)" do
269− lower = 14
253+ let lower = 14
270− upper = 42
254+ upper = 42
271 lowerOpen = false
255 lowerOpen = false
272 upperOpen = true
256 upperOpen = true
273− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
257+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
274− case mrange of
258+ case mrange of
275− Nothing ->
259+ Nothing ->
276− fail "invalid range provided"
260+ fail "invalid range provided"
277− Just range -> do
261+ Just range -> do
278− IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
262+ IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
279− IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
263+ IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
280− IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
264+ IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
281− IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
265+ IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
282− IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
266+ IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
283− IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
267+ IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
285− it "bound(14, 42, close, close)" do
269+ it "bound(14, 42, close, close)" do
287− lower = 14
270+ let lower = 14
288− upper = 42
271+ upper = 42
289 lowerOpen = false
272 lowerOpen = false
290 upperOpen = false
273 upperOpen = false
291− mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
274+ mrange = IDBKeyRange.bound { lower, upper, lowerOpen, upperOpen }
292− case mrange of
275+ case mrange of
293− Nothing ->
276+ Nothing ->
294− fail "invalid range provided"
277+ fail "invalid range provided"
295− Just range -> do
278+ Just range -> do
296− IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
279+ IDBKeyRange.includes range (toKey (lower + 1)) `shouldEqual` true
297− IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
280+ IDBKeyRange.includes range (toKey (upper - 1)) `shouldEqual` true
298− IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
281+ IDBKeyRange.includes range (toKey (lower - 1)) `shouldEqual` false
299− IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
282+ IDBKeyRange.includes range (toKey (upper + 1)) `shouldEqual` false
300− IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
283+ IDBKeyRange.includes range (toKey lower) `shouldEqual` (not lowerOpen)
301− IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
284+ IDBKeyRange.includes range (toKey upper) `shouldEqual` (not upperOpen)
303− it "can access attributes of a range" do
286+ it "can access attributes of a range" do
304− let range = IDBKeyRange.lowerBound 14 false
287+ let range = IDBKeyRange.lowerBound 14 false
305− IDBKeyRange.lower range `shouldEqual` (Just $ toKey 14)
288+ IDBKeyRange.lower range `shouldEqual` (Just $ toKey 14)
306− IDBKeyRange.upper range `shouldEqual` none
289+ IDBKeyRange.upper range `shouldEqual` none
307− IDBKeyRange.lowerOpen range `shouldEqual` false
290+ IDBKeyRange.lowerOpen range `shouldEqual` false
308− IDBKeyRange.upperOpen range `shouldEqual` true
291+ IDBKeyRange.upperOpen range `shouldEqual` true
310− describe "IDBDatabase" do
293+ describe "IDBDatabase" do
312 tearDown db = do
295 tearDown db = do
313 IDBDatabase.close db
296 IDBDatabase.close db
314 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
297 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
315 pure unit
298 pure unit
317 setup storeParams = do
300 setup storeParams = do
319− onUpgradeNeeded var db _ _ = launchAff' do
301+ let onUpgradeNeeded var db _ _ = launchAff' do
320− store <- IDBDatabase.createObjectStore db "store" storeParams
302+ store <- IDBDatabase.createObjectStore db "store" storeParams
321− _ <- AVar.put { db, store } var
303+ _ <- putVar { db, store } var
322− pure unit
304+ pure unit
324− var <- AVar.empty
306+ var <- makeEmptyVar
325− _ <- IDBFactory.open "db" Nothing
307+ db <- IDBFactory.open "db" Nothing
326− { onUpgradeNeeded: Just (onUpgradeNeeded var)
308+ { onUpgradeNeeded : Just (onUpgradeNeeded var)
327− , onBlocked: Nothing
309+ , onBlocked : Nothing
330− AVar.take var
312+ takeVar var
332− it "createObjectStore (keyPath: [], autoIncrement: true)" do
314+ it "createObjectStore (keyPath: [], autoIncrement: true)" do
333− { db, store } <- setup { keyPath: [], autoIncrement: true }
315+ { db, store } <- setup { keyPath: [], autoIncrement: true }
334− IDBObjectStore.name store `shouldEqual` "store"
316+ IDBObjectStore.name store `shouldEqual` "store"
335− IDBObjectStore.keyPath store `shouldEqual` []
317+ IDBObjectStore.keyPath store `shouldEqual` []
336− IDBObjectStore.autoIncrement store `shouldEqual` true
318+ IDBObjectStore.autoIncrement store `shouldEqual` true
337− IDBObjectStore.indexNames store `shouldEqual` []
319+ IDBObjectStore.indexNames store `shouldEqual` []
338− tearDown db
320+ tearDown db
340− it "createObjectStore (keyPath: [\"patate\"], autoIncrement: true)" do
322+ it "createObjectStore (keyPath: [\"patate\"], autoIncrement: true)" do
341− { db, store } <- setup { keyPath: [ "patate" ], autoIncrement: true }
323+ { db, store } <- setup { keyPath: ["patate"], autoIncrement: true }
342− IDBObjectStore.name store `shouldEqual` "store"
324+ IDBObjectStore.name store `shouldEqual` "store"
343− IDBObjectStore.keyPath store `shouldEqual` [ "patate" ]
325+ IDBObjectStore.keyPath store `shouldEqual` ["patate"]
344− IDBObjectStore.autoIncrement store `shouldEqual` true
326+ IDBObjectStore.autoIncrement store `shouldEqual` true
345− IDBObjectStore.indexNames store `shouldEqual` []
327+ IDBObjectStore.indexNames store `shouldEqual` []
346− tearDown db
328+ tearDown db
348− it "createObjectStore (keyPath: [\"a\", \"b\"], autoIncrement: false)" do
330+ it "createObjectStore (keyPath: [\"a\", \"b\"], autoIncrement: false)" do
349− { db, store } <- setup { keyPath: [ "patate", "autruche" ], autoIncrement: false }
331+ { db, store } <- setup { keyPath: ["patate", "autruche"], autoIncrement: false }
350− IDBObjectStore.name store `shouldEqual` "store"
332+ IDBObjectStore.name store `shouldEqual` "store"
351− IDBObjectStore.keyPath store `shouldEqual` [ "patate", "autruche" ]
333+ IDBObjectStore.keyPath store `shouldEqual` ["patate", "autruche"]
352− IDBObjectStore.autoIncrement store `shouldEqual` false
334+ IDBObjectStore.autoIncrement store `shouldEqual` false
353− IDBObjectStore.indexNames store `shouldEqual` []
335+ IDBObjectStore.indexNames store `shouldEqual` []
354− tearDown db
336+ tearDown db
356− it "deleteObjectStore" do
338+ it "deleteObjectStore" do
358− onUpgradeNeeded var db _ _ = launchAff' do
339+ let onUpgradeNeeded var db _ _ = launchAff' do
359 _ <- IDBDatabase.deleteObjectStore db "store"
340 _ <- IDBDatabase.deleteObjectStore db "store"
360− AVar.put true var
341+ putVar true var
363− { db } <- setup IDBDatabase.defaultParameters
364− IDBDatabase.close db
365− db' <- IDBFactory.open "db" (Just 999)
366− { onUpgradeNeeded: Just (onUpgradeNeeded var)
367− , onBlocked: Nothing
369− deleted <- AVar.take var
370− deleted `shouldEqual` true
344+ { db, store } <- setup IDBDatabase.defaultParameters
345+ IDBDatabase.close db
346+ db' <- IDBFactory.open "db" (Just 999) { onUpgradeNeeded : Just (onUpgradeNeeded var)
347+ , onBlocked : Nothing
349+ deleted <- takeVar var
350+ deleted `shouldEqual` true
373− describe "IDBObjectStore" do
354+ describe "IDBObjectStore" do
375 tearDown db = do
356 tearDown db = do
376 IDBDatabase.close db
357 IDBDatabase.close db
377 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
358 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
378 pure unit
359 pure unit
380 setup { storeParams, onUpgradeNeeded } = do
361 setup { storeParams, onUpgradeNeeded } = do
382− onUpgradeNeeded' var db _ _ = launchAff' do
362+ let onUpgradeNeeded' var db _ _ = launchAff' do
383− store <- IDBDatabase.createObjectStore db "store" storeParams
363+ store <- IDBDatabase.createObjectStore db "store" storeParams
384− liftEffect $ maybe (pure unit) identity (onUpgradeNeeded <*> pure db <*> pure store)
364+ liftEff $ maybe (pure unit) id (onUpgradeNeeded <*> pure db <*> pure store)
385− AVar.put { db, store } var
365+ putVar { db, store } var
387− var <- AVar.empty
367+ var <- makeEmptyVar
388− _ <- IDBFactory.open "db" Nothing
368+ db <- IDBFactory.open "db" Nothing
389− { onUpgradeNeeded: Just (onUpgradeNeeded' var)
369+ { onUpgradeNeeded : Just (onUpgradeNeeded' var)
390− , onBlocked: Nothing
370+ , onBlocked : Nothing
393− AVar.take var
373+ takeVar var
395− it "add()" do
375+ it "add()" do
396− date <- liftEffect $ toDateTime <$> now
376+ date <- liftEff $ toDateTime <$> now
397− { db } <- setup
377+ { db } <- setup
398− { storeParams: { autoIncrement: true, keyPath: [] }
378+ { storeParams: { autoIncrement: true, keyPath: [] }
399− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
379+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
400− -- no key
380+ -- no key
401− key <- IDBObjectStore.add store "patate" none
381+ key <- IDBObjectStore.add store "patate" none
402− (toKey 1) `shouldEqual` key
382+ (toKey 1) `shouldEqual` key
404− -- int key
384+ -- int key
405− key' <- IDBObjectStore.add store "patate" (Just 14)
385+ key' <- IDBObjectStore.add store "patate" (Just 14)
406− (toKey 14) `shouldEqual` key'
386+ (toKey 14) `shouldEqual` key'
408− -- number key
388+ -- number key
409− key'' <- IDBObjectStore.add store "patate" (Just 14.42)
389+ key'' <- IDBObjectStore.add store "patate" (Just 14.42)
410− (toKey 14.42) `shouldEqual` key''
390+ (toKey 14.42) `shouldEqual` key''
412− -- string key
392+ -- string key
413− key''' <- IDBObjectStore.add store "patate" (Just "key")
393+ key''' <- IDBObjectStore.add store "patate" (Just "key")
414− (toKey "key") `shouldEqual` key'''
394+ (toKey "key") `shouldEqual` key'''
416− -- date key
396+ -- date key
417− key'''' <- IDBObjectStore.add store "patate" (Just date)
397+ key'''' <- IDBObjectStore.add store "patate" (Just date)
418− (toKey date) `shouldEqual` key''''
398+ (toKey date) `shouldEqual` key''''
420− -- array key
400+ -- array key
421− key''''' <- IDBObjectStore.add store "patate" (Just $ toKey [ 14, 42 ])
401+ key''''' <- IDBObjectStore.add store "patate" (Just $ toKey [14, 42])
422− (toKey [ 14, 42 ]) `shouldEqual` key'''''
402+ (toKey [14, 42]) `shouldEqual` key'''''
424− tearDown db
404+ tearDown db
426− it "clear()" do
406+ it "clear()" do
427− { db } <- setup
407+ { db } <- setup
428− { storeParams: IDBDatabase.defaultParameters
408+ { storeParams: IDBDatabase.defaultParameters
429− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
409+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
430− key <- IDBObjectStore.add store "patate" (Just 14)
410+ key <- IDBObjectStore.add store "patate" (Just 14)
431− _ <- IDBObjectStore.clear store
411+ _ <- IDBObjectStore.clear store
432− val <- IDBObjectStore.get store (IDBKeyRange.only key)
412+ val <- IDBObjectStore.get store (IDBKeyRange.only key)
433− val `shouldEqual` (Nothing :: Maybe String)
413+ val `shouldEqual` (Nothing :: Maybe String)
435− tearDown db
415+ tearDown db
437− it "count()" do
417+ it "count()" do
438− { db } <- setup
418+ { db } <- setup
439− { storeParams: IDBDatabase.defaultParameters
419+ { storeParams: IDBDatabase.defaultParameters
440− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
420+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
441− _ <- IDBObjectStore.add store "patate" (Just 14)
421+ _ <- IDBObjectStore.add store "patate" (Just 14)
442− _ <- IDBObjectStore.add store "autruche" (Just 42)
422+ _ <- IDBObjectStore.add store "autruche" (Just 42)
443− n <- IDBObjectStore.count store Nothing
423+ n <- IDBObjectStore.count store Nothing
444− n `shouldEqual` 2
424+ n `shouldEqual` 2
446− tearDown db
426+ tearDown db
448− it "getKey()" do
428+ it "getKey()" do
449− { db } <- setup
429+ { db } <- setup
450− { storeParams: IDBDatabase.defaultParameters
430+ { storeParams: IDBDatabase.defaultParameters
451− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
431+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
452− key <- IDBObjectStore.add store "patate" (Just 14)
432+ key <- IDBObjectStore.add store "patate" (Just 14)
453− mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 14)
433+ mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 14)
454− mkey `shouldEqual` (Just key)
434+ mkey `shouldEqual` (Just key)
456− mkey' <- IDBObjectStore.getKey store (IDBKeyRange.only 42)
436+ mkey' <- IDBObjectStore.getKey store (IDBKeyRange.only 42)
457− mkey' `shouldEqual` none
437+ mkey' `shouldEqual` none
461− it "getAllKeys()" do
463− { storeParams: IDBDatabase.defaultParameters
464− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
465− key1 <- IDBObjectStore.add store "patate" (Just 14)
466− key2 <- IDBObjectStore.add store "autruche" (Just 42)
467− key3 <- IDBObjectStore.add store 14 (Just 1337)
470− keys <- IDBObjectStore.getAllKeys store Nothing Nothing
471− keys `shouldEqual` [ key1, key2, key3 ]
474− keys' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 14 true) Nothing
475− keys' `shouldEqual` [ key2, key3 ]
478− keys'' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.upperBound 42 false) Nothing
479− keys'' `shouldEqual` [ key1, key2 ]
482− keys''' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 1 true) (Just 2)
483− keys''' `shouldEqual` [ key1, key2 ]
485− tearDown db
439+ tearDown db
441+ it "getAllKeys()" do
443+ { storeParams: IDBDatabase.defaultParameters
444+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
445+ key1 <- IDBObjectStore.add store "patate" (Just 14)
446+ key2 <- IDBObjectStore.add store "autruche" (Just 42)
447+ key3 <- IDBObjectStore.add store 14 (Just 1337)
450+ keys <- IDBObjectStore.getAllKeys store Nothing Nothing
451+ keys `shouldEqual` [key1, key2, key3]
454+ keys' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 14 true) Nothing
455+ keys' `shouldEqual` [key2, key3]
458+ keys'' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.upperBound 42 false) Nothing
459+ keys'' `shouldEqual` [key1, key2]
462+ keys''' <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 1 true) (Just 2)
463+ keys''' `shouldEqual` [key1, key2]
487− it "openCursor()" do
467+ it "openCursor()" do
490− { onSuccess: const $ pure unit
469+ { onSuccess : const $ pure unit
491− , onError: show >>> fail >>> launchAff'
470+ , onError : show >>> fail >>> launchAff'
492 , onComplete: pure unit
471 , onComplete: pure unit
494− { db } <- setup
473+ { db } <- setup
495− { storeParams: IDBDatabase.defaultParameters
474+ { storeParams: IDBDatabase.defaultParameters
496− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
475+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
497− _ <- IDBObjectStore.openCursor store Nothing Next cb
476+ _ <- IDBObjectStore.openCursor store Nothing Next cb
498− _ <- IDBObjectStore.openCursor store Nothing NextUnique cb
477+ _ <- IDBObjectStore.openCursor store Nothing NextUnique cb
499− _ <- IDBObjectStore.openCursor store Nothing Prev cb
478+ _ <- IDBObjectStore.openCursor store Nothing Prev cb
500− _ <- IDBObjectStore.openCursor store Nothing PrevUnique cb
479+ _ <- IDBObjectStore.openCursor store Nothing PrevUnique cb
501− _ <- IDBObjectStore.openCursor store (Just $ IDBKeyRange.upperBound 1 true) Next cb
480+ _ <- IDBObjectStore.openCursor store (Just $ IDBKeyRange.upperBound 1 true) Next cb
502− pure unit
481+ pure unit
504− tearDown db
483+ tearDown db
506− it "openKeyCursor()" do
485+ it "openKeyCursor()" do
509− { onSuccess: const $ pure unit
487+ { onSuccess : const $ pure unit
510− , onError: show >>> fail >>> launchAff'
488+ , onError : show >>> fail >>> launchAff'
511 , onComplete: pure unit
489 , onComplete: pure unit
513− { db } <- setup
491+ { db } <- setup
514− { storeParams: IDBDatabase.defaultParameters
492+ { storeParams: IDBDatabase.defaultParameters
515− , onUpgradeNeeded: Just $ \_ store -> launchAff' do
493+ , onUpgradeNeeded: Just $ \_ store -> launchAff' do
516− _ <- IDBObjectStore.openKeyCursor store Nothing Next cb
494+ _ <- IDBObjectStore.openKeyCursor store Nothing Next cb
517− _ <- IDBObjectStore.openKeyCursor store Nothing NextUnique cb
495+ _ <- IDBObjectStore.openKeyCursor store Nothing NextUnique cb
518− _ <- IDBObjectStore.openKeyCursor store Nothing Prev cb
496+ _ <- IDBObjectStore.openKeyCursor store Nothing Prev cb
519− _ <- IDBObjectStore.openKeyCursor store Nothing PrevUnique cb
497+ _ <- IDBObjectStore.openKeyCursor store Nothing PrevUnique cb
520− _ <- IDBObjectStore.openKeyCursor store (Just $ IDBKeyRange.lowerBound 1 true) Next cb
498+ _ <- IDBObjectStore.openKeyCursor store (Just $ IDBKeyRange.lowerBound 1 true) Next cb
521− pure unit
499+ pure unit
523− tearDown db
501+ tearDown db
525− describe "IDBIndex" do
503+ describe "IDBIndex" do
527 tearDown db = do
505 tearDown db = do
528 IDBDatabase.close db
506 IDBDatabase.close db
529 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
507 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
530 pure unit
508 pure unit
533− :: forall value
510+ setup :: forall value e e'.
534− . { storeParams :: { keyPath :: Array String, autoIncrement :: Boolean }
511+ { storeParams :: { keyPath :: Array String, autoIncrement :: Boolean }
535− , indexParams :: { unique :: Boolean, multiEntry :: Boolean }
512+ , indexParams :: { unique :: Boolean, multiEntry :: Boolean }
536− , values :: Array (Tuple value (Maybe Key))
513+ , values :: Array (Tuple value (Maybe Key))
537− , keyPath :: Array String
514+ , keyPath :: Array String
538− , onUpgradeNeeded :: Maybe (Database -> Transaction -> Index -> Effect Unit)
515+ , onUpgradeNeeded :: Maybe (Database -> Transaction -> Index -> Eff (idb :: IDB, avar :: AVAR, exception :: EXCEPTION | e') Unit)
540− -> Aff { db :: Database, index :: Index, store :: ObjectStore }
516+ } -> Aff (idb :: IDB, avar :: AVAR | e) { db :: Database, index :: Index, store :: ObjectStore }
541 setup { storeParams, indexParams, values, keyPath, onUpgradeNeeded } = do
517 setup { storeParams, indexParams, values, keyPath, onUpgradeNeeded } = do
543− onUpgradeNeeded' var db tx _ = launchAff' do
518+ let onUpgradeNeeded' var db tx _ = launchAff' do
544− store <- IDBDatabase.createObjectStore db "store" storeParams
519+ store <- IDBDatabase.createObjectStore db "store" storeParams
545− _ <- traverse (uncurry (IDBObjectStore.add store)) values
520+ _ <- traverse (uncurry (IDBObjectStore.add store)) values
546− index <- IDBObjectStore.createIndex store "index" keyPath indexParams
521+ index <- IDBObjectStore.createIndex store "index" keyPath indexParams
547− liftEffect $ maybe (pure unit) identity (onUpgradeNeeded <*> pure db <*> pure tx <*> pure index)
522+ liftEff $ maybe (pure unit) id (onUpgradeNeeded <*> pure db <*> pure tx <*> pure index)
548− AVar.put { db, index, store } var
523+ putVar { db, index, store } var
550− var <- AVar.empty
525+ var <- makeEmptyVar
551− _ <- IDBFactory.open "db" Nothing
526+ db <- IDBFactory.open "db" Nothing
552− { onUpgradeNeeded: Just (onUpgradeNeeded' var)
527+ { onUpgradeNeeded : Just (onUpgradeNeeded' var)
553− , onBlocked: Nothing
528+ , onBlocked : Nothing
555− AVar.take var
530+ takeVar var
557− it "returns an IDBIndex and the properties are set correctly" do
533+ it "returns an IDBIndex and the properties are set correctly" do
558− { db, index } <- setup
534+ { db, index } <- setup
559− { storeParams: IDBDatabase.defaultParameters
535+ { storeParams : IDBDatabase.defaultParameters
560− , indexParams: IDBObjectStore.defaultParameters
536+ , indexParams : IDBObjectStore.defaultParameters
561− , onUpgradeNeeded: Nothing
537+ , onUpgradeNeeded : Nothing
562− , keyPath: []
538+ , keyPath : []
563− , values: []
539+ , values : []
565− IDBIndex.name index `shouldEqual` "index"
541+ IDBIndex.name index `shouldEqual` "index"
566− IDBIndex.keyPath index `shouldEqual` []
542+ IDBIndex.keyPath index `shouldEqual` []
567− IDBIndex.unique index `shouldEqual` IDBObjectStore.defaultParameters.unique
543+ IDBIndex.unique index `shouldEqual` IDBObjectStore.defaultParameters.unique
568− IDBIndex.multiEntry index `shouldEqual` IDBObjectStore.defaultParameters.multiEntry
544+ IDBIndex.multiEntry index `shouldEqual` IDBObjectStore.defaultParameters.multiEntry
569− tearDown db
545+ tearDown db
571− it "attempt to create an index that requires unique values on an object store already contains duplicates" do
547+ it "attempt to create an index that requires unique values on an object store already contains duplicates" do
572− let onAbort var = launchAff' (AVar.put true var)
548+ let onAbort var = launchAff' (putVar true var)
573− txVar <- AVar.empty
549+ txVar <- makeEmptyVar
574− dbVar <- AVar.empty
550+ dbVar <- makeEmptyVar
575− res <- attempt $ setup
551+ res <- attempt $ setup
576− { storeParams: IDBDatabase.defaultParameters
552+ { storeParams : IDBDatabase.defaultParameters
577− , indexParams:
553+ , indexParams : { unique : true
579− , multiEntry: false
554+ , multiEntry : false
581− , keyPath: [ "indexedProperty" ]
556+ , keyPath : ["indexedProperty"]
583− [ { indexedProperty: "bar" } :+: (Just $ toKey 1)
557+ , values : [ { indexedProperty: "bar" } :+: (Just $ toKey 1)
584− , { indexedProperty: "bar" } :+: (Just $ toKey 2)
558+ , { indexedProperty: "bar" } :+: (Just $ toKey 2)
586− , onUpgradeNeeded: Just $ \db tx _ -> launchAff' do
560+ , onUpgradeNeeded : Just $ \db tx _ -> launchAff' do
587− IDBTransaction.onAbort tx (onAbort txVar)
561+ IDBTransaction.onAbort tx (onAbort txVar)
588− IDBDatabase.onAbort db (onAbort dbVar)
562+ IDBDatabase.onAbort db (onAbort dbVar)
590− case res of
564+ case res of
591− Right _ ->
565+ Right _ ->
592− fail "expected abort"
566+ fail "expected abort"
594− shouldEqual true =<< AVar.take txVar
568+ shouldEqual true =<< takeVar txVar
595− shouldEqual true =<< AVar.take dbVar
569+ shouldEqual true =<< takeVar dbVar
597− it "the index is usable right after being made" do
572+ it "the index is usable right after being made" do
598− { db } <- setup
573+ { db } <- setup
599− { storeParams:
574+ { storeParams : { keyPath : ["key"]
600− { keyPath: [ "key" ]
601− , autoIncrement: false
575+ , autoIncrement : false
603− , indexParams: IDBObjectStore.defaultParameters
577+ , indexParams : IDBObjectStore.defaultParameters
604− , keyPath: [ "indexedProperty" ]
578+ , keyPath : ["indexedProperty"]
606− [ { key: "key1", indexedProperty: "indexed_1" } :+: Nothing
579+ , values : [ { key: "key1", indexedProperty: "indexed_1" } :+: Nothing
607− , { key: "key2", indexedProperty: "indexed_2" } :+: Nothing
580+ , { key: "key2", indexedProperty: "indexed_2" } :+: Nothing
608− , { key: "key3", indexedProperty: "indexed_3" } :+: Nothing
581+ , { key: "key3", indexedProperty: "indexed_3" } :+: Nothing
610− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
583+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
611− val <- IDBIndex.get index (IDBKeyRange.only "indexed_2")
584+ val <- IDBIndex.get index (IDBKeyRange.only "indexed_2")
612− ((\r -> r.key) <$> val) `shouldEqual` (Just $ toKey "key2")
585+ ((\r -> r.key) <$> val) `shouldEqual` (Just $ toKey "key2")
614− tearDown db
587+ tearDown db
616− it "empty keyPath" do
589+ it "empty keyPath" do
617− { db } <- setup
590+ { db } <- setup
618− { storeParams: IDBDatabase.defaultParameters
591+ { storeParams : IDBDatabase.defaultParameters
619− , indexParams: IDBObjectStore.defaultParameters
592+ , indexParams : IDBObjectStore.defaultParameters
620− , keyPath: []
593+ , keyPath : []
622− [ "object_1" :+: (Just $ toKey 1)
594+ , values : [ "object_1" :+: (Just $ toKey 1)
623− , "object_2" :+: (Just $ toKey 2)
595+ , "object_2" :+: (Just $ toKey 2)
624− , "object_3" :+: (Just $ toKey 3)
596+ , "object_3" :+: (Just $ toKey 3)
626− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
598+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
627− val <- IDBIndex.get index (IDBKeyRange.only "object_3")
599+ val <- IDBIndex.get index (IDBKeyRange.only "object_3")
628− val `shouldEqual` (Just "object_3")
600+ val `shouldEqual` (Just "object_3")
630− tearDown db
602+ tearDown db
632− it "index can be valid keys [date]" do
604+ it "index can be valid keys [date]" do
633− date <- liftEffect $ toDateTime <$> now
605+ date <- liftEff $ toDateTime <$> now
634− { db } <- setup
606+ { db } <- setup
635− { storeParams:
607+ { storeParams : { keyPath: ["key"]
636− { keyPath: [ "key" ]
637− , autoIncrement: false
608+ , autoIncrement: false
639− , indexParams: IDBObjectStore.defaultParameters
610+ , indexParams : IDBObjectStore.defaultParameters
640− , keyPath: [ "i" ]
611+ , keyPath : ["i"]
642− [ { key: "date", i: (toKey date) } :+: Nothing
612+ , values : [ { key: "date", i: (toKey date) } :+: Nothing
644− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
614+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
645− val <- IDBIndex.get index (IDBKeyRange.only date)
615+ val <- IDBIndex.get index (IDBKeyRange.only date)
646− ((\r -> r.key) <$> val) `shouldEqual` (Just "date")
616+ ((\r -> r.key) <$> val) `shouldEqual` (Just "date")
648− tearDown db
618+ tearDown db
650− it "index can be valid keys [num]" do
620+ it "index can be valid keys [num]" do
651− let num = 14
621+ let num = 14
652− { db } <- setup
622+ { db } <- setup
653− { storeParams:
623+ { storeParams : { keyPath: ["key"]
654− { keyPath: [ "key" ]
655− , autoIncrement: false
624+ , autoIncrement: false
657− , indexParams: IDBObjectStore.defaultParameters
626+ , indexParams : IDBObjectStore.defaultParameters
658− , keyPath: [ "i" ]
627+ , keyPath : ["i"]
660− [ { key: "num", i: (toKey num) } :+: Nothing
628+ , values : [ { key: "num", i: (toKey num) } :+: Nothing
662− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
630+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
663− val <- IDBIndex.get index (IDBKeyRange.only num)
631+ val <- IDBIndex.get index (IDBKeyRange.only num)
664− ((\r -> r.key) <$> val) `shouldEqual` (Just "num")
632+ ((\r -> r.key) <$> val) `shouldEqual` (Just "num")
666− tearDown db
634+ tearDown db
668− it "index can be valid keys [array]" do
636+ it "index can be valid keys [array]" do
669− let array = [ "patate", "autruche" ]
637+ let array = ["patate", "autruche"]
670− { db } <- setup
638+ { db } <- setup
671− { storeParams:
639+ { storeParams : { keyPath: ["key"]
672− { keyPath: [ "key" ]
673− , autoIncrement: false
640+ , autoIncrement: false
675− , indexParams: IDBObjectStore.defaultParameters
642+ , indexParams : IDBObjectStore.defaultParameters
676− , keyPath: [ "i" ]
643+ , keyPath : ["i"]
678− [ { key: "array", i: (toKey array) } :+: Nothing
644+ , values : [ { key: "array", i: (toKey array) } :+: Nothing
680− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
646+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
681− val <- IDBIndex.get index (IDBKeyRange.only array)
647+ val <- IDBIndex.get index (IDBKeyRange.only array)
682− ((\r -> r.key) <$> val) `shouldEqual` (Just "array")
648+ ((\r -> r.key) <$> val) `shouldEqual` (Just "array")
684− tearDown db
650+ tearDown db
686− it "openKeyCursor() - throw InvalidStateError on index deleted by aborted upgrade" do
652+ it "openKeyCursor() - throw InvalidStateError on index deleted by aborted upgrade" do
687− res <- attempt $ setup
653+ res <- attempt $ setup
688− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
654+ { storeParams : { keyPath: ["key"], autoIncrement: false }
689− , indexParams: IDBObjectStore.defaultParameters
655+ , indexParams : IDBObjectStore.defaultParameters
690− , keyPath: [ "indexedProperty" ]
656+ , keyPath : ["indexedProperty"]
692− [ { key: 14, indexedProperty: "patate" } :+: Nothing
657+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
694− , onUpgradeNeeded: Just $ \db tx index -> launchAff' do
659+ , onUpgradeNeeded : Just $ \db tx index -> launchAff' do
697− { onSuccess: const $ pure unit
661+ { onSuccess : const $ pure unit
698− , onError: show >>> fail >>> launchAff'
662+ , onError : show >>> fail >>> launchAff'
699 , onComplete: pure unit
663 , onComplete: pure unit
701− IDBTransaction.onAbort tx (pure unit)
665+ IDBTransaction.onAbort tx (pure unit)
702− IDBDatabase.onAbort db (pure unit)
666+ IDBDatabase.onAbort db (pure unit)
703− IDBTransaction.abort tx
667+ IDBTransaction.abort tx
704− cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
668+ cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
705− case cursor of
669+ case cursor of
706− Right _ -> fail "expected InvalidStateError"
670+ Right _ -> fail "expected InvalidStateError"
707− Left err -> name err `shouldEqual` "InvalidStateError"
671+ Left err -> name err `shouldEqual` "InvalidStateError"
709− case res of
673+ case res of
710− Right _ -> fail "expected InvalidStateError"
674+ Right _ -> fail "expected InvalidStateError"
711− _ -> pure unit
675+ _ -> pure unit
713− it "openKeyCursor() - throw TransactionInactiveError on aborted transaction" do
677+ it "openKeyCursor() - throw TransactionInactiveError on aborted transaction" do
714− { db } <- setup
678+ { db } <- setup
715− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
679+ { storeParams : { keyPath: ["key"], autoIncrement: false }
716− , indexParams: IDBObjectStore.defaultParameters
680+ , indexParams : IDBObjectStore.defaultParameters
717− , keyPath: [ "indexedProperty" ]
681+ , keyPath : ["indexedProperty"]
719− [ { key: 14, indexedProperty: "patate" } :+: Nothing
682+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
721− , onUpgradeNeeded: Nothing
684+ , onUpgradeNeeded : Nothing
725− { onSuccess: const $ pure unit
687+ { onSuccess : const $ pure unit
726− , onError: show >>> fail >>> launchAff'
688+ , onError : show >>> fail >>> launchAff'
727 , onComplete: pure unit
689 , onComplete: pure unit
729− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
691+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
730− store <- IDBTransaction.objectStore tx "store"
692+ store <- IDBTransaction.objectStore tx "store"
731− index <- IDBObjectStore.index store "index"
693+ index <- IDBObjectStore.index store "index"
732− IDBTransaction.onAbort tx (pure unit)
694+ IDBTransaction.onAbort tx (pure unit)
733− IDBTransaction.abort tx
695+ IDBTransaction.abort tx
734− cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
696+ cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
735− case cursor of
697+ case cursor of
736− Right _ -> fail "expected TransactionInactiveError"
698+ Right _ -> fail "expected TransactionInactiveError"
737− Left err -> name err `shouldEqual` "TransactionInactiveError"
699+ Left err -> name err `shouldEqual` "TransactionInactiveError"
739− tearDown db
701+ tearDown db
741− it "openKeyCursor() - throw InvalidStateError when the index is deleted" do
703+ it "openKeyCursor() - throw InvalidStateError when the index is deleted" do
742− { db } <- setup
704+ { db } <- setup
743− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
705+ { storeParams : { keyPath: ["key"], autoIncrement: false }
744− , indexParams: IDBObjectStore.defaultParameters
706+ , indexParams : IDBObjectStore.defaultParameters
745− , keyPath: [ "indexedProperty" ]
707+ , keyPath : ["indexedProperty"]
747− [ { key: 14, indexedProperty: "patate" } :+: Nothing
708+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
749− , onUpgradeNeeded: Just $ \_ tx index -> launchAff' do
710+ , onUpgradeNeeded : Just $ \db tx index -> launchAff' do
752− { onSuccess: const $ pure unit
712+ { onSuccess : const $ pure unit
753− , onError: show >>> fail >>> launchAff'
713+ , onError : show >>> fail >>> launchAff'
754 , onComplete: pure unit
714 , onComplete: pure unit
756− store <- IDBTransaction.objectStore tx "store"
716+ store <- IDBTransaction.objectStore tx "store"
757− IDBObjectStore.deleteIndex store "index"
717+ IDBObjectStore.deleteIndex store "index"
758− cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
718+ cursor <- attempt $ IDBIndex.openKeyCursor index Nothing Next cb
759− case cursor of
719+ case cursor of
760− Right _ -> fail "expected InvalidStateError"
720+ Right _ -> fail "expected InvalidStateError"
761− Left err -> name err `shouldEqual` "InvalidStateError"
721+ Left err -> name err `shouldEqual` "InvalidStateError"
764− tearDown db
724+ tearDown db
766− it "openCursor() - throw InvalidStateError on index deleted by aborted upgrade" do
726+ it "openCursor() - throw InvalidStateError on index deleted by aborted upgrade" do
767− res <- attempt $ setup
727+ res <- attempt $ setup
768− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
728+ { storeParams : { keyPath: ["key"], autoIncrement: false }
769− , indexParams: IDBObjectStore.defaultParameters
729+ , indexParams : IDBObjectStore.defaultParameters
770− , keyPath: [ "indexedProperty" ]
730+ , keyPath : ["indexedProperty"]
771− , values:
731+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
772− [ { key: 14, indexedProperty: "patate" } :+: Nothing
732+ ]
773− ]
733+ , onUpgradeNeeded : Just $ \db tx index -> launchAff' do
774− , onUpgradeNeeded: Just $ \db tx index -> launchAff' do
734+ let cb =
775− let
735+ { onSuccess : const $ pure unit
776− cb =
736+ , onError : show >>> fail >>> launchAff'
777− { onSuccess: const $ pure unit
778− , onError: show >>> fail >>> launchAff'
779 , onComplete: pure unit
737 , onComplete: pure unit
781− IDBTransaction.onAbort tx (pure unit)
739+ IDBTransaction.onAbort tx (pure unit)
782− IDBDatabase.onAbort db (pure unit)
740+ IDBDatabase.onAbort db (pure unit)
783− IDBTransaction.abort tx
741+ IDBTransaction.abort tx
784− cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
742+ cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
785− case cursor of
743+ case cursor of
786− Right _ -> fail "expected InvalidStateError"
744+ Right _ -> fail "expected InvalidStateError"
787− Left err -> name err `shouldEqual` "InvalidStateError"
745+ Left err -> name err `shouldEqual` "InvalidStateError"
789− case res of
747+ case res of
790− Right _ -> fail "expected InvalidStateError"
748+ Right _ -> fail "expected InvalidStateError"
791− _ -> pure unit
749+ _ -> pure unit
793− it "openCursor() - throw TransactionInactiveError on aborted transaction" do
751+ it "openCursor() - throw TransactionInactiveError on aborted transaction" do
794− { db } <- setup
752+ { db } <- setup
795− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
753+ { storeParams : { keyPath: ["key"], autoIncrement: false }
796− , indexParams: IDBObjectStore.defaultParameters
754+ , indexParams : IDBObjectStore.defaultParameters
797− , keyPath: [ "indexedProperty" ]
755+ , keyPath : ["indexedProperty"]
798− , values:
756+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
799− [ { key: 14, indexedProperty: "patate" } :+: Nothing
757+ ]
800− ]
758+ , onUpgradeNeeded : Nothing
801− , onUpgradeNeeded: Nothing
759+ }
803− let
761+ { onSuccess : const $ pure unit
804− cb =
762+ , onError : show >>> fail >>> launchAff'
805− { onSuccess: const $ pure unit
806− , onError: show >>> fail >>> launchAff'
807 , onComplete: pure unit
763 , onComplete: pure unit
809− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
765+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
810− store <- IDBTransaction.objectStore tx "store"
766+ store <- IDBTransaction.objectStore tx "store"
811− index <- IDBObjectStore.index store "index"
767+ index <- IDBObjectStore.index store "index"
812− IDBTransaction.onAbort tx (pure unit)
768+ IDBTransaction.onAbort tx (pure unit)
813− IDBTransaction.abort tx
769+ IDBTransaction.abort tx
814− cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
770+ cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
815− case cursor of
771+ case cursor of
816− Right _ -> fail "expected TransactionInactiveError"
772+ Right _ -> fail "expected TransactionInactiveError"
817− Left err -> name err `shouldEqual` "TransactionInactiveError"
773+ Left err -> name err `shouldEqual` "TransactionInactiveError"
819− tearDown db
775+ tearDown db
821− it "openCursor() - throw InvalidStateError when the index is deleted" do
777+ it "openCursor() - throw InvalidStateError when the index is deleted" do
822− { db } <- setup
778+ { db } <- setup
823− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
779+ { storeParams : { keyPath: ["key"], autoIncrement: false }
824− , indexParams: IDBObjectStore.defaultParameters
780+ , indexParams : IDBObjectStore.defaultParameters
825− , keyPath: [ "indexedProperty" ]
781+ , keyPath : ["indexedProperty"]
826− , values:
782+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
827− [ { key: 14, indexedProperty: "patate" } :+: Nothing
783+ ]
828− ]
784+ , onUpgradeNeeded : Just $ \db tx index -> launchAff' do
829− , onUpgradeNeeded: Just $ \db tx index -> launchAff' do
785+ let cb =
830− let
786+ { onSuccess : const $ pure unit
831− cb =
787+ , onError : show >>> fail >>> launchAff'
832− { onSuccess: const $ pure unit
833− , onError: show >>> fail >>> launchAff'
834 , onComplete: pure unit
788 , onComplete: pure unit
836− store <- IDBTransaction.objectStore tx "store"
790+ store <- IDBTransaction.objectStore tx "store"
837− IDBObjectStore.deleteIndex store "index"
791+ IDBObjectStore.deleteIndex store "index"
838− cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
792+ cursor <- attempt $ IDBIndex.openCursor index Nothing Next cb
839− case cursor of
793+ case cursor of
840− Right _ -> fail "expected InvalidStateError"
794+ Right _ -> fail "expected InvalidStateError"
841− Left err -> name err `shouldEqual` "InvalidStateError"
795+ Left err -> name err `shouldEqual` "InvalidStateError"
844− tearDown db
798+ tearDown db
846− it "getKey() - multiEntry - adding keys" do
800+ it "getKey() - multiEntry - adding keys" do
847− { db } <- setup
801+ { db } <- setup
848− { storeParams: IDBDatabase.defaultParameters
802+ { storeParams : IDBDatabase.defaultParameters
849− , indexParams: { unique: false, multiEntry: true }
803+ , indexParams : { unique: false, multiEntry: true }
850− , keyPath: [ "name" ]
804+ , keyPath : ["name"]
851− , values:
805+ , values : [ { name: ["patate", "autruche"] } :+: (Just $ toKey 1)
852− [ { name: [ "patate", "autruche" ] } :+: (Just $ toKey 1)
806+ , { name: ["bob"] } :+: (Just $ toKey 2)
853− , { name: [ "bob" ] } :+: (Just $ toKey 2)
807+ ]
854− ]
808+ , onUpgradeNeeded : Just $ \_ _ index -> launchAff' do
855− , onUpgradeNeeded: Just $ \_ _ index -> launchAff' do
809+ key <- IDBIndex.getKey index (IDBKeyRange.only "patate")
856− key <- IDBIndex.getKey index (IDBKeyRange.only "patate")
810+ key `shouldEqual` (Just $ toKey 1)
857− key `shouldEqual` (Just $ toKey 1)
811+
858−
812+ key' <- IDBIndex.getKey index (IDBKeyRange.only "autruche")
859− key' <- IDBIndex.getKey index (IDBKeyRange.only "autruche")
813+ key' `shouldEqual` (Just $ toKey 1)
860− key' `shouldEqual` (Just $ toKey 1)
814+
861−
815+ key'' <- IDBIndex.getKey index (IDBKeyRange.only "bob")
862− key'' <- IDBIndex.getKey index (IDBKeyRange.only "bob")
816+ key'' `shouldEqual` (Just $ toKey 2)
863− key'' `shouldEqual` (Just $ toKey 2)
817+ }
867− it "get() - returns the record with the first key in the range" do
821+ it "get() - returns the record with the first key in the range" do
868− { db } <- setup
822+ { db } <- setup
869− { storeParams: { keyPath: [ "key" ], autoIncrement: false }
823+ { storeParams : { keyPath: ["key"], autoIncrement: false }
870− , indexParams: IDBObjectStore.defaultParameters
824+ , indexParams : IDBObjectStore.defaultParameters
871− , keyPath: [ "indexedProperty" ]
825+ , keyPath : ["indexedProperty"]
872− , values:
826+ , values : [ { key: 14, indexedProperty: "patate" } :+: Nothing
873− [ { key: 14, indexedProperty: "patate" } :+: Nothing
827+ , { key: 42, indexedProperty: "autruche" } :+: Nothing
874− , { key: 42, indexedProperty: "autruche" } :+: Nothing
828+ , { key: 1337, indexedProperty: "baguette" } :+: Nothing
875− , { key: 1337, indexedProperty: "baguette" } :+: Nothing
829+ ]
876− ]
830+ , onUpgradeNeeded : Nothing
877− , onUpgradeNeeded: Nothing
831+ }
879−
833+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
880− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
834+ store <- IDBTransaction.objectStore tx "store"
881− store <- IDBTransaction.objectStore tx "store"
835+ index <- IDBObjectStore.index store "index"
882− index <- IDBObjectStore.index store "index"
836+ val <- IDBIndex.get index (IDBKeyRange.lowerBound "autruche" false)
883− val <- IDBIndex.get index (IDBKeyRange.lowerBound "autruche" false)
837+ ((\r -> r.key) <$> val) `shouldEqual` (Just 42)
884− ((\r -> r.key) <$> val) `shouldEqual` (Just 42)
838+
887−
841+ describe "IDBCursor" do
888− describe "IDBCursor" do
842+ let
890 tearDown db = do
843 tearDown db = do
891 IDBDatabase.close db
844 IDBDatabase.close db
892 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
845 _ <- IDBFactory.deleteDatabase (IDBDatabase.name db)
893 pure unit
846 pure unit
895− setup
848+ setup :: forall value e e'.
896− :: forall value
849+ { storeParams :: { keyPath :: Array String, autoIncrement :: Boolean }
897− . { storeParams :: { keyPath :: Array String, autoIncrement :: Boolean }
850+ , indexParams :: { unique :: Boolean, multiEntry :: Boolean }
898− , indexParams :: { unique :: Boolean, multiEntry :: Boolean }
851+ , values :: Array (Tuple value (Maybe Key))
899− , values :: Array (Tuple value (Maybe Key))
852+ , keyPath :: Array String
900− , keyPath :: Array String
853+ , onUpgradeNeeded :: Maybe (Database -> Transaction -> Index -> Eff (idb :: IDB, avar :: AVAR, exception :: EXCEPTION | e') Unit)
901− , onUpgradeNeeded :: Maybe (Database -> Transaction -> Index -> Effect Unit)
854+ } -> Aff (idb :: IDB, avar :: AVAR | e) { db :: Database, index :: Index, store :: ObjectStore }
903− -> Aff { db :: Database, index :: Index, store :: ObjectStore }
904 setup { storeParams, indexParams, values, keyPath, onUpgradeNeeded } = do
855 setup { storeParams, indexParams, values, keyPath, onUpgradeNeeded } = do
905− let
856+ let onUpgradeNeeded' var db tx _ = launchAff' do
906− onUpgradeNeeded' var db tx _ = launchAff' do
857+ store <- IDBDatabase.createObjectStore db "store" storeParams
907− store <- IDBDatabase.createObjectStore db "store" storeParams
858+ _ <- traverse (uncurry (IDBObjectStore.add store)) values
908− _ <- traverse (uncurry (IDBObjectStore.add store)) values
859+ index <- IDBObjectStore.createIndex store "index" keyPath indexParams
909− index <- IDBObjectStore.createIndex store "index" keyPath indexParams
860+ 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)
861+ putVar { db, index, store } var
911− AVar.put { db, index, store } var
862+
912−
863+ var <- makeEmptyVar
913− var <- AVar.empty
864+ db <- IDBFactory.open "db" Nothing
914− db <- IDBFactory.open "db" Nothing
865+ { onUpgradeNeeded : Just (onUpgradeNeeded' var)
915− { onUpgradeNeeded: Just (onUpgradeNeeded' var)
866+ , onBlocked : Nothing
916− , onBlocked: Nothing
918− AVar.take var
868+ takeVar var
920− it "continue() - iterate to the next record" do
870+ it "continue() - iterate to the next record" do
921− { db } <- setup
871+ { db } <- setup
922− { storeParams: IDBDatabase.defaultParameters
872+ { storeParams : IDBDatabase.defaultParameters
923− , indexParams: IDBObjectStore.defaultParameters
873+ , indexParams : IDBObjectStore.defaultParameters
924− , keyPath: []
874+ , keyPath : []
925− , values:
875+ , values : [ "cupcake" :+: (Just $ toKey 4)
926− [ "cupcake" :+: (Just $ toKey 4)
876+ , "pancake" :+: (Just $ toKey 2)
927− , "pancake" :+: (Just $ toKey 2)
877+ , "pie" :+: (Just $ toKey 1)
928− , "pie" :+: (Just $ toKey 1)
878+ , "pie" :+: (Just $ toKey 3)
929− , "pie" :+: (Just $ toKey 3)
879+ ]
930− ]
880+ , onUpgradeNeeded: Nothing
931− , onUpgradeNeeded: Nothing
881+ }
932− }
882+ let cb vdone vvals =
935 { onComplete: launchAff' do
883 { onComplete: launchAff' do
936− AVar.put unit vdone
884+ putVar unit vdone
938− , onError: \error -> launchAff' do
886+ , onError: \error -> launchAff' do
939 fail $ "unexpected error: " <> show error
887 fail $ "unexpected error: " <> show error
941 , onSuccess: \cursor -> launchAff' do
889 , onSuccess: \cursor -> launchAff' do
942− vals <- AVar.take vvals
890+ vals <- takeVar vvals
943 pure (IDBCursor.value cursor) >>= shouldEqual (maybe "" _.v $ head vals)
891 pure (IDBCursor.value cursor) >>= shouldEqual (maybe "" _.v $ head vals)
944− IDBCursor.primaryKey cursor >>= shouldEqual (maybe (toKey 0) _.k $ head vals)
892+ IDBCursor.primaryKey cursor >>= shouldEqual (maybe (toKey 0) _.k $ head vals)
945− AVar.put (drop 1 vals) vvals
893+ putVar (drop 1 vals) vvals
946 IDBCursor.continue cursor none
894 IDBCursor.continue cursor none
948− vdone <- AVar.empty
896+ vdone <- makeEmptyVar
949− vvals <- AVar.new
897+ vvals <- makeVar
950− [ { v: "pie", k: toKey 1 }
898+ [ { v: "pie" , k: toKey 1 }
951− , { v: "pancake", k: toKey 2 }
899+ , { v: "pancake", k: toKey 2 }
952− , { v: "pie", k: toKey 3 }
900+ , { v: "pie" , k: toKey 3 }
953− , { v: "cupcake", k: toKey 4 }
901+ , { v: "cupcake", k: toKey 4 }
955− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
903+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
956− store <- IDBTransaction.objectStore tx "store"
904+ store <- IDBTransaction.objectStore tx "store"
957− IDBObjectStore.openCursor store Nothing Next (cb vdone vvals)
905+ IDBObjectStore.openCursor store Nothing Next (cb vdone vvals)
958− AVar.take vdone
906+ takeVar vdone
959− tearDown db
907+ tearDown db
961− it "continue() - attempt to iterate in the wrong direction" do
909+ it "continue() - attempt to iterate in the wrong direction" do
962− { db } <- setup
910+ { db } <- setup
963− { storeParams: IDBDatabase.defaultParameters
911+ { storeParams : IDBDatabase.defaultParameters
964− , indexParams: IDBObjectStore.defaultParameters
912+ , indexParams : IDBObjectStore.defaultParameters
965− , keyPath: []
913+ , keyPath : []
966− , values:
914+ , values : [ "cupcake" :+: (Just $ toKey 4)
967− [ "cupcake" :+: (Just $ toKey 4)
915+ , "pancake" :+: (Just $ toKey 2)
968− , "pancake" :+: (Just $ toKey 2)
916+ , "pie" :+: (Just $ toKey 1)
969− , "pie" :+: (Just $ toKey 1)
917+ , "pie" :+: (Just $ toKey 3)
970− , "pie" :+: (Just $ toKey 3)
918+ ]
971− ]
919+ , onUpgradeNeeded: Nothing
972− , onUpgradeNeeded: Nothing
920+ }
973− }
921+ let cb vdone =
976 { onComplete: launchAff' do
922 { onComplete: launchAff' do
977 fail $ "shouldn't complete"
923 fail $ "shouldn't complete"
979− , onError: \error -> launchAff' do
925+ , onError: \error -> launchAff' do
980 fail $ "unexpected error: " <> show error
926 fail $ "unexpected error: " <> show error
982 , onSuccess: \cursor -> launchAff' do
928 , onSuccess: \cursor -> launchAff' do
983 res <- attempt $ IDBCursor.continue cursor (Just 1)
929 res <- attempt $ IDBCursor.continue cursor (Just 1)
984 case res of
930 case res of
985− Left err -> do
931+ Left err -> do
986 name err `shouldEqual` "DataError"
932 name err `shouldEqual` "DataError"
987− AVar.put unit vdone
933+ putVar unit vdone
988 Right _ -> do
934 Right _ -> do
989 fail "expected continue to fail"
935 fail "expected continue to fail"
991− vdone <- AVar.empty
937+ vdone <- makeEmptyVar
992− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
938+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
993− store <- IDBTransaction.objectStore tx "store"
939+ store <- IDBTransaction.objectStore tx "store"
994− IDBObjectStore.openCursor store Nothing Next (cb vdone)
940+ IDBObjectStore.openCursor store Nothing Next (cb vdone)
995− AVar.take vdone
941+ takeVar vdone
996− tearDown db
942+ tearDown db
998− it "advance() - iterate cursor number of times specified by count" do
944+
999− { db } <- setup
945+ it "advance() - iterate cursor number of times specified by count" do
1000− { storeParams: { keyPath: [ "pKey" ], autoIncrement: false }
946+ { db } <- setup
1001− , indexParams: IDBObjectStore.defaultParameters
947+ { storeParams : { keyPath: ["pKey"], autoIncrement: false }
1002− , keyPath: []
948+ , indexParams : IDBObjectStore.defaultParameters
1003− , values:
949+ , keyPath : []
1004− [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
950+ , values : [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1005− , { pKey: "pkey_1", iKey: "ikey_1" } :+: Nothing
951+ , { pKey: "pkey_1", iKey: "ikey_1" } :+: Nothing
1006− , { pKey: "pkey_2", iKey: "ikey_2" } :+: Nothing
952+ , { pKey: "pkey_2", iKey: "ikey_2" } :+: Nothing
1007− , { pKey: "pkey_3", iKey: "ikey_3" } :+: Nothing
953+ , { pKey: "pkey_3", iKey: "ikey_3" } :+: Nothing
1009− , onUpgradeNeeded: Nothing
955+ , onUpgradeNeeded: Nothing
1011− let
957+ let cb vdone vjump =
1013 { onComplete: launchAff' do
958 { onComplete: launchAff' do
1014− AVar.put unit vdone
959+ putVar unit vdone
1016− , onError: \error -> launchAff' do
961+ , onError: \error -> launchAff' do
1017 fail $ "unexpected error: " <> show error
962 fail $ "unexpected error: " <> show error
1019 , onSuccess: \cursor -> launchAff' do
964 , onSuccess: \cursor -> launchAff' do
1020− jump <- AVar.take vjump
965+ jump <- takeVar vjump
1021− if jump then do
966+ if jump
1022− IDBCursor.advance cursor 3
967+ then do
1023− else do
968+ IDBCursor.advance cursor 3
1024− let value = IDBCursor.value cursor
969+ else do
1025− value.pKey `shouldEqual` "pkey_3"
970+ let value = IDBCursor.value cursor
1026− value.iKey `shouldEqual` "ikey_3"
971+ value.pKey `shouldEqual` "pkey_3"
1027− IDBCursor.continue cursor none
972+ value.iKey `shouldEqual` "ikey_3"
1028− AVar.put false vjump
973+ IDBCursor.continue cursor none
1030− vdone <- AVar.empty
976+ vdone <- makeEmptyVar
1031− vjump <- AVar.new true
977+ vjump <- makeVar true
1032− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
978+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
1033− store <- IDBTransaction.objectStore tx "store"
979+ store <- IDBTransaction.objectStore tx "store"
1034− IDBObjectStore.openCursor store Nothing Next (cb vdone vjump)
980+ IDBObjectStore.openCursor store Nothing Next (cb vdone vjump)
1035− AVar.take vdone
981+ takeVar vdone
1036− tearDown db
982+ tearDown db
1038− it "delete() - remove a record from the object store" do
984+ it "delete() - remove a record from the object store" do
1039− { db } <- setup
985+ { db } <- setup
1040− { storeParams: { keyPath: [ "pKey" ], autoIncrement: false }
986+ { storeParams : { keyPath: ["pKey"], autoIncrement: false }
1041− , indexParams: IDBObjectStore.defaultParameters
987+ , indexParams : IDBObjectStore.defaultParameters
1042− , keyPath: []
988+ , keyPath : []
1043− , values:
989+ , values : [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1044− [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
990+ , { pKey: "pkey_1", iKey: "ikey_1" } :+: Nothing
1045− , { pKey: "pkey_1", iKey: "ikey_1" } :+: Nothing
991+ , { pKey: "pkey_2", iKey: "ikey_2" } :+: Nothing
1046− , { pKey: "pkey_2", iKey: "ikey_2" } :+: Nothing
992+ , { pKey: "pkey_3", iKey: "ikey_3" } :+: Nothing
1047− , { pKey: "pkey_3", iKey: "ikey_3" } :+: Nothing
993+ ]
1048− ]
994+ , onUpgradeNeeded: Nothing
1049− , onUpgradeNeeded: Nothing
995+ }
1050− }
996+ let cb vdone store =
1053 { onComplete: launchAff' do
997 { onComplete: launchAff' do
1054 mval <- map _.pKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
998 mval <- map _.pKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
1055 mval `shouldEqual` (Nothing :: Maybe String)
999 mval `shouldEqual` (Nothing :: Maybe String)
1056− AVar.put unit vdone
1000+ putVar unit vdone
1058− , onError: \error -> launchAff' do
1002+ , onError: \error -> launchAff' do
1059 fail $ "unexpected error: " <> show error
1003 fail $ "unexpected error: " <> show error
1061 , onSuccess: \cursor -> launchAff' do
1005 , onSuccess: \cursor -> launchAff' do
@@ -1064,31 +1008,29 @@ main = do
1064 IDBCursor.delete cursor
1008 IDBCursor.delete cursor
1065 IDBCursor.advance cursor 4
1009 IDBCursor.advance cursor 4
1067− vdone <- AVar.empty
1011+ vdone <- makeEmptyVar
1068− tx <- IDBDatabase.transaction db [ "store" ] ReadWrite
1012+ tx <- IDBDatabase.transaction db ["store"] ReadWrite
1069− store <- IDBTransaction.objectStore tx "store"
1013+ store <- IDBTransaction.objectStore tx "store"
1070− IDBObjectStore.openCursor store Nothing Next (cb vdone store)
1014+ IDBObjectStore.openCursor store Nothing Next (cb vdone store)
1071− AVar.take vdone
1015+ takeVar vdone
1072− tearDown db
1016+ tearDown db
1074− it "update() - modify a record in the object store" do
1018+ it "update() - modify a record in the object store" do
1075− { db } <- setup
1019+ { db } <- setup
1076− { storeParams: { keyPath: [ "pKey" ], autoIncrement: false }
1020+ { storeParams : { keyPath: ["pKey"], autoIncrement: false }
1077− , indexParams: IDBObjectStore.defaultParameters
1021+ , indexParams : IDBObjectStore.defaultParameters
1078− , keyPath: []
1022+ , keyPath : []
1079− , values:
1023+ , values : [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1080− [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1024+ ]
1081− ]
1025+ , onUpgradeNeeded: Nothing
1082− , onUpgradeNeeded: Nothing
1026+ }
1083− }
1027+ let cb vdone store =
1086 { onComplete: launchAff' do
1028 { onComplete: launchAff' do
1087 mval <- map _.iKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
1029 mval <- map _.iKey <$> IDBIndex.get store (IDBKeyRange.only "pkey_0")
1088 mval `shouldEqual` (Just "patate")
1030 mval `shouldEqual` (Just "patate")
1089− AVar.put unit vdone
1031+ putVar unit vdone
1091− , onError: \error -> launchAff' do
1033+ , onError: \error -> launchAff' do
1092 fail $ "unexpected error: " <> show error
1034 fail $ "unexpected error: " <> show error
1094 , onSuccess: \cursor -> launchAff' do
1036 , onSuccess: \cursor -> launchAff' do
@@ -1098,29 +1040,27 @@ main = do
1098 key `shouldEqual` toKey "pkey_0"
1040 key `shouldEqual` toKey "pkey_0"
1099 IDBCursor.advance cursor 4
1041 IDBCursor.advance cursor 4
1101− vdone <- AVar.empty
1043+ vdone <- makeEmptyVar
1102− tx <- IDBDatabase.transaction db [ "store" ] ReadWrite
1044+ tx <- IDBDatabase.transaction db ["store"] ReadWrite
1103− store <- IDBTransaction.objectStore tx "store"
1045+ store <- IDBTransaction.objectStore tx "store"
1104− IDBObjectStore.openCursor store Nothing Next (cb vdone store)
1046+ IDBObjectStore.openCursor store Nothing Next (cb vdone store)
1105− AVar.take vdone
1047+ takeVar vdone
1106− tearDown db
1048+ tearDown db
1108− it "update() - throw ReadOnlyError after update on ReadOnly transaction" do
1050+ it "update() - throw ReadOnlyError after update on ReadOnly transaction" do
1109− { db } <- setup
1051+ { db } <- setup
1110− { storeParams: { keyPath: [ "pKey" ], autoIncrement: false }
1052+ { storeParams : { keyPath: ["pKey"], autoIncrement: false }
1111− , indexParams: IDBObjectStore.defaultParameters
1053+ , indexParams : IDBObjectStore.defaultParameters
1112− , keyPath: []
1054+ , keyPath : []
1113− , values:
1055+ , values : [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1114− [ { pKey: "pkey_0", iKey: "ikey_0" } :+: Nothing
1056+ ]
1115− ]
1057+ , onUpgradeNeeded: Nothing
1116− , onUpgradeNeeded: Nothing
1058+ }
1117− }
1059+ let cb vdone =
1120 { onComplete: launchAff' do
1060 { onComplete: launchAff' do
1121 fail $ "shouldn't complete"
1061 fail $ "shouldn't complete"
1123− , onError: \error -> launchAff' do
1063+ , onError: \error -> launchAff' do
1124 fail $ "unexpected error: " <> show error
1064 fail $ "unexpected error: " <> show error
1126 , onSuccess: \cursor -> launchAff' do
1066 , onSuccess: \cursor -> launchAff' do
@@ -1128,14 +1068,13 @@ main = do
1128 case res of
1068 case res of
1129 Left err -> do
1069 Left err -> do
1130 name err `shouldEqual` "ReadOnlyError"
1070 name err `shouldEqual` "ReadOnlyError"
1131− AVar.put unit vdone
1071+ putVar unit vdone
1132 Right _ ->
1072 Right _ ->
1133 fail $ "expected ReadOnlyError"
1073 fail $ "expected ReadOnlyError"
1135− vdone <- AVar.empty
1075+ vdone <- makeEmptyVar
1136− tx <- IDBDatabase.transaction db [ "store" ] ReadOnly
1076+ tx <- IDBDatabase.transaction db ["store"] ReadOnly
1137− store <- IDBTransaction.objectStore tx "store"
1077+ store <- IDBTransaction.objectStore tx "store"
1138− IDBObjectStore.openCursor store Nothing Next (cb vdone)
1078+ IDBObjectStore.openCursor store Nothing Next (cb vdone)
1139− AVar.take vdone
1079+ takeVar vdone
1140− tearDown db
1080+ tearDown db