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

@pipelinedb/stride

v1.2.3

Published

Stride.io JavaScript API client

Downloads

5

Readme

stride.js

CircleCI npm version

JavaScript client for Stride

Install

npm install --save @pipelinedb/stride

Then in your project, you just need to instantiate a Stride instance using one of your API keys:

const Stride = require('@pipelinedb/stride')

let stride = new Stride('my_secret_key')
stride.post('/collect/mydata', {some: 'data', ...}).then(({status, response}) => {
  doStuff()
})

Usage

stride.js is a relatively thin wrapper around the Stride HTTP API. There are only a few main methods: get, post, put, delete, subscribe. Generally, each method returns a Promise and follows the signature:

stride.method(url, [data]).then(({status, [response], [stream]}) => {
  // status: Integer HTTP state
  // response: Object server response (via `get`, `post`, `delete`)
  // stream: Node readable object Stream (via `subscribe()`)
})

get()

  • url - Endpoint to GET from. Must not include the version, i.e. just /collect
stride.get('/collect').then(({status, response}) => {
  // status: 200,
  // response: [
  //   "commits",
  //   "pull_requests",
  //   "app_events",
  //   "web_logs"
  // ]
})

post()

  • url - Endpoint to POST to
  • data - data to post to server
let commit = {
  "$timestamp": "2015-05-05T23:40:27Z",
  "repo": "pipelinedb/pipelinedb",
  "username": "usmanm",
  "sha1": "690e6814144a174d38ff501c5d89bfff5ff8d6de"
}
stride.post('/collect/commits', commit).then(({status, response}) => {
  // status: 200,
  // response: null
})

put()

  • url - Endpoint to PUT to
  • data - data to post to server
let newQuery = {
  "query": "SELECT * FROM my_process",
}
stride.put('/analyze/a_query_name', newQuery).then(({status, response}) => {
  // status: 200,
  // response: null
})

delete()

  • url - Endpoint to DELETE. Must not include the version, i.e. just /collect
stride.delete('/collect/commits').then(({status, response}) => {
  // status: 200,
  // response: null
})

subscribe()

Due to the streaming nature of subscribe(), its usage is a little more complex than the other methods.

When the promise resolves, it will give you a stream—a Node Readable Stream which allows you to pipe it to other streams or subscribe events to retrieve objects.

  • url - Endpoint to subscribe to. Must not include the version, i.e. just /collect
stride.subscribe('/collect/commits/subscribe').then(({status, stream}) => {
  stream.on('data', (obj) => {
    // `stream` is an Object stream, meaning that it will emit JavaScript
    // objects rather than strings. You will get one event per call of this
    // function.
    doSomethingWithTheObject(obj)
  })

  stream.on('error', (err) => {
    // When there is an error
  })

  stream.on('end', () => {
    // When you destroy the stream; the server will never hang up
  })

  // ...
  stream.destroy() // when you're done listening
})

You can pipe the stream to other streams, e.g. stdout.

const through2 = require('through2')
stride.subscribe('/collect/commits/subscribe').then(({status, stream}) => {
  stream
    .pipe(through2.obj(function (chunk, enc, callback) {
      this.push(JSON.stringify(chunk, null, '  ') + '\n')
      callback()
    }))
    .pipe(process.stdout)
})

If the server returns any status code other than 200, stream will be null:

stride.subscribe('/collect/commits/subscribe').then(({status, stream}) => {
  // status: 404
  // stream: null
})