@@ -333,15 +333,17 @@ export const make = Effect.gen(function* BrowserSessionMake() {
333333
334334 const certificateTrust = new WeakMap < Session , CertificateTrust > ( ) ;
335335 const writeCertificateApprovals = yield * Semaphore . make ( 1 ) ;
336- const loadCertificateTrust = ( browserSession : Session ) => {
336+ const loadCertificateTrust = Effect . fn ( "BrowserSession.loadCertificateTrust" ) ( function * (
337+ browserSession : Session ,
338+ ) {
337339 const file =
338340 browserSession . storagePath == null
339341 ? null
340342 : path . join ( browserSession . storagePath , CERTIFICATE_APPROVALS_FILE ) ;
341- return (
343+ const approvals : ReadonlyArray < CertificateApproval > =
342344 file === null
343- ? Effect . succeed ( [ ] )
344- : fileSystem . readFileString ( file ) . pipe (
345+ ? [ ]
346+ : yield * fileSystem . readFileString ( file ) . pipe (
345347 Effect . flatMap ( decodeCertificateApprovals ) ,
346348 Effect . catchTags ( {
347349 PlatformError : ( error ) =>
@@ -352,60 +354,54 @@ export const make = Effect.gen(function* BrowserSessionMake() {
352354 Effect . as ( [ ] ) ,
353355 ) ,
354356 ) ,
355- )
356- ) . pipe (
357- Effect . map ( ( approvals ) : CertificateTrust => ( {
358- file,
359- approvals : new Map (
360- approvals . map ( ( approval ) => [ certificateApprovalKey ( approval ) , approval ] ) ,
361- ) ,
362- revocations : 0 ,
363- } ) ) ,
364- ) ;
365- } ;
366- const writeApprovalsFile = ( file : string , approvals : ReadonlyMap < string , CertificateApproval > ) =>
367- approvals . size === 0
368- ? fileSystem . remove ( file , { force : true } )
369- : Effect . gen ( function * ( ) {
370- yield * fileSystem . makeDirectory ( path . dirname ( file ) , { recursive : true } ) ;
371- yield * fileSystem . writeFileString (
372- file ,
373- yield * encodeCertificateApprovals ( [ ...approvals . values ( ) ] ) ,
374357 ) ;
375- } ) ;
358+ const trust : CertificateTrust = {
359+ file,
360+ approvals : new Map ( approvals . map ( ( approval ) => [ certificateApprovalKey ( approval ) , approval ] ) ) ,
361+ revocations : 0 ,
362+ } ;
363+ return trust ;
364+ } ) ;
365+ const writeApprovalsFile = Effect . fn ( "BrowserSession.writeApprovalsFile" ) ( function * (
366+ file : string ,
367+ approvals : ReadonlyMap < string , CertificateApproval > ,
368+ ) {
369+ if ( approvals . size === 0 ) return yield * fileSystem . remove ( file , { force : true } ) ;
370+ yield * fileSystem . makeDirectory ( path . dirname ( file ) , { recursive : true } ) ;
371+ yield * fileSystem . writeFileString (
372+ file ,
373+ yield * encodeCertificateApprovals ( [ ...approvals . values ( ) ] ) ,
374+ ) ;
375+ } ) ;
376376 /**
377377 * Saved before it is trusted, so a failed write cannot leave an approval that
378378 * silently ends at restart. Writes share one lock, so a slower write cannot
379379 * restore stale data.
380380 */
381- const rememberCertificate = (
381+ const rememberCertificate = Effect . fn ( "BrowserSession.rememberCertificate" ) ( function * (
382382 trust : CertificateTrust ,
383383 key : string ,
384384 approval : CertificateApproval ,
385385 revocations : number ,
386- ) =>
387- writeCertificateApprovals . withPermits ( 1 ) (
388- Effect . gen ( function * ( ) {
389- if ( trust . revocations !== revocations ) return false ;
390- if ( trust . file !== null ) {
391- yield * writeApprovalsFile ( trust . file , new Map ( trust . approvals ) . set ( key , approval ) ) ;
392- // A revocation during the write queues its own rewrite behind this one.
393- if ( trust . revocations !== revocations ) return false ;
394- }
395- trust . approvals . set ( key , approval ) ;
396- return true ;
397- } ) ,
398- ) ;
386+ ) {
387+ if ( trust . revocations !== revocations ) return false ;
388+ if ( trust . file !== null ) {
389+ yield * writeApprovalsFile ( trust . file , new Map ( trust . approvals ) . set ( key , approval ) ) ;
390+ // A revocation during the write queues its own rewrite behind this one.
391+ if ( trust . revocations !== revocations ) return false ;
392+ }
393+ trust . approvals . set ( key , approval ) ;
394+ return true ;
395+ } , writeCertificateApprovals . withPermits ( 1 ) ) ;
399396 /**
400397 * Rewrites the file from memory. Clearing cookies runs this even when memory
401398 * is already empty, so retrying after a failed removal still deletes the file.
402399 */
403- const saveCertificateApprovals = ( trust : CertificateTrust ) =>
404- writeCertificateApprovals . withPermits ( 1 ) (
405- Effect . suspend ( ( ) =>
406- trust . file === null ? Effect . void : writeApprovalsFile ( trust . file , trust . approvals ) ,
407- ) ,
408- ) ;
400+ const saveCertificateApprovals = Effect . fn ( "BrowserSession.saveCertificateApprovals" ) ( function * (
401+ trust : CertificateTrust ,
402+ ) {
403+ if ( trust . file !== null ) yield * writeApprovalsFile ( trust . file , trust . approvals ) ;
404+ } , writeCertificateApprovals . withPermits ( 1 ) ) ;
409405
410406 // One prompt at a time; tabs that hit the same certificate wait on it.
411407 let certificatePrompt : {
0 commit comments