throome-sdk
v0.1.0
Published
Official Throome SDK for Node.js and TypeScript
Maintainers
Readme
Throome Node.js/TypeScript SDK
Official Node.js and TypeScript SDK for Throome - Universal Gateway for Modern Applications.
Installation
npm install throome-sdk
# or
yarn add throome-sdk
# or
pnpm add throome-sdkQuick Start
JavaScript
const { ThroomClient } = require('throome-sdk');
const client = new ThroomClient({ baseURL: 'http://localhost:9000' });
async function main() {
const health = await client.health();
console.log('Gateway status:', health.status);
const clusters = await client.listClusters();
console.log(`Found ${clusters.length} clusters`);
}
main().catch(console.error);TypeScript
import { ThroomClient, ServiceConfig } from 'throome-sdk';
const client = new ThroomClient({ baseURL: 'http://localhost:9000' });
async function main() {
const health = await client.health();
console.log('Gateway status:', health.status);
const clusters = await client.listClusters();
console.log(`Found ${clusters.length} clusters`);
}
main().catch(console.error);Features
- Cluster Management: Create, list, get, and delete clusters
- Health Monitoring: Check gateway and cluster health
- Activity Logging: View detailed activity logs
- Service Operations: Get service info and logs
- Database Client: Execute SQL queries through the gateway
- Cache Client: Redis operations (GET, SET, DELETE)
- Queue Client: Publish messages to Kafka topics
- Full TypeScript Support: Complete type definitions included
Usage Examples
Create a Cluster
const services: Record<string, ServiceConfig> = {
'redis-1': {
type: 'redis',
port: 6379,
},
'postgres-1': {
type: 'postgres',
port: 5432,
username: 'postgres',
password: 'password',
database: 'mydb',
},
};
const response = await client.createCluster({
name: 'my-cluster',
services,
});
console.log('Created cluster:', response.cluster_id);Cache Operations
const cluster = client.cluster('cluster-id');
const cache = cluster.cache();
// Set value with TTL
await cache.set('user:123', 'John Doe', { expiration: 60 });
// Get value
const value = await cache.get('user:123');
// Delete value
await cache.delete('user:123');Database Operations
const db = cluster.db();
// Execute statement
await db.execute('CREATE TABLE users (id SERIAL, name VARCHAR(100))');
// Query rows
const rows = await db.query('SELECT * FROM users WHERE id = $1', 123);
// Query single row
const row = await db.queryRow('SELECT * FROM users WHERE id = $1', 123);Get Service Logs
const service = cluster.service('redis-1');
// Get last 100 lines
const logs = await service.getLogs({
tail: 100,
timestamps: true,
});Monitor Activity
// Get cluster activity logs
const logs = await cluster.getActivity({ limit: 50 });
logs.forEach((log) => {
console.log(
`[${log.timestamp}] ${log.service_name}.${log.operation}: ${log.command} (${log.status})`
);
});Complete Example
See examples/index.ts for a complete working example.
API Reference
ThroomClient
health(): Check gateway healthlistClusters(): List all clustersgetCluster(id): Get cluster detailscreateCluster(req): Create new clusterdeleteCluster(id): Delete clustergetActivity(filters?): Get global activity logscluster(id): Get cluster client
ClusterClient
health(): Check cluster healthmetrics(): Get cluster metricsgetActivity(filters?): Get cluster activity logsservice(name): Get service clientdb(): Get database clientcache(): Get cache clientqueue(): Get queue client
ServiceClient
getInfo(): Get service informationgetLogs(options?): Get Docker container logsgetActivity(filters?): Get service activity logs
TypeScript Types
All TypeScript types are exported from the main package:
import type {
Cluster,
Service,
ServiceConfig,
CreateClusterRequest,
HealthResponse,
ActivityLog,
// ... and more
} from 'throome-sdk';License
MIT
