@@ -2,6 +2,7 @@ import os from 'os';
2
2
import path from 'path' ;
3
3
import fs from 'fs' ;
4
4
import Logger , { LogLevel , StreamHandler } from '@matrixai/logger' ;
5
+ import { withF } from '@matrixai/resources' ;
5
6
import DB from '@/DB' ;
6
7
import DBTransaction from '@/DBTransaction' ;
7
8
import * as utils from '@/utils' ;
@@ -53,7 +54,7 @@ describe(DBTransaction.name, () => {
53
54
expect ( await db . dump ( db . transactionsDb ) ) . toStrictEqual ( { } ) ;
54
55
} ) ;
55
56
test ( 'get, put and del' , async ( ) => {
56
- const p = utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
57
+ const p = withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
57
58
expect ( await tran . get ( [ ] , 'foo' ) ) . toBeUndefined ( ) ;
58
59
// Add foo -> bar to the transaction
59
60
await tran . put ( [ ] , 'foo' , 'bar' ) ;
@@ -83,19 +84,19 @@ describe(DBTransaction.name, () => {
83
84
expect ( await db . dump ( db . transactionsDb ) ) . toStrictEqual ( { } ) ;
84
85
} ) ;
85
86
test ( 'no dirty reads' , async ( ) => {
86
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
87
+ await withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
87
88
expect ( await tran1 . get ( [ ] , 'hello' ) ) . toBeUndefined ( ) ;
88
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
89
+ await withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
89
90
await tran2 . put ( [ ] , 'hello' , 'world' ) ;
90
91
// `tran2` has not yet committed
91
92
expect ( await tran1 . get ( [ ] , 'hello' ) ) . toBeUndefined ( ) ;
92
93
} ) ;
93
94
} ) ;
94
95
await db . clear ( ) ;
95
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
96
+ await withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
96
97
expect ( await tran1 . get ( [ ] , 'hello' ) ) . toBeUndefined ( ) ;
97
98
await tran1 . put ( [ ] , 'hello' , 'foo' ) ;
98
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
99
+ await withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
99
100
// `tran1` has not yet committed
100
101
expect ( await tran2 . get ( [ ] , 'hello' ) ) . toBeUndefined ( ) ;
101
102
await tran2 . put ( [ ] , 'hello' , 'bar' ) ;
@@ -105,19 +106,19 @@ describe(DBTransaction.name, () => {
105
106
} ) ;
106
107
} ) ;
107
108
test ( 'non-repeatable reads' , async ( ) => {
108
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
109
+ await withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
109
110
expect ( await tran1 . get ( [ ] , 'hello' ) ) . toBeUndefined ( ) ;
110
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
111
+ await withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
111
112
await tran2 . put ( [ ] , 'hello' , 'world' ) ;
112
113
} ) ;
113
114
// `tran2` is now committed
114
115
expect ( await tran1 . get ( [ ] , 'hello' ) ) . toBe ( 'world' ) ;
115
116
} ) ;
116
117
await db . clear ( ) ;
117
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
118
+ await withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
118
119
expect ( await tran1 . get ( [ ] , 'hello' ) ) . toBeUndefined ( ) ;
119
120
await tran1 . put ( [ ] , 'hello' , 'foo' ) ;
120
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
121
+ await withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
121
122
// `tran1` has not yet committed
122
123
expect ( await tran2 . get ( [ ] , 'hello' ) ) . toBeUndefined ( ) ;
123
124
await tran2 . put ( [ ] , 'hello' , 'bar' ) ;
@@ -132,7 +133,7 @@ describe(DBTransaction.name, () => {
132
133
await db . put ( [ ] , '2' , '2' ) ;
133
134
await db . put ( [ ] , '3' , '3' ) ;
134
135
let rows : Array < [ string , string ] > ;
135
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
136
+ await withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
136
137
rows = [ ] ;
137
138
for await ( const [ k , v ] of await tran1 . iterator ( ) ) {
138
139
rows . push ( [ k . toString ( ) , JSON . parse ( v . toString ( ) ) ] ) ;
@@ -142,7 +143,7 @@ describe(DBTransaction.name, () => {
142
143
[ '2' , '2' ] ,
143
144
[ '3' , '3' ] ,
144
145
] ) ;
145
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
146
+ await withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
146
147
await tran2 . del ( [ ] , '1' ) ;
147
148
await tran2 . put ( [ ] , '4' , '4' ) ;
148
149
rows = [ ] ;
@@ -167,9 +168,9 @@ describe(DBTransaction.name, () => {
167
168
} ) ;
168
169
} ) ;
169
170
test ( 'lost updates' , async ( ) => {
170
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
171
+ await withF ( [ db . transaction ( ) ] , async ( [ tran1 ] ) => {
171
172
await tran1 . put ( [ ] , 'hello' , 'foo' ) ;
172
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
173
+ await withF ( [ db . transaction ( ) ] , async ( [ tran2 ] ) => {
173
174
await tran2 . put ( [ ] , 'hello' , 'bar' ) ;
174
175
} ) ;
175
176
expect ( await tran1 . get ( [ ] , 'hello' ) ) . toBe ( 'foo' ) ;
@@ -200,7 +201,7 @@ describe(DBTransaction.name, () => {
200
201
await db . put ( [ ] , 'e' , 'e' ) ;
201
202
await db . put ( [ ] , 'h' , 'h' ) ;
202
203
await db . put ( [ ] , 'k' , 'k' ) ;
203
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
204
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
204
205
await tran . put ( [ ] , 'a' , '1' ) ;
205
206
await tran . put ( [ ] , 'c' , '3' ) ;
206
207
await tran . put ( [ ] , 'e' , '5' ) ;
@@ -247,7 +248,7 @@ describe(DBTransaction.name, () => {
247
248
await db . put ( [ ] , 'e' , 'e' ) ;
248
249
await db . put ( [ ] , 'h' , 'h' ) ;
249
250
await db . put ( [ ] , 'k' , 'k' ) ;
250
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
251
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
251
252
await tran . put ( [ ] , 'a' , '1' ) ;
252
253
await tran . put ( [ ] , 'c' , '3' ) ;
253
254
await tran . put ( [ ] , 'e' , '5' ) ;
@@ -294,7 +295,7 @@ describe(DBTransaction.name, () => {
294
295
await db . put ( [ ] , 'd' , 'd' ) ;
295
296
await db . put ( [ ] , 'e' , 'e' ) ;
296
297
await db . put ( [ ] , 'h' , 'h' ) ;
297
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
298
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
298
299
await tran . put ( [ ] , 'a' , '1' ) ;
299
300
await tran . put ( [ ] , 'c' , '3' ) ;
300
301
await tran . put ( [ ] , 'e' , '5' ) ;
@@ -337,7 +338,7 @@ describe(DBTransaction.name, () => {
337
338
await db . put ( [ ] , 'd' , 'd' ) ;
338
339
await db . put ( [ ] , 'e' , 'e' ) ;
339
340
await db . put ( [ ] , 'h' , 'h' ) ;
340
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
341
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
341
342
await tran . put ( [ ] , 'a' , '1' ) ;
342
343
await tran . put ( [ ] , 'c' , '3' ) ;
343
344
await tran . put ( [ ] , 'e' , '5' ) ;
@@ -380,7 +381,7 @@ describe(DBTransaction.name, () => {
380
381
await db . put ( [ ] , 'd' , 'd' ) ;
381
382
await db . put ( [ ] , 'e' , 'e' ) ;
382
383
await db . put ( [ ] , 'h' , 'h' ) ;
383
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
384
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
384
385
await tran . put ( [ ] , 'a' , '1' ) ;
385
386
await tran . put ( [ ] , 'c' , '3' ) ;
386
387
await tran . put ( [ ] , 'e' , '5' ) ;
@@ -419,7 +420,7 @@ describe(DBTransaction.name, () => {
419
420
await db . put ( [ ] , 'd' , 'd' ) ;
420
421
await db . put ( [ ] , 'e' , 'e' ) ;
421
422
await db . put ( [ ] , 'h' , 'h' ) ;
422
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
423
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
423
424
await tran . put ( [ ] , 'a' , '1' ) ;
424
425
await tran . put ( [ ] , 'c' , '3' ) ;
425
426
await tran . put ( [ ] , 'e' , '5' ) ;
@@ -464,7 +465,7 @@ describe(DBTransaction.name, () => {
464
465
await db . put ( [ ] , 'e' , 'e' ) ;
465
466
await db . put ( [ ] , 'h' , 'h' ) ;
466
467
await db . put ( [ ] , 'k' , 'k' ) ;
467
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
468
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
468
469
await tran . put ( [ ] , 'a' , '1' ) ;
469
470
await tran . put ( [ ] , 'c' , '3' ) ;
470
471
await tran . put ( [ ] , 'e' , '5' ) ;
@@ -510,7 +511,7 @@ describe(DBTransaction.name, () => {
510
511
await db . put ( [ ] , 'e' , 'e' ) ;
511
512
await db . put ( [ ] , 'h' , 'h' ) ;
512
513
await db . put ( [ ] , 'k' , 'k' ) ;
513
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
514
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
514
515
await tran . put ( [ ] , 'a' , '1' ) ;
515
516
await tran . put ( [ ] , 'c' , '3' ) ;
516
517
await tran . put ( [ ] , 'e' , '5' ) ;
@@ -558,7 +559,7 @@ describe(DBTransaction.name, () => {
558
559
results . push ( 2 ) ;
559
560
} ) ;
560
561
const mockFailure = jest . fn ( ) ;
561
- await utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
562
+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
562
563
tran . queueSuccess ( mockSuccess1 ) ;
563
564
tran . queueSuccess ( mockSuccess2 ) ;
564
565
tran . queueFailure ( mockFailure ) ;
@@ -578,7 +579,7 @@ describe(DBTransaction.name, () => {
578
579
results . push ( 2 ) ;
579
580
} ) ;
580
581
await expect (
581
- utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
582
+ withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
582
583
tran . queueSuccess ( mockSuccess ) ;
583
584
tran . queueFailure ( mockFailure1 ) ;
584
585
tran . queueFailure ( mockFailure2 ) ;
@@ -595,7 +596,7 @@ describe(DBTransaction.name, () => {
595
596
await db . put ( [ ] , '2' , 'b' ) ;
596
597
const mockFailure = jest . fn ( ) ;
597
598
await expect (
598
- utils . withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
599
+ withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
599
600
await tran . put ( [ ] , '1' , '1' ) ;
600
601
await tran . put ( [ ] , '2' , '2' ) ;
601
602
tran . queueFailure ( mockFailure ) ;
0 commit comments