This directory contains Thrift definition files (.thrift) and the generated Node.js client code.
The IoTDB client uses Apache Thrift for RPC communication. The Thrift definitions are sourced from Apache IoTDB and are automatically synchronized weekly via GitHub Actions.
thrift/ ├── client.thrift # IoTDB client RPC interface definitions ├── common.thrift # Common types shared across services └── README.md # This file src/thrift/generated/ ├── IClientRPCService.js # Generated RPC client (JavaScript) ├── IClientRPCService.d.ts # TypeScript definitions for RPC client ├── client_types.js # Generated client types (JavaScript) ├── client_types.d.ts # TypeScript definitions for client types ├── common_types.js # Generated common types (JavaScript) └── common_types.d.ts # TypeScript definitions for common types
As of this update, the Thrift code generator produces both:
.js): Used at runtime.d.ts): Provide type safety and IDE autocompleteThis dual-generation approach ensures:
You need the Apache Thrift compiler installed:
# Ubuntu/Debian sudo apt-get install thrift-compiler # macOS brew install thrift # Verify installation thrift --version
To regenerate the Thrift client code:
npm run generate:thrift
This command:
.js and .d.ts filesthrift/client.thrift.d.ts) alongside the JavaScriptThe generated files include proper TypeScript types for:
common.thriftThe GitHub Actions workflow .github/workflows/check-thrift.yml automatically:
With the TypeScript definitions, you get full type safety:
import { Session } from './client/Session'; import * as ttypes from './thrift/generated/client_types'; const session = new Session({ host: 'localhost', port: 6667 }); // TypeScript knows the exact types of request fields const req = new ttypes.TSOpenSessionReq({ client_protocol: ttypes.TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V3, username: 'root', password: 'root', zoneId: 'UTC+8', }); // Full IntelliSense support session.executeQueryStatement('SELECT * FROM root.test');
The generator uses the official Apache Thrift compiler with the js:node,ts target:
thrift --gen js:node,ts -out src/thrift/generated thrift/client.thrift
Options:
js:node - Generate Node.js compatible JavaScriptts - Generate TypeScript definition files-out - Output directory for generated filesThe generated code depends on:
thrift - Apache Thrift Node.js librarynode-int64 - For 64-bit integer support@types/thrift - TypeScript definitions for Thrift library (dev dependency)If you see TypeScript errors about missing types, ensure:
npm install to install dependencies.d.ts files exist in src/thrift/generated/tsconfig.json includes the src directoryThe code generation requires Thrift compiler 0.14.0 or later for TypeScript support. Check your version:
thrift --version
If you encounter issues after updating Thrift definitions:
# Clean and regenerate rm -rf src/thrift/generated/*.js src/thrift/generated/*.d.ts npm run generate:thrift # Rebuild the project npm run build
When updating Thrift definitions:
.thrift files in the thrift/ directorynpm run generate:thrift to regenerate codenpm run build to ensure compilation succeedsnpm test to verify tests pass.thrift files and generated code