@@ -17,10 +17,23 @@ import type { Client, MetricsAggregator, Scope, VersionString } from '@sentry/ty
1717import type { SdkSource } from './env' ;
1818import { SDK_VERSION } from './version' ;
1919
20- type BackwardsCompatibleSentryCarrier = {
21- // v8 scope stack (replaces .hub)
22- stack ?: any ;
20+ interface SentryCarrier {
2321 acs ?: any ;
22+ stack ?: any ;
23+
24+ globalScope ?: Scope ;
25+ defaultIsolationScope ?: Scope ;
26+ defaultCurrentScope ?: Scope ;
27+ globalMetricsAggregators : WeakMap < Client , MetricsAggregator > | undefined ;
28+
29+ /** Overwrites TextEncoder used in `@sentry/utils`, need for `[email protected] ` and older */ 30+ encodePolyfill ?: ( input : string ) => Uint8Array ;
31+ /** Overwrites TextDecoder used in `@sentry/utils`, need for `[email protected] ` and older */ 32+ decodePolyfill ?: ( input : Uint8Array ) => string ;
33+ }
34+
35+ // TODO(v9): Clean up or remove this type
36+ type BackwardsCompatibleSentryCarrier = SentryCarrier & {
2437 // pre-v7 hub (replaced by .stack)
2538 hub : any ;
2639 integrations ?: any [ ] ;
@@ -30,14 +43,6 @@ type BackwardsCompatibleSentryCarrier = {
3043 // eslint-disable-next-line @typescript-eslint/ban-types
3144 [ key : string ] : Function ;
3245 } ;
33- globalScope : Scope | undefined ;
34- defaultCurrentScope : Scope | undefined ;
35- defaultIsolationScope : Scope | undefined ;
36- globalMetricsAggregators : WeakMap < Client , MetricsAggregator > | undefined ;
37- /** Overwrites TextEncoder used in `@sentry/utils`, need for `[email protected] ` and older */ 38- encodePolyfill ?: ( input : string ) => Uint8Array ;
39- /** Overwrites TextDecoder used in `@sentry/utils`, need for `[email protected] ` and older */ 40- decodePolyfill ?: ( input : Uint8Array ) => string ;
4146} ;
4247
4348/** Internal global with common properties and Sentry extensions */
@@ -68,7 +73,7 @@ export type InternalGlobal = {
6873 */
6974 _sentryDebugIds ?: Record < string , string > ;
7075 __SENTRY__ : {
71- [ key : VersionString ] : BackwardsCompatibleSentryCarrier ;
76+ [ key : VersionString ] : SentryCarrier ;
7277 version : VersionString ;
7378 } & BackwardsCompatibleSentryCarrier ;
7479 /**
@@ -83,10 +88,8 @@ export type InternalGlobal = {
8388/** Get's the global object for the current JavaScript runtime */
8489export const GLOBAL_OBJ = globalThis as unknown as InternalGlobal ;
8590
86- type SingletonKeys = Exclude < keyof InternalGlobal [ '__SENTRY__' ] , 'version' | VersionString > ;
87-
8891/**
89- * Returns a global singleton contained in the global `__SENTRY__` object.
92+ * Returns a global singleton contained in the global `__SENTRY__[] ` object.
9093 *
9194 * If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory
9295 * function and added to the `__SENTRY__` object.
@@ -96,7 +99,7 @@ type SingletonKeys = Exclude<keyof InternalGlobal['__SENTRY__'], 'version' | Ver
9699 * @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value
97100 * @returns the singleton
98101 */
99- export function getGlobalSingleton < T > ( name : SingletonKeys , creator : ( ) => T , obj ?: unknown ) : T {
102+ export function getGlobalSingleton < T > ( name : keyof SentryCarrier , creator : ( ) => T , obj ?: unknown ) : T {
100103 const gbl = ( obj || GLOBAL_OBJ ) as InternalGlobal ;
101104 const __SENTRY__ = ( gbl . __SENTRY__ = gbl . __SENTRY__ || { } ) ;
102105 const versionedCarrier = ( __SENTRY__ [ SDK_VERSION ] = __SENTRY__ [ SDK_VERSION ] || { } ) ;
0 commit comments