tero 0.0.0 â 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -24
- package/dist/acid-engine.d.ts +63 -0
- package/dist/acid-engine.js +76 -10
- package/dist/backup.d.ts +66 -0
- package/dist/backup.js +75 -22
- package/dist/index.d.ts +115 -0
- package/dist/index.js +55 -24
- package/dist/recovery.d.ts +46 -0
- package/dist/schema.d.ts +61 -0
- package/package.json +14 -11
- package/dist/fn.js +0 -192
- package/dist/transaction.js +0 -476
package/dist/transaction.js
DELETED
|
@@ -1,476 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync } from "fs";
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
import { randomUUID } from "crypto";
|
|
4
|
-
export class Transaction {
|
|
5
|
-
state;
|
|
6
|
-
config;
|
|
7
|
-
lockFiles = new Set();
|
|
8
|
-
timeoutHandle;
|
|
9
|
-
transactionDir;
|
|
10
|
-
committed = false;
|
|
11
|
-
rolledBack = false;
|
|
12
|
-
constructor(dbPath, config = {}) {
|
|
13
|
-
this.state = {
|
|
14
|
-
id: randomUUID(),
|
|
15
|
-
operations: [],
|
|
16
|
-
status: 'active',
|
|
17
|
-
startTime: Date.now(),
|
|
18
|
-
dbPath
|
|
19
|
-
};
|
|
20
|
-
this.config = {
|
|
21
|
-
timeout: config.timeout || 30000, // 30 seconds default
|
|
22
|
-
isolationLevel: config.isolationLevel || 'read_committed',
|
|
23
|
-
autoCommit: config.autoCommit || false
|
|
24
|
-
};
|
|
25
|
-
this.transactionDir = join(dbPath, '.transactions');
|
|
26
|
-
this.initializeTransaction();
|
|
27
|
-
}
|
|
28
|
-
initializeTransaction() {
|
|
29
|
-
try {
|
|
30
|
-
// Create transactions directory if it doesn't exist
|
|
31
|
-
if (!existsSync(this.transactionDir)) {
|
|
32
|
-
mkdirSync(this.transactionDir, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
// Set up transaction timeout
|
|
35
|
-
if (this.config.timeout && this.config.timeout > 0) {
|
|
36
|
-
this.timeoutHandle = setTimeout(() => {
|
|
37
|
-
this.handleTimeout();
|
|
38
|
-
}, this.config.timeout);
|
|
39
|
-
}
|
|
40
|
-
// Save initial transaction state
|
|
41
|
-
this.saveTransactionState();
|
|
42
|
-
console.log(`đ Transaction ${this.state.id} started`);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
throw new Error(`Failed to initialize transaction: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async handleTimeout() {
|
|
49
|
-
console.warn(`â° Transaction ${this.state.id} timed out after ${this.config.timeout}ms`);
|
|
50
|
-
try {
|
|
51
|
-
await this.rollback();
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
console.error(`Failed to rollback timed out transaction: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
saveTransactionState() {
|
|
58
|
-
try {
|
|
59
|
-
const statePath = join(this.transactionDir, `${this.state.id}.json`);
|
|
60
|
-
writeFileSync(statePath, JSON.stringify(this.state, null, 2));
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
console.warn(`Failed to save transaction state: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
validateKey(key) {
|
|
67
|
-
if (!key || typeof key !== 'string') {
|
|
68
|
-
throw new Error('Key must be a non-empty string');
|
|
69
|
-
}
|
|
70
|
-
if (key.includes('..') || key.includes('/') || key.includes('\\')) {
|
|
71
|
-
throw new Error('Key contains invalid characters');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
getFilePath(key) {
|
|
75
|
-
return join(this.state.dbPath, `${key}.json`);
|
|
76
|
-
}
|
|
77
|
-
getLockFilePath(key) {
|
|
78
|
-
return join(this.transactionDir, `${key}.lock`);
|
|
79
|
-
}
|
|
80
|
-
acquireLock(key) {
|
|
81
|
-
try {
|
|
82
|
-
const lockPath = this.getLockFilePath(key);
|
|
83
|
-
// Check if already locked by another transaction
|
|
84
|
-
if (existsSync(lockPath)) {
|
|
85
|
-
const lockData = JSON.parse(readFileSync(lockPath, 'utf-8'));
|
|
86
|
-
if (lockData.transactionId !== this.state.id) {
|
|
87
|
-
return false; // Lock held by another transaction
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Acquire lock
|
|
91
|
-
const lockData = {
|
|
92
|
-
transactionId: this.state.id,
|
|
93
|
-
timestamp: Date.now(),
|
|
94
|
-
key
|
|
95
|
-
};
|
|
96
|
-
writeFileSync(lockPath, JSON.stringify(lockData));
|
|
97
|
-
this.lockFiles.add(key);
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
releaseLock(key) {
|
|
105
|
-
try {
|
|
106
|
-
const lockPath = this.getLockFilePath(key);
|
|
107
|
-
if (existsSync(lockPath)) {
|
|
108
|
-
unlinkSync(lockPath);
|
|
109
|
-
}
|
|
110
|
-
this.lockFiles.delete(key);
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
console.warn(`Failed to release lock for key '${key}': ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
releaseAllLocks() {
|
|
117
|
-
for (const key of this.lockFiles) {
|
|
118
|
-
this.releaseLock(key);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
readCurrentData(key) {
|
|
122
|
-
try {
|
|
123
|
-
const filePath = this.getFilePath(key);
|
|
124
|
-
if (!existsSync(filePath)) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
const content = readFileSync(filePath, 'utf-8');
|
|
128
|
-
return content.trim() ? JSON.parse(content) : {};
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
ensureNotFinalized() {
|
|
135
|
-
if (this.committed) {
|
|
136
|
-
throw new Error('Transaction has already been committed');
|
|
137
|
-
}
|
|
138
|
-
if (this.rolledBack) {
|
|
139
|
-
throw new Error('Transaction has already been rolled back');
|
|
140
|
-
}
|
|
141
|
-
if (this.state.status !== 'active') {
|
|
142
|
-
throw new Error(`Transaction is not active (status: ${this.state.status})`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async create(key) {
|
|
146
|
-
try {
|
|
147
|
-
this.ensureNotFinalized();
|
|
148
|
-
this.validateKey(key);
|
|
149
|
-
// Acquire lock
|
|
150
|
-
if (!this.acquireLock(key)) {
|
|
151
|
-
throw new Error(`Cannot acquire lock for key '${key}' - may be locked by another transaction`);
|
|
152
|
-
}
|
|
153
|
-
// Check if file already exists
|
|
154
|
-
const filePath = this.getFilePath(key);
|
|
155
|
-
if (existsSync(filePath)) {
|
|
156
|
-
throw new Error(`Document '${key}' already exists`);
|
|
157
|
-
}
|
|
158
|
-
// Record operation
|
|
159
|
-
const operation = {
|
|
160
|
-
type: 'create',
|
|
161
|
-
key,
|
|
162
|
-
data: {},
|
|
163
|
-
timestamp: Date.now()
|
|
164
|
-
};
|
|
165
|
-
this.state.operations.push(operation);
|
|
166
|
-
this.saveTransactionState();
|
|
167
|
-
console.log(`đ Transaction ${this.state.id}: Queued create operation for '${key}'`);
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
throw new Error(`Transaction create failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async update(key, data) {
|
|
174
|
-
try {
|
|
175
|
-
this.ensureNotFinalized();
|
|
176
|
-
this.validateKey(key);
|
|
177
|
-
if (data === undefined || data === null) {
|
|
178
|
-
throw new Error('Data cannot be null or undefined');
|
|
179
|
-
}
|
|
180
|
-
// Acquire lock
|
|
181
|
-
if (!this.acquireLock(key)) {
|
|
182
|
-
throw new Error(`Cannot acquire lock for key '${key}' - may be locked by another transaction`);
|
|
183
|
-
}
|
|
184
|
-
// Read current data for rollback
|
|
185
|
-
const originalData = this.readCurrentData(key);
|
|
186
|
-
// Record operation
|
|
187
|
-
const operation = {
|
|
188
|
-
type: 'update',
|
|
189
|
-
key,
|
|
190
|
-
data,
|
|
191
|
-
originalData,
|
|
192
|
-
timestamp: Date.now()
|
|
193
|
-
};
|
|
194
|
-
this.state.operations.push(operation);
|
|
195
|
-
this.saveTransactionState();
|
|
196
|
-
console.log(`âī¸ Transaction ${this.state.id}: Queued update operation for '${key}'`);
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
throw new Error(`Transaction update failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async delete(key) {
|
|
203
|
-
try {
|
|
204
|
-
this.ensureNotFinalized();
|
|
205
|
-
this.validateKey(key);
|
|
206
|
-
// Acquire lock
|
|
207
|
-
if (!this.acquireLock(key)) {
|
|
208
|
-
throw new Error(`Cannot acquire lock for key '${key}' - may be locked by another transaction`);
|
|
209
|
-
}
|
|
210
|
-
// Read current data for rollback
|
|
211
|
-
const originalData = this.readCurrentData(key);
|
|
212
|
-
if (originalData === null) {
|
|
213
|
-
throw new Error(`Document '${key}' does not exist`);
|
|
214
|
-
}
|
|
215
|
-
// Record operation
|
|
216
|
-
const operation = {
|
|
217
|
-
type: 'delete',
|
|
218
|
-
key,
|
|
219
|
-
originalData,
|
|
220
|
-
timestamp: Date.now()
|
|
221
|
-
};
|
|
222
|
-
this.state.operations.push(operation);
|
|
223
|
-
this.saveTransactionState();
|
|
224
|
-
console.log(`đī¸ Transaction ${this.state.id}: Queued delete operation for '${key}'`);
|
|
225
|
-
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
throw new Error(`Transaction delete failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
async get(key) {
|
|
231
|
-
try {
|
|
232
|
-
this.ensureNotFinalized();
|
|
233
|
-
this.validateKey(key);
|
|
234
|
-
// Check if there's a pending operation for this key in the transaction
|
|
235
|
-
const pendingOps = this.state.operations.filter(op => op.key === key);
|
|
236
|
-
if (pendingOps.length > 0) {
|
|
237
|
-
const lastOp = pendingOps[pendingOps.length - 1];
|
|
238
|
-
switch (lastOp.type) {
|
|
239
|
-
case 'create':
|
|
240
|
-
return lastOp.data || {};
|
|
241
|
-
case 'update':
|
|
242
|
-
// Merge original data with updates
|
|
243
|
-
const original = lastOp.originalData || {};
|
|
244
|
-
return { ...original, ...lastOp.data };
|
|
245
|
-
case 'delete':
|
|
246
|
-
return null; // Document will be deleted
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
// Read from disk (current committed state)
|
|
250
|
-
return this.readCurrentData(key);
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
throw new Error(`Transaction get failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
async commit() {
|
|
257
|
-
try {
|
|
258
|
-
this.ensureNotFinalized();
|
|
259
|
-
if (this.timeoutHandle) {
|
|
260
|
-
clearTimeout(this.timeoutHandle);
|
|
261
|
-
}
|
|
262
|
-
console.log(`đž Committing transaction ${this.state.id} with ${this.state.operations.length} operations...`);
|
|
263
|
-
// Apply all operations atomically
|
|
264
|
-
const appliedOperations = [];
|
|
265
|
-
try {
|
|
266
|
-
for (const operation of this.state.operations) {
|
|
267
|
-
const filePath = this.getFilePath(operation.key);
|
|
268
|
-
switch (operation.type) {
|
|
269
|
-
case 'create':
|
|
270
|
-
writeFileSync(filePath, JSON.stringify(operation.data || {}, null, 2));
|
|
271
|
-
appliedOperations.push(`create:${operation.key}`);
|
|
272
|
-
break;
|
|
273
|
-
case 'update':
|
|
274
|
-
// Use the original data that was captured when the operation was queued
|
|
275
|
-
const baseData = operation.originalData || {};
|
|
276
|
-
const updatedData = { ...baseData, ...operation.data };
|
|
277
|
-
writeFileSync(filePath, JSON.stringify(updatedData, null, 2));
|
|
278
|
-
appliedOperations.push(`update:${operation.key}`);
|
|
279
|
-
break;
|
|
280
|
-
case 'delete':
|
|
281
|
-
if (existsSync(filePath)) {
|
|
282
|
-
unlinkSync(filePath);
|
|
283
|
-
}
|
|
284
|
-
appliedOperations.push(`delete:${operation.key}`);
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
// Mark as committed
|
|
289
|
-
this.state.status = 'committed';
|
|
290
|
-
this.state.endTime = Date.now();
|
|
291
|
-
this.committed = true;
|
|
292
|
-
this.saveTransactionState();
|
|
293
|
-
this.releaseAllLocks();
|
|
294
|
-
const duration = this.state.endTime - this.state.startTime;
|
|
295
|
-
console.log(`â
Transaction ${this.state.id} committed successfully in ${duration}ms`);
|
|
296
|
-
}
|
|
297
|
-
catch (error) {
|
|
298
|
-
// Rollback applied operations
|
|
299
|
-
console.error(`â Error during commit, rolling back applied operations...`);
|
|
300
|
-
await this.rollbackAppliedOperations(appliedOperations);
|
|
301
|
-
throw error;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
catch (error) {
|
|
305
|
-
this.state.status = 'failed';
|
|
306
|
-
this.state.endTime = Date.now();
|
|
307
|
-
this.saveTransactionState();
|
|
308
|
-
this.releaseAllLocks();
|
|
309
|
-
throw new Error(`Transaction commit failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
async rollbackAppliedOperations(appliedOperations) {
|
|
313
|
-
for (const opString of appliedOperations.reverse()) {
|
|
314
|
-
try {
|
|
315
|
-
const [type, key] = opString.split(':');
|
|
316
|
-
const operation = this.state.operations.find(op => op.key === key && op.type === type);
|
|
317
|
-
if (!operation)
|
|
318
|
-
continue;
|
|
319
|
-
const filePath = this.getFilePath(key);
|
|
320
|
-
switch (type) {
|
|
321
|
-
case 'create':
|
|
322
|
-
if (existsSync(filePath)) {
|
|
323
|
-
unlinkSync(filePath);
|
|
324
|
-
}
|
|
325
|
-
break;
|
|
326
|
-
case 'update':
|
|
327
|
-
if (operation.originalData !== null) {
|
|
328
|
-
writeFileSync(filePath, JSON.stringify(operation.originalData, null, 2));
|
|
329
|
-
}
|
|
330
|
-
else if (existsSync(filePath)) {
|
|
331
|
-
unlinkSync(filePath);
|
|
332
|
-
}
|
|
333
|
-
break;
|
|
334
|
-
case 'delete':
|
|
335
|
-
if (operation.originalData) {
|
|
336
|
-
writeFileSync(filePath, JSON.stringify(operation.originalData, null, 2));
|
|
337
|
-
}
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
catch (error) {
|
|
342
|
-
console.warn(`Failed to rollback operation ${opString}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
async rollback() {
|
|
347
|
-
try {
|
|
348
|
-
if (this.committed) {
|
|
349
|
-
throw new Error('Cannot rollback a committed transaction');
|
|
350
|
-
}
|
|
351
|
-
if (this.timeoutHandle) {
|
|
352
|
-
clearTimeout(this.timeoutHandle);
|
|
353
|
-
}
|
|
354
|
-
console.log(`đ Rolling back transaction ${this.state.id}...`);
|
|
355
|
-
this.state.status = 'rolled_back';
|
|
356
|
-
this.state.endTime = Date.now();
|
|
357
|
-
this.rolledBack = true;
|
|
358
|
-
this.saveTransactionState();
|
|
359
|
-
this.releaseAllLocks();
|
|
360
|
-
const duration = this.state.endTime - this.state.startTime;
|
|
361
|
-
console.log(`âŠī¸ Transaction ${this.state.id} rolled back in ${duration}ms`);
|
|
362
|
-
}
|
|
363
|
-
catch (error) {
|
|
364
|
-
this.state.status = 'failed';
|
|
365
|
-
this.state.endTime = Date.now();
|
|
366
|
-
this.saveTransactionState();
|
|
367
|
-
this.releaseAllLocks();
|
|
368
|
-
throw new Error(`Transaction rollback failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
getState() {
|
|
372
|
-
return { ...this.state };
|
|
373
|
-
}
|
|
374
|
-
getId() {
|
|
375
|
-
return this.state.id;
|
|
376
|
-
}
|
|
377
|
-
getOperationCount() {
|
|
378
|
-
return this.state.operations.length;
|
|
379
|
-
}
|
|
380
|
-
isActive() {
|
|
381
|
-
return this.state.status === 'active' && !this.committed && !this.rolledBack;
|
|
382
|
-
}
|
|
383
|
-
isCommitted() {
|
|
384
|
-
return this.committed;
|
|
385
|
-
}
|
|
386
|
-
isRolledBack() {
|
|
387
|
-
return this.rolledBack;
|
|
388
|
-
}
|
|
389
|
-
getDuration() {
|
|
390
|
-
const endTime = this.state.endTime || Date.now();
|
|
391
|
-
return endTime - this.state.startTime;
|
|
392
|
-
}
|
|
393
|
-
// Cleanup method
|
|
394
|
-
destroy() {
|
|
395
|
-
if (this.timeoutHandle) {
|
|
396
|
-
clearTimeout(this.timeoutHandle);
|
|
397
|
-
}
|
|
398
|
-
if (this.isActive()) {
|
|
399
|
-
console.warn(`â ī¸ Destroying active transaction ${this.state.id}, performing rollback...`);
|
|
400
|
-
this.rollback().catch(error => {
|
|
401
|
-
console.error(`Failed to rollback during destroy: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
this.releaseAllLocks();
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
export class TransactionManager {
|
|
408
|
-
activeTransactions = new Map();
|
|
409
|
-
dbPath;
|
|
410
|
-
constructor(dbPath) {
|
|
411
|
-
this.dbPath = dbPath;
|
|
412
|
-
}
|
|
413
|
-
beginTransaction(config) {
|
|
414
|
-
try {
|
|
415
|
-
const transaction = new Transaction(this.dbPath, config);
|
|
416
|
-
this.activeTransactions.set(transaction.getId(), transaction);
|
|
417
|
-
console.log(`đ Started transaction ${transaction.getId()}`);
|
|
418
|
-
return transaction;
|
|
419
|
-
}
|
|
420
|
-
catch (error) {
|
|
421
|
-
throw new Error(`Failed to begin transaction: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
getTransaction(id) {
|
|
425
|
-
return this.activeTransactions.get(id);
|
|
426
|
-
}
|
|
427
|
-
getActiveTransactions() {
|
|
428
|
-
return Array.from(this.activeTransactions.values()).filter(tx => tx.isActive());
|
|
429
|
-
}
|
|
430
|
-
async commitTransaction(id) {
|
|
431
|
-
const transaction = this.activeTransactions.get(id);
|
|
432
|
-
if (!transaction) {
|
|
433
|
-
throw new Error(`Transaction ${id} not found`);
|
|
434
|
-
}
|
|
435
|
-
await transaction.commit();
|
|
436
|
-
this.activeTransactions.delete(id);
|
|
437
|
-
}
|
|
438
|
-
async rollbackTransaction(id) {
|
|
439
|
-
const transaction = this.activeTransactions.get(id);
|
|
440
|
-
if (!transaction) {
|
|
441
|
-
throw new Error(`Transaction ${id} not found`);
|
|
442
|
-
}
|
|
443
|
-
await transaction.rollback();
|
|
444
|
-
this.activeTransactions.delete(id);
|
|
445
|
-
}
|
|
446
|
-
async rollbackAllTransactions() {
|
|
447
|
-
const rollbackPromises = Array.from(this.activeTransactions.values()).map(async (tx) => {
|
|
448
|
-
try {
|
|
449
|
-
if (tx.isActive()) {
|
|
450
|
-
await tx.rollback();
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
catch (error) {
|
|
454
|
-
console.error(`Failed to rollback transaction ${tx.getId()}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
await Promise.all(rollbackPromises);
|
|
458
|
-
this.activeTransactions.clear();
|
|
459
|
-
}
|
|
460
|
-
getStats() {
|
|
461
|
-
const transactions = Array.from(this.activeTransactions.values());
|
|
462
|
-
return {
|
|
463
|
-
active: transactions.filter(tx => tx.isActive()).length,
|
|
464
|
-
total: transactions.length,
|
|
465
|
-
committed: transactions.filter(tx => tx.isCommitted()).length,
|
|
466
|
-
rolledBack: transactions.filter(tx => tx.isRolledBack()).length
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
// Cleanup method
|
|
470
|
-
destroy() {
|
|
471
|
-
console.log('đ Destroying TransactionManager, rolling back all active transactions...');
|
|
472
|
-
this.rollbackAllTransactions().catch(error => {
|
|
473
|
-
console.error(`Failed to rollback all transactions during destroy: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
}
|