Giter VIP home page Giter VIP logo

nebula-node's Introduction

Nebula Nodejs SDK

This repository provides Nebula client API in Nodejs.

Features

  • Muti-Server Support

  • Auto-reconnection support

    Client will try to reconnect forever, until the server is available again.

  • Connection pool support

  • Disconnection detection

    A heartbeat mechanism is implemented, client will send ping to server each pingInterval ms for detect connective

  • Thrift enhancement

    fix auto reconnect issue#2407

    fix performance issue in huge data scene#2483

API

Connection Options

parameter type description
servers string[] nebula servers
userName string username for login
password string password for login
space string space name in nebula server
poolSize number Pool size for each server(Optional, default:5)
bufferSize number Command cache in offline or before established connect (Optional, defaul: 2000)
executeTimeout number Command executing timeout in ms (Optional, default:10000)
pingInterval number for keepalive, ping duration in ms, (Optional, default:60000)

How To

Install

For compiling C++ native module, node-gyp is required, you can install node-gyp by npm install -g node-gyp

npm install @nebula-contrib/nebula-nodejs --save --unsafe-perm

Simple and convenient API

// ESM
import { createClient } from '@nebula-contrib/nebula-nodejs'

// CommonJS
// const { createClient } = require('@nebula-contrib/nebula-nodejs')

// Connection Options
const options = {
  servers: ['ip-1:port','ip-2:port'],
  userName: 'xxx',
  password: 'xxx',
  space: 'space name',
  poolSize: 5,
  bufferSize: 2000,
  executeTimeout: 15000,
  pingInterval: 60000
}

// Create client
const client = createClient(options)

// Execute command
// 1. return parsed data (recommend)
const response = await client.execute('GET SUBGRAPH 3 STEPS FROM -7897618527020261406')
// 2. return nebula original data
const responseOriginal = await client.execute('GET SUBGRAPH 3 STEPS FROM -7897618527020261406', true)

Events

parameter description
sender the individual connection in connection pool
error Nebula Error
retryInfo Retry information
retryInfo.delay delay time
retryInfo.attempt total attempts
const client = createClient(options)

// connection is ready for executing command
client.on('ready', ({sender}) => {

})

// error occurs
client.on('error', ({ sender, error }) => {

})

// connected event
client.on('connected', ({ sender }) => {

})

// authorized successfully
client.on('authorized', ({ sender }) => {

})

// reconnecting
client.on('reconnecting', ({ sender, retryInfo }) => {

})

// closed
client.on('close', { sender }) => {

}

About hash64 function

nebula-nodejs exports hash64 function for converting string to string[], it's based on MurmurHash3.

// ESM
import { hash64 } from '@nebula-contrib/nebula-nodejs'

// CommonJS
// const { hash64 } = require('@nebula-contrib/nebula-nodejs')

const results = hash64('f10011b64aa4e7503cd45a7fdc24387b')

console.log(results)

// Output:
// ['2852836996923339651', '-6853534673140605817']

About Int64

nodejs cannot repreent Int64, so we convert Int64 bytes to string

// ESM
import { bytesToLongLongString } from '@nebula-contrib/nebula-nodejs'

// CommonJS
// const { bytesToLongLongString } = require('@nebula-contrib/nebula-nodejs')

const s = '-7897618527020261406'

const buffer = [146, 102, 5, 203, 5, 105, 223, 226]
const result = bytesToLongLongString(buffer)

// result equals s

Development

Build

git clone https://github.com/nebula-contrib/nebula-node.git
cd nebula-node
npm install --unsafe-perm
npm run build

Unit Test

npm run build
npm run test

Unit Test Coverage

npm run coverage

Publish

npm run build
cd dist
npm publish

TODO

Not implemented data type for auto parser

Data Type property name in nebula response
DataSet gVal
Geography ggVal
Duration duVal

Released Versions in npmjs.com

NodeJS Client Version Nebula Graph Version
2.6.2 2.6.x
3.0.3 3.x

nebula-node's People

Contributors

dutor avatar jjsimps avatar laura-ding avatar re0marb1e avatar wey-gu avatar wujjpp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nebula-node's Issues

等更新

可以发相关资料给我吗?
或许我可以协助 开发

RFC: Refactor of Nebula-Node

@huaxiabuluo is working on a refactor of this project.

  • remove 3pp package from the repo(leave them in package*.json only)
  • introduce package-lock.json
  • jest for test
  • removed the thrift-gen code
  • more(@huaxiabuluo to add more)

master...huaxiabuluo:nebula-node:master
PR: #27

@wujjpp what do you think? He assumed no modification of dep packages and thrift-gen code was not modified manually, for now the test cases passed but not sure if it could work in production, could you help advise on this proposal?

Thanks!

v3.0.2 - Error: Cannot find module

3.0.1 works fine, but 3.0.2 drops an error while importing ...
at line:
const { createClient } = require( '@nebula-contrib/nebula-nodejs' )

OS: MacOS 13.3.1
Node 20.1.0

Error: Cannot find module '/Users/vii/Ruse/Argus/argus-entitier/node_modules/@nebula-contrib/nebula-nodejs/index.js'. Please verify that the package.json has a valid "main" entry

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.