/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Resource } from "./Resource.js";
import { Status } from "./Status.js";
import { open } from "./Tx.js";
const Transaction = {
  /**
   * Perform a transactional operation.
   *
   * This creates a read/write transaction scoped to the life of an optionally async function call.
   *
   * The transaction will commit automatically if it is exclusive (write mode) after the actor returns.
   *
   * The transaction is destroyed when {@link act} returns.  You will receive an error if you access it after it is
   * destroyed.
   */
  act(via, lifetime, actor) {
    const tx = open(via, lifetime);
    let result;
    try {
      result = actor(tx);
    } catch (e) {
      return tx.reject(e);
    }
    return tx.resolve(result);
  },
  /**
   * Create a transaction.
   *
   * Transactions must be closed using {@link Finalization#resolve} or {@link Finalization#reject}.
   *
   * When closed the transaction commits automatically if exclusive.
   */
  open(via, lifetime, isolation = "rw") {
    return open(via, lifetime, isolation);
  },
  Status,
  Resource,
  [Symbol.toStringTag]: "Transaction"
};
Transaction.open = open;
export {
  Transaction
};
//# sourceMappingURL=Transaction.js.map
