@logbrew/react-native 0.1.38 → 0.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/LogBrewReactNative.podspec +1 -1
  2. package/README.md +17 -15
  3. package/android-native-diagnostics.d.ts +15 -5
  4. package/android-native-diagnostics.js +170 -94
  5. package/apollo.cjs +435 -226
  6. package/apollo.d.cts +2 -70
  7. package/apollo.d.ts +24 -12
  8. package/apollo.js +438 -221
  9. package/apple-native-diagnostics-config.js +176 -0
  10. package/apple-native-diagnostics-context.js +232 -0
  11. package/apple-native-diagnostics-module.js +229 -0
  12. package/apple-native-diagnostics.d.ts +42 -11
  13. package/apple-native-diagnostics.js +60 -389
  14. package/expo.cjs +29 -16
  15. package/expo.d.ts +10 -9
  16. package/expo.js +4 -3
  17. package/fatal-admission.cjs +113 -0
  18. package/fatal-record.cjs +317 -0
  19. package/fatal-replay.cjs +297 -508
  20. package/global-errors-capture.cjs +369 -0
  21. package/global-errors-event.cjs +174 -0
  22. package/global-errors-support.cjs +128 -0
  23. package/global-errors.cjs +75 -351
  24. package/global-errors.d.cts +29 -278
  25. package/global-errors.d.ts +57 -27
  26. package/global-errors.js +7 -2
  27. package/global-errors.native.js +83 -48
  28. package/index-breadcrumbs.cjs +139 -0
  29. package/index-errors.cjs +167 -0
  30. package/index-events.cjs +365 -0
  31. package/index-navigation.cjs +327 -0
  32. package/index-random.cjs +120 -0
  33. package/index-react.cjs +189 -0
  34. package/index-spans.cjs +190 -0
  35. package/index-trace-fetch.cjs +322 -0
  36. package/index-trace.cjs +335 -0
  37. package/index-transport.cjs +201 -0
  38. package/index-values.cjs +232 -0
  39. package/index.cjs +95 -1220
  40. package/index.d.cts +2 -505
  41. package/index.d.ts +130 -469
  42. package/index.native.d.ts +146 -22
  43. package/index.native.js +184 -159
  44. package/instrumentation-fetch.cjs +113 -0
  45. package/instrumentation-install.cjs +241 -0
  46. package/instrumentation-runtime.cjs +65 -0
  47. package/instrumentation-teardown.cjs +93 -0
  48. package/instrumentation-values.cjs +282 -0
  49. package/instrumentation-xhr-request.cjs +298 -0
  50. package/instrumentation-xhr.cjs +233 -0
  51. package/instrumentation.cjs +110 -599
  52. package/instrumentation.d.cts +2 -84
  53. package/instrumentation.d.ts +22 -8
  54. package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
  55. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +7 -1
  56. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +36 -4
  57. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +17 -0
  58. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +2 -0
  59. package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +41 -6
  60. package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +5 -5
  61. package/lifecycle.cjs +181 -78
  62. package/lifecycle.d.cts +1 -50
  63. package/lifecycle.d.ts +17 -6
  64. package/metadata.cjs +279 -114
  65. package/metro-debug-id.cjs +296 -0
  66. package/metro-serializer.cjs +219 -0
  67. package/metro.cjs +153 -297
  68. package/metro.d.cts +2 -57
  69. package/metro.d.ts +27 -13
  70. package/metro.js +2 -3
  71. package/native-bridge-async.cjs +165 -0
  72. package/native-bridge-scope.cjs +148 -0
  73. package/native-bridge.cjs +83 -186
  74. package/native-bridge.d.cts +2 -94
  75. package/native-bridge.d.ts +28 -15
  76. package/native-client-bindings.js +230 -0
  77. package/native-diagnostics-values.js +120 -0
  78. package/native-module-lookup.js +31 -0
  79. package/native-null.js +3 -0
  80. package/null-value.cjs +4 -0
  81. package/package.json +44 -2
  82. package/persistent-delivery-store.js +247 -0
  83. package/persistent-delivery.native.js +183 -261
  84. package/promise-rejection-handlers.cjs +368 -0
  85. package/promise-rejections.cjs +169 -361
  86. package/react-native.config.js +3 -1
  87. package/release-artifacts-files.cjs +94 -0
  88. package/release-artifacts-options.cjs +182 -0
  89. package/release-artifacts.cjs +278 -207
  90. package/release-artifacts.d.cts +2 -55
  91. package/release-artifacts.d.ts +18 -7
  92. package/release-artifacts.js +2 -4
  93. package/resource-fetch-graphql.cjs +265 -0
  94. package/resource-fetch-size.cjs +156 -0
  95. package/resource-fetch.cjs +227 -428
  96. package/resource-fetch.d.cts +1 -60
  97. package/resource-fetch.d.ts +17 -6
  98. package/scripts/sync-apple-native-sources.mjs +101 -53
  99. package/types/capture.d.ts +95 -0
  100. package/types/config.d.ts +85 -0
  101. package/types/defaults.d.ts +55 -0
  102. package/types/events.d.ts +203 -0
  103. package/types/provider.d.ts +81 -0
  104. package/types/trace.d.ts +104 -0
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ const { SdkError } = require("@logbrew/sdk");
4
+ const { isCallable, isWritableRecord, readField } = require("./instrumentation-values.cjs");
5
+ const { resourceFetchRuntime } = require("./instrumentation-runtime.cjs");
6
+
7
+ /**
8
+ * @import { LogBrewClient } from "@logbrew/sdk"
9
+ * @import { ResourceFetch, ResourceFetchOptions } from "./instrumentation-runtime.cjs"
10
+ * @import { Callable } from "./instrumentation-values.cjs"
11
+ */
12
+
13
+ /**
14
+ * @typedef {{
15
+ * readonly globalObject: unknown,
16
+ * readonly measureResponseBodySize: boolean,
17
+ * readonly resourceOptions: ResourceFetchOptions
18
+ * }} GlobalFetchOptions
19
+ */
20
+
21
+ /**
22
+ * @param {unknown} globalObject
23
+ * @returns {{ readonly globalObject: Record<PropertyKey, unknown>, readonly originalFetch: Callable }}
24
+ */
25
+ function requireGlobalFetch(globalObject) {
26
+ if (!isWritableRecord(globalObject)) {
27
+ throw new SdkError("configuration_error", "instrumentGlobalFetch requires a globalObject");
28
+ }
29
+ const originalFetch = globalObject["fetch"];
30
+ if (!isCallable(originalFetch)) {
31
+ throw new SdkError("configuration_error", "instrumentGlobalFetch requires globalObject.fetch");
32
+ }
33
+ return { globalObject, originalFetch };
34
+ }
35
+
36
+ /**
37
+ * @param {LogBrewClient} client
38
+ * @param {GlobalFetchOptions} options
39
+ * @param {Callable} originalFetch
40
+ * @returns {ResourceFetch}
41
+ */
42
+ function createGlobalResourceFetch(client, { globalObject, measureResponseBodySize, resourceOptions }, originalFetch) {
43
+ /** @type {{ readonly fetchImpl: (input: unknown, init?: unknown) => unknown }} */
44
+ const fetchOptions = {
45
+ fetchImpl: (input, init) => Reflect.apply(originalFetch, globalObject, [input, init])
46
+ };
47
+ return resourceFetchRuntime.createReactNativeResourceFetch(client, {
48
+ ...resourceOptions,
49
+ fetchImpl: fetchOptions.fetchImpl,
50
+ measureResponseBodySize
51
+ });
52
+ }
53
+
54
+ /**
55
+ * @param {LogBrewClient} client
56
+ * @param {GlobalFetchOptions} options
57
+ * @param {Callable} originalFetch
58
+ * @returns {ResourceFetch}
59
+ */
60
+ function createWrappedFetch(client, options, originalFetch) {
61
+ const globalResourceFetch = createGlobalResourceFetch(client, options, originalFetch);
62
+ /** @type {{ readonly wrappedFetch: ResourceFetch }} */
63
+ const wrapper = {
64
+ wrappedFetch: (input, init) => globalResourceFetch(input, init)
65
+ };
66
+ return wrapper.wrappedFetch;
67
+ }
68
+
69
+ /**
70
+ * @param {unknown} globalObject
71
+ * @param {ResourceFetch} wrappedFetch
72
+ * @returns {void}
73
+ */
74
+ function requirePatched(globalObject, wrappedFetch) {
75
+ if (readField(globalObject, "fetch") !== wrappedFetch) {
76
+ throw new SdkError("configuration_error", "instrumentGlobalFetch could not patch globalObject.fetch");
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @param {LogBrewClient} client
82
+ * @param {GlobalFetchOptions} options
83
+ * @returns {Readonly<{ fetch: ResourceFetch, remove: () => void, stop: () => void }>}
84
+ */
85
+ function installGlobalFetchInstrumentation(client, options) {
86
+ const { globalObject, originalFetch } = requireGlobalFetch(options.globalObject);
87
+ const wrappedFetch = createWrappedFetch(client, options, originalFetch);
88
+ try {
89
+ globalObject["fetch"] = wrappedFetch;
90
+ } catch {
91
+ throw new SdkError("configuration_error", "instrumentGlobalFetch could not patch globalObject.fetch");
92
+ }
93
+ requirePatched(globalObject, wrappedFetch);
94
+ let removed = false;
95
+ const { remove } = {
96
+ remove: () => {
97
+ if (removed) {
98
+ return;
99
+ }
100
+ removed = true;
101
+ if (globalObject["fetch"] === wrappedFetch) {
102
+ globalObject["fetch"] = originalFetch;
103
+ }
104
+ }
105
+ };
106
+ return Object.freeze({
107
+ fetch: wrappedFetch,
108
+ remove,
109
+ stop: remove
110
+ });
111
+ }
112
+
113
+ module.exports = { installGlobalFetchInstrumentation };
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+
3
+ const { installGlobalFetchInstrumentation } = require("./instrumentation-fetch.cjs");
4
+ const { lifecycleRuntime, nativeBridgeRuntime, resourceFetchRuntime } = require("./instrumentation-runtime.cjs");
5
+ const { indexRuntime } = require("./instrumentation-values.cjs");
6
+ const { installGlobalXMLHttpRequestInstrumentation } = require("./instrumentation-xhr.cjs");
7
+
8
+ /**
9
+ * @import { LogBrewClient, Metadata } from "@logbrew/sdk"
10
+ * @import { TracePropagationTarget } from "./index.cjs"
11
+ * @import { InstrumentationTeardown } from "./instrumentation-teardown.cjs"
12
+ * @import { ResourceFetch, ResourceFetchOptions } from "./instrumentation-runtime.cjs"
13
+ * @import { AppStateInput, PlatformInput, RandomValues, TraceInput } from "./instrumentation-values.cjs"
14
+ * @import { XhrInstallOptions } from "./instrumentation-xhr.cjs"
15
+ * @import { NativeBridgeScopeInput } from "./native-bridge-scope.cjs"
16
+ */
17
+
18
+ /**
19
+ * @typedef {{
20
+ * readonly appState?: AppStateInput | undefined,
21
+ * readonly captureInitialLifecycleState?: boolean | undefined,
22
+ * readonly captureInitialNavigationRoute?: boolean | undefined,
23
+ * readonly fetchImpl?: unknown,
24
+ * readonly globalObject?: unknown,
25
+ * readonly includeRouteKey?: boolean | undefined,
26
+ * readonly instrumentGlobalFetch?: boolean | undefined,
27
+ * readonly instrumentGlobalXMLHttpRequest?: boolean | undefined,
28
+ * readonly logger?: string | undefined,
29
+ * readonly measureFetchResponseBodySize?: boolean | undefined,
30
+ * readonly measureXhrResponseBodySize?: boolean | undefined,
31
+ * readonly metadata?: Readonly<Metadata> | undefined,
32
+ * readonly metadataFactory?: unknown,
33
+ * readonly nativeBridge?: unknown,
34
+ * readonly navigation?: unknown,
35
+ * readonly navigationContainer?: unknown,
36
+ * readonly now?: (() => string) | undefined,
37
+ * readonly nowMs?: (() => number) | undefined,
38
+ * readonly onError?: ((error: unknown) => void) | undefined,
39
+ * readonly platform?: PlatformInput | undefined,
40
+ * readonly randomValues?: RandomValues | undefined,
41
+ * readonly routeTemplate?: string | undefined,
42
+ * readonly routeTemplateFactory?: unknown,
43
+ * readonly screen?: string | undefined,
44
+ * readonly sessionId?: string | undefined,
45
+ * readonly trace?: TraceInput | undefined,
46
+ * readonly traceFlags?: string | undefined,
47
+ * readonly tracePropagationTargets?: readonly TracePropagationTarget[] | undefined
48
+ * }} InstrumentationOptions
49
+ * @typedef {{
50
+ * readonly appState: AppStateInput | undefined,
51
+ * readonly captureInitialLifecycleState: boolean,
52
+ * readonly captureInitialNavigationRoute: boolean,
53
+ * readonly fetchImpl: unknown,
54
+ * readonly globalObject: unknown,
55
+ * readonly includeRouteKey: boolean,
56
+ * readonly instrumentGlobalFetch: boolean,
57
+ * readonly instrumentGlobalXMLHttpRequest: boolean,
58
+ * readonly logger: string | undefined,
59
+ * readonly measureFetchResponseBodySize: boolean,
60
+ * readonly measureXhrResponseBodySize: boolean,
61
+ * readonly metadata: Readonly<Metadata>,
62
+ * readonly metadataFactory: unknown,
63
+ * readonly nativeBridge: unknown,
64
+ * readonly navigation: unknown,
65
+ * readonly navigationContainer: unknown,
66
+ * readonly now: () => string,
67
+ * readonly nowMs: () => number,
68
+ * readonly onError: ((error: unknown) => void) | undefined,
69
+ * readonly platform: PlatformInput | undefined,
70
+ * readonly randomValues: RandomValues | undefined,
71
+ * readonly routeTemplate: string | undefined,
72
+ * readonly routeTemplateFactory: unknown,
73
+ * readonly screen: string | undefined,
74
+ * readonly sessionId: string | undefined,
75
+ * readonly trace: TraceInput | undefined,
76
+ * readonly traceFlags: string,
77
+ * readonly tracePropagationTargets: readonly TracePropagationTarget[]
78
+ * }} InstrumentationSettings
79
+ * @typedef {Readonly<Omit<InstrumentationSettings, "trace"> & { trace: TraceInput }>} ActiveSettings
80
+ * @typedef {{ readonly client: LogBrewClient, readonly settings: ActiveSettings }} InstrumentationContext
81
+ * @typedef {{
82
+ * readonly globalFetch: Readonly<{ fetch: ResourceFetch, remove: () => void, stop: () => void }> | undefined,
83
+ * readonly globalXMLHttpRequest: Readonly<{ remove: () => void, stop: () => void }> | undefined,
84
+ * readonly resourceFetch: ResourceFetch
85
+ * }} InstalledHooks
86
+ */
87
+
88
+ const SCOPE_SOURCE = "react-native.instrumentation";
89
+
90
+ /**
91
+ * @param {ActiveSettings} settings
92
+ * @returns {NativeBridgeScopeInput}
93
+ */
94
+ function nativeScopeOptions({ logger, metadata, screen, sessionId, trace }) {
95
+ return { logger, metadata, screen, sessionId, source: SCOPE_SOURCE, trace };
96
+ }
97
+
98
+ /**
99
+ * @param {ActiveSettings} settings
100
+ * @returns {ResourceFetchOptions}
101
+ */
102
+ function resourceOptions(settings) {
103
+ return {
104
+ appState: settings.appState,
105
+ metadata: settings.metadata,
106
+ metadataFactory: settings.metadataFactory,
107
+ now: settings.now,
108
+ nowMs: settings.nowMs,
109
+ platform: settings.platform,
110
+ randomValues: settings.randomValues,
111
+ routeTemplate: settings.routeTemplate,
112
+ routeTemplateFactory: settings.routeTemplateFactory,
113
+ screen: settings.screen,
114
+ sessionId: settings.sessionId,
115
+ trace: settings.trace,
116
+ traceFlags: settings.traceFlags,
117
+ tracePropagationTargets: settings.tracePropagationTargets
118
+ };
119
+ }
120
+
121
+ /**
122
+ * @param {ActiveSettings} settings
123
+ * @returns {XhrInstallOptions}
124
+ */
125
+ function xhrOptions(settings) {
126
+ return {
127
+ appState: settings.appState,
128
+ globalObject: settings.globalObject,
129
+ measureXhrResponseBodySize: settings.measureXhrResponseBodySize,
130
+ metadata: settings.metadata,
131
+ metadataFactory: settings.metadataFactory,
132
+ now: settings.now,
133
+ nowMs: settings.nowMs,
134
+ platform: settings.platform,
135
+ routeTemplate: settings.routeTemplate,
136
+ routeTemplateFactory: settings.routeTemplateFactory,
137
+ screen: settings.screen,
138
+ sessionId: settings.sessionId,
139
+ trace: settings.trace,
140
+ tracePropagationTargets: settings.tracePropagationTargets
141
+ };
142
+ }
143
+
144
+ /**
145
+ * @param {InstrumentationContext} context
146
+ * @param {InstrumentationTeardown} teardown
147
+ * @returns {void}
148
+ */
149
+ function installListeners({ client, settings }, teardown) {
150
+ const hasAppStateListener = Boolean(settings.appState?.addEventListener);
151
+ if (hasAppStateListener) {
152
+ teardown.add(lifecycleRuntime.createAppStateLifecycleSpanListener(client, settings.appState, {
153
+ captureInitialState: settings.captureInitialLifecycleState,
154
+ metadata: settings.metadata,
155
+ now: settings.now,
156
+ nowMs: settings.nowMs,
157
+ onError: settings.onError,
158
+ platform: settings.platform,
159
+ screen: settings.screen,
160
+ sessionId: settings.sessionId,
161
+ trace: settings.trace
162
+ }));
163
+ }
164
+ const resolvedNavigation = settings.navigationContainer ?? settings.navigation;
165
+ const hasNavigation = Boolean(resolvedNavigation);
166
+ if (hasNavigation) {
167
+ teardown.add(indexRuntime.createReactNavigationSpanListener(client, resolvedNavigation, {
168
+ appState: settings.appState,
169
+ captureInitialRoute: settings.captureInitialNavigationRoute,
170
+ includeRouteKey: settings.includeRouteKey,
171
+ metadata: settings.metadata,
172
+ now: settings.now,
173
+ nowMs: settings.nowMs,
174
+ onError: settings.onError,
175
+ platform: settings.platform,
176
+ trace: settings.trace
177
+ }));
178
+ }
179
+ }
180
+
181
+ /**
182
+ * @param {InstrumentationContext} context
183
+ * @param {InstrumentationTeardown} teardown
184
+ * @returns {void}
185
+ */
186
+ function syncInitialNativeScope({ settings }, teardown) {
187
+ const hasNativeBridge = Boolean(settings.nativeBridge);
188
+ if (hasNativeBridge) {
189
+ nativeBridgeRuntime.syncLogBrewNativeBridgeScope(settings.nativeBridge, nativeScopeOptions(settings));
190
+ teardown.markNativeScopeApplied();
191
+ }
192
+ }
193
+
194
+ /**
195
+ * @param {InstrumentationContext} context
196
+ * @param {InstrumentationTeardown} teardown
197
+ * @returns {InstalledHooks}
198
+ */
199
+ function installFetchHooks({ client, settings }, teardown) {
200
+ const resourceFetch = resourceFetchRuntime.createReactNativeResourceFetch(client, {
201
+ ...resourceOptions(settings),
202
+ fetchImpl: settings.fetchImpl,
203
+ measureResponseBodySize: settings.measureFetchResponseBodySize
204
+ });
205
+ const globalFetch = settings.instrumentGlobalFetch ? installGlobalFetchInstrumentation(client, {
206
+ globalObject: settings.globalObject,
207
+ measureResponseBodySize: settings.measureFetchResponseBodySize,
208
+ resourceOptions: resourceOptions(settings)
209
+ }) : undefined;
210
+ if (globalFetch !== undefined) {
211
+ teardown.add(globalFetch.remove);
212
+ }
213
+ const globalXMLHttpRequest = settings.instrumentGlobalXMLHttpRequest
214
+ ? installGlobalXMLHttpRequestInstrumentation(client, xhrOptions(settings))
215
+ : undefined;
216
+ if (globalXMLHttpRequest !== undefined) {
217
+ teardown.add(globalXMLHttpRequest.remove);
218
+ }
219
+ return { globalFetch, globalXMLHttpRequest, resourceFetch };
220
+ }
221
+
222
+ /**
223
+ * @param {InstrumentationContext} context
224
+ * @param {InstrumentationTeardown} teardown
225
+ * @returns {InstalledHooks}
226
+ */
227
+ function installInstrumentation(context, teardown) {
228
+ try {
229
+ installListeners(context, teardown);
230
+ syncInitialNativeScope(context, teardown);
231
+ return installFetchHooks(context, teardown);
232
+ } catch (error) {
233
+ teardown.removeAfterSetupFailure(context.settings.nativeBridge);
234
+ throw error;
235
+ }
236
+ }
237
+
238
+ module.exports = {
239
+ installInstrumentation,
240
+ nativeScopeOptions
241
+ };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @import { LogBrewClient, Metadata } from "@logbrew/sdk"
5
+ * @import { TracePropagationTarget } from "./index.cjs"
6
+ * @import { AppStateInput, Callable, PlatformInput, RandomValues, TraceInput } from "./instrumentation-values.cjs"
7
+ * @import { NativeBridgeScopeInput } from "./native-bridge-scope.cjs"
8
+ */
9
+
10
+ /**
11
+ * @typedef {{
12
+ * readonly captureInitialState?: boolean | undefined,
13
+ * readonly metadata?: Readonly<Metadata> | undefined,
14
+ * readonly now?: (() => string) | undefined,
15
+ * readonly nowMs?: (() => number) | undefined,
16
+ * readonly onError?: ((error: unknown) => void) | undefined,
17
+ * readonly platform?: PlatformInput | undefined,
18
+ * readonly screen?: string | undefined,
19
+ * readonly sessionId?: string | undefined,
20
+ * readonly trace?: TraceInput | undefined
21
+ * }} LifecycleListenerOptions
22
+ * @typedef {{
23
+ * readonly appState?: AppStateInput | undefined,
24
+ * readonly fetchImpl?: unknown,
25
+ * readonly measureResponseBodySize?: boolean | undefined,
26
+ * readonly metadata?: Readonly<Metadata> | undefined,
27
+ * readonly metadataFactory?: unknown,
28
+ * readonly now?: (() => string) | undefined,
29
+ * readonly nowMs?: (() => number) | undefined,
30
+ * readonly platform?: PlatformInput | undefined,
31
+ * readonly randomValues?: RandomValues | undefined,
32
+ * readonly routeTemplate?: string | undefined,
33
+ * readonly routeTemplateFactory?: unknown,
34
+ * readonly screen?: string | undefined,
35
+ * readonly sessionId?: string | undefined,
36
+ * readonly trace?: TraceInput | undefined,
37
+ * readonly traceFlags?: string | undefined,
38
+ * readonly tracePropagationTargets?: readonly TracePropagationTarget[] | undefined
39
+ * }} ResourceFetchOptions
40
+ * @typedef {{
41
+ * createAppStateLifecycleSpanListener(client: LogBrewClient, appState: AppStateInput | null | undefined, options?: LifecycleListenerOptions): () => unknown
42
+ * }} LifecycleRuntime
43
+ * @typedef {{
44
+ * clearLogBrewNativeBridgeScope(nativeBridge: unknown): void,
45
+ * syncLogBrewNativeBridgeScope(nativeBridge: unknown, options?: NativeBridgeScopeInput): unknown,
46
+ * withLogBrewNativeBridgeScope(nativeBridge: unknown, options: NativeBridgeScopeInput | Callable | null | undefined, work?: unknown): unknown
47
+ * }} NativeBridgeRuntime
48
+ * @typedef {(input: unknown, init?: unknown) => PromiseLike<unknown>} ResourceFetch
49
+ * @typedef {{
50
+ * createReactNativeResourceFetch(client: LogBrewClient, options?: ResourceFetchOptions): ResourceFetch
51
+ * }} ResourceFetchRuntime
52
+ */
53
+
54
+ /** @type {LifecycleRuntime} */
55
+ const lifecycleRuntime = require("./lifecycle.cjs");
56
+ /** @type {NativeBridgeRuntime} */
57
+ const nativeBridgeRuntime = require("./native-bridge.cjs");
58
+ /** @type {ResourceFetchRuntime} */
59
+ const resourceFetchRuntime = require("./resource-fetch.cjs");
60
+
61
+ module.exports = {
62
+ lifecycleRuntime,
63
+ nativeBridgeRuntime,
64
+ resourceFetchRuntime
65
+ };
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ const { nativeBridgeRuntime } = require("./instrumentation-runtime.cjs");
4
+
5
+ /**
6
+ * @typedef {() => unknown} Remover
7
+ * @typedef {{
8
+ * readonly add: (remover: Remover) => void,
9
+ * readonly markNativeScopeApplied: () => void,
10
+ * readonly removeAfterSetupFailure: (nativeBridge: unknown) => boolean,
11
+ * readonly removeAll: (nativeBridge: unknown) => void
12
+ * }} InstrumentationTeardown
13
+ * @typedef {{ readonly failed: Remover[], readonly failures: unknown[] }} RemovalOutcome
14
+ */
15
+
16
+ const NO_FAILURES = 0;
17
+
18
+ /**
19
+ * @param {unknown} nativeBridge
20
+ * @returns {unknown[]}
21
+ */
22
+ function clearNativeBridgeFailures(nativeBridge) {
23
+ const hasNativeBridge = Boolean(nativeBridge);
24
+ if (!hasNativeBridge) {
25
+ return [];
26
+ }
27
+ try {
28
+ nativeBridgeRuntime.clearLogBrewNativeBridgeScope(nativeBridge);
29
+ return [];
30
+ } catch (error) {
31
+ return [error];
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @param {unknown} nativeBridge
37
+ * @param {readonly Remover[]} pending
38
+ * @returns {RemovalOutcome}
39
+ */
40
+ function runRemovers(nativeBridge, pending) {
41
+ const failures = clearNativeBridgeFailures(nativeBridge);
42
+ /** @type {Remover[]} */
43
+ const failed = [];
44
+ for (const removeListener of pending) {
45
+ try {
46
+ removeListener();
47
+ } catch (error) {
48
+ failed.push(removeListener);
49
+ failures.push(error);
50
+ }
51
+ }
52
+ return { failed, failures };
53
+ }
54
+
55
+ /**
56
+ * @returns {InstrumentationTeardown}
57
+ */
58
+ function createInstrumentationTeardown() {
59
+ /** @type {Remover[]} */
60
+ const removers = [];
61
+ let nativeScopeApplied = false;
62
+ /**
63
+ * @param {unknown} nativeBridge
64
+ * @returns {void}
65
+ */
66
+ function removeConfigured(nativeBridge) {
67
+ const { failed, failures } = runRemovers(nativeBridge, removers.splice(NO_FAILURES));
68
+ removers.push(...failed);
69
+ const [firstFailure] = failures;
70
+ if (failures.length > NO_FAILURES) {
71
+ throw firstFailure;
72
+ }
73
+ }
74
+ return {
75
+ add: (remover) => {
76
+ removers.unshift(remover);
77
+ },
78
+ markNativeScopeApplied: () => {
79
+ nativeScopeApplied = true;
80
+ },
81
+ removeAfterSetupFailure: (nativeBridge) => {
82
+ try {
83
+ removeConfigured(nativeScopeApplied ? nativeBridge : undefined);
84
+ return true;
85
+ } catch {
86
+ return false;
87
+ }
88
+ },
89
+ removeAll: removeConfigured
90
+ };
91
+ }
92
+
93
+ module.exports = { createInstrumentationTeardown };