@@ -4,7 +4,7 @@ import { EventsCacheInMemory } from '../inMemory/EventsCacheInMemory';
44import { IStorageFactoryParams , IStorageSync , IStorageSyncFactory } from '../types' ;
55import { validatePrefix } from '../KeyBuilder' ;
66import { KeyBuilderCS , myLargeSegmentsKeyBuilder } from '../KeyBuilderCS' ;
7- import { isLocalStorageAvailable , isStorageValid } from '../../utils/env/isLocalStorageAvailable' ;
7+ import { isLocalStorageAvailable , isStorageWrapperValid } from '../../utils/env/isLocalStorageAvailable' ;
88import { SplitsCacheInLocal } from './SplitsCacheInLocal' ;
99import { RBSegmentsCacheInLocal } from './RBSegmentsCacheInLocal' ;
1010import { MySegmentsCacheInLocal } from './MySegmentsCacheInLocal' ;
@@ -34,23 +34,23 @@ function isTillKey(key: string) {
3434 return key . endsWith ( '.till' ) ;
3535}
3636
37- export function storageAdapter ( log : ILogger , prefix : string , storage : SplitIO . Storage ) : StorageAdapter {
37+ export function storageAdapter ( log : ILogger , prefix : string , wrapper : SplitIO . StorageWrapper ) : StorageAdapter {
3838 let cache : Record < string , string > = { } ;
3939
4040 let connectPromise : Promise < void > | undefined ;
4141 let disconnectPromise = Promise . resolve ( ) ;
4242
4343 return {
4444 load ( ) {
45- return connectPromise || ( connectPromise = storage . getItem ( prefix ) . then ( ( storedCache ) => {
45+ return connectPromise || ( connectPromise = wrapper . getItem ( prefix ) . then ( ( storedCache ) => {
4646 cache = JSON . parse ( storedCache || '{}' ) ;
4747 } ) . catch ( ( e ) => {
4848 log . error ( LOG_PREFIX + 'Rejected promise calling storage getItem, with error: ' + e ) ;
4949 } ) ) ;
5050 } ,
5151 save ( ) {
5252 return disconnectPromise = disconnectPromise . then ( ( ) => {
53- return storage . setItem ( prefix , JSON . stringify ( cache ) ) . catch ( ( e ) => {
53+ return wrapper . setItem ( prefix , JSON . stringify ( cache ) ) . catch ( ( e ) => {
5454 log . error ( LOG_PREFIX + 'Rejected promise calling storage setItem, with error: ' + e ) ;
5555 } ) ;
5656 } ) ;
@@ -76,9 +76,9 @@ export function storageAdapter(log: ILogger, prefix: string, storage: SplitIO.St
7676 } ;
7777}
7878
79- function validateStorage ( log : ILogger , prefix : string , storage ?: SplitIO . Storage ) : StorageAdapter | undefined {
80- if ( storage ) {
81- if ( isStorageValid ( storage ) ) return storageAdapter ( log , prefix , storage ) ;
79+ function validateStorage ( log : ILogger , prefix : string , wrapper ?: SplitIO . StorageWrapper ) : StorageAdapter | undefined {
80+ if ( wrapper ) {
81+ if ( isStorageWrapperValid ( wrapper ) ) return storageAdapter ( log , prefix , wrapper ) ;
8282 log . warn ( LOG_PREFIX + 'Invalid storage provided. Falling back to LocalStorage API' ) ;
8383 }
8484
@@ -97,7 +97,7 @@ export function InLocalStorage(options: SplitIO.InLocalStorageOptions = {}): ISt
9797 function InLocalStorageCSFactory ( params : IStorageFactoryParams ) : IStorageSync {
9898 const { settings, settings : { log, scheduler : { impressionsQueueSize, eventsQueueSize } } } = params ;
9999
100- const storage = validateStorage ( log , prefix , options . storage ) ;
100+ const storage = validateStorage ( log , prefix , options . wrapper ) ;
101101 if ( ! storage ) return InMemoryStorageCSFactory ( params ) ;
102102
103103 const matchingKey = getMatching ( settings . core . key ) ;
0 commit comments