• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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?

Crisp

👋 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.

More Repositories

1

sonic

đŸĻ” Fast, lightweight & schema-less search backend. An alternative to Elasticsearch that runs on a few MBs of RAM.
Rust
19,769
star
2

vigil

đŸšĻ Microservices Status Page. Monitors a distributed infrastructure and sends alerts (Slack, SMS, etc.).
Rust
1,690
star
3

bloom

🌸 HTTP REST API caching middleware, to be used between load balancers and REST API workers.
Rust
711
star
4

node-sales-tax

💰 International sales tax calculator for Node (offline, but provides optional online VAT number fraud check). Tax rates are kept up-to-date.
JavaScript
298
star
5

raider

🐎 Affiliates dashboard. Used by affiliates to generate tracking codes and review their balance.
Rust
144
star
6

constellation

🌌 Pluggable authoritative DNS server. Entries can be added & removed from an HTTP REST API.
Rust
127
star
7

node-fast-ratelimit

☔ Fast and efficient in-memory rate-limit for Node, used to alleviate most common DOS attacks.
JavaScript
107
star
8

jquery.clipboard

✂ī¸ jQuery Clipboard plugin (newest version) - Copy any text to the user's clipboard. Implements ZeroClipboard over the jQuery plugin layer.
JavaScript
70
star
9

giggle

📞 Giggle Jingle library for XMPP, implementation of XEP-0166.
JavaScript
57
star
10

vigil-local

đŸ•¯ Vigil Local daemon. Used as a slave service to monitor hosts behind a firewall and report their status to Vigil.
Rust
21
star
11

boulder-dash

:godmode: Boulder Dash game remake, done in Java.
Java
14
star
12

django-gitlab-logging

🍷 A logging handler for Django that opens GitLab issues on server error.
Python
13
star
13

plotters-conrod

📈 Conrod backend for Plotters. This is more efficient than using the default Bitmap backend when plotting in Conrod.
Rust
13
star
14

callisto

đŸ’Ģ Yet another Solar System simulator, written in Go.
Go
11
star
15

go-vigil-reporter

🚧 Vigil Reporter for Golang. Used in pair with Vigil, the Microservices Status Page.
Go
11
star
16

node-vigil-reporter

🚧 Vigil Reporter for Node. Used in pair with Vigil, the Microservices Status Page.
JavaScript
10
star
17

gulp-remove-logging

đŸšŋ Removes console logging statements.
JavaScript
8
star
18

rs-vigil-reporter

🚧 Vigil Reporter for Rust. Used in pair with Vigil, the Microservices Status Page.
Rust
7
star
19

progressio

🎈 Beautiful & stylish asynchronous page loader. Makes a static website dynamic in a breeze.
JavaScript
7
star
20

node-gitlab-logging

đŸē A logging handler for NodeJS that opens GitLab issues on provided exception.
JavaScript
7
star
21

node-bloom-control

💐 Bloom Control integration for Node. Used in pair with Bloom, the HTTP REST API caching middleware.
JavaScript
7
star
22

grunt-blurred-images

🔮 Produce blurred versions of images. Used to reproduce Medium blur-on-scroll effect.
JavaScript
5
star
23

django-request-mock

🙈 Create a Django request object that mocks a real one. Useful in case a real request object is not available, but is needed (delayed Celery tasks for instance)
Python
5
star
24

waaave-bootstrap

🏄 The Waaave Bootstrap. Efficient by design.
JavaScript
4
star
25

waaave-web

🏄 Waaave, The Developer Sharing Network. Tutorials, Shots and more.
Python
4
star
26

lab-iot-homekit

💡 HomeKit-powered home automation IoT projects, running on ESP32.
C
3
star
27

node-spamassassin-client

đŸ”Ē SpamAssassin client for Node. Lets you check if an email is spam or ham.
JavaScript
3
star
28

grunt-contrib-lualint

💊 Grunt task for validating Lua code.
Lua
2
star
29

server-workflow-scripts

🐹 Server workflow scripts for fast project deployment and execution - used with valeriansaliou/gitlab-deploy-hooks
Shell
2
star
30

datastore.js

🐘 A complete Web storage wrapper (sessionStorage/localStorage). Provides a fallback when not supported.
JavaScript
2
star
31

jquery.hasparent

💡 jQuery hasParent helper. Checks if the selected element has a defined parent element.
JavaScript
2
star
32

medius

🍊 Learn how the immune system works with Medius, a real-time fight game.
Python
2
star
33

gulp-jade-client

🐰 Compiles Jade templates from the browser.
JavaScript
1
star
34

waaave-hitcount

🏄 Basic app that allows you to track the number of hits/views for a particular object.
Python
1
star
35

valeriansaliou

👱đŸģ‍♂ī¸ My GitHub profile.
1
star
36

backlinks-manager

🎃 BackLinks.com ads manager. Easily deploy a BackLinks.com ad code, with a fast cache system.
PHP
1
star
37

lab-eigenfaces

💡 Face recognition algorithm implementation, using the eigenfaces technique.
MATLAB
1
star
38

grunt-contrib-rubylint

💊 Grunt task for validating Ruby code.
JavaScript
1
star
39

dns-deploy-utilities

đŸŦ Utilities to deploy DNS configurations for the BIND9 nameserver.
1
star