Contributing to Apache IoTDB Node.js Client
Thank you for your interest in contributing to the Apache IoTDB Node.js client!
Getting Started
Prerequisites
- Node.js >= 14.0.0
- npm or yarn
- Apache Thrift compiler (for regenerating Thrift files)
- Git
Development Setup
- Clone the repository:
git clone https://github.com/CritasWang/@iotdb/client.git
cd @iotdb/client
- Install dependencies:
npm install
- Build the project:
npm run build
- Run tests:
npm test
Development Workflow
Building
npm run build
This compiles TypeScript files to JavaScript in the dist/ directory.
Testing
Run all tests:
npm test
Run only unit tests:
npm run test:unit
Run only E2E tests (requires running IoTDB instance):
export IOTDB_HOST=localhost
export IOTDB_PORT=6667
npm run test:e2e
Linting
npm run lint
Formatting
npm run format
Code Style
- Use TypeScript strict mode
- Follow existing code formatting (use Prettier)
- Add JSDoc comments for public APIs
- Keep functions focused and concise
- Use async/await instead of callbacks
- Handle errors appropriately
Testing Guidelines
Unit Tests
- Place in
tests/unit/ - Test individual functions and classes
- Mock external dependencies
- Aim for high coverage
E2E Tests
- Place in
tests/e2e/ - Test against real IoTDB instance
- Use environment variables for configuration
- Gracefully handle missing IoTDB instance
- Clean up test data
Example E2E test pattern:
describe('Feature E2E Tests', () => {
let client;
beforeAll(async () => {
try {
client = new Session({
host: process.env.IOTDB_HOST || 'localhost',
port: parseInt(process.env.IOTDB_PORT || '6667'),
});
await client.open();
} catch (error) {
console.warn('IoTDB not available, tests will be skipped');
}
});
afterAll(async () => {
if (client?.isOpen()) {
await client.close();
}
});
test('Should do something', async () => {
if (!client?.isOpen()) {
console.log('Skipping - no IoTDB connection');
return;
}
// Test implementation
});
});
Pull Request Process
- Create a feature branch from
main - Make your changes
- Add/update tests as needed
- Ensure all tests pass
- Update documentation if needed
- Submit a pull request
Pull Request Checklist
- [ ] Code builds without errors
- [ ] All tests pass
- [ ] New code has tests
- [ ] Documentation updated (if applicable)
- [ ] CHANGELOG.md updated
- [ ] Code follows project style
- [ ] Commit messages are clear
Regenerating Thrift Files
If you need to update to a newer version of IoTDB's Thrift definitions:
- Download the latest Thrift files from Apache IoTDB:
git clone --depth 1 https://github.com/apache/iotdb.git /tmp/iotdb
- Copy the Thrift files:
cp /tmp/iotdb/iotdb-protocol/thrift-datanode/src/main/thrift/client.thrift thrift/
cp /tmp/iotdb/iotdb-protocol/thrift-commons/src/main/thrift/common.thrift thrift/
- Regenerate the Node.js client:
thrift --gen js:node -out src/thrift/generated thrift/client.thrift
- Test thoroughly to ensure compatibility
Adding New Features
When adding new features:
- Check if the feature is supported in Apache IoTDB
- Add the implementation in the appropriate file
- Add TypeScript type definitions
- Write unit tests
- Write E2E tests
- Add example usage
- Update README.md
- Update IMPLEMENTATION.md
- Update CHANGELOG.md
Common Development Tasks
Adding a New Method to Session
- Add method to
src/client/Session.ts - Add the same method to
src/client/SessionPool.ts (delegating to pool) - Add tests in
tests/e2e/Session.test.ts and tests/e2e/SessionPool.test.ts - Update TypeScript exports in
src/index.ts if needed - Add example usage in README.md
Updating Configuration
- Update interfaces in
src/utils/Config.ts - Update DEFAULT_CONFIG or DEFAULT_POOL_CONFIG
- Update tests in
tests/unit/Config.test.ts - Document in README.md
Reporting Issues
When reporting issues, please include:
- Node.js version
- IoTDB version
- Operating system
- Steps to reproduce
- Expected behavior
- Actual behavior
- Error messages/stack traces
Questions?
For questions or discussions:
- Open an issue on GitHub
- Check existing issues and documentation
License
By contributing, you agree that your contributions will be licensed under the Apache License 2.0.