@@ -31,6 +31,10 @@ import {
3131 buildRestoreAssessment ,
3232 collectBackupMetadata ,
3333} from "./storage/restore-assessment.js" ;
34+ import {
35+ createEmptyStorageWithRestoreMetadata ,
36+ withRestoreMetadata ,
37+ } from "./storage/restore-metadata.js" ;
3438import {
3539 describeAccountsWalSnapshot ,
3640 describeFlaggedSnapshot ,
@@ -116,11 +120,6 @@ export interface FlaggedAccountStorageV1 {
116120
117121type RestoreReason = "empty-storage" | "intentional-reset" | "missing-storage" ;
118122
119- type AccountStorageWithMetadata = AccountStorageV3 & {
120- restoreEligible ?: boolean ;
121- restoreReason ?: RestoreReason ;
122- } ;
123-
124123export type BackupMetadata = {
125124 accounts : BackupMetadataSection ;
126125 flaggedAccounts : BackupMetadataSection ;
@@ -472,32 +471,6 @@ async function cleanupStaleRotatingBackupArtifacts(
472471 }
473472}
474473
475- function createEmptyStorageWithMetadata (
476- restoreEligible : boolean ,
477- restoreReason : RestoreReason ,
478- ) : AccountStorageWithMetadata {
479- return {
480- version : 3 ,
481- accounts : [ ] ,
482- activeIndex : 0 ,
483- activeIndexByFamily : { } ,
484- restoreEligible,
485- restoreReason,
486- } ;
487- }
488-
489- function withRestoreMetadata (
490- storage : AccountStorageV3 ,
491- restoreEligible : boolean ,
492- restoreReason : RestoreReason ,
493- ) : AccountStorageWithMetadata {
494- return {
495- ...storage ,
496- restoreEligible,
497- restoreReason,
498- } ;
499- }
500-
501474async function loadFlaggedAccountsFromPath (
502475 path : string ,
503476) : Promise < FlaggedAccountStorageV1 > {
@@ -1313,7 +1286,7 @@ async function loadAccountsInternal(
13131286 }
13141287
13151288 if ( existsSync ( resetMarkerPath ) ) {
1316- return createEmptyStorageWithMetadata ( false , "intentional-reset" ) ;
1289+ return createEmptyStorageWithRestoreMetadata ( false , "intentional-reset" ) ;
13171290 }
13181291
13191292 if ( normalized && normalized . accounts . length === 0 ) {
@@ -1370,7 +1343,7 @@ async function loadAccountsInternal(
13701343 } catch ( error ) {
13711344 const code = ( error as NodeJS . ErrnoException ) . code ;
13721345 if ( existsSync ( resetMarkerPath ) ) {
1373- return createEmptyStorageWithMetadata ( false , "intentional-reset" ) ;
1346+ return createEmptyStorageWithRestoreMetadata ( false , "intentional-reset" ) ;
13741347 }
13751348 if ( code === "ENOENT" && migratedLegacyStorage ) {
13761349 return migratedLegacyStorage ;
@@ -1391,7 +1364,7 @@ async function loadAccountsInternal(
13911364 return recoveredFromWal ;
13921365 }
13931366 if ( existsSync ( resetMarkerPath ) ) {
1394- return createEmptyStorageWithMetadata ( false , "intentional-reset" ) ;
1367+ return createEmptyStorageWithRestoreMetadata ( false , "intentional-reset" ) ;
13951368 }
13961369
13971370 if ( storageBackupEnabled ) {
@@ -1439,7 +1412,7 @@ async function loadAccountsInternal(
14391412 log . error ( "Failed to load account storage" , { error : String ( error ) } ) ;
14401413 }
14411414 if ( code === "ENOENT" ) {
1442- return createEmptyStorageWithMetadata ( true , "missing-storage" ) ;
1415+ return createEmptyStorageWithRestoreMetadata ( true , "missing-storage" ) ;
14431416 }
14441417 return null ;
14451418 }
0 commit comments