1- import { FileAttachmentsManager , FileBreadcrumbsStorage , NodeFileSystem } from '@backtrace/node' ;
2- import type { BacktraceDatabase } from '@backtrace/sdk-core' ;
1+ import {
2+ AttachmentBacktraceDatabaseRecordFactory ,
3+ BacktraceConfiguration ,
4+ BacktraceStorageModule ,
5+ BacktraceStreamStorage ,
6+ FileAttachmentsManager ,
7+ FileBreadcrumbsStorage ,
8+ } from '@backtrace/node' ;
9+ import type { BacktraceDatabase , BacktraceStorage , BacktraceSyncStorage } from '@backtrace/sdk-core' ;
310import {
411 BacktraceData ,
512 BacktraceModule ,
@@ -18,10 +25,10 @@ import { MainIpcTransportHandler } from '../ipc/MainIpcTransportHandler.js';
1825import { WindowIpcTransport } from '../ipc/WindowIpcTransport.js' ;
1926import { IpcAttachment } from './IpcAttachment.js' ;
2027
21- export class BacktraceMainElectronModule implements BacktraceModule {
22- private _bindData ?: BacktraceModuleBindData ;
28+ export class BacktraceMainElectronModule implements BacktraceModule < BacktraceConfiguration > {
29+ private _bindData ?: BacktraceModuleBindData < BacktraceConfiguration > ;
2330
24- public bind ( bindData : BacktraceModuleBindData ) : void {
31+ public bind ( bindData : BacktraceModuleBindData < BacktraceConfiguration > ) : void {
2532 const { requestHandler, reportSubmission, client, attributeManager } = bindData ;
2633
2734 const getSyncData = ( ) : SyncData => ( {
@@ -102,7 +109,7 @@ export class BacktraceMainElectronModule implements BacktraceModule {
102109 return ;
103110 }
104111
105- const { options, attributeManager, sessionFiles, fileSystem , database } = this . _bindData ;
112+ const { options, attributeManager, sessionFiles, storage , database } = this . _bindData ;
106113
107114 if ( options . database ?. captureNativeCrashes ) {
108115 if ( options . database . path ) {
@@ -125,9 +132,9 @@ export class BacktraceMainElectronModule implements BacktraceModule {
125132 }
126133 } ) ;
127134
128- if ( sessionFiles && database && fileSystem ) {
135+ if ( sessionFiles && database && storage ) {
129136 const lockId = sessionFiles . lockPreviousSessions ( ) ;
130- this . sendPreviousCrashAttachments ( database , sessionFiles , fileSystem as NodeFileSystem ) . finally (
137+ this . sendPreviousCrashAttachments ( database , sessionFiles , storage as BacktraceStorageModule ) . finally (
131138 ( ) => lockId && sessionFiles . unlockPreviousSessions ( lockId ) ,
132139 ) ;
133140 }
@@ -145,7 +152,7 @@ export class BacktraceMainElectronModule implements BacktraceModule {
145152 private async sendPreviousCrashAttachments (
146153 database : BacktraceDatabase ,
147154 session : SessionFiles ,
148- fileSystem : NodeFileSystem ,
155+ storage : BacktraceStorage & BacktraceSyncStorage & BacktraceStreamStorage ,
149156 ) {
150157 // Sort crashes and sessions by timestamp descending
151158 const crashes = crashReporter . getUploadedReports ( ) . sort ( ( a , b ) => b . date . getTime ( ) - a . date . getTime ( ) ) ;
@@ -167,22 +174,24 @@ export class BacktraceMainElectronModule implements BacktraceModule {
167174
168175 const crashLock = session . getFileName ( `electron-crash-lock-${ rxid } ` ) ;
169176 // If crash lock exists, do not attempt to add attachments twice
170- if ( await fileSystem . exists ( crashLock ) ) {
177+ if ( await storage . has ( crashLock ) ) {
171178 continue ;
172179 }
173180
174- const fileAttachmentsManager = FileAttachmentsManager . createFromSession ( session , fileSystem ) ;
181+ const fileAttachmentsManager = FileAttachmentsManager . createFromSession ( session , storage ) ;
175182 const sessionAttachments = [
176- ...FileBreadcrumbsStorage . getSessionAttachments ( session , fileSystem ) ,
183+ ...FileBreadcrumbsStorage . getSessionAttachments ( session , storage ) ,
177184 ...( await fileAttachmentsManager . get ( ) ) ,
178185 ] ;
179186
187+ const recordFactory = AttachmentBacktraceDatabaseRecordFactory . default ( ) ;
180188 for ( const attachment of sessionAttachments ) {
181- database . addAttachment ( rxid , attachment , session . sessionId ) ;
189+ const record = recordFactory . create ( rxid , session . sessionId , attachment ) ;
190+ database . addRecord ( record ) ;
182191 }
183192
184193 // Write an empty crash lock, so we know that this crash is already taken care of
185- await fileSystem . writeFile ( crashLock , '' ) ;
194+ await storage . set ( crashLock , '' ) ;
186195 } catch {
187196 // Do nothing, skip the report
188197 }
0 commit comments