(function() {
/**
* @abstract
* @augments Help4.jscore.ControlBase
* @property {boolean} available
* @property {number} storageLevel
* @property {boolean} _isReady
*/
Help4.service.StorageService.StorageInterface = class extends Help4.jscore.ControlBase {
/**
* @override
* @constructor
* @param {Help4.jscore.ControlBase.Params} derived
*/
constructor(derived) {
const {TYPES: T} = Help4.jscore.ControlBase;
const {STORAGE_LEVEL: {manual}} = Help4.service.StorageService;
super(null, {
params: {
available: {type: T.boolean, init: false, readonly: true},
storageLevel: {type: T.number, init: manual, readonly: true}
},
statics: {
_isReady: {init: false, destroy: false}
},
derived
});
}
/**
* @param {Object} config
* @returns {Promise<void>}
*/
async config(config) {}
/**
* @abstract
* @param {string} key
* @returns {Promise<*>}
*/
async get(key) {}
/**
* @abstract
* @param {string} key
* @param {*} value
* @returns {Promise<boolean>}
*/
async set(key, value) {}
/**
* @abstract
* @param {string} key
* @returns {Promise<*>}
*/
async del(key) {}
/** @returns {Promise<void>} */
async waitReady() {
await new Help4.Promise(resolve => {
const check = () => {
if (this._isReady) return resolve();
setTimeout(check, 100);
}
check();
});
}
/**
* @protected
* @returns {Promise<boolean>}
*/
async _test() {
// perform test whether this interface really works
const key = 'sap-cmp-test';
const randomValue = Help4.createId();
const success = await this.set(key, randomValue);
const value = success ? await this.get(key) : null;
return value === randomValue;
}
}
})();