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

hide-a-bed

v1.2.0

Published

An abstraction over couchdb calls that includes easy mock/stubs with pouchdb

Downloads

6

Readme

hide-a-bed

A simple way to abstract couchdb, and make your interface to the database testable.

Install

There are two packages, one for runtime that contains the real implementations and schema, and the other contains the stubs for tests.

npm i hide-a-bed --save
npm i hide-a-bed-stub --save-dev

Code that uses some example db apis

export function doStuff (config, services, id) {
  const doc = await services.db.get(config, id)
  const apiResult = services.callSomeApi(config, doc.userName)
  const query = {
    startkey: apiResult.startTime,
    endkey: apiResult.endTime
  }
  const queryResults = await db.query(config, '_design/userThings/_view/byTime', query)
  return queryResults.rows
}

Using doStuff, in a real env, connecting to a real couch

import db from 'hide-a-bed'
import { doStuff } from './doStuff'
import { callSomeApi } from './api'
// the config object needs a couch url
const config = { couch: 'http://localhost:5984/mydb' }
// build up a service api for all your external calls that can be mocked/stubbed
const services = { db, callSomeApi }
const afterStuff = await doStuff(config, services, 'happy-doc-id')

Mocking out the calls in a test, never connects to the network

import { setup } from 'hide-a-bed-stub' // different package, since installed with --save-dev reduces space
import { doStuff } from './doStuff'
import { callSomeApiMock } from './test/mock/api'
// the config object needs a couch url, prove to yourself that its mocked with a fakeurl
const config = { couch: 'http://fakeurl:5984/mydb' }

// we import or design docs that we will need for the db
import userThingsDesignDoc from './ddocs/userThingsDDoc.js'

test('doStuff works in stub mode', async t => {
    // we have to setup the db with the design docs that are required
    const db = await setup([userThingsDesignDoc])

    // build up a service api with all your fake endpoints
    const services = { db, callSomeApi: callSomeApiMock }
    const afterStuff = await doStuff(config, services, 'happy-doc-id')
})

Below are all the couch apis available

TODO