npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fh-rest-memory-adapter

v0.2.0

Published

An in-memory adapter for fh-rest-express-router

Downloads

10

Readme

fh-rest-memory-adapter

Circle CI

Creates an adapter that uses process memory to store data. Created adapters do not share memory!

IMPORTANT NOTE: This is useful for debugging and local development, but should not be used in a real application since it's a volatile store and would lead to data loss and inconsistency upon MBaaS Service process restarts.

Install

npm install feedhenry-staff/fh-rest-memory-adapter

Usage

Red Hat Mobile MBaaS Service

'use strict';

/**
 * filename: application.js
 * The entry point of our RHAMP MBaaS Service
 */

var express = require('express')
  , mbaasApi = require('fh-mbaas-api')
  , mbaasExpress = mbaasApi.mbaasExpress()
  , app = module.exports = express()
  , log = require('fh-bunyan').getLogger(__filename);

log.info('starting application');

// Note: the order which we add middleware to Express here is important!
app.use('/sys', mbaasExpress.sys([]));
app.use('/mbaas', mbaasExpress.mbaas);

// Note: important that this is added just before your own Routes
app.use(mbaasExpress.fhmiddleware());

// Module used to create RESTful router instances
var fhRestExpressRouter = require('fh-rest-express-router');

// Module that RESTful router will use to retrieve data
// Note: this is not yet developed
var fhRestMemoryAdapter = require('fh-rest-memory-adapter');

// Creates a handler for incoming HTTP requests that want to perform CRUDL
// operations on the "orders" dataset stored in memory
var ordersRouter = fhRestExpressRouter('orders', fhRestMemoryAdapter())

// Expose a RESTful API to orders data, e.g:
// GET /orders/12345
app.use(ordersRouter);

// Important that this is last!
app.use(mbaasExpress.errorHandler());

var port = process.env.FH_PORT || process.env.VCAP_APP_PORT || 8001;
app.listen(port, function() {
  log.info('app started on port: %s', port);
});

Direct API

module(opts)

This module behaves as a factory function. Created adapters do not share memory!


var memoryAdapter = require('fh-rest-memory-adapter');

var catStore = memoryAdapter();
var dogStore = memoryAdapter();

catStore.create({
  data: {
    name: 'Felix'
  }
});

dogStore.create({
  data: {
    name: 'Fido'
  }
});

dogStore.create({
  data: {
    name: 'Max'
  }
});

dogStore.list(function (err, dogs) {
  // dogs =
  // {
  //    0: {
  //      name: 'Fido'
  //    }
  //    1: {
  //      name: 'Max'
  //    }
  // }
});

catStore.list(function (err, cats) {
  // cats =
  // {
  //    0: {
  //      name: 'Felix'
  //    }
  // }
});

adapter.create(params, callback)

Create an item in the store.

store.create({
  data: {
    // Keys and values
  }
}, function (err, createdItem) {});

adapter.read(params, callback)

Read an item. id must be passed in the params.

store.read({
  id: '0'
}, function (err, readItem) {});

adapter.update(params, callback)

Update an item in the store. id and data must be passed in the params.

store.update({
  id: '0'
  data: {
    name: 'Fido',
    age: 12
  }
}, function (err, updatedItem) {});

adapter.delete(params, callback)

Delete an item in the store. id must be passed in the params.

store.delete({
  id: '0'
}, function (err, deletedItem) {});

adapter.list(params, callback)

List items in the store.

store.list({
  // Params to use to filter, not yet supported
  query: {}
}, function (err, listedItems) {});