|
12 | 12 |
|
13 | 13 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
14 | 14 |
|
15 | | -import type { Client, MetricsAggregator, Scope } from '../types-hoist'; |
16 | | - |
| 15 | +import type { Carrier } from '../carrier'; |
17 | 16 | import type { SdkSource } from './env'; |
18 | | -import type { logger } from './logger'; |
19 | | -import { SDK_VERSION } from './version'; |
20 | | - |
21 | | -interface SentryCarrier { |
22 | | - acs?: any; |
23 | | - stack?: any; |
24 | | - |
25 | | - globalScope?: Scope; |
26 | | - defaultIsolationScope?: Scope; |
27 | | - defaultCurrentScope?: Scope; |
28 | | - globalMetricsAggregators?: WeakMap<Client, MetricsAggregator> | undefined; |
29 | | - logger?: typeof logger; |
30 | | - |
31 | | - /** Overwrites TextEncoder used in `@sentry/core`, need for `react-native@0.73` and older */ |
32 | | - encodePolyfill?: (input: string) => Uint8Array; |
33 | | - /** Overwrites TextDecoder used in `@sentry/core`, need for `react-native@0.73` and older */ |
34 | | - decodePolyfill?: (input: Uint8Array) => string; |
35 | | -} |
36 | | - |
37 | | -// TODO(v9): Clean up or remove this type |
38 | | -type BackwardsCompatibleSentryCarrier = SentryCarrier & { |
39 | | - // pre-v7 hub (replaced by .stack) |
40 | | - hub: any; |
41 | | - integrations?: any[]; |
42 | | - logger: any; |
43 | | - extensions?: { |
44 | | - /** Extension methods for the hub, which are bound to the current Hub instance */ |
45 | | - // eslint-disable-next-line @typescript-eslint/ban-types |
46 | | - [key: string]: Function; |
47 | | - }; |
48 | | -}; |
49 | 17 |
|
50 | 18 | /** Internal global with common properties and Sentry extensions */ |
51 | 19 | export type InternalGlobal = { |
@@ -73,35 +41,14 @@ export type InternalGlobal = { |
73 | 41 | * file. |
74 | 42 | */ |
75 | 43 | _sentryDebugIds?: Record<string, string>; |
76 | | - __SENTRY__: Record<Exclude<string, 'version'>, SentryCarrier> & { |
77 | | - version?: string; |
78 | | - } & BackwardsCompatibleSentryCarrier; |
79 | 44 | /** |
80 | 45 | * Raw module metadata that is injected by bundler plugins. |
81 | 46 | * |
82 | 47 | * Keys are `error.stack` strings, values are the metadata. |
83 | 48 | */ |
84 | 49 | _sentryModuleMetadata?: Record<string, any>; |
85 | 50 | _sentryEsmLoaderHookRegistered?: boolean; |
86 | | -}; |
| 51 | +} & Carrier; |
87 | 52 |
|
88 | 53 | /** Get's the global object for the current JavaScript runtime */ |
89 | 54 | export const GLOBAL_OBJ = globalThis as unknown as InternalGlobal; |
90 | | - |
91 | | -/** |
92 | | - * Returns a global singleton contained in the global `__SENTRY__[]` object. |
93 | | - * |
94 | | - * If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory |
95 | | - * function and added to the `__SENTRY__` object. |
96 | | - * |
97 | | - * @param name name of the global singleton on __SENTRY__ |
98 | | - * @param creator creator Factory function to create the singleton if it doesn't already exist on `__SENTRY__` |
99 | | - * @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value |
100 | | - * @returns the singleton |
101 | | - */ |
102 | | -export function getGlobalSingleton<T>(name: keyof SentryCarrier, creator: () => T, obj?: unknown): T { |
103 | | - const gbl = (obj || GLOBAL_OBJ) as InternalGlobal; |
104 | | - const __SENTRY__ = (gbl.__SENTRY__ = gbl.__SENTRY__ || {}); |
105 | | - const versionedCarrier = (__SENTRY__[SDK_VERSION] = __SENTRY__[SDK_VERSION] || {}); |
106 | | - return versionedCarrier[name] || (versionedCarrier[name] = creator()); |
107 | | -} |
0 commit comments