* Names the current transaction or selects an existing named transaction. * * If a transaction with the given name already exists, it becomes the selected transaction and its details are loaded into the working context. If not, the current working transaction is assigned the provided name and
({ transactionName }: NameParams)
| 960 | * - If a new name is provided, the current working transaction is saved under that name. |
| 961 | */ |
| 962 | name({ transactionName }: NameParams): INamedTransaction { |
| 963 | if (typeof transactionName !== 'string' || transactionName.trim() === '') { |
| 964 | this.throwError( |
| 965 | 'name(): transactionName is required and must be a non-empty string.' |
| 966 | ); |
| 967 | } |
| 968 | |
| 969 | // Check if transaction exists |
| 970 | if (this.namedTransactions[transactionName]) { |
| 971 | // Selecting existing transaction |
| 972 | this.selectedTransactionName = transactionName; |
| 973 | this.workingTransaction = { ...this.namedTransactions[transactionName] }; |
| 974 | log( |
| 975 | `name(): Selected existing transaction: ${transactionName}`, |
| 976 | undefined, |
| 977 | this.debugMode |
| 978 | ); |
| 979 | } else { |
| 980 | // Creating new transaction |
| 981 | if (!this.workingTransaction) { |
| 982 | this.throwError( |
| 983 | 'name(): No transaction data to name. Call transaction() first.' |
| 984 | ); |
| 985 | } |
| 986 | this.selectedTransactionName = transactionName; |
| 987 | this.workingTransaction.transactionName = transactionName; |
| 988 | this.namedTransactions[transactionName] = { ...this.workingTransaction }; |
| 989 | log( |
| 990 | `name(): Named new transaction: ${transactionName}`, |
| 991 | undefined, |
| 992 | this.debugMode |
| 993 | ); |
| 994 | } |
| 995 | |
| 996 | return this as INamedTransaction; |
| 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * Selects a batch by name for subsequent batch operations. |