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:
- JavaScript files (
.js): Used at runtime - TypeScript declaration files (
.d.ts): Provide type safety and IDE autocomplete
This dual-generation approach ensures:
- Full TypeScript support with proper types and interfaces
- Compatibility with the existing JavaScript runtime
- Better developer experience with IntelliSense and type checking
- No runtime overhead
You need the Apache Thrift compiler installed:
# Ubuntu/Debian
sudo apt-get install thrift-compiler
# macOS
brew install thrift
# Verify installation
thrift --versionTo regenerate the Thrift client code:
npm run generate:thriftThis command:
- Removes existing generated
.jsand.d.tsfiles - Generates new JavaScript files from
thrift/client.thrift - Generates TypeScript definition files (
.d.ts) alongside the JavaScript
The generated files include proper TypeScript types for:
- All Thrift structs and enums
- RPC service methods
- Request and response types
- Common types from
common.thrift
The GitHub Actions workflow .github/workflows/check-thrift.yml automatically:
- Checks for updates to Thrift definitions in Apache IoTDB master branch (weekly)
- Regenerates the client code with TypeScript definitions if changes are detected
- Creates a pull request with the updates
With the TypeScript definitions, you get full type safety:
import{Session}from'./client/Session';import*asttypesfrom'./thrift/generated/client_types';constsession=newSession({host: 'localhost',port: 6667});// TypeScript knows the exact types of request fieldsconstreq=newttypes.TSOpenSessionReq({client_protocol: ttypes.TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V3,username: 'root',password: 'root',zoneId: 'UTC+8',});// Full IntelliSense supportsession.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.thriftOptions:
js:node- Generate Node.js compatible JavaScriptts- Generate TypeScript definition files-out- Output directory for generated files
The 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:
- You've run
npm installto install dependencies - The
.d.tsfiles exist insrc/thrift/generated/ - Your
tsconfig.jsonincludes thesrcdirectory
The code generation requires Thrift compiler 0.14.0 or later for TypeScript support. Check your version:
thrift --versionIf 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 buildWhen updating Thrift definitions:
- Update the
.thriftfiles in thethrift/directory - Run
npm run generate:thriftto regenerate code - Run
npm run buildto ensure compilation succeeds - Run
npm testto verify tests pass - Commit both the
.thriftfiles and generated code