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

@coboxcoop/repository

v1.0.1-alpha.1

Published

a simple repository pattern for caching, creating, loading collections

Downloads

3

Readme

Repository

standard-readme compliant

Table of Contents

About

CoBox is an encrypted p2p file system and distributed back-up tool. README provides a map of the project.

repository provides a simple repository pattern for caching, creating, loading and saving the following models:

Why?

In CoBox we're using this to load each multifeed and kappa-core instance and cache them in this repository. This ensures that our indexes are always up to date by calling the ready function on each instance before returning the instance itself. The basic querying functionality allows for our controllers to pass a set of parameters to a where or findBy function and match on that basis.

Currently supports matching parameters based on the following types:

  • Buffers
  • Strings

Install

npm i -g @coboxcoop/schemas

Usage

const Repository = require('@coboxcoop/repository')

const repository = Repository(storage, factory, opts)

All opts get passed down to the instance generated by the factory.

Here's an example of what a controller would look like using @coboxcoop/repository:

const Repository = require('@coboxcoop/repository')

// Suppose a POST create has been sent with the following parameters
var params = {
  name: 'myspace',
  address: '4cef27e9702ae90c07056aa88cb4527a7037368311c0b0ed58db28344613ebd6'
}

function SpacesController () {
  const spaces = Repository('path/to/yaml/file/for/spaces', createSpace, { onCreate })

  return { create }

  async function create (request, response) {
    try {
      await spaces.ready()
      var space = await spaces.create(request.params)
      response.send('success! you created a space')
    } catch (err) {
      if (err.found) return response.send('validation failed: space with these parameters already exists')
    }
  }

  function onCreate (entry, cb) {
    // callback executes just before caching, but after building
  }
}

API

All functions can be called either with a callback as the last argument, or using async/await (i.e. they return a promise).

repository.all()

Get all entries

repository.where(attributes)

Get all entries that match the strongly matches the attributes provided (will ignore if one or more attributes doesn't match while but others match)

repository.findBy(attributes)

Get first entry that matches attributes provided (same as where but returns the first one)

repository.create(attributes)

Use the factory function provided to build an instance and cache it. ready function expected on the entry class produced by the factory.

repository.ready()

Load and get all entries ready. should always be called first.

repository.close()

Gracefully close all entries. close function expected on the entry class produced by the factory

repository.save()

Persist all entries to a YAML file. create one if it doesn't exist already.

repository.load()

Load all entries from the YAML file.

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

AGPL-3.0-or-later