1- import type { MongoServerEvents , MongoServerOptions } from './mongoserver' ;
1+ import type {
2+ MongoServerEvents ,
3+ MongoServerOptions ,
4+ SerializedServerProperties ,
5+ } from './mongoserver' ;
26import { MongoServer } from './mongoserver' ;
37import { ConnectionString } from 'mongodb-connection-string-url' ;
48import type { DownloadOptions } from '@mongodb-js/mongodb-downloader' ;
@@ -162,6 +166,17 @@ export type MongoClusterEvents = {
162166 removeListener : [ keyof MongoClusterEvents ] ;
163167} ;
164168
169+ export interface SerializedClusterProperties {
170+ topology : MongoClusterOptions [ 'topology' ] ;
171+ replSetName ?: string ;
172+ servers : SerializedServerProperties [ ] ;
173+ shards : SerializedClusterProperties [ ] ;
174+ oidcMockProviderProcess ?: ReturnType < OIDCMockProviderProcess [ 'serialize' ] > ;
175+ defaultConnectionOptions : Partial < MongoClientOptions > ;
176+ users : MongoDBUserDoc [ ] ;
177+ options ?: MongoClusterOptions ;
178+ }
179+
165180function removePortArg ( [ ...args ] : string [ ] ) : string [ ] {
166181 let portArgIndex = - 1 ;
167182 if ( ( portArgIndex = args . indexOf ( '--port' ) ) !== - 1 ) {
@@ -278,6 +293,7 @@ export class MongoCluster extends EventEmitter<MongoClusterEvents> {
278293 private oidcMockProviderProcess ?: OIDCMockProviderProcess ;
279294 private defaultConnectionOptions : Partial < MongoClientOptions > = { } ;
280295 private users : MongoDBUserDoc [ ] = [ ] ;
296+ private originalOptions ?: MongoClusterOptions ;
281297
282298 private constructor ( ) {
283299 super ( ) ;
@@ -309,7 +325,7 @@ export class MongoCluster extends EventEmitter<MongoClusterEvents> {
309325 } ) ;
310326 }
311327
312- serialize ( ) : unknown /* JSON-serializable */ {
328+ serialize ( ) : SerializedClusterProperties {
313329 return {
314330 topology : this . topology ,
315331 replSetName : this . replSetName ,
@@ -318,6 +334,7 @@ export class MongoCluster extends EventEmitter<MongoClusterEvents> {
318334 oidcMockProviderProcess : this . oidcMockProviderProcess ?. serialize ( ) ,
319335 defaultConnectionOptions : jsonClone ( this . defaultConnectionOptions ?? { } ) ,
320336 users : jsonClone ( this . users ) ,
337+ options : jsonClone ( this . originalOptions ) ,
321338 } ;
322339 }
323340
@@ -328,7 +345,9 @@ export class MongoCluster extends EventEmitter<MongoClusterEvents> {
328345 return true ;
329346 }
330347
331- static async deserialize ( serialized : any ) : Promise < MongoCluster > {
348+ static async deserialize (
349+ serialized : SerializedClusterProperties ,
350+ ) : Promise < MongoCluster > {
332351 const cluster = new MongoCluster ( ) ;
333352 cluster . topology = serialized . topology ;
334353 cluster . replSetName = serialized . replSetName ;
@@ -343,6 +362,7 @@ export class MongoCluster extends EventEmitter<MongoClusterEvents> {
343362 cluster . oidcMockProviderProcess = serialized . oidcMockProviderProcess
344363 ? OIDCMockProviderProcess . deserialize ( serialized . oidcMockProviderProcess )
345364 : undefined ;
365+ cluster . originalOptions = serialized . options ;
346366 return cluster ;
347367 }
348368
@@ -380,6 +400,7 @@ export class MongoCluster extends EventEmitter<MongoClusterEvents> {
380400 options = { ...options , ...( await handleTLSClientKeyOptions ( options ) ) } ;
381401
382402 const cluster = new MongoCluster ( ) ;
403+ cluster . originalOptions = options ;
383404 cluster . topology = options . topology ;
384405 cluster . users = options . users ?? [ ] ;
385406 cluster . defaultConnectionOptions = { ...options . internalClientOptions } ;
0 commit comments