"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Transaction_exports = {};
__export(Transaction_exports, {
  Transaction: () => Transaction
});
module.exports = __toCommonJS(Transaction_exports);
var import_Resource = require("./Resource.js");
var import_Status = require("./Status.js");
var import_Tx = require("./Tx.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
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 = (0, import_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 (0, import_Tx.open)(via, lifetime, isolation);
  },
  Status: import_Status.Status,
  Resource: import_Resource.Resource,
  [Symbol.toStringTag]: "Transaction"
};
Transaction.open = import_Tx.open;
//# sourceMappingURL=Transaction.js.map
