@@ -17,10 +17,23 @@ import type { Client, MetricsAggregator, Scope, VersionString } from '@sentry/ty
17
17
import type { SdkSource } from './env' ;
18
18
import { SDK_VERSION } from './version' ;
19
19
20
- type BackwardsCompatibleSentryCarrier = {
21
- // v8 scope stack (replaces .hub)
22
- stack ?: any ;
20
+ interface SentryCarrier {
23
21
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 & {
24
37
// pre-v7 hub (replaced by .stack)
25
38
hub : any ;
26
39
integrations ?: any [ ] ;
@@ -30,14 +43,6 @@ type BackwardsCompatibleSentryCarrier = {
30
43
// eslint-disable-next-line @typescript-eslint/ban-types
31
44
[ key : string ] : Function ;
32
45
} ;
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 ;
41
46
} ;
42
47
43
48
/** Internal global with common properties and Sentry extensions */
@@ -68,7 +73,7 @@ export type InternalGlobal = {
68
73
*/
69
74
_sentryDebugIds ?: Record < string , string > ;
70
75
__SENTRY__ : {
71
- [ key : VersionString ] : BackwardsCompatibleSentryCarrier ;
76
+ [ key : VersionString ] : SentryCarrier ;
72
77
version : VersionString ;
73
78
} & BackwardsCompatibleSentryCarrier ;
74
79
/**
@@ -83,10 +88,8 @@ export type InternalGlobal = {
83
88
/** Get's the global object for the current JavaScript runtime */
84
89
export const GLOBAL_OBJ = globalThis as unknown as InternalGlobal ;
85
90
86
- type SingletonKeys = Exclude < keyof InternalGlobal [ '__SENTRY__' ] , 'version' | VersionString > ;
87
-
88
91
/**
89
- * Returns a global singleton contained in the global `__SENTRY__` object.
92
+ * Returns a global singleton contained in the global `__SENTRY__[] ` object.
90
93
*
91
94
* If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory
92
95
* function and added to the `__SENTRY__` object.
@@ -96,7 +99,7 @@ type SingletonKeys = Exclude<keyof InternalGlobal['__SENTRY__'], 'version' | Ver
96
99
* @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value
97
100
* @returns the singleton
98
101
*/
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 {
100
103
const gbl = ( obj || GLOBAL_OBJ ) as InternalGlobal ;
101
104
const __SENTRY__ = ( gbl . __SENTRY__ = gbl . __SENTRY__ || { } ) ;
102
105
const versionedCarrier = ( __SENTRY__ [ SDK_VERSION ] = __SENTRY__ [ SDK_VERSION ] || { } ) ;
0 commit comments