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

discovery

v1.1.0

Published

Discovery provides dynamic service discovery over a pluggable interface.

Downloads

28

Readme

Discovery

Discovery provides dynamic service discovery over a pluggable interface.

Design

The Registry is the cornerstone of Discovery. Each node in the cluster is expected to have at least one Registry, with that Registry being responsible for one or more local Services. Its Manager, in turn, synchronizes the Registry's understanding of the cluster and its remotely-available Services.

Services

Discovery makes few assumptions about the format or purpose of Service objects. All Services must be given a name, and will be assigned a universally-unique id to identify instances of a Service that share the same name. The Service interface provides a consistent interface for managing the metadata associated with ths service it represents and the announcements thereof.

Registry

Each Registry is, in essence, a list of Service objects associated with a Manager to synchronize them across machines. Additionally, the Registry makes an internal distinction between "local" Services (those in the same process), and "remote" Services (those on other processes, even if they're on the same machine).

Managers

Managers seek to broadcast the presence of a Registry's local Services while receiving broadcasts about the Services contained in other Registries. The Manager interface abstracts both the algorithm and transport(s) used for this synchronization; new transports and algorithms can be plugged into Discovery through the implementation of a new Manager and the assignment of that Manager as the manager option/property of all Registries within the system.

API

Registry new discovery.Registry(options) Alias: discovery.createRegistry

Creates a new instance of Registry with the provided options.

The Registry is the cornerstone of Discovery. Each node in the cluster is expected to have at least one Registry, with that Registry being responsible for one or more local Services. Its Manager, in turn, synchronizes the Registry's understanding of the cluster and its remotely-available Services.

destroy registry.destroy()

Signals a graceful shutdown of the Registry's and its Manager's internal resources.

createService registry.createService(name, [data], [available])

Creates a new, local Service object to represent the named service. This Service will be synchronized via the Manager to all other Registry objects in its network. That is, all other Registry objects whose Managers are both compatible and reachable by this Registry's Manager will emit 'available' events for this Service.

Event: "available"

The Registry emits an "available" event for every Service that comes available, whether they be local or remote. Two arguments are passed in to the event handler: the name of the Service and the data currently associated with that Service.

If you need a unique identifier for this Service "instance", use id, as name is preserved from the original createService call, and may not be unique.

Event: "unavailable"

The Registry emits an "unavailable" event for every Service that comes unavailable after being available at some point in the past. The arguments passed in to "unavailable" mirror those of "available": name and `data.

No guarantees are made beyond the order of events: available, unavailable, available, unavailable, ... - two events may arrive in the same tick, the Managers involved may elect to consider your Service(s) "unavailable" for implementation-specific reasons, and so forth. Design and plan accordingly.

Service

update service.update(data)

Merges data with the Service's existing data property. Returns true if the update was required (i.e. something was different), false otherwise (e.g. data remains unchanged).

toJSON service.toJSON()

Returns a JSON representation of the Service, omitting process-local details that are inappropriate within other processes, e.g. local.

Manager new discovery.Manager(options) Alias: discovery.createManager

Creates a new instance of Manager with the provided options.

This class provides the abstract interface for more specific Manager implementations.

See UdpBroadcastManager for a specific example.

destroy manager.destroy()

Signals a graceful shutdown of the Manager's internal resources.

generateId manager.generateId()

Returns a Manager-specific unique identifier.

See Registry.generateId for more information.

addLocalService manager.addLocalService(service)

Used as a signal from the Registry to its Manager that a new local Service is available.

removeLocalService manager.removeLocalService(service)

Used as a signal from the Registry to its Manager that a local Service is no longer available.

updateLocalService manager.updateLocalService(service)

Used as a signal from the Registry to its Manager that a local Service has updated its data without updating its availability.

toJSON manager.toJSON()

Returns a JSON representation of the Manager suitable for logging debug information.

UdpBroadcastManager discovery.UdpBroadcast(options)

Creates a new instance of UdpBroadcastManager with the provided options.

The UdpBroadcastManager provides a client connection to the zero-configuration, UDP-based discovery system that is used by Discovery by default. Because it requires zero configuration to use, it's ideal for initial exploration and development. However, it's not expected to work at-scale, and should be replaced with the included HTTP-based version.

destroy udpBroadcastManager.destroy()

Signals a graceful shutdown of the UdpBroadcastManager.

generateId udpBroadcastManager.generateId()

Returns a UDP-specific unique identifier using the machine's IP address and the configured port number.

See Manager.generateId for more information.

HttpManager discovery.Http(options)

Creates a new instance of HttpManager with the provided options.

The HttpManager provides a client connection to the HTTP-based, Tracker discovery system.

destroy httpManager.destroy()

Signals a graceful shutdown of the HttpManager.

generateId httpManager.generateId()

Returns an HTTP-specific unique identifier using the machine's IP address and the configured port number.

See Manager.generateId for more information.