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

@nhz.io/pouch-db-manager-registry

v0.1.3

Published

PouchDB Manager Registry

Downloads

6

Readme

PouchDB Manager Registry

Travis Build NPM Version

Install

npm i -S @nhz.io/pouch-db-manager-registry

Usage

const Registry = require('@nhz.io/pouch-db-manager-registry')

...

Literate Source

Imports

{ urlname, allPass, mkkey, priority } = require '@nhz.io/pouch-db-manager-helpers'

Resource

class Resource

  constructor: ({ @uid, @type, @queue, @name, @local, @remote }) ->
    ['uid', 'type', 'queue' ].forEach (name) =>
      throw TypeError "Missing #{ name }" unless @[name]

    throw TypeError 'Missing name' unless @name or @local

Registry

class Registry

  @Resource = Resource

  constructor: ({ @resources = {}, @types, @queues }) ->

    throw TypeError 'Missing types' unless @types?.length
    throw TypeError 'Missing queues' unless @queues?.length

  sanitize: (resource) ->

    ['uid', 'type', 'queue' ].forEach (name) ->
      throw TypeError "Missing resource #{ name }" unless resource[name]

    throw TypeError 'Unknown resource type: #{ resource.type }' unless resource.type in @types

    throw TypeError 'Unknown resource queue: #{ resource.queue }' unless resource.queue in @queues

    { name, local, remote } = resource

    resource.local ?= resource.name

    if resource.local.match /^\s*https?:\/\//

      resource.remote = resource.local

      resource.name = resource.local = urlname resource.local

    resource.key = mkkey resource

    resource

  register: (resource) ->

    resource = @sanitize resource

    return existing if existing = @resources[resource.uid]

    @resources[resource.uid] = resource

  unregister: (resource) ->

    uid = resource.uid or resource

    return unless resource = @resources[uid]

    delete @resources[uid]

    resource

  find: (query, predicates = []) ->

    match = allPass [

      if query.type then (resource) -> resource.type?.match query.type

      if query.queue then (resource) -> resource.queue?.match query.queue

      if query.name then (resource) -> resource.name?.match query.name

      if query.local then (resource) -> resource.local?.match query.local

      if query.remote then (resource) -> resource.remote?.match query.remote

      if query.job then (resource) -> resource.job is job

      predicates...

    ]

    resources = (Object.keys @resources).map (uid) => @resources[uid]

    resources.find (resource) -> match resource

Exports

module.exports = Registry

Tests

test = require 'tape-async'

test 'Resource constructor', (t) ->

  t.plan 6

  t.throws -> new Resource {}

  t.throws -> new Resource { uid: 1 }

  t.throws -> new Resource { uid: 1, name: 'foo' }

  t.throws -> new Resource { uid: 1, name: 'foo', type: 'a' }


  t.ok new Resource { uid: 1, name: 'foo', type: 'a', queue: 'b' }

  t.ok new Resource { uid: 1, local: 'foo', type: 'a', queue: 'b' }


test 'Registry constructor', (t) ->

  t.plan 4

  t.throws -> new Registry {}

  t.throws -> new Registry { types: [] }

  t.throws -> new Registry { types: [], queues: [] }

  t.ok new Registry { types: ['a'], queues: ['b'] }

Version 0.1.3

License MIT