2.1.2 • Published 2 years ago

@kevroadrunner/storage v2.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@kevroadrunner/storage

Very simple, if not superfast, storage options

Features

  • Synchronous API (maybe asynchronous in future)
  • Different storage options with similar APIs
  • Popular persistence options
    • Manually read and write data (at any time)

Challenges

  • Missing asynchronicity (performance)
  • Unhandled memory overflow
  • Unchecked performance overall
  • Unchecked file permissions

Install

yarn add @kevroadrunner/storage

API

new KeyValueStore()

This store acts like a classic cache but is missing ttl options and uses a simpler data structure.

import {KeyValueStore} from '@kevroadrunner/storage';

type Person = {
  name: string
};

const store = new KeyValueStore<Person>();
store.read();
store.set('dennis', {name: 'Dennis'});
store.get('dennis'); // {name: 'Dennis'}
store.has('dennis'); // true
store.size(); // 1
store.remove('dennis');
store.clear();
store.write();

new Cache()

Simple ttl cache.

import {Cache} from '@kevroadrunner/storage';

type Person = {
  name: string
};

// Create 5 minutes in memory cache
const cache = new Cache<Person>({ttl: 5 * 60 * 1000});
cache.read();
cache.set('dennis', {name: 'Dennis'});
cache.get('dennis'); // {name: 'Dennis'}
cache.has('dennis'); // true
cache.size(); // 1
cache.remove('dennis');
cache.clear();
cache.clean(); // Remove all stale entries
cache.write();

new BlobStore()

Is this store even useful? 😅

import {BlobStore} from '@kevroadrunner/storage';

type Person = {
  name: string,
  age: number
};

const store = new BlobStore<Person>();
store.read();
store.set({name: 'dennis', age: 1});
store.get(); // {name: 'dennis', age: 1}
store.write();

new DocumentStore()

import {DocumentStore} from '@kevroadrunner/storage';

type Person = {
  name: string,
  age: number
};

const store = new DocumentStore<Person>();
store.read();
// Create item
store.set('persons', {name: ''}, {name: 'dennis', age: 1});
store.has('persons', {name: 'dennis'}); // true
// Update item
store.set('persons', {name: 'dennis'}, {name: 'dennis', age: 2});
store.get('persons', {name: 'dennis'}); // {name: 'dennis', age: 2}
// Remove item
store.set('persons', {name: 'dennis'});
store.has('persons', {name: 'dennis'}); // false
store.write();

new MemoryAdapter()

Default adapter for all stores.

import {KeyValueStore, MemoryAdapter} from '@kevroadrunner/storage';

const adapter = MemoryAdapter();
const store = new KeyValueStore<string>({adapter});

new JSONFileAdapter()

Data must be serializable.

import {DocumentStore, JSONFileAdapter} from '@kevroadrunner/storage';

const adapter = new JSONFileAdapter('~/path/to/file.json');
const store = new DocumentStore<string>({adapter});

new FileAdapter()

import {BlobStore, FileAdapter} from '@kevroadrunner/storage';

const adapter = new FileAdapter('~/path/to/.file');
const store = new BlobStore<string>({adapter});
2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago