@react-native-firebase/perf 25.1.0 → 26.1.0

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 (81) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/RNFBPerf.podspec +9 -7
  3. package/android/build.gradle +19 -0
  4. package/android/src/main/java/io/invertase/firebase/perf/UniversalFirebasePerfModule.java +88 -0
  5. package/android/src/reactnative/java/io/invertase/firebase/perf/NativeRNFBTurboPerf.java +108 -0
  6. package/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfPackage.java +1 -1
  7. package/android/src/reactnative/java/io/invertase/firebase/perf/generated/java/com/facebook/fbreact/specs/NativeRNFBTurboPerfSpec.java +100 -0
  8. package/android/src/reactnative/java/io/invertase/firebase/perf/generated/jni/CMakeLists.txt +36 -0
  9. package/android/src/reactnative/java/io/invertase/firebase/perf/generated/jni/RNFBPerfTurboModules-generated.cpp +80 -0
  10. package/android/src/reactnative/java/io/invertase/firebase/perf/generated/jni/RNFBPerfTurboModules.h +31 -0
  11. package/android/src/reactnative/java/io/invertase/firebase/perf/generated/jni/react/renderer/components/RNFBPerfTurboModules/RNFBPerfTurboModulesJSI-generated.cpp +94 -0
  12. package/android/src/reactnative/java/io/invertase/firebase/perf/generated/jni/react/renderer/components/RNFBPerfTurboModules/RNFBPerfTurboModulesJSI.h +267 -0
  13. package/app.plugin.js +1 -1
  14. package/dist/module/HttpMetric.js +4 -4
  15. package/dist/module/HttpMetric.js.map +1 -1
  16. package/dist/module/ScreenTrace.js +5 -5
  17. package/dist/module/ScreenTrace.js.map +1 -1
  18. package/dist/module/Trace.js +4 -4
  19. package/dist/module/Trace.js.map +1 -1
  20. package/dist/module/index.js +142 -3
  21. package/dist/module/index.js.map +1 -1
  22. package/dist/module/version.js +1 -1
  23. package/dist/typescript/lib/HttpMetric.d.ts +2 -2
  24. package/dist/typescript/lib/HttpMetric.d.ts.map +1 -1
  25. package/dist/typescript/lib/ScreenTrace.d.ts +2 -2
  26. package/dist/typescript/lib/ScreenTrace.d.ts.map +1 -1
  27. package/dist/typescript/lib/Trace.d.ts +2 -2
  28. package/dist/typescript/lib/Trace.d.ts.map +1 -1
  29. package/dist/typescript/lib/index.d.ts +23 -4
  30. package/dist/typescript/lib/index.d.ts.map +1 -1
  31. package/dist/typescript/lib/types/internal.d.ts +12 -16
  32. package/dist/typescript/lib/types/internal.d.ts.map +1 -1
  33. package/dist/typescript/lib/types/perf.d.ts +7 -7
  34. package/dist/typescript/lib/types/perf.d.ts.map +1 -1
  35. package/dist/typescript/lib/version.d.ts +1 -1
  36. package/ios/RNFBPerf/RNFBPerfModule.h +3 -2
  37. package/ios/RNFBPerf/RNFBPerfModule.mm +268 -0
  38. package/ios/RNFBPerf.xcodeproj/project.pbxproj +8 -8
  39. package/ios/generated/RCTAppDependencyProvider.h +25 -0
  40. package/ios/generated/RCTAppDependencyProvider.mm +55 -0
  41. package/ios/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
  42. package/ios/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
  43. package/ios/generated/RCTThirdPartyComponentsProvider.h +16 -0
  44. package/ios/generated/RCTThirdPartyComponentsProvider.mm +23 -0
  45. package/ios/generated/RNFBPerfTurboModules/RNFBPerfTurboModules-generated.mm +106 -0
  46. package/ios/generated/RNFBPerfTurboModules/RNFBPerfTurboModules.h +191 -0
  47. package/ios/generated/RNFBPerfTurboModulesJSI-generated.cpp +94 -0
  48. package/ios/generated/RNFBPerfTurboModulesJSI.h +267 -0
  49. package/ios/generated/ReactAppDependencyProvider.podspec +34 -0
  50. package/lib/HttpMetric.ts +6 -6
  51. package/lib/ScreenTrace.ts +7 -7
  52. package/lib/Trace.ts +6 -6
  53. package/lib/index.ts +228 -5
  54. package/lib/types/internal.ts +12 -24
  55. package/lib/types/perf.ts +7 -7
  56. package/lib/version.ts +1 -1
  57. package/package.json +30 -5
  58. package/plugin/build/app.plugin.d.ts +2 -0
  59. package/plugin/build/app.plugin.js +6 -0
  60. package/plugin/src/app.plugin.ts +3 -0
  61. package/plugin/tsconfig.tsbuildinfo +1 -1
  62. package/react-native.config.js +10 -0
  63. package/specs/NativeRNFBTurboPerf.ts +44 -0
  64. package/typedoc.json +1 -1
  65. package/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java +0 -158
  66. package/dist/module/modular.js +0 -93
  67. package/dist/module/modular.js.map +0 -1
  68. package/dist/module/namespaced.js +0 -130
  69. package/dist/module/namespaced.js.map +0 -1
  70. package/dist/module/types/namespaced.js +0 -65
  71. package/dist/module/types/namespaced.js.map +0 -1
  72. package/dist/typescript/lib/modular.d.ts +0 -43
  73. package/dist/typescript/lib/modular.d.ts.map +0 -1
  74. package/dist/typescript/lib/namespaced.d.ts +0 -11
  75. package/dist/typescript/lib/namespaced.d.ts.map +0 -1
  76. package/dist/typescript/lib/types/namespaced.d.ts +0 -128
  77. package/dist/typescript/lib/types/namespaced.d.ts.map +0 -1
  78. package/ios/RNFBPerf/RNFBPerfModule.m +0 -215
  79. package/lib/modular.ts +0 -116
  80. package/lib/namespaced.ts +0 -200
  81. package/lib/types/namespaced.ts +0 -162
