Jamie Pine c1fff9b27b feat: Implement CLI Configuration Management for Library ID
- Introduced a new `CliConfig` struct for managing CLI-specific configurations, including the current library ID.
- Added methods to load, save, set, and clear the current library ID within the CLI context.
- Updated the `Context` struct to integrate `CliConfig`, ensuring library ID management is consistent across the application.
- Enhanced command implementations to utilize the new CLI configuration features, improving user experience and functionality.
2025-09-23 22:17:10 -07:00
..

Spacedrive Swift Client

A type-safe Swift client for interacting with the Spacedrive daemon.

Features

  • Type Safety: Full compile-time type checking with generated Swift types
  • Automatic Generation: Types are automatically generated from Rust definitions
  • Simple API: Three core methods: executeQuery, executeAction, and subscribe
  • Modern Swift: Uses async/await and AsyncStream for clean asynchronous code

Installation

Swift Package Manager

Add this to your Package.swift:

dependencies: [
    .package(path: "path/to/spacedrive/packages/swift-client")
]

Usage

import SpacedriveClient

// Initialize the client
let client = SpacedriveClient(socketPath: "/path/to/daemon.sock")

// Execute a query
let status = try await client.executeQuery(
    CoreStatusQuery(),
    method: "query:core.status.v1",
    responseType: CoreStatus.self
)

// Execute an action
let result = try await client.executeAction(
    LibraryCreateInput(name: "My Library"),
    method: "action:libraries.create.input.v1",
    responseType: LibraryCreateOutput.self
)

// Subscribe to events
for await event in client.subscribe(to: ["JobProgress", "JobCompleted"]) {
    print("Received event: \(event)")
}

Development

Regenerating Types

After making changes to Rust types in the core:

  1. Build the core to generate the schema:

    cd core && cargo build
    
  2. Regenerate the Swift client:

    cd packages/swift-client
    ./generate_client.sh
    

Requirements

  • Swift 5.9+
  • macOS 13+ or iOS 16+
  • quicktype (for type generation): npm install -g quicktype

Architecture

The client uses a two-layer architecture:

  1. Generated Types Layer: types.swift contains all the generated types from quicktype
  2. Client API Layer: SpacedriveClient.swift provides the clean, user-facing API

This separation ensures that the generated types don't pollute the main API and can be regenerated without affecting user code.