UNPKG

@tai-kun/surrealdb

Version:

The SurrealDB SDK for JavaScript

77 lines 3.65 kB
import { type ConnectionInfo, type ConnectionState, type EngineAbc, type EngineAbcConfig, type EngineEventMap, type ProcessEndpointOptions } from "@tai-kun/surrealdb/engine"; import type { Formatter } from "@tai-kun/surrealdb/formatter"; import type { RpcMethod, RpcParams, RpcResult } from "@tai-kun/surrealdb/types"; import { type StatefulPromise, TaskEmitter, type TaskListener, type TaskListenerOptions } from "@tai-kun/surrealdb/utils"; export type CreateEngine = (config: EngineAbcConfig) => EngineAbc | PromiseLike<EngineAbc>; export type ClientEngines = { readonly [_ in string]?: CreateEngine | string | undefined; }; export interface ClientConfig { readonly engines: ClientEngines; readonly formatter: Formatter; readonly disableDefaultErrorHandler?: boolean | undefined; } export interface ClientConnectOptions extends ProcessEndpointOptions { readonly signal?: AbortSignal | undefined; } export interface ClientCloseOptions { readonly force?: boolean | undefined; readonly signal?: AbortSignal | undefined; } export interface ClientRpcOptions { readonly signal?: AbortSignal | undefined; } export default class BasicClient { protected readonly ee: TaskEmitter<EngineEventMap>; protected readonly fmt: Formatter; protected eng: EngineAbc | null; private readonly _engines; constructor(config: ClientConfig); protected createEngine(scheme: string): Promise<EngineAbc>; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#state) */ get state(): ConnectionState; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#endpoint) */ get endpoint(): URL | null | undefined; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#namespace) */ get namespace(): string | null | undefined; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#database) */ get database(): string | null | undefined; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#token) */ get token(): string | null | undefined; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#getconnectioninfo) */ getConnectionInfo(): ConnectionInfo | undefined; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#on) */ on<TEvent extends keyof EngineEventMap>(event: TEvent, listener: TaskListener<EngineEventMap[TEvent]>): void; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#off) */ off<TEvent extends keyof EngineEventMap>(event: TEvent, listener: TaskListener<EngineEventMap[TEvent]>): void; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#once) */ once<TEvent extends keyof EngineEventMap>(event: TEvent, options?: TaskListenerOptions | undefined): StatefulPromise<EngineEventMap[TEvent]>; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#connect) */ connect(endpoint: string | URL, options?: ClientConnectOptions | undefined): Promise<void>; /** * [API Reference](https://tai-kun.github.io/surrealdb.js/v2/guides/connecting/#close) */ close(options?: ClientCloseOptions | undefined): Promise<void>; rpc<TMethod extends RpcMethod, TResult extends RpcResult<TMethod>>(method: TMethod, params: RpcParams<TMethod>, options?: ClientRpcOptions | undefined): Promise<TResult>; } //# sourceMappingURL=client.d.ts.map