UNPKG

@levo-so/client

Version:

<img alt="Levo" src="https://static.levocdn.com/png/Levo-Logo.png" width="50" height="50">

47 lines (46 loc) 1.68 kB
import { Content } from './content'; import { Membership } from './membership'; import { Notification } from './notification'; import type { ClientOptions, LevoTransaction } from './types'; declare class Levo { #private; content: Content; membership: Membership; notification: Notification; constructor(options: ClientOptions); /** * * Start a transaction and run the provided function within the transaction. * If the function throws an error, the transaction will be rolled back. * If the function completes successfully, the transaction will be committed. * * @example * * const result = await levo.withTransaction(async (transaction) => { * const document = await levo.content.findUnique('posts', '12345', { transaction }); * * const data = { * title: document.title, * content: document.content, * created_at: new Date(), * updated_at: new Date(), * _status: 'published', * comments: 0, * likes: 0 * } * * const document = await levo.content.create('posts', data, { transaction }); * * const published = await levo.content.publish('posts', document._id, { transaction }); * * return published; * }); * * @param {(transaction: LevoTransaction) => Promise<T>} fn - The function to run within the transaction. * @returns {Promise<T>} The result of the function. */ withTransaction<T>(fn: (transaction: LevoTransaction) => T): Promise<T>; } export declare const createClient: (options: ClientOptions) => Levo; export * from './error'; export * from './types';