Skip to content

Commit c565856

Browse files
authored
Updated examples and js doc, code cleanup (#52)
1 parent e54ca74 commit c565856

File tree

93 files changed

+3163
-29262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3163
-29262
lines changed

CLAUDE.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is the QuestDB Node.js client library (@questdb/nodejs-client) that provides data ingestion capabilities to QuestDB databases. The client supports multiple transport protocols (HTTP/HTTPS, TCP/TCPS) and authentication methods.
8+
9+
## Development Commands
10+
11+
### Build
12+
```bash
13+
pnpm build # Build the library using bunchee (produces both ESM and CJS outputs)
14+
```
15+
16+
### Testing
17+
```bash
18+
pnpm test # Run all tests using Vitest
19+
```
20+
21+
### Code Quality
22+
```bash
23+
pnpm eslint # Run ESLint on all source files
24+
pnpm typecheck # Run TypeScript type checking without emitting files
25+
pnpm format # Format code using Prettier
26+
```
27+
28+
### Documentation
29+
```bash
30+
pnpm docs # Build JSDoc documentation
31+
pnpm preview:docs # Preview generated documentation locally
32+
```
33+
34+
## Architecture
35+
36+
### Core Components
37+
38+
1. **Sender** (`src/sender.ts`): Main API class that orchestrates data ingestion. Handles auto-flushing, connection management, and provides the builder pattern API for constructing rows.
39+
40+
2. **Transport Layer** (`src/transport/`):
41+
- `http/undici.ts`: Default HTTP transport using Undici library for high performance
42+
- `http/stdlib.ts`: Alternative HTTP transport using Node.js built-in modules
43+
- `tcp.ts`: TCP/TCPS transport for persistent connections with JWK authentication
44+
- Protocol negotiation and retry logic for HTTP transports
45+
46+
3. **Buffer System** (`src/buffer/`):
47+
- `bufferv1.ts`: Text-based protocol (version 1) for backward compatibility
48+
- `bufferv2.ts`: Binary protocol (version 2) with double encoding and array support
49+
- Dynamic buffer resizing and row-level transaction support
50+
51+
4. **Configuration** (`src/options.ts`): Comprehensive options parsing from connection strings with validation and deprecation handling.
52+
53+
### Protocol Versions
54+
55+
- **Version 1**: Text-based serialization, compatible with older QuestDB versions
56+
- **Version 2**: Binary encoding for doubles, supports array columns, better performance
57+
- **Auto-negotiation**: HTTP transport can automatically detect and use the best protocol version
58+
59+
### Key Design Patterns
60+
61+
- Builder pattern for row construction with method chaining
62+
- Factory methods (`Sender.fromConfig()`, `Sender.fromEnv()`) for validated initialization
63+
- Abstract base classes for transport and buffer implementations
64+
- Automatic buffer management with configurable auto-flush behavior
65+
66+
## Testing Strategy
67+
68+
Tests are organized by component:
69+
- `sender.config.test.ts`: Configuration parsing and validation
70+
- `sender.buffer.test.ts`: Buffer operations and protocol serialization
71+
- `sender.transport.test.ts`: Transport layer functionality
72+
- `sender.integration.test.ts`: End-to-end integration tests with QuestDB
73+
74+
Integration tests use TestContainers to spin up QuestDB instances for realistic testing.
75+
76+
## Important Implementation Notes
77+
78+
- The client requires Node.js v20+ for Undici support
79+
- Authentication is handled differently per transport (Basic/Bearer for HTTP, JWK for TCP)
80+
- Buffer automatically resizes up to `max_buf_size` (default 100MB)
81+
- Auto-flush triggers based on row count or time interval
82+
- Each worker thread needs its own Sender instance (buffers cannot be shared)
83+
- Protocol version 2 is recommended for new implementations with array column support

0 commit comments

Comments
 (0)