packages/ts-client/README.md
Type-safe TypeScript client for the Spacedrive daemon, automatically generated from Rust core types using Specta.
npm install @spacedrive/client
import { SpacedriveClient } from '@spacedrive/client';
const client = new SpacedriveClient();
// Test connection
await client.ping();
// Get libraries (fully typed)
const libraries = await client.getLibraries();
console.log('Libraries:', libraries);
// Get jobs with status filtering
const jobs = await client.getJobs('running');
console.log('Running jobs:', jobs);
// Create a new library
const newLibrary = await client.createLibrary('My Photos', '/Users/me/Photos');
console.log('Created library:', newLibrary);
// Subscribe to specific event types
await client.subscribe(['JobStarted', 'JobProgress', 'JobCompleted']);
// Listen for events (fully typed)
client.on('event', (event) => {
switch (event) {
case 'CoreStarted':
console.log('Daemon started');
break;
default:
if ('JobStarted' in event) {
console.log(`Job started: ${event.JobStarted.job_type} (${event.JobStarted.job_id})`);
} else if ('JobProgress' in event) {
console.log(`Job progress: ${event.JobProgress.progress * 100}%`);
} else if ('JobCompleted' in event) {
console.log(`Job completed: ${event.JobCompleted.job_type}`);
console.log('Output:', event.JobCompleted.output);
}
break;
}
});
client.on('error', (error) => {
console.error('Client error:', error);
});
client.on('disconnected', () => {
console.log('Disconnected from daemon');
});
Types are automatically generated from the Rust core using Specta. To regenerate types:
npm run generate-types
ping() - Test daemon connectivityexecuteQuery<Q, R>(query: Q, method: string): Promise<R> - Execute a query operationexecuteAction<A, R>(action: A, method: string): Promise<R> - Execute an action operationsubscribe(eventTypes?: string[]): Promise<void> - Subscribe to daemon eventsgetLibraries(includeStats?: boolean): Promise<LibraryInfo[]> - Get all librariescreateLibrary(name: string, path?: string): Promise<LibraryCreateOutput> - Create a new librarygetJobs(status?: JobStatus): Promise<JobListOutput> - Get job list with optional filteringAll event types are fully typed TypeScript unions:
Event - Main event union typeJobOutput - Job completion output (adjacently tagged)JobStatus - Job status enum ("queued" | "running" | "completed" | ...)FileOperation - File operation typesProgress - Progress information with multiple formatsThis client uses the same architecture as the Swift client:
# Install dependencies
npm install
# Build the client
npm run build
# Run tests
npm test
# Watch mode for development
npm run dev