A streaming REST client for Timeplus Proton, designed for real-time SQL queries with infinite result streams.
npm install @timeplus/proton-javascript-driverimport { ProtonClient } from "@timeplus/proton-javascript-driver";
const client = new ProtonClient({
host: "localhost", // optional, default: "localhost"
port: 3218, // optional, default: 3218
timeout: 30000, // optional: connection timeout in ms
});
// Execute a streaming query
const { rows, abort } = await client.query(
"SELECT * FROM my_stream"
);
// Consume results as they arrive
for await (const row of rows) {
console.log(row);
}
// Or abort the stream when needed
setTimeout(() => abort(), 10000);interface ProtonConfig {
host?: string; // Proton server host (default: "localhost")
port?: number; // Proton server port (default: 3218)
username?: string; // Optional basic auth username
password?: string; // Optional basic auth password
timeout?: number; // Connection timeout in milliseconds
}Executes a SQL query and returns a streaming result.
Parameters:
sql- SQL query stringoptions.signal- OptionalAbortSignalfor external cancellation
Returns: Promise<QueryResult<T>>
rows-AsyncIterableIterator<T>for streaming consumptionabort()- Function to cancel the query
Low-level NDJSON parser exposed for custom use cases.
import { ndjsonStreamParser } from "@timeplus/proton-javascript-driver";
const response = await fetch(url);
const reader = response.body.getReader();
for await (const row of ndjsonStreamParser(reader)) {
console.log(row);
}See docs/API.md for complete API reference including:
- All configuration options
- Authentication setup
- Type definitions
- Error handling
- Connection management
- Node.js >= 16.0.0
- Timeplus Proton server
Apache-2.0