@@ -43,10 +43,11 @@ enum StorageState {
4343
4444export interface IStorage extends IDisposable {
4545
46+ readonly items : Map < string , string > ;
4647 readonly size : number ;
4748 readonly onDidChangeStorage : Event < string > ;
4849
49- init ( ) : Promise < void > ;
50+ init ( ) : Thenable < void > ;
5051
5152 get ( key : string , fallbackValue : string ) : string ;
5253 get ( key : string , fallbackValue ?: string ) : string | undefined ;
@@ -62,8 +63,16 @@ export interface IStorage extends IDisposable {
6263
6364 close ( ) : Thenable < void > ;
6465
65- getItems ( ) : Promise < Map < string , string > > ;
66- checkIntegrity ( full : boolean ) : Promise < string > ;
66+ checkIntegrity ( full : boolean ) : Thenable < string > ;
67+ }
68+
69+ export interface IStorageDatabase {
70+ getItems ( ) : Thenable < Map < string , string > > ;
71+ updateItems ( request : IUpdateRequest ) : Thenable < void > ;
72+
73+ close ( ) : Thenable < void > ;
74+
75+ checkIntegrity ( full : boolean ) : Thenable < string > ;
6776}
6877
6978export class Storage extends Disposable implements IStorage {
@@ -76,29 +85,34 @@ export class Storage extends Disposable implements IStorage {
7685 private _onDidChangeStorage : Emitter < string > = this . _register ( new Emitter < string > ( ) ) ;
7786 get onDidChangeStorage ( ) : Event < string > { return this . _onDidChangeStorage . event ; }
7887
88+ protected storage : IStorageDatabase ;
89+
7990 private state = StorageState . None ;
8091
81- private storage : SQLiteStorageImpl ;
8292 private cache : Map < string , string > = new Map < string , string > ( ) ;
8393
8494 private flushDelayer : ThrottledDelayer < void > ;
8595
8696 private pendingDeletes : Set < string > = new Set < string > ( ) ;
8797 private pendingInserts : Map < string , string > = new Map ( ) ;
8898
89- constructor ( private options : IStorageOptions ) {
99+ constructor ( private options : IStorageOptions , storage ?: IStorageDatabase ) {
90100 super ( ) ;
91101
92- this . storage = new SQLiteStorageImpl ( options ) ;
102+ this . storage = storage || new SQLiteStorageImpl ( options ) ;
93103
94104 this . flushDelayer = this . _register ( new ThrottledDelayer ( Storage . FLUSH_DELAY ) ) ;
95105 }
96106
107+ get items ( ) : Map < string , string > {
108+ return this . cache ;
109+ }
110+
97111 get size ( ) : number {
98112 return this . cache . size ;
99113 }
100114
101- init ( ) : Promise < void > {
115+ init ( ) : Thenable < void > {
102116 if ( this . state !== StorageState . None ) {
103117 return Promise . resolve ( ) ; // either closed or already initialized
104118 }
@@ -236,11 +250,7 @@ export class Storage extends Disposable implements IStorage {
236250 return this . storage . updateItems ( updateRequest ) ;
237251 }
238252
239- getItems ( ) : Promise < Map < string , string > > {
240- return this . storage . getItems ( ) ;
241- }
242-
243- checkIntegrity ( full : boolean ) : Promise < string > {
253+ checkIntegrity ( full : boolean ) : Thenable < string > {
244254 return this . storage . checkIntegrity ( full ) ;
245255 }
246256}
@@ -255,7 +265,7 @@ interface IOpenDatabaseResult {
255265 path : string ;
256266}
257267
258- export class SQLiteStorageImpl {
268+ export class SQLiteStorageImpl implements IStorageDatabase {
259269
260270 private static measuredRequireDuration : boolean ; // TODO@Ben remove me after a while
261271
@@ -604,11 +614,10 @@ class SQLiteStorageLogger {
604614
605615export class NullStorage extends Disposable implements IStorage {
606616
617+ readonly items = new Map < string , string > ( ) ;
607618 readonly size = 0 ;
608619 readonly onDidChangeStorage = Event . None ;
609620
610- private items = new Map < string , string > ( ) ;
611-
612621 init ( ) : Promise < void > { return Promise . resolve ( ) ; }
613622
614623 get ( key : string , fallbackValue : string ) : string ;
@@ -641,10 +650,6 @@ export class NullStorage extends Disposable implements IStorage {
641650 return Promise . resolve ( ) ;
642651 }
643652
644- getItems ( ) : Promise < Map < string , string > > {
645- return Promise . resolve ( this . items ) ;
646- }
647-
648653 checkIntegrity ( full : boolean ) : Promise < string > {
649654 return Promise . resolve ( 'ok' ) ;
650655 }
0 commit comments