-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nebula nodejs SDK implementation #6
Conversation
@wey-gu here is the pr, pls take a look. |
package.json
Outdated
"sinon-chai": "^3.7.0", | ||
"source-map-support": "^0.5.19", | ||
"typescript": "4.1.5", | ||
"uuid": "^8.3.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these lib be in the package.json dependencies
instead of devDependencies
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
browser-or-node
,isomorphic-ws
,node-int64
,q
,ws
dependent by thrift, because we have copy & modified thrift in local package, so we should add thoese libs asdependencies
bindings
,lodash
dependent bynebula-node
- all other libs treat as
devDependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌,I just find all the libs in the devDependencies.
package.json
Outdated
"inquirer": "^8.1.1", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^8.4.0", | ||
"moment": "^2.29.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for advice: Is it better to use day.js instead of monent.js for reducing the package size? https://medium.datadriveninvestor.com/https-medium-com-sabesan96-why-you-should-choose-day-js-instead-of-moment-js-9cf7bb274bbd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moment
is useless, I will remove it
|
||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const asyncHooks = require('async_hooks') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about why not just import import async_hooks
directly, is it possible that the module can't be imported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I find you use import
other place: https://github.com/vesoft-inc/nebula-node/blob/5d71bfd743ae512d2dc490b47897022cce5d6d4b/src/nebula/types.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async_hooks
module added in nodejs v8.1.0 and in fact nebula-node
can be run on nodejs
below v8.1.0
, although I have specifed v10.0.0 in package.json
. we use require
for detecting the target node compatibility. If it not support, our module can also working fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directory Layout:
.
├── /dist/ # Build results for publishing (this folder generated after npm run build
, its for publish)
├── /specs/ # Misc knowledge and docs
├── /src/ # Source Dir
├── /tests/ # Unit test case, if you have nebula server, Put your test case in this folder for testing
├── /tools/ # Tiny build system
└── .... # Supporting files
Build & Publish:
In short: typescript
-> ESM
-> CommonJS
-> Copy & Generate necessary assets
-> publish
@wey-gu 这个PR还合吗? |
We'll deal with it in this week, thanks for your following🤝 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wujjpp Is there any plan to make up the unit test/example in future?
I find it only like a todo
demo about test?
src/nebula/types.ts
Outdated
// 密码 | ||
password: string; | ||
// 数据库名称 | ||
database: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for space? maybe it's more clear to rename it to space ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nianiaJR rename database
to space
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've simply tried this lib, work fine. Because of it's too big changes, it's important to make up the enough unit test/examples for long-term maintaining. Thanks for your contributions. I'll approved it and make it merged soon🤝
I have a full test case located at /* eslint-disable max-len */
/**
* Created by Wu Jian Ping on - 2021/06/09.
*/
import { expect } from 'chai'
import createClient, { ClientOption } from '../dist'
const relationServer: ClientOption = {
servers: ['10.0.1.100:9669', '10.0.1.101:9669', '10.0.1.102:9669'],
userName: 'xxxxx',
space: 'xxxxx',
database: 'partion1',
pingInterval: 5000,
poolSize: 2
}
const riskInfoServer: ClientOption = {
servers: ['10.0.1.100:9669', '10.0.1.101:9669', '10.0.1.102:9669'],
userName: 'xxxxx',
space: 'xxxxx',
database: 'partion2',
pingInterval: 5000,
poolSize: 2
}
const commands = {
cmd1: 'GET SUBGRAPH 2 STEPS FROM -7897618527020261406',
cmd2: 'fetch prop on Company -7897618527020261406',
cmd3: 'go from 815677140545765099 over Relation yield Relation._src as src, Relation._dst as dst, Relation.relation_name as relation_name, Relation.prop1 as prop1, Relation.prop2 as prop2, Relation.prop3 as prop3, Relation.prop4 as prop4, $^.Person.name as src_p_name, $^.Company.name as src_c_name, $$.Person.name as dst_p_name, $$.Company.name as dst_c_name | limit 1000',
cmd4: 'find noloop path from -4075961126534726064 to 815677140545765099 over Relation bidirect upto 2 steps',
cmd5: 'fetch prop on Relation -4075961126534726064->815677140545765099@-5101473608195470769'
}
describe('nebula', () => {
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
it('test-case-1', async () => {
const client = createClient(relationServer)
const response1 = await client.execute(commands.cmd1)
expect(response1.data?._vertices?.length).greaterThan(0)
expect(response1.data?._edges?.length).greaterThan(0)
await client.close()
})
it('test-case-2', async () => {
const client = createClient(relationServer)
const response1 = await client.execute(commands.cmd2)
expect(response1.data?.vertices_?.length).greaterThan(0)
await client.close()
})
it('test-case-3', async () => {
const client = createClient(riskInfoServer)
const response1 = await client.execute(commands.cmd3)
expect(response1.data?.src?.length).greaterThan(0)
await client.close()
})
it('test-case-4', async () => {
const client = createClient(riskInfoServer)
const response1 = await client.execute(commands.cmd4)
expect(response1.data?.path?.length).greaterThan(0)
await client.close()
})
it('test-case-5', async () => {
const client = createClient(riskInfoServer)
const response1 = await client.execute(commands.cmd5)
expect(response1.data?.edges_?.length).greaterThan(0)
await client.close()
})
it('test-promise-all', async () => {
const client = createClient(relationServer)
const [resp1, resp2, resp3] = await Promise.all([
client.execute('GET SUBGRAPH 1 STEPS FROM -7897618527020261406', false),
client.execute('GET SUBGRAPH 2 STEPS FROM -7897618527020261406', false),
client.execute('GET SUBGRAPH 3 STEPS FROM -7897618527020261406', false)
])
console.log(`resp11:${resp1.data._vertices.length}, ${resp1.data._edges.length}`) // eslint-disable-line
console.log(`resp21:${resp2.data._vertices.length}, ${resp2.data._edges.length}`) // eslint-disable-line
console.log(`resp31:${resp3.data._vertices.length}, ${resp3.data._edges.length}`) // eslint-disable-line
await client.close()
})
after(async () => {
process.exit()
})
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 connectiveThrift enhancement
fix auto reconnect issue#2407
fix performance issue in huge data scene#2483
API
Connection Options
How To
Install
For compiling C++ native module,
node-gyp
is required, you can installnode-gyp
bynpm install -g node-gyp
Simple and convenient API
Events
About hash64 function
nebula-nodejs
exportshash64
function for convertingstring
tostring[]
, it's based onMurmurHash3
.About Int64
nodejs cannot repreent
Int64
, so we convertInt64
bytes tostring
Development
Build
git clone https://github.com/vesoft-inc/nebula-node.git cd nebula-node npm install --unsafe-perm npm run build
Unit Test
npm run build npm run test
Unit Test Coverage
Publish
npm run build cd dist npm publish
TODO
Not implemented data type for auto parser