import { TransactionReq, TransactionRes, TransactionResPart, TransactionType as TransactionTypeProto } from "typedb-protocol/proto/transaction"; import { Stream } from "../../common/util/Stream"; import { ConceptManager } from "../concept/ConceptManager"; import { LogicManager } from "../logic/LogicManager"; import { QueryManager } from "../query/QueryManager"; import { TypeDBOptions } from "./TypeDBOptions"; export interface TypeDBTransaction { /** * Checks whether this transaction is open. * * ### Examples * * ```ts * transaction.isOpen() * ``` */ isOpen(): boolean; /** The transaction’s type (READ or WRITE) */ readonly type: TransactionType; /** The options for the transaction. */ readonly options: TypeDBOptions; /** The ConceptManager for this transaction, providing access to all Concept API methods. */ readonly concepts: ConceptManager; /** The LogicManager for this Transaction, providing access to all Concept API - Logic methods. */ readonly logic: LogicManager; /** TheQueryManager for this Transaction, from which any TypeQL query can be executed. */ readonly query: QueryManager; /** * Registers a callback function which will be executed when this transaction is closed. * * ### Examples * * ```ts * transaction.onClose(function); * ``` * * @param callback The callback function. */ onClose(callback: (error?: Error | string) => Promise): void; /** * Commits the changes made via this transaction to the TypeDB database. Whether or not the transaction is commited successfully, it gets closed after the commit call. * * ### Examples * * ```ts * transaction.commit() * ``` */ commit(): Promise; /** * Rolls back the uncommitted changes made via this transaction. * * ### Examples * * ```ts * transaction.rollback() * ``` */ rollback(): Promise; /** * Closes the transaction. * * ### Examples * * ```ts * transaction.close() * ``` */ close(): Promise; } /** * This class is used to specify the type of transaction. * * ### Examples * * ```ts * session.transaction(TransactionType.READ) * ``` */ export interface TransactionType { proto(): TransactionTypeProto; /** Checks whether this is the READ TransactionType */ isRead(): boolean; /** Checks whether this is the WRITE TransactionType */ isWrite(): boolean; } export declare namespace TransactionType { class TransactionTypeImpl implements TransactionType { private readonly _type; constructor(type: TransactionTypeProto); proto(): TransactionTypeProto; isRead(): boolean; isWrite(): boolean; } /** Constant used to specify a READ transaction must be created */ export const READ: TransactionTypeImpl; /** Constant used to specify a WRITE transaction must be created */ export const WRITE: TransactionTypeImpl; export {}; } /** @ignore */ export declare namespace TypeDBTransaction { interface Extended extends TypeDBTransaction { rpcExecute(request: TransactionReq, batch?: boolean): Promise; rpcStream(request: TransactionReq): Stream; } }