You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@wireapp/store-engine

Package Overview
Dependencies
Maintainers
6
Versions
387
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wireapp/store-engine

Provides a storage wrapper API to unify access to different storage technologies.


Version published
Maintainers
6
Created

Readme

Source

Wire

This repository is part of the source code of Wire. You can find more information at wire.com or by contacting opensource@wire.com.

You can find the published source code at github.com/wireapp.

For licensing information, see the attached LICENSE file and the list of third-party licenses at wire.com/legal/licenses/.

Store Engine

The Store Engine is an interface which can be used to implement various storage technologies in a uniform manner. There is a MemoryEngine which serves as an example. Additional implementations can be found in separate packages.

Popular implementations

Store EngineDescription
store-engineImplementation for in-memory.
store-engine-bro-fsImplementation for the browser's File and Directory Entries API.
store-engine-dexieImplementation for the browser's IndexedDB.
store-engine-fsImplementation for Node.js' File System.
store-engine-sqleetImplementation for SQLite 3 (WebAssembly) with encryption.
store-engine-web-storageImplementation for the browser's Web Storage API.

Motivation

Nowadays there are more and more storage possibilities and developers must be familiar with the characteristics of each individual solution to reliably store data. Because it can be sometimes hard to keep up with the highly dynamic world of data storages, we have developed a system which unifies the use of different storages / databases.

Quickstart

Engine instantiation
const {MemoryEngine} = require('@wireapp/store-engine');
const engine = new MemoryEngine();
await engine.init('my-database-name');

API

No matter which engine you use, they all support common CRUD operations.

Example

The following API calls we use this data:

const TABLE_NAME = 'the-simpsons';
const PRIMARY_KEY = 'lisa-simpson';
const ENTITY = {name: 'Lisa Simpson'};
create
const primaryKey = await engine.create(TABLE_NAME, PRIMARY_KEY, ENTITY);
console.log(`Saved record with primary key "${primaryKey}".`);
delete
const primaryKey = await engine.delete(TABLE_NAME, PRIMARY_KEY);
console.log(`Deleted record with primary key "${primaryKey}".`);
deleteAll
const wasDeleted = await engine.deleteAll(TABLE_NAME);
if (wasDeleted) {
  console.log('The Simpsons have been deleted. Poor Simpsons!');
}
purge
await engine.purge();
console.log('The Simpson Universe has been deleted. Doh!');
read
const record = await engine.read(TABLE_NAME, PRIMARY_KEY);
console.log(`Her name is "${record.name}".`);
readAll
const records = await engine.readAll(TABLE_NAME);
console.log(`There are "${records.length}" Simpsons in our database.`);
readAllPrimaryKeys
const primaryKeys = await engine.readAllPrimaryKeys(TABLE_NAME);
console.log(`Identifiers of our Simpsons: "${primaryKeys.join(', ')}"`);
update
const primaryKey = await engine.update(TABLE_NAME, PRIMARY_KEY, {brother: 'Bart Simpson'});
const updatedRecord = await engine.read(TABLE_NAME, PRIMARY_KEY);
console.log(`The brother of "${updatedRecord.name}" is "${updatedRecord.brother}".`);

Transient store

The Store Engine interface also provides a transient store which deletes data after a specified TTL.

Example

const {Store} = require('@wireapp/store-engine');
const {WebStorageEngine} = require('@wireapp/store-engine-web-storage');

const engine = new WebStorageEngine();
const store = new Store.TransientStore(engine);

(async () => {
  const ttl = 1000;

  await engine.init('my-database-name');
  await store.init('the-simpsons');
  const transientBundle = await store.set('bart', {name: 'Bart Simpson'}, ttl);
  console.log(`The record of "${transientBundle.payload.name}" will expire in "${transientBundle.expires}"ms.`);
})();

Keywords

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc