@@ -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,27 +169,35 @@ 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- this . sessionId ,
181- this . options . database . maximumOldSessions ?? 1 ,
182- ) ;
183- this . _modules . set ( SessionFiles , sessionFiles ) ;
184- }
185+ const sessionFiles = new SessionFiles (
186+ this . databaseStorage ,
187+ this . sessionId ,
188+ this . options . database . maximumOldSessions ?? 1 ,
189+ ) ;
190+ this . _modules . set ( SessionFiles , sessionFiles ) ;
185191
186192 if ( provider ) {
187193 const database = new BacktraceDatabase (
188194 this . options . database ,
189195 provider ,
190- this . _reportSubmission ,
196+ {
197+ report : new ReportBacktraceDatabaseRecordSender ( this . _reportSubmission ) ,
198+ ...setup . database ?. recordSenders ?.( this . _reportSubmission ) ,
199+ } ,
200+ setup . database ?. reportRecordFactory ?? DefaultReportBacktraceDatabaseRecordFactory . default ( ) ,
191201 this . sessionFiles ,
192202 ) ;
193203 this . _modules . set ( BacktraceDatabase , database ) ;
@@ -220,16 +230,6 @@ export abstract class BacktraceCoreClient<
220230 public initialize ( ) {
221231 this . validateAttributes ( ) ;
222232
223- if ( this . fileSystem && this . options . database ?. createDatabaseDirectory ) {
224- if ( ! this . options . database . path ) {
225- throw new Error (
226- 'Missing mandatory path to the database. Please define the database.path option in the configuration.' ,
227- ) ;
228- }
229-
230- this . fileSystem . createDirSync ( this . options . database ?. path ) ;
231- }
232-
233233 for ( const module of this . _modules . values ( ) ) {
234234 if ( module . bind ) {
235235 module . bind ( this . getModuleBindData ( ) ) ;
@@ -403,7 +403,7 @@ export abstract class BacktraceCoreClient<
403403 return data instanceof BacktraceReport ;
404404 }
405405
406- private getModuleBindData ( ) : BacktraceModuleBindData {
406+ private getModuleBindData ( ) : BacktraceModuleBindData < O > {
407407 return {
408408 client : this ,
409409 options : this . options ,
@@ -413,7 +413,7 @@ export abstract class BacktraceCoreClient<
413413 requestHandler : this . _requestHandler ,
414414 database : this . database ,
415415 sessionFiles : this . sessionFiles ,
416- fileSystem : this . fileSystem ,
416+ storage : this . databaseStorage ,
417417 } ;
418418 }
419419
0 commit comments