14
14
* limitations under the License.
15
15
*/
16
16
import {
17
- DbDocumentMutation , DbInstance ,
18
- DbMutationBatch , DbMutationQueue , DbOwner ,
19
- DbRemoteDocument , DbTarget ,
20
- DbTargetDocument , DbTargetGlobal
17
+ DbDocumentMutation ,
18
+ DbInstance ,
19
+ DbMutationBatch ,
20
+ DbMutationQueue ,
21
+ DbOwner ,
22
+ DbRemoteDocument ,
23
+ DbTarget ,
24
+ DbTargetDocument ,
25
+ DbTargetGlobal
21
26
} from './indexeddb_schema' ;
22
- import { assert , fail } from '../util/assert' ;
27
+ import { assert , fail } from '../util/assert' ;
23
28
24
29
// TODO(mikelehen): Get rid of "as any" if/when TypeScript fixes their types.
25
30
// https://github.com/Microsoft/TypeScript/issues/14322
26
31
type KeyPath = any ; // tslint:disable-line:no-any
27
32
28
33
function createCache ( db : IDBDatabase ) : void {
29
- const targetDocumentsStore = db . createObjectStore (
30
- DbTargetDocument . store ,
31
- { keyPath : DbTargetDocument . keyPath as KeyPath }
32
- ) ;
34
+ const targetDocumentsStore = db . createObjectStore ( DbTargetDocument . store , {
35
+ keyPath : DbTargetDocument . keyPath as KeyPath
36
+ } ) ;
33
37
targetDocumentsStore . createIndex (
34
- DbTargetDocument . documentTargetsIndex ,
35
- DbTargetDocument . documentTargetsKeyPath ,
36
- { unique : true }
38
+ DbTargetDocument . documentTargetsIndex ,
39
+ DbTargetDocument . documentTargetsKeyPath ,
40
+ { unique : true }
37
41
) ;
38
42
39
43
const targetStore = db . createObjectStore ( DbTarget . store , {
@@ -42,9 +46,9 @@ function createCache(db: IDBDatabase): void {
42
46
43
47
// NOTE: This is unique only because the TargetId is the suffix.
44
48
targetStore . createIndex (
45
- DbTarget . queryTargetsIndexName ,
46
- DbTarget . queryTargetsKeyPath ,
47
- { unique : true }
49
+ DbTarget . queryTargetsIndexName ,
50
+ DbTarget . queryTargetsKeyPath ,
51
+ { unique : true }
48
52
) ;
49
53
db . createObjectStore ( DbRemoteDocument . store ) ;
50
54
db . createObjectStore ( DbTargetGlobal . store ) ;
@@ -57,25 +61,24 @@ function dropCache(db: IDBDatabase): void {
57
61
db . deleteObjectStore ( DbTargetGlobal . store ) ;
58
62
}
59
63
60
- function createOwnerStore ( db : IDBDatabase ) : void {
64
+ function createOwnerStore ( db : IDBDatabase ) : void {
61
65
db . createObjectStore ( DbOwner . store ) ;
62
66
}
63
67
64
- function createInstanceStore ( db : IDBDatabase ) : void {
68
+ function createInstanceStore ( db : IDBDatabase ) : void {
65
69
db . createObjectStore ( DbInstance . store , {
66
70
keyPath : DbInstance . keyPath as KeyPath
67
71
} ) ;
68
72
}
69
73
70
- function createMutationQueue ( db : IDBDatabase ) : void {
74
+ function createMutationQueue ( db : IDBDatabase ) : void {
71
75
db . createObjectStore ( DbMutationQueue . store , {
72
76
keyPath : DbMutationQueue . keyPath
73
77
} ) ;
74
78
75
- db . createObjectStore (
76
- DbMutationBatch . store ,
77
- { keyPath : DbMutationBatch . keyPath as KeyPath }
78
- ) ;
79
+ db . createObjectStore ( DbMutationBatch . store , {
80
+ keyPath : DbMutationBatch . keyPath as KeyPath
81
+ } ) ;
79
82
80
83
// NOTE: keys for these stores are specified explicitly rather than using a
81
84
// keyPath.
@@ -86,9 +89,19 @@ function createMutationQueue(db: IDBDatabase) : void {
86
89
* Runs any migrations needed to bring the given database up to the current
87
90
* schema version.
88
91
*/
89
- export function createOrUpgradeDb ( db : IDBDatabase , oldVersion : number , newVersion : number ) : void {
90
- assert ( oldVersion >= 0 || oldVersion <= 1 , 'Unexpected upgrade from version ' + oldVersion ) ;
91
- assert ( newVersion >= 1 || newVersion <= 2 , 'Unexpected upgrade to version ' + newVersion ) ;
92
+ export function createOrUpgradeDb (
93
+ db : IDBDatabase ,
94
+ oldVersion : number ,
95
+ newVersion : number
96
+ ) : void {
97
+ assert (
98
+ oldVersion >= 0 || oldVersion <= 1 ,
99
+ 'Unexpected upgrade from version ' + oldVersion
100
+ ) ;
101
+ assert (
102
+ newVersion >= 1 || newVersion <= 2 ,
103
+ 'Unexpected upgrade to version ' + newVersion
104
+ ) ;
92
105
93
106
const createV1 = newVersion >= 1 && oldVersion <= 1 ;
94
107
const dropV1 = oldVersion >= 1 ;
@@ -107,4 +120,4 @@ export function createOrUpgradeDb(db: IDBDatabase, oldVersion: number, newVersio
107
120
if ( createV2 ) {
108
121
createInstanceStore ( db ) ;
109
122
}
110
- }
123
+ }
0 commit comments