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