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

act-streams-client

v1.1.4-alpha

Published

A client library used for establishing connection with streaming server to get/push activity stream data and also maintain a persistent queue on client side

Downloads

2

Readme

GITLAB ACTIVITY LIBRARY

Methods

  • configure(tokenvalue,callback)
  • clientOn(tokenValue,listenForEvent,callback)
  • push(eventType,activity,callback)
  • publishSpec(specFileData)
  • on(listenForEvent,callback)
  • openQueue()
  • startQueue(activity)
  • addToQueue(activity)
  • done()
  • queueLength()
  • downloadToken(applicationName, apiPath, version)
  • removeQueueJob(id)
  • queueHas(id)
  • abortQueue()

configure(tokenvalue,callback)

method used to send jwt token stored in json file to the connected machine defined in the constructor.

syntax :

const Client = import('act-streams-client');
const client = new client('127.0.0.1:4000','path/to/sqllite.db');

client.configure(require('./configure.json').access_token);

publishSpec(specFileData,apiPath)

method used for publishing spec. file(yaml/json) to the apiPath defined as the method parameter using fetch.

syntax :

const Client = import('act-streams-client');
const client = new client('127.0.0.1:4000','path/to/sqllite.db');

client.publishSpec(require('./specFile.yaml'),'http://172.0.0.1:8000/register-yaml');

push(eventType,activity,callback)

method used to emit eventType and corresponding activity to the connected machine defined in the constructor.

syntax :

const Client = import('act-streams-client');
const client = new client('127.0.0.1:4000','path/to/sqllite.db');

client.push('CreateProject',activity, (ack)=>{ ... });

clientOn(tokenValue,listenForEvent,callback)

method will first emit the token value to connected machine and then listen for the event defined at listenForEvent and will perform callback on it.

syntax:

const Client = import('act-streams-client');
const client = new client('127.0.0.1:8000','path/to/sqllite.db');

client.clientOn(tokenValue,'event',(activity)=>{ ... });

queueLength()

method will return queue length.

syntax:

const Client = import('act-streams-client');
const client = new client('127.0.0.1:8000','path/to/sqllite.db');

let length = client.queueLength();

downloadToken(applicationName, apiPath, version)

provided applicationName and apiPath. User will be able to download token for valid registered application.

if version is not provided, by default, it will download the token for latest version of app.

const Client = import('act-streams-client');
const client = new client('127.0.0.1:8000','path/to/sqllite.db');

client.downloadToken('AppName','http://path-to-api'); //latest version
client.downloadToken('AppName','http://path-to-api','0.0.1'); //for version 0.0.1 (if it exist)

Events

Queue emits events according to the following table:

| Event | Description | Event Handler Parameters | |:-----:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------| | start | Emitted when the queue starts processing tasks (after calling .startQueue() method) | client.on('start',function(){ }) ; | | next | Emitted when the next task is to be executed. This occurs: * when there are items in the queue and .start() has been called; or * after .add() has been called to add a task to an empty queue and queue isStarted() already | client.on('next',function(job) {  job.id,  job.job }) ; | | add | Emitted when a task has been added to the queue (after calling .addToQueue() method) | client.on('add',function(job) {  job.id,  job.job }) ; | | open | Emitted when the sqlite database has been opened successfully (after calling .openQueuue() method) | client.on('open',function(sqlite) {  sqlite //instance of sqlite3.Database }) ; | | close | Emitted when the sqlite database has been closed successfully (after calling .closeQueue() method) | client.on('close',function() { }) ; |

Contrived Example

This example illustrates the use of the the client library in reading a file and emmiting events.


const { Tail } = require('tail');
let Client = require('act-streams-client');
const client = new Client('127.0.0.0:8000','./sqllite.db');

const tail = new Tail('./path/to/file');

// console.log('docker-running');

//Emitted when the sqlite database has been opened successfully (after calling .open() method)
client.on('open', function () {
  console.log('Opening SQLite DB');
  console.log('Queue contains ' + client.queueLength() + ' job/s');
});

//Emitted when a task has been added to the queue (after calling .add() method)
client.on('add', function (task) {
  console.log('Adding task: ' + JSON.stringify(task));
  console.log('Queue contains ' + client.queueLength() + ' job/s');

});

//Emitted when the queue starts processing tasks (after calling .start() method)
client.on('start', function () {
  console.log('Starting queue');
});

//Emitted when the next task is to be executed.
client.on('next', function (task) {
  console.log('Queue contains ' + client.queueLength() + ' job/s');
  console.log('Process task: ');
  console.log(JSON.stringify(task));

  console.log(`in next----------------------------------------------------\n`);

  client.push('activities', task, (ack) => {
    if (ack === 'received') {
      // tell Queue that we have finished this task
      // This call will schedule the next task (if there is one)
      client.done();
    }
  });

});

//opening queue
client.openQueue()
  .then(function () {
    //Streaming Log File Data
    tail.on('line', (data) => {
      const activity = JSON.parse(data);
      console.log('activity\n', activity);
      // client.push('activities', activity);
      if (activity !== undefined) {
        client.addToQueue(activity);
        client.startQueue(activity);
      }
    })
    // error handling
    tail.on('error', error => error);
  })
  .catch(function (err) { //error handling
    console.log('Error occurred:');
    console.log(err);
    process.exit(1);
  });

//sending token to the server
console.log(require('./configure.json').token);
client.configure(require('./configure.json').token);