@@ -7,6 +7,10 @@ import {BumpApi} from '../api/index.js'
77import { DiffRequest , DiffResponse , VersionRequest , VersionResponse , WithDiff } from '../api/models.js'
88import { API } from '../definition.js'
99
10+ export interface DiffResult extends DiffResponse {
11+ doc_name ?: string
12+ }
13+
1014export class Diff {
1115 // 120 seconds = 2 minutes
1216 static readonly TIMEOUT = 120
@@ -108,7 +112,7 @@ export class Diff {
108112 return debug ( `bump-cli:core:diff` ) ( formatter , ...args )
109113 }
110114
111- extractDiff ( versionWithDiff : VersionResponse & WithDiff ) : DiffResponse {
115+ extractDiff ( versionWithDiff : VersionResponse & WithDiff ) : DiffResult {
112116 // TODO: return a real diff_id in the GET /version API
113117 return {
114118 breaking : versionWithDiff . diff_breaking ,
@@ -145,7 +149,7 @@ export class Diff {
145149 expires ?: string | undefined ,
146150 overlays1 ?: string [ ] | undefined ,
147151 overlays2 ?: string [ ] | undefined ,
148- ) : Promise < DiffResponse | undefined > {
152+ ) : Promise < DiffResult | undefined > {
149153 if ( ! this . _config ) this . _config = await Config . load ( resolve ( import . meta. dirname , './../../' ) )
150154
151155 let diffVersion : DiffResponse | VersionResponse | undefined
@@ -183,13 +187,14 @@ export class Diff {
183187 }
184188
185189 async waitResult (
186- result : DiffResponse | VersionResponse ,
190+ apiResponse : DiffResponse | VersionResponse ,
187191 token : string | undefined ,
188192 opts : { format : string ; timeout : number } ,
189- ) : Promise < DiffResponse > {
190- const pollingResponse = await ( this . isVersion ( result ) && token
191- ? this . bumpClient . getVersion ( result . id , token )
192- : this . bumpClient . getDiff ( result . id , opts . format ) )
193+ ) : Promise < DiffResult > {
194+ let diffResult : DiffResult = { id : apiResponse . id }
195+ const pollingResponse = await ( this . isVersion ( apiResponse ) && token
196+ ? this . bumpClient . getVersion ( apiResponse . id , token )
197+ : this . bumpClient . getDiff ( apiResponse . id , opts . format ) )
193198
194199 if ( opts . timeout <= 0 ) {
195200 throw new CLIError (
@@ -199,30 +204,28 @@ export class Diff {
199204
200205 switch ( pollingResponse . status ) {
201206 case 200 : {
202- let diff : DiffResponse | ( VersionResponse & WithDiff ) = pollingResponse . data
207+ const diff : DiffResponse | ( VersionResponse & WithDiff ) = pollingResponse . data
203208
204- if ( this . isVersionWithDiff ( diff ) ) {
205- diff = this . extractDiff ( diff )
206- }
209+ diffResult = this . isVersionWithDiff ( diff ) ? this . extractDiff ( diff ) : diff
207210
208211 this . d ( 'Received diff:' )
209- this . d ( diff )
210- return diff
212+ this . d ( diffResult )
213+ return diffResult
211214 break
212215 }
213216
214217 case 202 : {
215218 this . d ( 'Waiting 1 sec before next poll' )
216219 await this . pollingDelay ( )
217- return this . waitResult ( result , token , {
220+ return this . waitResult ( apiResponse , token , {
218221 format : opts . format ,
219222 timeout : opts . timeout - 1 ,
220223 } )
221224 break
222225 }
223226 }
224227
225- return { } as DiffResponse
228+ return diffResult
226229 }
227230
228231 private async delay ( ms : number ) : Promise < void > {
0 commit comments