@did-connect/storage
TypeScript icon, indicating that this package has built-in type declarations

2.2.4 • Public • Published

styled with prettier

Introduction

Defines the interface for DID Connect Session Storage, basic APIs that a session storage includes:

  • async create(session, attrs), create a new session record, persist in storage
  • async read(session), read a session from storage,
  • async update(session, updates), update session record
  • async delete(session), remove a session record

Install

npm install @did-connect/storage
// or
yarn add @did-connect/storage

Usage

const { BaseStorage } = require('@did-connect/storage');
const keystone = require('keystone');

module.exports = class KeystoneStorage extends BaseStorage {
  constructor() {
    this.model = keystone.list('sessions').model;
  }

  create(sessionId, attrs) {
    const LoginToken = this.model;
    const item = new LoginToken({ sessionId, ...attrs });
    return item.save();
  }

  read(sessionId) {
    return this.model.findOne({ sessionId });
  }

  update(sessionId, updates) {
    return this.model.findOneAndUpdate({ sessionId }, updates);
  }

  delete(sessionId) {
    return this.model.remove({ sessionId });
  }
};

Readme

Keywords

Package Sidebar

Install

npm i @did-connect/storage

Weekly Downloads

1,275

Version

2.2.4

License

Apache-2.0

Unpacked Size

9.94 kB

Total Files

6

Last publish

Collaborators

  • wangshijun