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

zkstream

v0.11.9

Published

zkstream ========

Downloads

12

Readme

zkstream

A minimal streams-based node client for the ZooKeeper protocol.

API

Client

new mod_zkstream.Client(options)

Opens a new ZooKeeper connection and returns the Client instance.

Parameters:

  • options: an Object, with keys:
    • address: a String, hostname or IP to connect to
    • port: an optional Number (default: 2181)
    • sessionTimeout: an optional Number (default: 30000 ms)
    • collector: an optional Object, artedi collector

Client#close([cb])

Closes the connection.

Parameters:

  • cb: an optional Function, called once the connection has ended

Events

session

Emitted when the client establishes a new session with the ZK server. Will generally be followed immediately by a connect event.

connect

Emitted when the client successfully connects to a ZooKeeper server, either for the first time, or on subsequent reconnects after an error and failover on to a different server.

failed

Emitted when the client has exhausted its retry policy and cannot connect to any ZooKeeper servers.

expire

Emitted when the client's ZK session has expired. All ephemeral nodes created by this client will have now disappeared from the view of other clients, and any watchers will be invalid (will no longer emit events).

close

Emitted when the client has shut down at the request of a call to Client#close.

Client#ping([cb])

Manually pings the ZooKeeper server. Automatic pings occur every 2 seconds without calling this function.

Parameters:

  • cb: an optional Function (err)

Client#list(path[, cb])

Lists the children at a given path.

Parameters

  • path: a String, path to list children of
  • cb: an optional Function (err, children) with parameters:
    • children: an Array of Strings

Client#isConnected()

Determines whether the client has a working connection to ZooKeeper at the present time.

Returns boolean.

Client#stat(path[, cb])

Gathers basic information about the node at a given path, including its version number (useful if you want to delete it).

Parameters

  • path: a String, path to the node
  • cb: an optional Function (err, stat) with parameters:
    • stat: an Object, with fields:
      • version: a Number, latest version
      • dataLength: a Number, size of data in bytes stored at node
      • numChildren: a Number, number of children
      • ctime: a mod_jsbn.BigNumber
      • mtime: a mod_jsbn.BigNumber
      • ephemeralOwner: a Buffer, ID of connection that owns this node if it is ephemeral

Client#get(path[, cb])

Gets the data stored in a given node.

Parameters

  • path: a String, path to the node
  • cb: an optional Function (err, data, stat) with parameters:
    • data: a Buffer
    • stat: an Object, same format as stat in Client#stat

Client#getACL(path[, cb])

Gets the data stored in a given node.

Parameters

  • path: a String, path to the node
  • cb: an optional Function (err, acl) with parameters:
    • acl: an Array of Objects, ACL entries, with properties:
      • id: an Object, the principal the ACL entry applies to
        • scheme: a String, the principal URI scheme
        • id: a String, the remainder of the URI
      • perms: an Array of Strings, the permissions given to this principal

Client#delete(path, version[, cb])

Deletes a given node as long as its latest version matches the given version.

Parameters

  • path: a String, path to the node
  • version: a Number, latest version to check against
  • cb: an optional Function (err)

Client#create(path, data[, options[, cb]])

Creates a new node at the given path, containing some provided data.

Parameters

  • path: a String, path to the node to be created
  • data: a Buffer
  • options: an optional Object, with keys:
    • flags: an optional Array of Strings, can be 'EPHEMERAL' or 'SEQUENTIAL'
    • acl: an optional Array of ACL objects
  • cb: a Function (err, createdPath), the createdPath argument refers to the created node. It is important if the SEQUENTIAL flag was provided because it communicates to the client what name, and therefore sequence number, was selected for the final node.

Client#createWithEmptyParents(path, data[, options[, cb]])

Creates a new node at the given path, creating any intermediate path components and populating them with the data string null. If any of the intermediate znodes already exist, neither their ACLs nor data will be modified. Any intermediate component that doesn't exist will be created with the ACLs given in the options object, if they are provided. Any flags provided will be applied only to the final node in the path. All intermediate nodes created by this function are regular persistent zookeeper nodes.

Parameters:

  • path: a String, path to the node to be created
  • data: a Buffer
  • options: an optional Object, with keys:
    • flags: an optional Array of String, can be 'EPHEMERAL' or 'SEQUENTIAL'. These flags will only be applied to the node represented by the final path component, and not to any of the intermediate (parent) nodes. These intermediate nodes will be created with no flags.
    • acl: an optional Array of ACL objects
  • cb: a Function (err, createdPath), the createdPath argument is passed through from the call to Client#create that creates the final node in the path specified as an argument to this function.

Client#set(path, data, version[, cb])

Sets the contents of a given node as long as its latest version matches the given version.

Parameters

  • path: a String, path to the node
  • data: a Buffer, the new data to place in the node
  • version: a Number, version number as returned from Client#stat
  • cb: an optional Function (err)

Client#sync(path[, cb])

Forces the ZK leader to sync up with its followers on the state of the given node.

Parameters

  • path: a String, path to the node
  • cb: an optional Function (err)

Client#watcher(path)

Returns a watcher EventEmitter for a given path.

Parameters

  • path: a String, path to the node to watch

Watchers

Watcher#on('created', cb)

Registers a callback to be called when a particular node is created. If the node already exists right now, the callback will be called straight away.

Parameters

  • cb: a Function (stat) with arguments:
    • stat: an Object, same as the stat returned by Client#stat above

Watcher#on('deleted', cb)

Registers a callback to be called when a particular node is deleted. If the node does not exist right now, the callback will be called straight away.

NOTE: Deleted events may be missed during network outages.

Parameters

  • cb: a Function ()

Watcher#on('dataChanged', cb)

Registers a callback to be called when a particular node's data has changed. Always fires immediately with the current contents of the node if it exists.

Parameters

  • cb: a Function (data) with arguments:
    • data: a Buffer, contents of the node

Watcher#on('childrenChanged', cb)

Registers a callback to be called when a particular node's children have changed. Always fires immediately with the current children of the node if it exists.

Parameters

  • cb: a Function (children) with arguments:
    • children: an Array of Strings

ACL objects

Some methods return or take ACL objects as a parameter. These are plain Objects, with keys:

  • id: an Object, with keys:
    • scheme: a String, the URI scheme of the target of the ACL entry
    • id: a String
  • perms: an Array of Strings, can be 'read', 'write', 'create', 'delete', 'admin'