@@ -1,215 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import <React/RCTConvert.h>
19
- #import <React/RCTUtils.h>
20
-
21
- #import <Firebase/Firebase.h>
22
- #import "RNFBPerfModule.h"
23
-
24
- static __strong NSMutableDictionary *traces;
25
- static __strong NSMutableDictionary *httpMetrics;
26
-
27
- @implementation RNFBPerfModule
28
- #pragma mark -
29
- #pragma mark Module Setup
30
-
31
- RCT_EXPORT_MODULE();
32
-
33
- - (instancetype)init {
34
- self = [super init];
35
-
36
- static dispatch_once_t onceToken;
37
- dispatch_once(&onceToken, ^{
38
- traces = [[NSMutableDictionary alloc] init];
39
- httpMetrics = [[NSMutableDictionary alloc] init];
40
- });
41
-
42
- return self;
43
- }
44
-
45
- - (void)dealloc {
46
- @synchronized([self class]) {
47
- for (NSString *key in [traces allKeys]) {
48
- [traces removeObjectForKey:key];
49
- }
50
-
51
- for (NSString *key in [httpMetrics allKeys]) {
52
- [httpMetrics removeObjectForKey:key];
53
- }
54
- }
55
- }
56
-
57
- - (NSDictionary *)constantsToExport {
58
- NSMutableDictionary *constants = [NSMutableDictionary new];
59
- constants[@"isPerformanceCollectionEnabled"] =
60
- @([RCTConvert BOOL:@([FIRPerformance sharedInstance].dataCollectionEnabled)]);
61
- constants[@"isInstrumentationEnabled"] =
62
- @([RCTConvert BOOL:@([FIRPerformance sharedInstance].instrumentationEnabled)]);
63
- return constants;
64
- }
65
-
66
- + (BOOL)requiresMainQueueSetup {
67
- return NO;
68
- }
69
-
70
- #pragma mark -
71
- #pragma mark Firebase Perf Methods
72
-
73
- RCT_EXPORT_METHOD(setPerformanceCollectionEnabled
74
- : (BOOL)enabled resolver
75
- : (RCTPromiseResolveBlock)resolve rejecter
76
- : (RCTPromiseRejectBlock)reject) {
77
- [FIRPerformance sharedInstance].dataCollectionEnabled = (BOOL)enabled;
78
- resolve([NSNull null]);
79
- }
80
-
81
- RCT_EXPORT_METHOD(startTrace
82
- : (nonnull NSNumber *)id identifier
83
- : (NSString *)identifier resolver
84
- : (RCTPromiseResolveBlock)resolve rejecter
85
- : (RCTPromiseRejectBlock)reject) {
86
- FIRTrace *trace = [[FIRPerformance sharedInstance] traceWithName:identifier];
87
- [trace start];
88
-
89
- @synchronized([self class]) {
90
- traces[id] = trace;
91
- }
92
-
93
- resolve([NSNull null]);
94
- }
95
-
96
- RCT_EXPORT_METHOD(stopTrace
97
- : (nonnull NSNumber *)id traceData
98
- : (NSDictionary *)traceData resolver
99
- : (RCTPromiseResolveBlock)resolve rejecter
100
- : (RCTPromiseRejectBlock)reject) {
101
- FIRTrace *trace;
102
- @synchronized([self class]) {
103
- trace = traces[id];
104
- }
105
-
106
- NSDictionary *metrics = traceData[@"metrics"];
107
- NSDictionary *attributes = traceData[@"attributes"];
108
-
109
- [metrics enumerateKeysAndObjectsUsingBlock:^(NSString *metricName, NSNumber *value, BOOL *stop) {
110
- [trace setIntValue:[value longLongValue] forMetric:metricName];
111
- }];
112
-
113
- [attributes
114
- enumerateKeysAndObjectsUsingBlock:^(NSString *attributeName, NSString *value, BOOL *stop) {
115
- [trace setValue:value forAttribute:attributeName];
116
- }];
117
-
118
- [trace stop];
119
-
120
- @synchronized([self class]) {
121
- [traces removeObjectForKey:id];
122
- }
123
-
124
- resolve([NSNull null]);
125
- }
126
-
127
- RCT_EXPORT_METHOD(startHttpMetric
128
- : (nonnull NSNumber *)id url
129
- : (NSString *)url httpMethod
130
- : (NSString *)httpMethod resolver
131
- : (RCTPromiseResolveBlock)resolve rejecter
132
- : (RCTPromiseRejectBlock)reject) {
133
- FIRHTTPMethod method = FIRHTTPMethodGET;
134
- NSURL *toNSURL = [NSURL URLWithString:url];
135
- if ([httpMethod compare:@"put" options:NSCaseInsensitiveSearch] == NSOrderedSame)
136
- method = FIRHTTPMethodPUT;
137
- if ([httpMethod compare:@"post" options:NSCaseInsensitiveSearch] == NSOrderedSame)
138
- method = FIRHTTPMethodPUT;
139
- if ([httpMethod compare:@"head" options:NSCaseInsensitiveSearch] == NSOrderedSame)
140
- method = FIRHTTPMethodHEAD;
141
- if ([httpMethod compare:@"trace" options:NSCaseInsensitiveSearch] == NSOrderedSame)
142
- method = FIRHTTPMethodTRACE;
143
- if ([httpMethod compare:@"patch" options:NSCaseInsensitiveSearch] == NSOrderedSame)
144
- method = FIRHTTPMethodPATCH;
145
- if ([httpMethod compare:@"delete" options:NSCaseInsensitiveSearch] == NSOrderedSame)
146
- method = FIRHTTPMethodDELETE;
147
- if ([httpMethod compare:@"options" options:NSCaseInsensitiveSearch] == NSOrderedSame)
148
- method = FIRHTTPMethodOPTIONS;
149
- if ([httpMethod compare:@"connect" options:NSCaseInsensitiveSearch] == NSOrderedSame)
150
- method = FIRHTTPMethodCONNECT;
151
-
152
- FIRHTTPMetric *httpMetric = [[FIRHTTPMetric alloc] initWithURL:toNSURL HTTPMethod:method];
153
- [httpMetric start];
154
-
155
- @synchronized([self class]) {
156
- httpMetrics[id] = httpMetric;
157
- }
158
-
159
- resolve([NSNull null]);
160
- }
161
-
162
- RCT_EXPORT_METHOD(stopHttpMetric
163
- : (nonnull NSNumber *)id metricData
164
- : (NSDictionary *)metricData resolver
165
- : (RCTPromiseResolveBlock)resolve rejecter
166
- : (RCTPromiseRejectBlock)reject) {
167
- FIRHTTPMetric *httpMetric;
168
- @synchronized([self class]) {
169
- httpMetric = httpMetrics[id];
170
- }
171
-
172
- NSDictionary *attributes = metricData[@"attributes"];
173
- [attributes
174
- enumerateKeysAndObjectsUsingBlock:^(NSString *attributeName, NSString *value, BOOL *stop) {
175
- [httpMetric setValue:value forAttribute:attributeName];
176
- }];
177
-
178
- if (metricData[@"httpResponseCode"]) {
179
- NSNumber *responseCode = (NSNumber *)metricData[@"httpResponseCode"];
180
- [httpMetric setResponseCode:[responseCode integerValue]];
181
- }
182
-
183
- if (metricData[@"requestPayloadSize"]) {
184
- NSNumber *requestPayloadSize = (NSNumber *)metricData[@"requestPayloadSize"];
185
- [httpMetric setRequestPayloadSize:[requestPayloadSize longValue]];
186
- }
187
-
188
- if (metricData[@"responsePayloadSize"]) {
189
- NSNumber *responsePayloadSize = (NSNumber *)metricData[@"responsePayloadSize"];
190
- [httpMetric setResponsePayloadSize:[responsePayloadSize longValue]];
191
- }
192
-
193
- if (metricData[@"responseContentType"]) {
194
- NSString *responseContentType = (NSString *)metricData[@"responseContentType"];
195
- [httpMetric setResponseContentType:responseContentType];
196
- }
197
-
198
- [httpMetric stop];
199
-
200
- @synchronized([self class]) {
201
- [httpMetrics removeObjectForKey:id];
202
- }
203
-
204
- resolve([NSNull null]);
205
- }
206
-
207
- RCT_EXPORT_METHOD(instrumentationEnabled
208
- : (BOOL)enabled resolver
209
- : (RCTPromiseResolveBlock)resolve rejecter
210
- : (RCTPromiseRejectBlock)reject) {
211
- [FIRPerformance sharedInstance].instrumentationEnabled = (BOOL)enabled;
212
- resolve([NSNull null]);
213
- }
214
-
215
- @end
package/lib/modular.ts DELETED
@@ -1,116 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- import { getApp } from '@react-native-firebase/app';
19
- import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/dist/module/common';
20
-
21
- import type { FirebaseApp } from '@react-native-firebase/app';
22
- import type {
23
- FirebasePerformance,
24
- HttpMetric,
25
- HttpMethod,
26
- PerformanceSettings,
27
- PerformanceTrace,
28
- ScreenTrace,
29
- } from './types/perf';
30
-
31
- import type { PerfInternal } from './types/internal';
32
-
33
- function perfInternal(performance: FirebasePerformance): PerfInternal {
34
- return performance as PerfInternal;
35
- }
36
-
37
- /**
38
- * Returns a {@link FirebasePerformance} instance for the given app.
39
- * @param app - The FirebaseApp to use. Optional; defaults to the default app.
40
- */
41
- export function getPerformance(app?: FirebaseApp): FirebasePerformance {
42
- if (app) {
43
- return getApp(app.name).perf() as FirebasePerformance;
44
- }
45
-
46
- return getApp().perf() as FirebasePerformance;
47
- }
48
-
49
- /**
50
- * Returns a {@link FirebasePerformance} instance for the given app (aligned with the Firebase JS SDK).
51
- * Can only be called once per app during initialization in typical usage.
52
- *
53
- * @param app - The FirebaseApp to use.
54
- * @param settings - Optional {@link PerformanceSettings}.
55
- */
56
- export function initializePerformance(
57
- app: FirebaseApp,
58
- settings?: PerformanceSettings,
59
- ): FirebasePerformance {
60
- const perf = getPerformance(app);
61
-
62
- if (settings?.dataCollectionEnabled !== undefined) {
63
- perf.dataCollectionEnabled = settings.dataCollectionEnabled;
64
- }
65
- if (settings?.instrumentationEnabled !== undefined) {
66
- perf.instrumentationEnabled = settings.instrumentationEnabled;
67
- }
68
-
69
- return perf;
70
- }
71
-
72
- /**
73
- * Returns a new {@link PerformanceTrace} instance.
74
- * @param performance - The {@link FirebasePerformance} instance to use.
75
- * @param name - The name of the trace.
76
- */
77
- export function trace(performance: FirebasePerformance, name: string): PerformanceTrace {
78
- return perfInternal(performance).newTrace(name, MODULAR_DEPRECATION_ARG);
79
- }
80
-
81
- /**
82
- * Creates an {@link HttpMetric} for a URL and HTTP method (React Native).
83
- * @param performance - The {@link FirebasePerformance} instance to use.
84
- * @param url - Request URL.
85
- * @param httpMethod - HTTP method.
86
- */
87
- export function httpMetric(
88
- performance: FirebasePerformance,
89
- url: string,
90
- httpMethod: HttpMethod,
91
- ): HttpMetric {
92
- return perfInternal(performance).newHttpMetric(url, httpMethod, MODULAR_DEPRECATION_ARG);
93
- }
94
-
95
- /**
96
- * Creates a {@link ScreenTrace} with the given screen name.
97
- * Android only; throws if hardware acceleration is disabled or if Android is 9.0 or 9.1.
98
- * @param performance - The {@link FirebasePerformance} instance to use.
99
- * @param screenName - Screen name; no leading/trailing whitespace, no leading `_`, max length 100.
100
- */
101
- export function newScreenTrace(performance: FirebasePerformance, screenName: string): ScreenTrace {
102
- return perfInternal(performance).newScreenTrace(screenName, MODULAR_DEPRECATION_ARG);
103
- }
104
-
105
- /**
106
- * Creates a {@link ScreenTrace} and starts it immediately.
107
- * Android only; throws if hardware acceleration is disabled or if Android is 9.0 or 9.1.
108
- * @param performance - The {@link FirebasePerformance} instance to use.
109
- * @param screenName - Name of the screen.
110
- */
111
- export function startScreenTrace(
112
- performance: FirebasePerformance,
113
- screenName: string,
114
- ): Promise<ScreenTrace> {
115
- return perfInternal(performance).startScreenTrace(screenName, MODULAR_DEPRECATION_ARG);
116
- }
package/lib/namespaced.ts DELETED
@@ -1,200 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- import { isBoolean, isOneOf, isString } from '@react-native-firebase/app/dist/module/common';
19
- import {
20
- createModuleNamespace,
21
- FirebaseModule,
22
- getFirebaseRoot,
23
- type ModuleConfig,
24
- } from '@react-native-firebase/app/dist/module/internal';
25
- import { Platform } from 'react-native';
26
-
27
- import HttpMetric from './HttpMetric';
28
- import ScreenTrace from './ScreenTrace';
29
- import Trace from './Trace';
30
- import { version } from './version';
31
-
32
- import type { ReactNativeFirebase } from '@react-native-firebase/app';
33
- import type { FirebasePerformanceTypes } from './types/namespaced';
34
-
35
- const statics: FirebasePerformanceTypes.Statics = {
36
- SDK_VERSION: version,
37
- };
38
-
39
- const namespace = 'perf';
40
-
41
- const nativeModuleName = 'RNFBPerfModule' as const;
42
-
43
- const VALID_HTTP_METHODS: FirebasePerformanceTypes.HttpMethod[] = [
44
- 'CONNECT',
45
- 'DELETE',
46
- 'GET',
47
- 'HEAD',
48
- 'OPTIONS',
49
- 'PATCH',
50
- 'POST',
51
- 'PUT',
52
- 'TRACE',
53
- ];
54
-
55
- class FirebasePerfModule extends FirebaseModule<typeof nativeModuleName> {
56
- private _isPerformanceCollectionEnabled: boolean;
57
- private _instrumentationEnabled: boolean;
58
-
59
- constructor(
60
- app: ReactNativeFirebase.FirebaseAppBase,
61
- config: ModuleConfig,
62
- customUrlOrRegion?: string | null,
63
- ) {
64
- super(app, config, customUrlOrRegion);
65
- this._isPerformanceCollectionEnabled = this.native.isPerformanceCollectionEnabled;
66
- this._instrumentationEnabled = this.native.isInstrumentationEnabled;
67
- }
68
-
69
- get isPerformanceCollectionEnabled(): boolean {
70
- return this._isPerformanceCollectionEnabled;
71
- }
72
-
73
- get instrumentationEnabled(): boolean {
74
- return this._instrumentationEnabled;
75
- }
76
-
77
- set instrumentationEnabled(enabled: boolean) {
78
- if (!isBoolean(enabled)) {
79
- throw new Error("firebase.perf().instrumentationEnabled = 'enabled' must be a boolean.");
80
- }
81
- if (Platform.OS === 'ios') {
82
- // We don't change for android as it cannot be set from code, it is set at gradle build time.
83
- this._instrumentationEnabled = enabled;
84
- // No need to await, as it only takes effect on the next app run.
85
- this.native.instrumentationEnabled(enabled);
86
- }
87
- }
88
-
89
- get dataCollectionEnabled(): boolean {
90
- return this._isPerformanceCollectionEnabled;
91
- }
92
-
93
- set dataCollectionEnabled(enabled: boolean) {
94
- if (!isBoolean(enabled)) {
95
- throw new Error("firebase.perf().dataCollectionEnabled = 'enabled' must be a boolean.");
96
- }
97
- this._isPerformanceCollectionEnabled = enabled;
98
- // Keep setter behavior fire-and-forget; callers that need completion should use setPerformanceCollectionEnabled().
99
- void this.native.setPerformanceCollectionEnabled(enabled);
100
- }
101
-
102
- async setPerformanceCollectionEnabled(enabled: boolean): Promise<null> {
103
- if (!isBoolean(enabled)) {
104
- throw new Error(
105
- "firebase.perf().setPerformanceCollectionEnabled(*) 'enabled' must be a boolean.",
106
- );
107
- }
108
-
109
- if (Platform.OS === 'ios') {
110
- // '_instrumentationEnabled' is updated here as well to maintain backward compatibility. See:
111
- // https://github.com/invertase/react-native-firebase/commit/b705622e64d6ebf4ee026d50841e2404cf692f85
112
- this._instrumentationEnabled = enabled;
113
- await this.native.instrumentationEnabled(enabled);
114
- }
115
-
116
- this._isPerformanceCollectionEnabled = enabled;
117
- return this.native.setPerformanceCollectionEnabled(enabled);
118
- }
119
-
120
- newTrace(identifier: string): Trace {
121
- // TODO(VALIDATION): identifier: no leading or trailing whitespace, no leading underscore '_'
122
- if (!isString(identifier) || identifier.length > 100) {
123
- throw new Error(
124
- "firebase.perf().newTrace(*) 'identifier' must be a string with a maximum length of 100 characters.",
125
- );
126
- }
127
-
128
- return new Trace(this.native, identifier);
129
- }
130
-
131
- startTrace(identifier: string): Promise<Trace> {
132
- const traceInstance = this.newTrace(identifier);
133
- return traceInstance.start().then(() => traceInstance);
134
- }
135
-
136
- newScreenTrace(identifier: string): ScreenTrace {
137
- if (!isString(identifier) || identifier.length > 100) {
138
- throw new Error(
139
- "firebase.perf().newScreenTrace(*) 'identifier' must be a string with a maximum length of 100 characters.",
140
- );
141
- }
142
-
143
- return new ScreenTrace(this.native, identifier);
144
- }
145
-
146
- startScreenTrace(identifier: string): Promise<ScreenTrace> {
147
- const screenTrace = this.newScreenTrace(identifier);
148
- return screenTrace.start().then(() => screenTrace);
149
- }
150
-
151
- newHttpMetric(url: string, httpMethod: FirebasePerformanceTypes.HttpMethod): HttpMetric {
152
- if (!isString(url)) {
153
- throw new Error("firebase.perf().newHttpMetric(*, _) 'url' must be a string.");
154
- }
155
-
156
- if (!isOneOf(httpMethod, VALID_HTTP_METHODS)) {
157
- throw new Error(
158
- `firebase.perf().newHttpMetric(_, *) 'httpMethod' must be one of ${VALID_HTTP_METHODS.join(
159
- ', ',
160
- )}.`,
161
- );
162
- }
163
-
164
- return new HttpMetric(this.native, url, httpMethod);
165
- }
166
- }
167
-
168
- // import { SDK_VERSION } from '@react-native-firebase/perf';
169
- export const SDK_VERSION = version;
170
-
171
- export type PerfNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
172
- FirebasePerformanceTypes.Module,
173
- FirebasePerformanceTypes.Statics
174
- > & {
175
- firebase: ReactNativeFirebase.Module;
176
- app(name?: string): ReactNativeFirebase.FirebaseApp;
177
- };
178
-
179
- const defaultExport = createModuleNamespace({
180
- statics,
181
- version,
182
- namespace,
183
- nativeModuleName,
184
- nativeEvents: false,
185
- hasMultiAppSupport: false,
186
- hasCustomUrlOrRegionSupport: false,
187
- ModuleClass: FirebasePerfModule,
188
- }) as unknown as PerfNamespace;
189
-
190
- export default defaultExport;
191
-
192
- // import perf, { firebase } from '@react-native-firebase/perf';
193
- // perf().X(...);
194
- // firebase.perf().X(...);
195
- export const firebase =
196
- getFirebaseRoot() as unknown as ReactNativeFirebase.FirebaseNamespacedExport<
197
- 'perf',
198
- FirebasePerformanceTypes.Module,
199
- FirebasePerformanceTypes.Statics
200
- >;
@@ -1,162 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- import type { ReactNativeFirebase } from '@react-native-firebase/app';
19
-
20
- /**
21
- * Firebase Performance Monitoring package for React Native.
22
- *
23
- * #### Example 1
24
- *
25
- * Access the firebase export from the `perf` package:
26
- *
27
- * ```js
28
- * import { firebase } from '@react-native-firebase/perf';
29
- *
30
- * // firebase.perf().X
31
- * ```
32
- *
33
- * #### Example 2
34
- *
35
- * Using the default export from the `perf` package:
36
- *
37
- * ```js
38
- * import perf from '@react-native-firebase/perf';
39
- *
40
- * // perf().X
41
- * ```
42
- *
43
- * #### Example 3
44
- *
45
- * Using the default export from the `app` package:
46
- *
47
- * ```js
48
- * import firebase from '@react-native-firebase/app';
49
- * import '@react-native-firebase/perf';
50
- *
51
- * // firebase.perf().X
52
- * ```
53
- *
54
- * @firebase perf
55
- */
56
- /**
57
- * @deprecated Use the modular type exports from `@react-native-firebase/perf` instead.
58
- * `FirebasePerformanceTypes` is kept for backwards compatibility with the namespaced API.
59
- */
60
- /* eslint-disable @typescript-eslint/no-namespace */
61
- export namespace FirebasePerformanceTypes {
62
- type FirebaseModule = ReactNativeFirebase.FirebaseModule;
63
-
64
- /**
65
- * @deprecated Use the `HttpMethod` type from the modular package exports instead.
66
- */
67
- export type HttpMethod =
68
- | 'GET'
69
- | 'HEAD'
70
- | 'PUT'
71
- | 'POST'
72
- | 'PATCH'
73
- | 'TRACE'
74
- | 'DELETE'
75
- | 'CONNECT'
76
- | 'OPTIONS';
77
-
78
- /**
79
- * @deprecated Use the `PerformanceTrace` type from the modular package exports instead.
80
- */
81
- export interface Trace {
82
- getAttribute(attribute: string): string | undefined;
83
- putAttribute(attribute: string, value: string): void;
84
- getMetric(metricName: string): number;
85
- getMetrics(): { [key: string]: number };
86
- putMetric(metricName: string, value: number): void;
87
- incrementMetric(metricName: string, incrementBy?: number): void;
88
- removeMetric(metricName: string): void;
89
- start(): Promise<null>;
90
- stop(): Promise<null>;
91
- }
92
-
93
- /**
94
- * @deprecated Use the `ScreenTrace` type from the modular package exports instead.
95
- */
96
- export interface ScreenTrace {
97
- start(): Promise<null>;
98
- stop(): Promise<null>;
99
- }
100
-
101
- /**
102
- * @deprecated Use the `HttpMetric` type from the modular package exports instead.
103
- */
104
- export interface HttpMetric {
105
- getAttribute(attribute: string): string | undefined;
106
- getAttributes(): { [key: string]: string };
107
- putAttribute(attribute: string, value: string): void;
108
- removeAttribute(attribute: string): void;
109
- setHttpResponseCode(code: number | null): void;
110
- setRequestPayloadSize(bytes: number | null): void;
111
- setResponsePayloadSize(bytes: number | null): void;
112
- setResponseContentType(contentType: string | null): void;
113
- start(): Promise<null>;
114
- stop(): Promise<null>;
115
- }
116
-
117
- /**
118
- * @deprecated Use static exports from the package root instead.
119
- */
120
- export interface Statics {
121
- SDK_VERSION: string;
122
- }
123
-
124
- /**
125
- * @deprecated Use the `FirebasePerformance` type from the modular package exports instead.
126
- */
127
- export interface Module extends FirebaseModule {
128
- app: ReactNativeFirebase.FirebaseApp;
129
- isPerformanceCollectionEnabled: boolean;
130
- instrumentationEnabled: boolean;
131
- dataCollectionEnabled: boolean;
132
- /**
133
- * @deprecated prefer setting `dataCollectionEnabled = boolean`.
134
- */
135
- setPerformanceCollectionEnabled(enabled: boolean): Promise<null>;
136
- newTrace(identifier: string): Trace;
137
- startTrace(identifier: string): Promise<Trace>;
138
- newScreenTrace(identifier: string): ScreenTrace;
139
- startScreenTrace(identifier: string): Promise<ScreenTrace>;
140
- newHttpMetric(url: string, httpMethod: HttpMethod): HttpMetric;
141
- }
142
- }
143
- /* eslint-enable @typescript-eslint/no-namespace */
144
-
145
- /**
146
- * Attach namespace to `firebase.` and `FirebaseApp.`.
147
- */
148
- declare module '@react-native-firebase/app' {
149
- // eslint-disable-next-line @typescript-eslint/no-namespace
150
- namespace ReactNativeFirebase {
151
- import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics;
152
- interface Module {
153
- perf: FirebaseModuleWithStatics<
154
- FirebasePerformanceTypes.Module,
155
- FirebasePerformanceTypes.Statics
156
- >;
157
- }
158
- interface FirebaseApp {
159
- perf(): FirebasePerformanceTypes.Module;
160
- }
161
- }
162
- }