File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -575,8 +575,12 @@ export class MemoryDriver implements Driver {
575575 async beginTransaction ( ) : Promise < any > {
576576 const txId = `tx_${ Date . now ( ) } _${ Math . random ( ) . toString ( 36 ) . substring ( 7 ) } ` ;
577577
578- // Create a snapshot of the current store
579- const snapshot = new Map ( this . store ) ;
578+ // Create a deep snapshot of the current store to ensure complete transaction isolation
579+ // This prevents issues with nested objects and arrays being modified during the transaction
580+ const snapshot = new Map < string , any > ( ) ;
581+ for ( const [ key , value ] of this . store . entries ( ) ) {
582+ snapshot . set ( key , JSON . parse ( JSON . stringify ( value ) ) ) ;
583+ }
580584
581585 const transaction : MemoryTransaction = {
582586 id : txId ,
@@ -676,9 +680,11 @@ export class MemoryDriver implements Driver {
676680 }
677681
678682 // Set up auto-save timer
683+ // Use unref() to allow Node.js process to exit gracefully when idle
679684 this . persistenceTimer = setInterval ( ( ) => {
680685 this . saveToDisk ( ) ;
681686 } , autoSaveInterval ) ;
687+ this . persistenceTimer . unref ( ) ;
682688 }
683689
684690 /**
Original file line number Diff line number Diff line change @@ -545,8 +545,10 @@ export class MongoDriver implements Driver {
545545 const result = await collection . findOneAndUpdate ( filter , update , mongoOptions ) ;
546546
547547 // Map MongoDB document to API format (convert _id to id)
548- // MongoDB's findOneAndUpdate returns { value: document } in newer versions
549- const doc = result ?. value || result ;
548+ // MongoDB driver v5+ returns { value: document, ok: number }
549+ // Older versions (v4) return the document directly
550+ // We handle both for backward compatibility
551+ const doc = result ?. value !== undefined ? result . value : result ;
550552 return doc ? this . mapFromMongo ( doc ) : null ;
551553 }
552554
You can’t perform that action at this time.
0 commit comments