Skip to content

Commit

Permalink
feat: Add the abstract DataStore class
Browse files Browse the repository at this point in the history
  • Loading branch information
iainjreid committed Apr 18, 2020
1 parent 14eb75d commit 2edb3e5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,58 @@ export.PatSDK = class PatSDK {
}
}

/**
* An abstract implementation of the required data storage API.
*
* @abstract
*/
export.DataStore = class DataStore {
constructor() {
if (new.target === DataStore) {
throw new TypeError('DataStore is abstract and must be extended')
}
}

/**
* List all of the keys currently in the delegate storage provider.
*
* @returns {Promise<String>}
*/
getKeys() {
throw new TypeError('"getKeys" must be implemented by the extending class')
}

/**
* Store the `value` alongside the given `key` inside the delegate storage provider.
*
* @param {String} key
* @param {String} value
*
* @returns {Promise<None>}
*/
setItem(key, value) {
throw new TypeError('"setItem" must be implemented by the extending class')
}

/**
* Retrieve the data assigned to the given `key` from the delegate storage provider.
*
* @param {String} key
*
* @returns {Promise<String>}
*/
getItem(key) {
throw new TypeError('"getItem" must be implemented by the extending class')
}

/**
* Remove the data at the `key` provided from the delegate storage provider.
*
* @param {String} key
*
* @returns {Promise<None>}
*/
removeItem(key) {
throw new TypeError('"removeItem" must be implemented by the extending class')
}
}

0 comments on commit 2edb3e5

Please sign in to comment.