# Synchronization

Pull strategies and per-relay recovery results.

[Read the negentropy sync guide](/docs/synchronization/). Signatures below come from the published SDK declarations. Access SDK services through `db`; use their constructors only when integrating at a lower level.

## SyncOptions


```ts
interface SyncOptions {
  tables?: readonly string[];
  initial?: boolean;
  reconnect?: boolean;
  timeout?: number;
  onError?: (error: NostrbaseError) => void;
}
```

## SyncPullOptions


```ts
interface SyncPullOptions {
  signal?: AbortSignal;
  relays?: readonly string[];
  /** Disable reconciliation and request normal events directly. */
  strategy?: "auto" | "query";
}
```

## SyncRelayResult


```ts
interface SyncRelayResult extends RelayResult {
  strategy: "negentropy" | "query" | "mixed";
  fallbackReason?: string;
  received: number;
}
```

## SyncMeta


```ts
interface SyncMeta extends ResultMeta {
  sync: SyncRelayResult[];
}
```

## SyncResult


```ts
interface SyncResult extends Result<NostrEvent[]> {
  meta?: SyncMeta;
}
```

## NostrbaseSync


```ts
/** Pull-only reconciliation. Cached events belonging to other authors are never published. */
declare class NostrbaseSync {}
```

### constructor


```ts
constructor(host: SyncHost, options?: SyncOptions);
```

### registerTable


```ts
registerTable(table: string, initial?: boolean): void;
```

### table


```ts
table(table: string, options?: SyncPullOptions): Promise<SyncResult>;
```

### pull


```ts
pull(input?: Filter | Filter[], options?: SyncPullOptions): Promise<SyncResult>;
```

### start


```ts
/** Opt-in startup/reconnect recovery. This does not replace live subscriptions. */
start(): void;
```

### close


```ts
close(): void;
```


## Supporting declarations

These types appear in public signatures but are not package exports.

### SyncHost


```ts
interface SyncHost {
  namespace: string;
  relays: string[];
  pool: RelayPool;
  eventStore: EventStore;
  transport: Transport;
  timeout: number;
  ready(): Promise<void>;
  assertOpen(): void;
  signal(signal?: AbortSignal): AbortSignal;
  ingest(event: NostrEvent): boolean;
}
```
