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

sonic-channel

v1.3.1

Published

Sonic Channel integration for Node. Used in pair with Sonic, the fast, lightweight and schema-less search backend.

Downloads

3,566

Readme

node-sonic-channel

Test and Build Build and Release NPM Downloads Buy Me A Coffee

Sonic Channel integration for Node. Used in pair with Sonic, the fast, lightweight and schema-less search backend.

Sonic Channel lets you manage your Sonic search index, from your NodeJS code. Query your index and get search results, push entries to your index and pop them programmatically.

🇫🇷 Crafted in Nantes, France.

Who uses it?

👋 You use sonic-channel and you want to be listed there? Contact me.

How to install?

Include sonic-channel in your package.json dependencies.

Alternatively, you can run npm install sonic-channel --save.

How to use?

1️⃣ Search channel

1. Create the connection

node-sonic-channel can be instanciated in search mode as such:

var SonicChannelSearch = require("sonic-channel").Search;

var sonicChannelSearch = new SonicChannelSearch({
  host : "::1",            // Or '127.0.0.1' if you are still using IPv4
  port : 1491,             // Default port is '1491'
  auth : "SecretPassword"  // Authentication password (if any)
}).connect({
  connected : function() {
    // Connected handler
    console.info("Sonic Channel succeeded to connect to host (search).");
  },

  disconnected : function() {
    // Disconnected handler
    console.error("Sonic Channel is now disconnected (search).");
  },

  timeout : function() {
    // Timeout handler
    console.error("Sonic Channel connection timed out (search).");
  },

  retrying : function() {
    // Retry handler
    console.error("Trying to reconnect to Sonic Channel (search)...");
  },

  error : function(error) {
    // Failure handler
    console.error("Sonic Channel failed to connect to host (search).", error);
  }
});

2. Query the search index

Use the same sonicChannelSearch instance to query the search index:

sonicChannelSearch.query("messages", "default", "valerian saliou")
  .then(function(results) {
    // Query results come there
  })
  .catch(function(error) {
    // Query errors come there
  });

3. Teardown connection

If you need to teardown an ongoing connection to Sonic, use:

sonicChannelSearch.close()
  .then(function() {
    // Close success handler
  })
  .catch(function(error) {
    // Close errors come there
  });

2️⃣ Ingest channel

1. Create the connection

node-sonic-channel can be instanciated in ingest mode as such:

var SonicChannelIngest = require("sonic-channel").Ingest;

var sonicChannelIngest = new SonicChannelIngest({
  host : "::1",            // Or '127.0.0.1' if you are still using IPv4
  port : 1491,             // Default port is '1491'
  auth : "SecretPassword"  // Authentication password (if any)
}).connect({
  connected : function() {
    // Connected handler
    console.info("Sonic Channel succeeded to connect to host (ingest).");
  },

  disconnected : function() {
    // Disconnected handler
    console.error("Sonic Channel is now disconnected (ingest).");
  },

  timeout : function() {
    // Timeout handler
    console.error("Sonic Channel connection timed out (ingest).");
  },

  retrying : function() {
    // Retry handler
    console.error("Trying to reconnect to Sonic Channel (ingest)...");
  },

  error : function(error) {
    // Failure handler
    console.error("Sonic Channel failed to connect to host (ingest).", error);
  }
});

2. Manage the search index

Use the same sonicChannelIngest instance to push text to the search index:

sonicChannelIngest.push("messages", "default", "conversation:1", "I met Valerian Saliou yesterday. Great fun!")
  .then(function() {
    // Push success handler
  })
  .catch(function(error) {
    // Push errors come there
  });

3. Teardown connection

If you need to teardown an ongoing connection to Sonic, use:

sonicChannelIngest.close()
  .then(function() {
    // Close success handler
  })
  .catch(function(error) {
    // Close errors come there
  });

3️⃣ Control channel

1. Create the connection

node-sonic-channel can be instanciated in control mode as such:

var SonicChannelControl = require("sonic-channel").Control;

var sonicChannelControl = new SonicChannelControl({
  host : "::1",            // Or '127.0.0.1' if you are still using IPv4
  port : 1491,             // Default port is '1491'
  auth : "SecretPassword"  // Authentication password (if any)
}).connect({
  connected : function() {
    // Connected handler
    console.info("Sonic Channel succeeded to connect to host (control).");
  },

  disconnected : function() {
    // Disconnected handler
    console.error("Sonic Channel is now disconnected (control).");
  },

  timeout : function() {
    // Timeout handler
    console.error("Sonic Channel connection timed out (control).");
  },

  retrying : function() {
    // Retry handler
    console.error("Trying to reconnect to Sonic Channel (control)...");
  },

  error : function(error) {
    // Failure handler
    console.error("Sonic Channel failed to connect to host (control).", error);
  }
});

2. Administrate your Sonic server

You may use the same sonicChannelControl instance to administrate your Sonic server.

3. Teardown connection

If you need to teardown an ongoing connection to Sonic, use:

sonicChannelControl.close()
  .then(function() {
    // Close success handler
  })
  .catch(function(error) {
    // Close errors come there
  });

List of channel methods

For details on argument values, see the Sonic Channel Protocol specification.

Search channel

  • sonicChannelSearch.query(collection_id<string>, bucket_id<string>, terms_text<string>, [options{limit<number>, offset<number>, lang<string>}<object>]?) ➡️ Promise(results<object>, error<object>)
  • sonicChannelSearch.suggest(collection_id<string>, bucket_id<string>, word_text<string>, [options{limit<number>}<object>]?) ➡️ Promise(results<object>, error<object>)
  • sonicChannelSearch.list(collection_id<string>, bucket_id<string>, [options{limit<number>, offset<number>}<object>]?) ➡️ Promise(results<object>, error<object>)

Ingest channel

  • sonicChannelIngest.push(collection_id<string>, bucket_id<string>, object_id<string>, text<string>, [options{lang<string>}<object>]?) ➡️ Promise(_, error<object>)
  • sonicChannelIngest.pop(collection_id<string>, bucket_id<string>, object_id<string>, text<string>) ➡️ Promise(count<number>, error<object>)
  • sonicChannelIngest.count<number>(collection_id<string>, [bucket_id<string>]?, [object_id<string>]?) ➡️ Promise(count<number>, error<object>)
  • sonicChannelIngest.flushc(collection_id<string>) ➡️ Promise(count<number>, error<object>)
  • sonicChannelIngest.flushb(collection_id<string>, bucket_id<string>) ➡️ Promise(count<number>, error<object>)
  • sonicChannelIngest.flusho(collection_id<string>, bucket_id<string>, object_id<string>) ➡️ Promise(count<number>, error<object>)

Control channel

  • sonicChannelControl.trigger(action<string>, [data<string>]?) ➡️ Promise(_, error<object>)
  • sonicChannelControl.info() ➡️ Promise(results<object>, error<object>)

What is Sonic?

ℹ️ Wondering what Sonic is? Check out valeriansaliou/sonic.

How is it linked to Sonic?

node-sonic-channel maintains persistent TCP connections to the Sonic network interfaces that are listening on your running Sonic instance. In case node-sonic-channel gets disconnected from Sonic, it will retry to connect once the connection is established again.

You can configure the connection details of your Sonic instance when initializing node-sonic-channel from your code; via the Sonic host and port.