@@ -120,7 +120,32 @@ export class MergedProfileSelection implements ProfileSelection {
120120 }
121121}
122122
123+ // Type tag carried on instances so we can identify them reliably even when the
124+ // class gets duplicated across bundle chunks (prod builds sometimes end up with
125+ // two copies of the same class, making `instanceof` unreliable).
126+ export const PROFILE_SOURCE_TYPE_MERGED = 'merged' as const ;
127+ export const PROFILE_SOURCE_TYPE_DIFF = 'diff' as const ;
128+
129+ const getProfileSourceType = ( source : ProfileSource | null | undefined ) : string | undefined => {
130+ if ( source == null ) return undefined ;
131+ const tag = ( source as { profileSourceType ?: unknown } ) . profileSourceType ;
132+ return typeof tag === 'string' ? tag : undefined ;
133+ } ;
134+
135+ export const isMergedProfileSource = (
136+ source : ProfileSource | null | undefined
137+ ) : source is MergedProfileSource => {
138+ return getProfileSourceType ( source ) === PROFILE_SOURCE_TYPE_MERGED ;
139+ } ;
140+
141+ export const isProfileDiffSource = (
142+ source : ProfileSource | null | undefined
143+ ) : source is ProfileDiffSource => {
144+ return getProfileSourceType ( source ) === PROFILE_SOURCE_TYPE_DIFF ;
145+ } ;
146+
123147export class ProfileDiffSource implements ProfileSource {
148+ readonly profileSourceType = PROFILE_SOURCE_TYPE_DIFF ;
124149 a : ProfileSource ;
125150 b : ProfileSource ;
126151 profileType : ProfileType ;
@@ -194,6 +219,7 @@ function nanosToTimestamp(nanos: bigint): Timestamp {
194219}
195220
196221export class MergedProfileSource implements ProfileSource {
222+ readonly profileSourceType = PROFILE_SOURCE_TYPE_MERGED ;
197223 mergeFrom : bigint ;
198224 mergeTo : bigint ;
199225 query : Query ;
0 commit comments