Skip to content

@statesync/tauri


@statesync/tauri / createTauriSnapshotProvider

Function: createTauriSnapshotProvider()

ts
function createTauriSnapshotProvider<T>(options): SnapshotProvider<T>;

Defined in: transport.ts:210

Creates a SnapshotProvider that fetches snapshots by invoking a Tauri command.

Each call to getSnapshot() invokes the specified Rust command and expects a SnapshotEnvelope in return. The command receives any extra args provided in the options.

Rust backend requirement: The command must return a JSON-serializable struct with { revision: String, data: T }.

Type Parameters

Type ParameterDescription
TThe application-specific snapshot data type.

Parameters

ParameterTypeDescription
optionsTauriSnapshotProviderOptionsConfiguration specifying the invoke function, command name, and optional args.

Returns

SnapshotProvider<T>

A SnapshotProvider that can be passed to createRevisionSync.

Example

typescript
import { invoke } from '@tauri-apps/api/core';

interface AppState {
  counters: Record<string, number>;
}

const provider = createTauriSnapshotProvider<AppState>({
  invoke,
  commandName: 'get_app_state',
  args: { workspaceId: 'ws_abc123' },
});

const envelope = await provider.getSnapshot();
console.log(envelope.revision, envelope.data.counters);

Released under the MIT License.