# Client

createClient and client lifecycle.

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

## NostrbaseClient


```ts
declare class NostrbaseClient<
  DB extends SchemaShape<DB> = DefaultSchema,
> implements QueryHost {}
```

### Properties


```ts
readonly auth: NostrbaseAuth;
readonly pool: RelayPool;
readonly eventStore: EventStore;
readonly transport: Transport;
readonly events: NostrbaseEvents;
readonly diagnostics: NostrbaseDiagnostics;
readonly persistence?: NostrbasePersistence;
readonly offline: NostrbaseOffline;
readonly sync: NostrbaseSync;
readonly private: NostrbasePrivateTables<DB>;
readonly groups: NostrbaseGroups<DB>;
readonly storage: NostrbaseStorage<DB>;
readonly backup: NostrbaseBackup;
readonly relations: NostrbaseRelations<DB>;
readonly migrations: NostrbaseMigrations<DB>;
readonly dashboard: NostrbaseDashboard;
readonly ingested$: rxjs.Observable<NostrEvent>;
readonly namespace: string;
readonly relays: string[];
readonly timeout: number;
readonly minWriteAcks: number;
```

### constructor


```ts
constructor(options: ClientOptions<DB>);
```

### ready


```ts
ready(): Promise<void>;
```

### nextTimestamp


```ts
nextTimestamp(address: string): number;
```

### cachedEvents


```ts
cachedEvents(): NostrEvent[];
```

### assertOpen


```ts
assertOpen(): void;
```

### signal


```ts
signal(signal?: AbortSignal): AbortSignal;
```

### definition


```ts
definition<T extends object>(table: string): TableDefinition<T> | undefined;
```

### assertTable


```ts
assertTable(table: string): void;
```

### from


```ts
from<K extends keyof DB & string>(table: K): QueryBuilder<DB[K]>;
```

### request


```ts
request(filters: Filter[], signal?: AbortSignal): Promise<TransportRead>;
```

### ingest


```ts
ingest(event: NostrEvent): boolean;
```

### isDeleted


```ts
isDeleted(event: NostrEvent): boolean;
```

### readTable


```ts
readTable<T extends object>(
  table: string,
  state: QueryState,
  authors?: string[] | undefined,
  definition?: TableDefinition<T> | undefined,
): Promise<{
  rows: Row<T>[];
  meta: ResultMeta;
}>;
```

### sign


```ts
sign(template: EventTemplate, expectedPubkey?: string): Promise<NostrEvent>;
```

### publish


```ts
publish(event: NostrEvent, signal?: AbortSignal): Promise<WriteReceipt>;
```

### executeInGroup


```ts
/** Execute the query only within a stored private Marmot group. */
executeInGroup<T extends object>(
  groupId: string,
  table: string,
  state: QueryState,
): Promise<Result<Row<T>[]>>;
```

### execute


```ts
execute<T extends object>(
  table: string,
  state: QueryState,
): Promise<Result<Row<T>[]>>;
```

### channel


```ts
channel(name: string, options?: ChannelOptions): NostrbaseChannel<DB>;
```

### removeChannel


```ts
removeChannel(channel: NostrbaseChannel<DB>): Promise<void>;
```

### removeAllChannels


```ts
removeAllChannels(): Promise<void>;
```

### trackEventSubscription


```ts
trackEventSubscription(dispose: () => void): () => void;
```

### close


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

### closeAsync


```ts
closeAsync(): Promise<void>;
```

### [Symbol.dispose]


```ts
[Symbol.dispose](): void;
```

## createClient


```ts
declare function createClient<DB extends SchemaShape<DB> = DefaultSchema>(
  options: ClientOptions<DB>,
): NostrbaseClient<DB>;
```
