@@ -293,22 +293,20 @@ export class IndexedDbProvider extends NoSqlProvider.DbProvider {
293293 }
294294
295295 protected _deleteDatabaseInternal ( ) : SyncTasks . Promise < void > {
296- let trans : IDBOpenDBRequest ;
297-
298- const err = _ . attempt ( ( ) => {
299- trans = this . _dbFactory . deleteDatabase ( this . _dbName ! ! ! ) ;
296+ const trans = _ . attempt ( ( ) => {
297+ return this . _dbFactory . deleteDatabase ( this . _dbName ! ! ! ) ;
300298 } ) ;
301299
302- if ( err ) {
303- return SyncTasks . Rejected ( err ) ;
300+ if ( _ . isError ( trans ) ) {
301+ return SyncTasks . Rejected ( trans ) ;
304302 }
305303
306304 const deferred = SyncTasks . Defer < void > ( ) ;
307305
308- trans ! ! ! . onsuccess = ( ) => {
306+ trans . onsuccess = ( ) => {
309307 deferred . resolve ( void 0 ) ;
310308 } ;
311- trans ! ! ! . onerror = ( ev ) => {
309+ trans . onerror = ( ev ) => {
312310 deferred . reject ( ev ) ;
313311 } ;
314312
@@ -348,15 +346,14 @@ export class IndexedDbProvider extends NoSqlProvider.DbProvider {
348346 }
349347
350348 return this . _lockHelper ! ! ! . openTransaction ( storeNames , writeNeeded ) . then ( transToken => {
351- let trans : IDBTransaction ;
352- const err = _ . attempt ( ( ) => {
353- trans = this . _db ! ! ! . transaction ( intStoreNames , writeNeeded ? 'readwrite' : 'readonly' ) ;
349+ const trans = _ . attempt ( ( ) => {
350+ return this . _db ! ! ! . transaction ( intStoreNames , writeNeeded ? 'readwrite' : 'readonly' ) ;
354351 } ) ;
355- if ( err ) {
356- return SyncTasks . Rejected ( err ) ;
352+ if ( _ . isError ( trans ) ) {
353+ return SyncTasks . Rejected ( trans ) ;
357354 }
358355
359- return new IndexedDbTransaction ( trans ! ! ! , this . _lockHelper , transToken , this . _schema ! ! ! , this . _fakeComplicatedKeys ) ;
356+ return new IndexedDbTransaction ( trans , this . _lockHelper , transToken , this . _schema ! ! ! , this . _fakeComplicatedKeys ) ;
360357 } ) ;
361358 }
362359}
@@ -483,20 +480,20 @@ class IndexedDbStore implements NoSqlProvider.DbStore {
483480 }
484481
485482 getMultiple ( keyOrKeys : KeyType | KeyType [ ] ) : SyncTasks . Promise < ItemType [ ] > {
486- let keys : any [ ] ;
487- const err = _ . attempt ( ( ) => {
488- keys = NoSqlProviderUtils . formListOfKeys ( keyOrKeys , this . _schema . primaryKeyPath ) ;
483+ const keys = _ . attempt ( ( ) => {
484+ const keys = NoSqlProviderUtils . formListOfKeys ( keyOrKeys , this . _schema . primaryKeyPath ) ;
489485
490486 if ( this . _fakeComplicatedKeys && NoSqlProviderUtils . isCompoundKeyPath ( this . _schema . primaryKeyPath ) ) {
491- keys = _ . map ( keys , key => NoSqlProviderUtils . serializeKeyToString ( key , this . _schema . primaryKeyPath ) ) ;
487+ return _ . map ( keys , key => NoSqlProviderUtils . serializeKeyToString ( key , this . _schema . primaryKeyPath ) ) ;
492488 }
489+ return keys ;
493490 } ) ;
494- if ( err ) {
495- return SyncTasks . Rejected ( err ) ;
491+ if ( _ . isError ( keys ) ) {
492+ return SyncTasks . Rejected ( keys ) ;
496493 }
497494
498495 // There isn't a more optimized way to do this with indexeddb, have to get the results one by one
499- return SyncTasks . all ( _ . map ( keys ! ! ! , key =>
496+ return SyncTasks . all ( _ . map ( keys , key =>
500497 IndexedDbProvider . WrapRequest ( this . _store . get ( key ) ) . then ( val => removeFullTextMetadataAndReturn ( this . _schema , val ) ) ) )
501498 . then ( _ . compact ) ;
502499 }
@@ -612,44 +609,41 @@ class IndexedDbStore implements NoSqlProvider.DbStore {
612609 }
613610
614611 remove ( keyOrKeys : KeyType | KeyType [ ] ) : SyncTasks . Promise < void > {
615- let keys : any [ ] ;
616- const err = _ . attempt ( ( ) => {
617- keys = NoSqlProviderUtils . formListOfKeys ( keyOrKeys , this . _schema . primaryKeyPath ) ;
612+ const keys = _ . attempt ( ( ) => {
613+ const keys = NoSqlProviderUtils . formListOfKeys ( keyOrKeys , this . _schema . primaryKeyPath ) ;
618614
619615 if ( this . _fakeComplicatedKeys && NoSqlProviderUtils . isCompoundKeyPath ( this . _schema . primaryKeyPath ) ) {
620- keys = _ . map ( keys , key => NoSqlProviderUtils . serializeKeyToString ( key , this . _schema . primaryKeyPath ) ) ;
616+ return _ . map ( keys , key => NoSqlProviderUtils . serializeKeyToString ( key , this . _schema . primaryKeyPath ) ) ;
621617 }
618+ return keys ;
622619 } ) ;
623- if ( err ) {
624- return SyncTasks . Rejected < void > ( err ) ;
620+ if ( _ . isError ( keys ) ) {
621+ return SyncTasks . Rejected < void > ( keys ) ;
625622 }
626623
627- return SyncTasks . all ( _ . map ( keys ! ! ! , key => {
624+ return SyncTasks . all ( _ . map ( keys , key => {
628625 if ( this . _fakeComplicatedKeys && _ . some ( this . _schema . indexes , index => index . multiEntry || index . fullText ) ) {
629626 // If we're faking keys and there's any multientry indexes, we have to do the way more complicated version...
630627 return IndexedDbProvider . WrapRequest < any > ( this . _store . get ( key ) ) . then ( item => {
631628 if ( item ) {
632629 // Go through each multiEntry index and nuke the referenced items from the sub-stores
633630 let promises = _ . map ( _ . filter ( this . _schema . indexes , index => ! ! index . multiEntry ) , index => {
634631 let indexStore = _ . find ( this . _indexStores , store => store . name === this . _schema . name + '_' + index . name ) ! ! ! ;
635-
636- let refKey : KeyType ;
637- const err = _ . attempt ( ( ) => {
638-
632+ const refKey = _ . attempt ( ( ) => {
639633 // We need to reference the PK of the actual row we're using here, so calculate the actual PK -- if it's
640634 // compound, we're already faking complicated keys, so we know to serialize it to a string. If not, use the
641635 // raw value.
642636 const tempRefKey = NoSqlProviderUtils . getKeyForKeypath ( item , this . _schema . primaryKeyPath ) ! ! ! ;
643- refKey = _ . isArray ( this . _schema . primaryKeyPath ) ?
637+ return _ . isArray ( this . _schema . primaryKeyPath ) ?
644638 NoSqlProviderUtils . serializeKeyToString ( tempRefKey , this . _schema . primaryKeyPath ) :
645639 tempRefKey ;
646640 } ) ;
647- if ( err ) {
648- return SyncTasks . Rejected < void > ( err ) ;
641+ if ( _ . isError ( refKey ) ) {
642+ return SyncTasks . Rejected < void > ( refKey ) ;
649643 }
650644
651645 // First clear out the old values from the index store for the refkey
652- const cursorReq = indexStore . index ( 'refkey' ) . openCursor ( IDBKeyRange . only ( refKey ! ! ! ) ) ;
646+ const cursorReq = indexStore . index ( 'refkey' ) . openCursor ( IDBKeyRange . only ( refKey ) ) ;
653647 return IndexedDbIndex . iterateOverCursorRequest ( cursorReq , cursor => {
654648 cursor [ 'delete' ] ( ) ;
655649 } ) ;
@@ -735,12 +729,11 @@ class IndexedDbIndex extends FullTextSearchHelpers.DbIndexFTSFromRangeQueries {
735729 }
736730
737731 getOnly ( key : KeyType , reverse ?: boolean , limit ?: number , offset ?: number ) : SyncTasks . Promise < ItemType [ ] > {
738- let keyRange : any ;
739- const err = _ . attempt ( ( ) => {
740- keyRange = this . _getKeyRangeForOnly ( key ) ;
732+ const keyRange = _ . attempt ( ( ) => {
733+ return this . _getKeyRangeForOnly ( key ) ;
741734 } ) ;
742- if ( err ) {
743- return SyncTasks . Rejected ( err ) ;
735+ if ( _ . isError ( keyRange ) ) {
736+ return SyncTasks . Rejected ( keyRange ) ;
744737 }
745738
746739 const req = this . _store . openCursor ( keyRange , reverse ? 'prev' : 'next' ) ;
@@ -757,12 +750,11 @@ class IndexedDbIndex extends FullTextSearchHelpers.DbIndexFTSFromRangeQueries {
757750
758751 getRange ( keyLowRange : KeyType , keyHighRange : KeyType , lowRangeExclusive ?: boolean , highRangeExclusive ?: boolean ,
759752 reverse ?: boolean , limit ?: number , offset ?: number ) : SyncTasks . Promise < ItemType [ ] > {
760- let keyRange : any ;
761- const err = _ . attempt ( ( ) => {
762- keyRange = this . _getKeyRangeForRange ( keyLowRange , keyHighRange , lowRangeExclusive , highRangeExclusive ) ;
753+ const keyRange = _ . attempt ( ( ) => {
754+ return this . _getKeyRangeForRange ( keyLowRange , keyHighRange , lowRangeExclusive , highRangeExclusive ) ;
763755 } ) ;
764- if ( err ) {
765- return SyncTasks . Rejected ( err ) ;
756+ if ( _ . isError ( keyRange ) ) {
757+ return SyncTasks . Rejected ( keyRange ) ;
766758 }
767759
768760 const req = this . _store . openCursor ( keyRange , reverse ? 'prev' : 'next' ) ;
@@ -788,12 +780,11 @@ class IndexedDbIndex extends FullTextSearchHelpers.DbIndexFTSFromRangeQueries {
788780 }
789781
790782 countOnly ( key : KeyType ) : SyncTasks . Promise < number > {
791- let keyRange : any ;
792- const err = _ . attempt ( ( ) => {
793- keyRange = this . _getKeyRangeForOnly ( key ) ;
783+ const keyRange = _ . attempt ( ( ) => {
784+ return this . _getKeyRangeForOnly ( key ) ;
794785 } ) ;
795- if ( err ) {
796- return SyncTasks . Rejected ( err ) ;
786+ if ( _ . isError ( keyRange ) ) {
787+ return SyncTasks . Rejected ( keyRange ) ;
797788 }
798789
799790 const req = this . _store . count ( keyRange ) ;
@@ -802,12 +793,11 @@ class IndexedDbIndex extends FullTextSearchHelpers.DbIndexFTSFromRangeQueries {
802793
803794 countRange ( keyLowRange : KeyType , keyHighRange : KeyType , lowRangeExclusive ?: boolean , highRangeExclusive ?: boolean )
804795 : SyncTasks . Promise < number > {
805- let keyRange : any ;
806- const err = _ . attempt ( ( ) => {
807- keyRange = this . _getKeyRangeForRange ( keyLowRange , keyHighRange , lowRangeExclusive , highRangeExclusive ) ;
796+ let keyRange = _ . attempt ( ( ) => {
797+ return this . _getKeyRangeForRange ( keyLowRange , keyHighRange , lowRangeExclusive , highRangeExclusive ) ;
808798 } ) ;
809- if ( err ) {
810- return SyncTasks . Rejected ( err ) ;
799+ if ( _ . isError ( keyRange ) ) {
800+ return SyncTasks . Rejected ( keyRange ) ;
811801 }
812802
813803 const req = this . _store . count ( keyRange ) ;
0 commit comments