import { SessionType as SessionTypeProto } from "typedb-protocol/proto/session"; import { Database } from "./database/Database"; import { TypeDBOptions } from "./TypeDBOptions"; import { TransactionType, TypeDBTransaction } from "./TypeDBTransaction"; export interface TypeDBSession { /** * Checks whether this session is open. * * ### Examples * * ```ts * session.isOpen() * ``` */ isOpen(): boolean; /** The current session’s type (SCHEMA or DATA) */ readonly type: SessionType; /** * The database of the session. * * ### Examples * * ```ts * session.database() * ``` */ readonly database: Database; /** Gets the options for the session */ readonly options: TypeDBOptions; /** * Opens a transaction to perform read or write queries on the database connected to the session. * * ### Examples * * ```ts * session.transaction(transactionType, options) * ``` * * @param transactionType - The type of transaction to be created (READ or WRITE) * @param options - Options for the session */ transaction(type: TransactionType, options?: TypeDBOptions): Promise; /** * Registers a callback function which will be executed when this session is closed. * * ### Examples * * ```ts * session.onClose(function) * ``` * * @param callback The callback function. */ onClose(callback: () => Promise): void; /** * Registers a callback function which will be executed when this session is reopened. * A session may be closed if it times out, or loses the connection to the database. * In such situations, the session is reopened automatically when opening a new transaction. * * ### Examples * * ```ts * session.onReopen(function) * ``` * * @param callback The callback function. */ onReopen(callback: () => Promise): void; /** * Closes the session. Before opening a new session, the session currently open should first be closed. * * ### Examples * * ```ts * session.close() * ``` */ close(): Promise; } export interface SessionType { proto(): SessionTypeProto; isData(): boolean; isSchema(): boolean; } /** * This class is used to specify the type of the session. * * ### Examples * * ```ts * driver.session(database, SessionType.SCHEMA) * ``` */ export declare namespace SessionType { class SessionTypeImpl implements SessionType { private readonly _type; constructor(type: SessionTypeProto); proto(): SessionTypeProto; isData(): boolean; isSchema(): boolean; } /** Constant used to specify a DATA session must be created */ export const DATA: SessionTypeImpl; /** Constant used to specify a SCHEMA session must be created */ export const SCHEMA: SessionTypeImpl; export {}; }