@@ -9,9 +9,12 @@ import {
99 BacktraceReportSubmissionResult ,
1010 BacktraceRequestHandler ,
1111 BacktraceSessionProvider ,
12+ BacktraceStorageModule ,
1213 BacktraceSubmissionResponse ,
1314 DebugIdProvider ,
14- FileSystem ,
15+ DefaultReportBacktraceDatabaseRecordFactory ,
16+ ReportBacktraceDatabaseRecordSender ,
17+ ReportBacktraceDatabaseRecordSerializer ,
1518 SdkOptions ,
1619 SessionFiles ,
1720} from './index.js' ;
@@ -117,7 +120,7 @@ export abstract class BacktraceCoreClient<
117120
118121 protected readonly attributeManager : AttributeManager ;
119122 protected readonly attachmentManager : AttachmentManager ;
120- protected readonly fileSystem ?: FileSystem ;
123+ protected readonly databaseStorage ?: BacktraceStorageModule ;
121124
122125 private readonly _modules : BacktraceModules = new Map ( ) ;
123126 private readonly _dataBuilder : BacktraceDataBuilder ;
@@ -133,7 +136,6 @@ export abstract class BacktraceCoreClient<
133136 super ( ) ;
134137
135138 this . options = setup . options ;
136- this . fileSystem = setup . fileSystem ;
137139 this . _sdkOptions = setup . sdkOptions ;
138140 this . _sessionProvider = setup . sessionProvider ?? new SingleSessionProvider ( ) ;
139141 this . _reportSubmission =
@@ -167,30 +169,38 @@ export abstract class BacktraceCoreClient<
167169 new DebugIdProvider ( stackTraceConverter , setup . debugIdMapProvider ) ,
168170 ) ;
169171
170- if ( this . options ?. database ?. enable === true && setup . fileSystem ) {
172+ if ( this . options ?. database ?. enable === true && setup . database ?. storage ) {
173+ this . databaseStorage = setup . database . storage ;
174+ this . addModule ( this . databaseStorage ) ;
175+
171176 const provider = BacktraceDatabaseFileStorageProvider . createIfValid (
172- setup . fileSystem ,
177+ {
178+ report : new ReportBacktraceDatabaseRecordSerializer ( ) ,
179+ ...setup . database ?. recordSerializers ,
180+ } ,
181+ this . databaseStorage ,
173182 this . options . database ,
174183 ) ;
175184
176- if ( this . fileSystem ) {
177- const sessionFiles = new SessionFiles (
178- this . fileSystem ,
179- this . options . database . path ,
180- {
181- id : this . sessionId ,
182- timestamp : Date . now ( ) ,
183- } ,
184- this . options . database . maximumOldSessions ?? 1 ,
185- ) ;
186- this . _modules . set ( SessionFiles , sessionFiles ) ;
187- }
185+ const sessionFiles = new SessionFiles (
186+ this . databaseStorage ,
187+ {
188+ id : this . sessionId ,
189+ timestamp : Date . now ( ) ,
190+ } ,
191+ this . options . database . maximumOldSessions ?? 1 ,
192+ ) ;
193+ this . _modules . set ( SessionFiles , sessionFiles ) ;
188194
189195 if ( provider ) {
190196 const database = new BacktraceDatabase (
191197 this . options . database ,
192198 provider ,
193- this . _reportSubmission ,
199+ {
200+ report : new ReportBacktraceDatabaseRecordSender ( this . _reportSubmission ) ,
201+ ...setup . database ?. recordSenders ?.( this . _reportSubmission ) ,
202+ } ,
203+ setup . database ?. reportRecordFactory ?? DefaultReportBacktraceDatabaseRecordFactory . default ( ) ,
194204 this . sessionFiles ,
195205 ) ;
196206 this . _modules . set ( BacktraceDatabase , database ) ;
@@ -223,16 +233,6 @@ export abstract class BacktraceCoreClient<
223233 public initialize ( ) {
224234 this . validateAttributes ( ) ;
225235
226- if ( this . fileSystem && this . options . database ?. createDatabaseDirectory ) {
227- if ( ! this . options . database . path ) {
228- throw new Error (
229- 'Missing mandatory path to the database. Please define the database.path option in the configuration.' ,
230- ) ;
231- }
232-
233- this . fileSystem . createDirSync ( this . options . database ?. path ) ;
234- }
235-
236236 for ( const module of this . _modules . values ( ) ) {
237237 if ( module . bind ) {
238238 module . bind ( this . getModuleBindData ( ) ) ;
@@ -406,7 +406,7 @@ export abstract class BacktraceCoreClient<
406406 return data instanceof BacktraceReport ;
407407 }
408408
409- private getModuleBindData ( ) : BacktraceModuleBindData {
409+ private getModuleBindData ( ) : BacktraceModuleBindData < O > {
410410 return {
411411 client : this ,
412412 options : this . options ,
@@ -416,7 +416,7 @@ export abstract class BacktraceCoreClient<
416416 requestHandler : this . _requestHandler ,
417417 database : this . database ,
418418 sessionFiles : this . sessionFiles ,
419- fileSystem : this . fileSystem ,
419+ storage : this . databaseStorage ,
420420 } ;
421421 }
422422
0 commit comments