@@ -15,11 +15,12 @@ import { BacktraceClientBuilder } from './builder/BacktraceClientBuilder';
1515import type { BacktraceClientSetup } from './builder/BacktraceClientSetup' ;
1616import { version } from './common/platformHelper' ;
1717import { CrashReporter } from './crashReporter/CrashReporter' ;
18+ import { assertDatabasePath } from './database/utils' ;
1819import { generateUnhandledExceptionHandler } from './handlers' ;
1920import { type ExceptionHandler } from './handlers/ExceptionHandler' ;
2021import { ReactNativeRequestHandler } from './ReactNativeRequestHandler' ;
2122import { ReactStackTraceConverter } from './ReactStackTraceConverter' ;
22- import { type FileSystem } from './storage/FileSystem ' ;
23+ import { ReactNativePathBacktraceStorageFactory , type BacktraceStorageModule } from './storage' ;
2324
2425export class BacktraceClient extends BacktraceCoreClient < BacktraceConfiguration > {
2526 private readonly _crashReporter ?: CrashReporter ;
@@ -33,7 +34,21 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
3334 return NativeModules . BacktraceDirectoryProvider ?. applicationDirectory ( ) ?? '' ;
3435 }
3536
37+ protected get databaseRnStorage ( ) {
38+ return this . databaseStorage as BacktraceStorageModule | undefined ;
39+ }
40+
3641 constructor ( clientSetup : BacktraceClientSetup ) {
42+ const storageFactory = clientSetup . storageFactory ?? new ReactNativePathBacktraceStorageFactory ( ) ;
43+ const storage =
44+ clientSetup . database ?. storage ??
45+ ( clientSetup . options . database ?. enable
46+ ? storageFactory . create ( {
47+ path : assertDatabasePath ( clientSetup . options . database ?. path ) ,
48+ createDirectory : clientSetup . options . database . createDatabaseDirectory ,
49+ } )
50+ : undefined ) ;
51+
3752 super ( {
3853 sdkOptions : {
3954 agent : '@backtrace/react-native' ,
@@ -48,14 +63,9 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
4863 ...clientSetup ,
4964 } ) ;
5065
51- const fileSystem = clientSetup . fileSystem as FileSystem ;
52- if ( ! fileSystem ) {
53- return ;
54- }
55-
5666 const breadcrumbsManager = this . modules . get ( BreadcrumbsManager ) ;
57- if ( breadcrumbsManager && this . sessionFiles ) {
58- breadcrumbsManager . setStorage ( FileBreadcrumbsStorage . factory ( this . sessionFiles , fileSystem ) ) ;
67+ if ( breadcrumbsManager && this . sessionFiles && storage ) {
68+ breadcrumbsManager . setStorage ( FileBreadcrumbsStorage . factory ( this . sessionFiles , storage ) ) ;
5969 }
6070
6171 this . attributeManager . attributeEvents . on (
@@ -137,21 +147,20 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
137147 return ;
138148 }
139149
140- const fileSystem = this . fileSystem ;
141- if ( ! fileSystem ) {
150+ const storage = this . databaseRnStorage ;
151+ if ( ! storage ) {
142152 return ;
143153 }
144154
145155 const submissionUrl = SubmissionUrlInformation . toJsonReportSubmissionUrl ( this . options . url ) ;
146156
147- const crashReporter = new CrashReporter ( fileSystem ) ;
157+ const crashReporter = new CrashReporter ( storage ) ;
148158 crashReporter . initialize (
149159 Platform . select ( {
150160 ios : SubmissionUrlInformation . toPlCrashReporterSubmissionUrl ( submissionUrl ) ,
151161 android : SubmissionUrlInformation . toMinidumpSubmissionUrl ( submissionUrl ) ,
152162 default : submissionUrl ,
153163 } ) ,
154- this . options . database . path ,
155164 this . attributeManager . get ( 'scoped' ) . attributes ,
156165 this . attachments ,
157166 ) ;
0 commit comments