kevast.js
Kevast is a dependency-free key-value storage interface, allowing you to access key-value based data wherever you want, memory, file, gist, redis, google drive, etc.
Kevast.js is Javascript version of kevast for both Node.js and browser.
Installation
Node.js
Using yarn
yarn add kevast
Using npm
npm install kevast
Browser
Latest version
Specific version
Hello Kevast
const Kevast = ;// Install these package with yarn or npmconst KevastFile = ;const KevastGist = ;const KevastEncrypt = ; const fileStore = './storage.json';const gistStore = 'YOUR GITHUB ACCESS TOKEN'; // Kevast stores data in all storagesconst kevast = fileStore gistStore; // Use encryption as a middlewareconst password = KevastEncrypt;kevast; async { // Save key-value data await kevast; // According to configuration, // data will be saved in both file and gist // Of course, after encryption // Read data from memory // and decrypt const value = await kevast; console;};
Documentation
Usage
Create an instance
Kevast requires at least one storage to read and store data.
const Kevast = ;const KevastMemory = ;const KevastFile = ;const KevastGist = ; const memoryStore = ;const fileStore = './storage.json';const gistStore = 'YOUR GITHUB ACCESS TOKEN'; const kevast = memoryStore fileStore gistStore;
const Kevast = ;const KevastMemory = ;const KevastFile = ;const KevastGist = ; const kevast = ; const memoryStore = ;const fileStore = './storage.json';const gistStore = 'YOUR GITHUB ACCESS TOKEN'; kevast ;
Basic function
.constructor(master: Storage, redundancies?: Storage[])
: Instantiates kevast..set(key: string, value: string | undefined): Promise<void>
: Sets the value for the key..bulkSet(pairs: Pair[]): Promise<void>
: Sets several pairs..get(key: string): Promise<string | undefined>
: Returns the value associated to the key,undefined
if there is none..remove(key: string): Promise<void>
: Removes a key-value pair..bulkRemove(keys: string[]): Promise<void>
: Removes several pairs..clear(): Promise<void>
: Removes all key-value pairs..add(storage: Storage): Kevast
: Adds a storage..use(middleware: DuplexMiddleware): Kevast
: Adds a middleware that works when bothSet
andGet
..afterGet.use(middleware: SimplexMiddleware)
: Adds a middleware that works afterGet
..beforeSet.use(middleware: SimplexMiddleware)
: Adds a middleware that works beforeSet
..config(options: Options)
: Update configuration.
Configuration
Edit by .config(options: Options))
backwardUpdate: boolean
: Enable backward updating or not. Defaultfalse
.
Fallback getting
While performing get
, kevast will find the value corresponding to the key from all the stores sequentially.
In other words, the latter Storage will become the fallback of the previous Storage.
const Kevast = ;const KevastMemory = ; async { // Currently, both memoryStore1 and memoryStore2 are empty const memoryStore1 = ; const memoryStore2 = ; // Now, memoryStore1 is still empty, // but memoryStore2 is { 'key' => 'value' } const kevast1 = memoryStore2; await kevast1; const kevast2 = memoryStore1 memoryStore2; // Outputs 'value' console; // kevast2 initially tried to get value from memoryStore1 but failed, // then it got the value from memoryStore2.};
Backward updating
In the above example of Fallback Getting, if the specified value is not found in the previous storage, kevast will try to take the value from the following storage. Once the value is found in a certain storage, it will be returned immediately.
If Backward Updating is enabled, kevast will update the key-value pairs to all previous storages after finding the value.
const Kevast = ;const KevastMemory = ; async { // Now, both memoryStore1 and memoryStore2 are empty const memoryStore1 = ; const memoryStore2 = ; const kevast1 = memoryStore2; // Now, memoryStore1 is still empty, // but memoryStore2 is { 'key' => 'value' } await kevast1; const kevast2 = memoryStore1 memoryStore2; // Enable backward updating kevast2; // Outputs 'value' console; // kevast2 initially tried to get value from memoryStore1 but failed, // then it got the value from memoryStore2. // IMPORTANT! // Because backward updating is enabled, // Now, { 'key' => 'value' } is also stored in memoryStore1 const kevast3 = memoryStore1; // Outputs 'value' console;};
Use a middleware
Kevast has three kinds of middleware:
afterGet
middleware works afterGet
operation.beforeSet
middleware works beforeSet
operation.DuplexMiddleware
is a combination of the two above.
const kevast = await Kevast;kevastafterGet; kevastbeforeSet; kevast;
Development
Compatibility
Kevast requires
Browser support:
70 | 63 | ≤11 12 | 55 | 17 | 9 10 11 | ≤10 11 12 | ≤3 4 |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Build
yarn build
Both Node.js and browser version will be built. Locate at kevast.js/dist
.
Running Tests
yarn test
Both Node.js and browser version will be tested. Note that it will finally open your browser to finish the test.
Coverage
yarn coverage
LICENSE
Why the funky name?
Kevast stands for ke(y) va(lue) st(orage).