@@ -24,7 +24,7 @@ export const readFile = async (): Promise<State> => {
2424
2525 // If content is empty object, write base state
2626 if ( Object . keys ( content ) . length === 0 ) {
27- await fs . writeFile ( FILE_NAME , JSON . stringify ( StateObject , null , 2 ) ) ;
27+ await fs . writeFile ( FILE_NAME , stringify ( StateObject ) ) ;
2828 return StateObject ;
2929 }
3030
@@ -42,7 +42,7 @@ export const readFile = async (): Promise<State> => {
4242
4343// create the file if it doesn't exist
4444export const createFile = async ( ) => {
45- await fs . writeFile ( FILE_NAME , JSON . stringify ( StateObject , null , 2 ) ) ;
45+ await fs . writeFile ( FILE_NAME , stringify ( StateObject ) ) ;
4646} ;
4747
4848// Type-safe field paths - dynamically derived from State type
@@ -93,7 +93,7 @@ export const updateField = async <T extends StatePaths>(
9393 state [ rootKey ] !== null
9494 ) {
9595 ( state [ rootKey ] as any ) [ nestedKey ] = value ;
96- await fs . writeFile ( FILE_NAME , JSON . stringify ( state , null , 2 ) ) ;
96+ await fs . writeFile ( FILE_NAME , stringify ( state ) ) ;
9797 } else {
9898 throw new Error ( `Invalid path: ${ path } ` ) ;
9999 }
@@ -123,7 +123,7 @@ export const getOrUpdate = async <T extends StatePaths>(
123123
124124 // Otherwise, update with default value and return it
125125 ( state as any ) [ path ] = defaultValue ;
126- await fs . writeFile ( FILE_NAME , JSON . stringify ( state , null , 2 ) ) ;
126+ await fs . writeFile ( FILE_NAME , stringify ( state ) ) ;
127127 return defaultValue ;
128128 } else {
129129 // Nested property
@@ -144,10 +144,17 @@ export const getOrUpdate = async <T extends StatePaths>(
144144
145145 // Otherwise, update with default value and return it
146146 ( state [ rootKey ] as any ) [ nestedKey ] = defaultValue ;
147- await fs . writeFile ( FILE_NAME , JSON . stringify ( state , null , 2 ) ) ;
147+ await fs . writeFile ( FILE_NAME , stringify ( state ) ) ;
148148 return defaultValue ;
149149 } else {
150150 throw new Error ( `Invalid path: ${ path } ` ) ;
151151 }
152152 }
153153} ;
154+
155+ const stringify = ( value : unknown ) =>
156+ JSON . stringify (
157+ value ,
158+ ( _ , val ) => ( typeof val === 'bigint' ? val . toString ( ) : val ) ,
159+ 2
160+ ) ;
0 commit comments