@react-native-firebase/perf 26.3.3 → 27.0.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 (36) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/RNFBPerf.podspec +6 -1
  3. package/android/build.gradle +5 -0
  4. package/android/src/main/java/io/invertase/firebase/perf/RNFBPerfHandleRegistry.kt +71 -0
  5. package/android/src/main/java/io/invertase/firebase/perf/UniversalFirebasePerfModule.java +65 -28
  6. package/android/src/test/java/io/invertase/firebase/perf/RNFBPerfHandleRegistryTest.java +205 -0
  7. package/dist/module/version.js +1 -1
  8. package/dist/typescript/lib/index.d.ts +1 -1
  9. package/dist/typescript/lib/version.d.ts +1 -1
  10. package/ios/RNFBPerf/RNFBPerfHandleRegistry.h +41 -0
  11. package/ios/RNFBPerf/RNFBPerfHandleRegistry.m +87 -0
  12. package/ios/RNFBPerf/RNFBPerfHandleRegistryStorage.swift +58 -0
  13. package/ios/RNFBPerf/RNFBPerfHelper.h +71 -0
  14. package/ios/RNFBPerf/RNFBPerfHelper.m +219 -0
  15. package/ios/RNFBPerf/RNFBPerfHttpMethodMapper.swift +86 -0
  16. package/ios/RNFBPerf/RNFBPerfHttpMetricStopApplier.swift +87 -0
  17. package/ios/RNFBPerf/RNFBPerfModule.mm +41 -174
  18. package/ios/RNFBPerf/RNFBPerfTraceStopApplier.swift +68 -0
  19. package/ios/RNFBPerf.xcodeproj/project.pbxproj +32 -0
  20. package/ios/RNFBPerfUnitTests/HostStubs/Firebase/FIRPerformanceHostStub.m +170 -0
  21. package/ios/RNFBPerfUnitTests/HostStubs/Firebase/Firebase.h +75 -0
  22. package/ios/RNFBPerfUnitTests/HostStubs/RNFBApp/RNFBSharedUtils.h +12 -0
  23. package/ios/RNFBPerfUnitTests/HostStubs/RNFBApp/RNFBSharedUtilsHostStub.m +18 -0
  24. package/ios/RNFBPerfUnitTests/HostStubs/React/RCTBridgeModule.h +10 -0
  25. package/ios/RNFBPerfUnitTests/RNFBPerfHandleRegistryTests.m +169 -0
  26. package/ios/RNFBPerfUnitTests/RNFBPerfHelperHostStubTests.m +200 -0
  27. package/ios/RNFBPerfUnitTests/RNFBPerfHttpMethodMapperFacadeTests.m +52 -0
  28. package/ios/RNFBPerfUnitTests/RNFBPerfHttpMethodMapperTests.swift +92 -0
  29. package/ios/RNFBPerfUnitTests/RNFBPerfHttpMetricStopApplierFacadeTests.m +105 -0
  30. package/ios/RNFBPerfUnitTests/RNFBPerfHttpMetricStopApplierTests.swift +201 -0
  31. package/ios/RNFBPerfUnitTests/RNFBPerfTraceStopApplierFacadeTests.m +75 -0
  32. package/ios/RNFBPerfUnitTests/RNFBPerfTraceStopApplierTests.swift +142 -0
  33. package/ios/RNFBPerfUnitTests/RNFBPerfUnitTests.xcodeproj/project.pbxproj +321 -0
  34. package/ios/RNFBPerfUnitTests/RNFBPerfUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBPerfUnitTests.xcscheme +69 -0
  35. package/lib/version.ts +1 -1
  36. package/package.json +5 -4
@@ -15,30 +15,17 @@
15
15
  *
16
16
  */
17
17
 
18
- #import <React/RCTConvert.h>
19
- #import <React/RCTUtils.h>
20
-
21
- #if __has_include(<Firebase/Firebase.h>)
22
- #import <Firebase/Firebase.h>
23
- #define RNFB_PERF_SDK_AVAILABLE 1
24
- #elif __has_include(<FirebasePerformance/FirebasePerformance.h>)
25
- #import <FirebaseCore/FirebaseCore.h>
26
- #import <FirebasePerformance/FirebasePerformance.h>
27
- #define RNFB_PERF_SDK_AVAILABLE 1
28
- #else
29
- // Product headers absent (typical Mac Catalyst + SPM). Upstream Package.swift
30
- // omits .macCatalyst from FirebasePerformanceTarget; CocoaPods historically
31
- // masked this via the Firebase umbrella. Temporary stubs pending
32
- // https://github.com/firebase/firebase-ios-sdk/pull/16468 (or permanent if
33
- // upstream declines). Never fall through to @import in this .mm — that
34
- // requires -fcxx-modules and breaks RN C++/JSI.
35
- #define RNFB_PERF_SDK_AVAILABLE 0
36
- #endif
37
- #import "RNFBApp/RNFBSharedUtils.h"
18
+ // This module intentionally has no Firebase imports and no `*-Swift.h` —
19
+ // see RNFBPerfHelper.h. Every Firebase Performance touch (and the Swift
20
+ // stop appliers / HTTP method mapper) is routed through the plain
21
+ // Objective-C RNFBPerfHelper class instead, which can safely import Firebase
22
+ // and the generated Swift interface because it compiles as ObjC, not ObjC++.
38
23
  #import "RNFBPerfModule.h"
24
+ #import "RNFBPerfHandleRegistry.h"
25
+ #import "RNFBPerfHelper.h"
39
26
 
40
- static __strong NSMutableDictionary *traces;
41
- static __strong NSMutableDictionary *httpMetrics;
27
+ static RNFBPerfHandleRegistry *traces;
28
+ static RNFBPerfHandleRegistry *httpMetrics;
42
29
 
43
30
  @implementation RNFBPerfModule
44
31
 
@@ -53,48 +40,20 @@ RCT_EXPORT_MODULE(NativeRNFBTurboPerf)
53
40
 
54
41
  static dispatch_once_t onceToken;
55
42
  dispatch_once(&onceToken, ^{
56
- traces = [[NSMutableDictionary alloc] init];
57
- httpMetrics = [[NSMutableDictionary alloc] init];
43
+ traces = [[RNFBPerfHandleRegistry alloc] init];
44
+ httpMetrics = [[RNFBPerfHandleRegistry alloc] init];
58
45
  });
59
46
 
60
47
  return self;
61
48
  }
62
49
 
63
50
  - (void)invalidate {
64
- @synchronized([self class]) {
65
- for (NSString *key in [traces allKeys]) {
66
- [traces removeObjectForKey:key];
67
- }
68
-
69
- for (NSString *key in [httpMetrics allKeys]) {
70
- [httpMetrics removeObjectForKey:key];
71
- }
72
- }
73
- }
74
-
75
- #if !RNFB_PERF_SDK_AVAILABLE
76
- - (void)rejectUnavailable:(RCTPromiseRejectBlock)reject {
77
- [RNFBSharedUtils rejectPromiseWithUserInfo:reject
78
- userInfo:(NSMutableDictionary *)@{
79
- @"code" : @"unsupported",
80
- @"message" : @"Firebase Performance is not available on "
81
- @"this platform or dependency configuration.",
82
- }];
51
+ [traces takeAll];
52
+ [httpMetrics takeAll];
83
53
  }
84
- #endif
85
54
 
86
55
  - (NSDictionary *)perfConstantsDictionary {
87
- NSMutableDictionary *constants = [NSMutableDictionary new];
88
- #if RNFB_PERF_SDK_AVAILABLE
89
- constants[@"isPerformanceCollectionEnabled"] =
90
- @([RCTConvert BOOL:@([FIRPerformance sharedInstance].dataCollectionEnabled)]);
91
- constants[@"isInstrumentationEnabled"] =
92
- @([RCTConvert BOOL:@([FIRPerformance sharedInstance].instrumentationEnabled)]);
93
- #else
94
- constants[@"isPerformanceCollectionEnabled"] = @(NO);
95
- constants[@"isInstrumentationEnabled"] = @(NO);
96
- #endif
97
- return constants;
56
+ return [RNFBPerfHelper constantsDictionary];
98
57
  }
99
58
 
100
59
  - (facebook::react::ModuleConstants<JS::NativeRNFBTurboPerf::Constants>)constantsToExport {
@@ -113,71 +72,26 @@ RCT_EXPORT_MODULE(NativeRNFBTurboPerf)
113
72
  - (void)setPerformanceCollectionEnabled:(BOOL)enabled
114
73
  resolve:(RCTPromiseResolveBlock)resolve
115
74
  reject:(RCTPromiseRejectBlock)reject {
116
- #if RNFB_PERF_SDK_AVAILABLE
117
- [FIRPerformance sharedInstance].dataCollectionEnabled = (BOOL)enabled;
118
- resolve([NSNull null]);
119
- #else
120
- (void)enabled;
121
- (void)resolve;
122
- [self rejectUnavailable:reject];
123
- #endif
75
+ [RNFBPerfHelper setPerformanceCollectionEnabled:enabled resolve:resolve reject:reject];
124
76
  }
125
77
 
126
78
  - (void)instrumentationEnabled:(BOOL)enabled
127
79
  resolve:(RCTPromiseResolveBlock)resolve
128
80
  reject:(RCTPromiseRejectBlock)reject {
129
- #if RNFB_PERF_SDK_AVAILABLE
130
- [FIRPerformance sharedInstance].instrumentationEnabled = (BOOL)enabled;
131
- resolve([NSNull null]);
132
- #else
133
- (void)enabled;
134
- (void)resolve;
135
- [self rejectUnavailable:reject];
136
- #endif
81
+ [RNFBPerfHelper setInstrumentationEnabled:enabled resolve:resolve reject:reject];
137
82
  }
138
83
 
139
84
  - (void)startTrace:(double)id identifier:(NSString *)identifier {
140
- #if RNFB_PERF_SDK_AVAILABLE
141
- FIRTrace *trace = [[FIRPerformance sharedInstance] traceWithName:identifier];
142
- [trace start];
143
-
144
- @synchronized([self class]) {
145
- traces[@((int)id)] = trace;
146
- }
147
- #else
148
- (void)id;
149
- (void)identifier;
150
- #endif
85
+ [RNFBPerfHelper startTraceWithId:@((int)id) identifier:identifier inRegistry:traces];
151
86
  }
152
87
 
153
88
  - (void)stopTrace:(double)id traceData:(JS::NativeRNFBTurboPerf::TraceData &)traceData {
154
- #if RNFB_PERF_SDK_AVAILABLE
155
- FIRTrace *trace;
156
- @synchronized([self class]) {
157
- trace = traces[@((int)id)];
158
- }
159
-
160
89
  NSDictionary *metrics = (NSDictionary *)traceData.metrics();
161
90
  NSDictionary *attributes = (NSDictionary *)traceData.attributes();
162
-
163
- [metrics enumerateKeysAndObjectsUsingBlock:^(NSString *metricName, NSNumber *value, BOOL *stop) {
164
- [trace setIntValue:[value longLongValue] forMetric:metricName];
165
- }];
166
-
167
- [attributes
168
- enumerateKeysAndObjectsUsingBlock:^(NSString *attributeName, NSString *value, BOOL *stop) {
169
- [trace setValue:value forAttribute:attributeName];
170
- }];
171
-
172
- [trace stop];
173
-
174
- @synchronized([self class]) {
175
- [traces removeObjectForKey:@((int)id)];
176
- }
177
- #else
178
- (void)id;
179
- (void)traceData;
180
- #endif
91
+ [RNFBPerfHelper stopTraceWithId:@((int)id)
92
+ metrics:metrics
93
+ attributes:attributes
94
+ inRegistry:traces];
181
95
  }
182
96
 
183
97
  - (void)startScreenTrace:(double)id identifier:(NSString *)identifier {
@@ -192,77 +106,30 @@ RCT_EXPORT_MODULE(NativeRNFBTurboPerf)
192
106
  }
193
107
 
194
108
  - (void)startHttpMetric:(double)id url:(NSString *)url httpMethod:(NSString *)httpMethod {
195
- #if RNFB_PERF_SDK_AVAILABLE
196
- FIRHTTPMethod method = FIRHTTPMethodGET;
197
- NSURL *toNSURL = [NSURL URLWithString:url];
198
- if ([httpMethod compare:@"put" options:NSCaseInsensitiveSearch] == NSOrderedSame)
199
- method = FIRHTTPMethodPUT;
200
- if ([httpMethod compare:@"post" options:NSCaseInsensitiveSearch] == NSOrderedSame)
201
- method = FIRHTTPMethodPOST;
202
- if ([httpMethod compare:@"head" options:NSCaseInsensitiveSearch] == NSOrderedSame)
203
- method = FIRHTTPMethodHEAD;
204
- if ([httpMethod compare:@"trace" options:NSCaseInsensitiveSearch] == NSOrderedSame)
205
- method = FIRHTTPMethodTRACE;
206
- if ([httpMethod compare:@"patch" options:NSCaseInsensitiveSearch] == NSOrderedSame)
207
- method = FIRHTTPMethodPATCH;
208
- if ([httpMethod compare:@"delete" options:NSCaseInsensitiveSearch] == NSOrderedSame)
209
- method = FIRHTTPMethodDELETE;
210
- if ([httpMethod compare:@"options" options:NSCaseInsensitiveSearch] == NSOrderedSame)
211
- method = FIRHTTPMethodOPTIONS;
212
- if ([httpMethod compare:@"connect" options:NSCaseInsensitiveSearch] == NSOrderedSame)
213
- method = FIRHTTPMethodCONNECT;
214
-
215
- FIRHTTPMetric *httpMetric = [[FIRHTTPMetric alloc] initWithURL:toNSURL HTTPMethod:method];
216
- [httpMetric start];
217
-
218
- @synchronized([self class]) {
219
- httpMetrics[@((int)id)] = httpMetric;
220
- }
221
- #else
222
- (void)id;
223
- (void)url;
224
- (void)httpMethod;
225
- #endif
109
+ [RNFBPerfHelper startHttpMetricWithId:@((int)id)
110
+ url:url
111
+ httpMethod:httpMethod
112
+ inRegistry:httpMetrics];
226
113
  }
227
114
 
228
115
  - (void)stopHttpMetric:(double)id metricData:(JS::NativeRNFBTurboPerf::HttpMetricData &)metricData {
229
- #if RNFB_PERF_SDK_AVAILABLE
230
- FIRHTTPMetric *httpMetric;
231
- @synchronized([self class]) {
232
- httpMetric = httpMetrics[@((int)id)];
233
- }
234
-
235
116
  NSDictionary *attributes = (NSDictionary *)metricData.attributes();
236
- [attributes
237
- enumerateKeysAndObjectsUsingBlock:^(NSString *attributeName, NSString *value, BOOL *stop) {
238
- [httpMetric setValue:value forAttribute:attributeName];
239
- }];
240
-
241
- if (metricData.httpResponseCode().has_value()) {
242
- [httpMetric setResponseCode:(NSInteger)metricData.httpResponseCode().value()];
243
- }
244
-
245
- if (metricData.requestPayloadSize().has_value()) {
246
- [httpMetric setRequestPayloadSize:(NSInteger)metricData.requestPayloadSize().value()];
247
- }
248
-
249
- if (metricData.responsePayloadSize().has_value()) {
250
- [httpMetric setResponsePayloadSize:(NSInteger)metricData.responsePayloadSize().value()];
251
- }
252
-
253
- if (metricData.responseContentType() != nil) {
254
- [httpMetric setResponseContentType:metricData.responseContentType()];
255
- }
256
-
257
- [httpMetric stop];
258
-
259
- @synchronized([self class]) {
260
- [httpMetrics removeObjectForKey:@((int)id)];
261
- }
262
- #else
263
- (void)id;
264
- (void)metricData;
265
- #endif
117
+ NSNumber *httpResponseCode = metricData.httpResponseCode().has_value()
118
+ ? @((NSInteger)metricData.httpResponseCode().value())
119
+ : nil;
120
+ NSNumber *requestPayloadSize = metricData.requestPayloadSize().has_value()
121
+ ? @((NSInteger)metricData.requestPayloadSize().value())
122
+ : nil;
123
+ NSNumber *responsePayloadSize = metricData.responsePayloadSize().has_value()
124
+ ? @((NSInteger)metricData.responsePayloadSize().value())
125
+ : nil;
126
+ [RNFBPerfHelper stopHttpMetricWithId:@((int)id)
127
+ attributes:attributes
128
+ httpResponseCode:httpResponseCode
129
+ requestPayloadSize:requestPayloadSize
130
+ responsePayloadSize:responsePayloadSize
131
+ responseContentType:metricData.responseContentType()
132
+ inRegistry:httpMetrics];
266
133
  }
267
134
 
268
135
  @end
@@ -0,0 +1,68 @@
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
+ import Foundation
18
+
19
+ /**
20
+ * Subset of `FIRTrace` metric/attribute setters used by
21
+ * `-[RNFBPerfModule stopTrace:traceData:]`. Protocol-shaped so unit tests can
22
+ * stub without linking FirebasePerformance.
23
+ */
24
+ @objc public protocol RNFBPerfTraceApplying: AnyObject {
25
+ @objc(setIntValue:forMetric:)
26
+ func setIntValue(_ value: Int64, forMetric metricName: String)
27
+
28
+ @objc(setValue:forAttribute:)
29
+ func setValue(_ value: String, forAttribute attributeName: String)
30
+ }
31
+
32
+ /**
33
+ * Applies `metrics` then `attributes` dictionaries previously enumerated inline
34
+ * in `-[RNFBPerfModule stopTrace:traceData:]`.
35
+ *
36
+ * Pre-port contracts:
37
+ * - metrics: `[trace setIntValue:[value longLongValue] forMetric:metricName]`
38
+ * - attributes: `[trace setValue:value forAttribute:attributeName]`
39
+ * - nil / missing dictionaries → empty (no crash)
40
+ * - order: metrics first, then attributes
41
+ */
42
+ @objc(RNFBPerfTraceStopApplier)
43
+ public final class RNFBPerfTraceStopApplier: NSObject {
44
+ @objc(applyMetrics:attributes:to:)
45
+ public static func apply(
46
+ metrics: NSDictionary?,
47
+ attributes: NSDictionary?,
48
+ to trace: RNFBPerfTraceApplying
49
+ ) {
50
+ if let metrics {
51
+ metrics.enumerateKeysAndObjects { key, value, _ in
52
+ guard let metricName = key as? String, let number = value as? NSNumber else {
53
+ return
54
+ }
55
+ trace.setIntValue(number.int64Value, forMetric: metricName)
56
+ }
57
+ }
58
+
59
+ if let attributes {
60
+ attributes.enumerateKeysAndObjects { key, value, _ in
61
+ guard let attributeName = key as? String, let stringValue = value as? String else {
62
+ return
63
+ }
64
+ trace.setValue(stringValue, forAttribute: attributeName)
65
+ }
66
+ }
67
+ }
68
+ }
@@ -8,6 +8,12 @@
8
8
 
9
9
  /* Begin PBXBuildFile section */
10
10
  2744B98621F45429004F8E3F /* RNFBPerfModule.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2744B98521F45429004F8E3F /* RNFBPerfModule.mm */; };
11
+ RNFBPERF0000000000000001 /* RNFBPerfHandleRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF0000000000000002 /* RNFBPerfHandleRegistry.m */; };
12
+ RNFBPERF0000000000000003 /* RNFBPerfHandleRegistryStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF0000000000000004 /* RNFBPerfHandleRegistryStorage.swift */; };
13
+ RNFBPERF0000000000000006 /* RNFBPerfHttpMethodMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF0000000000000007 /* RNFBPerfHttpMethodMapper.swift */; };
14
+ RNFBPERF0000000000000008 /* RNFBPerfTraceStopApplier.swift in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF0000000000000009 /* RNFBPerfTraceStopApplier.swift */; };
15
+ RNFBPERF000000000000000A /* RNFBPerfHttpMetricStopApplier.swift in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF000000000000000B /* RNFBPerfHttpMetricStopApplier.swift */; };
16
+ RNFBPERF000000000000000C /* RNFBPerfHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF000000000000000D /* RNFBPerfHelper.m */; };
11
17
  /* End PBXBuildFile section */
12
18
 
13
19
  /* Begin PBXCopyFilesBuildPhase section */
@@ -26,6 +32,14 @@
26
32
  2744B98221F45429004F8E3F /* libRNFBPerf.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFBPerf.a; sourceTree = BUILT_PRODUCTS_DIR; };
27
33
  2744B98421F45429004F8E3F /* RNFBPerfModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFBPerfModule.h; path = RNFBPerf/RNFBPerfModule.h; sourceTree = SOURCE_ROOT; };
28
34
  2744B98521F45429004F8E3F /* RNFBPerfModule.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFBPerfModule.mm; path = RNFBPerf/RNFBPerfModule.mm; sourceTree = SOURCE_ROOT; };
35
+ RNFBPERF0000000000000005 /* RNFBPerfHandleRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFBPerfHandleRegistry.h; path = RNFBPerf/RNFBPerfHandleRegistry.h; sourceTree = SOURCE_ROOT; };
36
+ RNFBPERF0000000000000002 /* RNFBPerfHandleRegistry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFBPerfHandleRegistry.m; path = RNFBPerf/RNFBPerfHandleRegistry.m; sourceTree = SOURCE_ROOT; };
37
+ RNFBPERF0000000000000004 /* RNFBPerfHandleRegistryStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RNFBPerfHandleRegistryStorage.swift; path = RNFBPerf/RNFBPerfHandleRegistryStorage.swift; sourceTree = SOURCE_ROOT; };
38
+ RNFBPERF0000000000000007 /* RNFBPerfHttpMethodMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RNFBPerfHttpMethodMapper.swift; path = RNFBPerf/RNFBPerfHttpMethodMapper.swift; sourceTree = SOURCE_ROOT; };
39
+ RNFBPERF0000000000000009 /* RNFBPerfTraceStopApplier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RNFBPerfTraceStopApplier.swift; path = RNFBPerf/RNFBPerfTraceStopApplier.swift; sourceTree = SOURCE_ROOT; };
40
+ RNFBPERF000000000000000B /* RNFBPerfHttpMetricStopApplier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RNFBPerfHttpMetricStopApplier.swift; path = RNFBPerf/RNFBPerfHttpMetricStopApplier.swift; sourceTree = SOURCE_ROOT; };
41
+ RNFBPERF000000000000000E /* RNFBPerfHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFBPerfHelper.h; path = RNFBPerf/RNFBPerfHelper.h; sourceTree = SOURCE_ROOT; };
42
+ RNFBPERF000000000000000D /* RNFBPerfHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFBPerfHelper.m; path = RNFBPerf/RNFBPerfHelper.m; sourceTree = SOURCE_ROOT; };
29
43
  /* End PBXFileReference section */
30
44
 
31
45
  /* Begin PBXFrameworksBuildPhase section */
@@ -52,6 +66,14 @@
52
66
  children = (
53
67
  2744B9A121F48736004F8E3F /* converters */,
54
68
  2744B98C21F45C64004F8E3F /* common */,
69
+ RNFBPERF0000000000000005 /* RNFBPerfHandleRegistry.h */,
70
+ RNFBPERF0000000000000002 /* RNFBPerfHandleRegistry.m */,
71
+ RNFBPERF0000000000000004 /* RNFBPerfHandleRegistryStorage.swift */,
72
+ RNFBPERF0000000000000007 /* RNFBPerfHttpMethodMapper.swift */,
73
+ RNFBPERF0000000000000009 /* RNFBPerfTraceStopApplier.swift */,
74
+ RNFBPERF000000000000000B /* RNFBPerfHttpMetricStopApplier.swift */,
75
+ RNFBPERF000000000000000E /* RNFBPerfHelper.h */,
76
+ RNFBPERF000000000000000D /* RNFBPerfHelper.m */,
55
77
  2744B98421F45429004F8E3F /* RNFBPerfModule.h */,
56
78
  2744B98521F45429004F8E3F /* RNFBPerfModule.mm */,
57
79
  );
@@ -124,6 +146,12 @@
124
146
  isa = PBXSourcesBuildPhase;
125
147
  buildActionMask = 2147483647;
126
148
  files = (
149
+ RNFBPERF0000000000000003 /* RNFBPerfHandleRegistryStorage.swift in Sources */,
150
+ RNFBPERF0000000000000006 /* RNFBPerfHttpMethodMapper.swift in Sources */,
151
+ RNFBPERF0000000000000008 /* RNFBPerfTraceStopApplier.swift in Sources */,
152
+ RNFBPERF000000000000000A /* RNFBPerfHttpMetricStopApplier.swift in Sources */,
153
+ RNFBPERF0000000000000001 /* RNFBPerfHandleRegistry.m in Sources */,
154
+ RNFBPERF000000000000000C /* RNFBPerfHelper.m in Sources */,
127
155
  2744B98621F45429004F8E3F /* RNFBPerfModule.mm in Sources */,
128
156
  );
129
157
  runOnlyForDeploymentPostprocessing = 0;
@@ -150,6 +178,7 @@
150
178
  CODE_SIGN_STYLE = Automatic;
151
179
  COPY_PHASE_STRIP = NO;
152
180
  DEBUG_INFORMATION_FORMAT = dwarf;
181
+ DEFINES_MODULE = YES;
153
182
  GCC_C_LANGUAGE_STANDARD = gnu11;
154
183
  GCC_DYNAMIC_NO_PIC = NO;
155
184
  GCC_OPTIMIZATION_LEVEL = 0;
@@ -166,6 +195,7 @@
166
195
  PRODUCT_NAME = "$(TARGET_NAME)";
167
196
  SDKROOT = iphoneos;
168
197
  SKIP_INSTALL = YES;
198
+ SWIFT_VERSION = 5.10;
169
199
  TARGETED_DEVICE_FAMILY = "1,2";
170
200
  };
171
201
  name = Debug;
@@ -189,6 +219,7 @@
189
219
  CODE_SIGN_STYLE = Automatic;
190
220
  COPY_PHASE_STRIP = NO;
191
221
  DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
222
+ DEFINES_MODULE = YES;
192
223
  ENABLE_NS_ASSERTIONS = NO;
193
224
  GCC_C_LANGUAGE_STANDARD = gnu11;
194
225
  GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
@@ -200,6 +231,7 @@
200
231
  PRODUCT_NAME = "$(TARGET_NAME)";
201
232
  SDKROOT = iphoneos;
202
233
  SKIP_INSTALL = YES;
234
+ SWIFT_VERSION = 5.10;
203
235
  TARGETED_DEVICE_FAMILY = "1,2";
204
236
  VALIDATE_PRODUCT = YES;
205
237
  };
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ */
4
+ #import <Firebase/Firebase.h>
5
+
6
+ @implementation FIRTrace {
7
+ NSString *_name;
8
+ NSMutableDictionary<NSString *, NSNumber *> *_metrics;
9
+ NSMutableDictionary<NSString *, NSString *> *_attributes;
10
+ }
11
+
12
+ - (instancetype)initWithName:(NSString *)name {
13
+ self = [super init];
14
+ if (self) {
15
+ _name = [name copy];
16
+ _metrics = [NSMutableDictionary new];
17
+ _attributes = [NSMutableDictionary new];
18
+ }
19
+ return self;
20
+ }
21
+
22
+ - (NSString *)name {
23
+ return _name;
24
+ }
25
+
26
+ - (NSMutableDictionary<NSString *, NSNumber *> *)metrics {
27
+ return _metrics;
28
+ }
29
+
30
+ - (NSMutableDictionary<NSString *, NSString *> *)attributes {
31
+ return _attributes;
32
+ }
33
+
34
+ - (void)start {
35
+ self.startCallCount += 1;
36
+ }
37
+
38
+ - (void)stop {
39
+ self.stopCallCount += 1;
40
+ }
41
+
42
+ - (void)setIntValue:(int64_t)value forMetric:(NSString *)metricName {
43
+ _metrics[metricName] = @(value);
44
+ }
45
+
46
+ - (void)setValue:(NSString *)value forAttribute:(NSString *)attributeName {
47
+ _attributes[attributeName] = value;
48
+ }
49
+
50
+ @end
51
+
52
+ @implementation FIRHTTPMetric {
53
+ NSURL *_url;
54
+ FIRHTTPMethod _HTTPMethod;
55
+ NSMutableDictionary<NSString *, NSString *> *_attributes;
56
+ }
57
+
58
+ - (instancetype)initWithURL:(NSURL *)url HTTPMethod:(FIRHTTPMethod)httpMethod {
59
+ self = [super init];
60
+ if (self) {
61
+ _url = url;
62
+ _HTTPMethod = httpMethod;
63
+ _attributes = [NSMutableDictionary new];
64
+ _responseCode = 0;
65
+ _requestPayloadSize = 0;
66
+ _responsePayloadSize = 0;
67
+ [FIRPerformance recordCreatedHttpMetric:self];
68
+ }
69
+ return self;
70
+ }
71
+
72
+ - (NSURL *)url {
73
+ return _url;
74
+ }
75
+
76
+ - (FIRHTTPMethod)HTTPMethod {
77
+ return _HTTPMethod;
78
+ }
79
+
80
+ - (NSMutableDictionary<NSString *, NSString *> *)attributes {
81
+ return _attributes;
82
+ }
83
+
84
+ - (void)start {
85
+ self.startCallCount += 1;
86
+ }
87
+
88
+ - (void)stop {
89
+ self.stopCallCount += 1;
90
+ }
91
+
92
+ - (void)setValue:(NSString *)value forAttribute:(NSString *)attributeName {
93
+ _attributes[attributeName] = value;
94
+ }
95
+
96
+ - (void)setResponseCode:(NSInteger)responseCode {
97
+ _responseCode = responseCode;
98
+ }
99
+
100
+ - (void)setRequestPayloadSize:(NSInteger)bytes {
101
+ _requestPayloadSize = bytes;
102
+ }
103
+
104
+ - (void)setResponsePayloadSize:(NSInteger)bytes {
105
+ _responsePayloadSize = bytes;
106
+ }
107
+
108
+ - (void)setResponseContentType:(NSString *)contentType {
109
+ _responseContentType = [contentType copy];
110
+ }
111
+
112
+ @end
113
+
114
+ @implementation FIRPerformance
115
+
116
+ static FIRPerformance *sShared;
117
+ static NSMutableArray<FIRTrace *> *sCreatedTraces;
118
+ static NSMutableArray<FIRHTTPMetric *> *sCreatedHttpMetrics;
119
+
120
+ + (void)initialize {
121
+ if (self == [FIRPerformance class]) {
122
+ sCreatedTraces = [NSMutableArray new];
123
+ sCreatedHttpMetrics = [NSMutableArray new];
124
+ }
125
+ }
126
+
127
+ + (instancetype)sharedInstance {
128
+ static dispatch_once_t once;
129
+ dispatch_once(&once, ^{
130
+ sShared = [[FIRPerformance alloc] init];
131
+ });
132
+ return sShared;
133
+ }
134
+
135
+ - (FIRTrace *)traceWithName:(NSString *)name {
136
+ FIRTrace *trace = [[FIRTrace alloc] initWithName:name];
137
+ [sCreatedTraces addObject:trace];
138
+ return trace;
139
+ }
140
+
141
+ + (NSArray<FIRTrace *> *)createdTraces {
142
+ return [sCreatedTraces copy];
143
+ }
144
+
145
+ + (void)setCreatedTraces:(NSArray<FIRTrace *> *)createdTraces {
146
+ sCreatedTraces = createdTraces ? [createdTraces mutableCopy] : [NSMutableArray new];
147
+ }
148
+
149
+ + (NSArray<FIRHTTPMetric *> *)createdHttpMetrics {
150
+ return [sCreatedHttpMetrics copy];
151
+ }
152
+
153
+ + (void)setCreatedHttpMetrics:(NSArray<FIRHTTPMetric *> *)createdHttpMetrics {
154
+ sCreatedHttpMetrics =
155
+ createdHttpMetrics ? [createdHttpMetrics mutableCopy] : [NSMutableArray new];
156
+ }
157
+
158
+ + (void)recordCreatedHttpMetric:(FIRHTTPMetric *)metric {
159
+ [sCreatedHttpMetrics addObject:metric];
160
+ }
161
+
162
+ + (void)resetTestState {
163
+ FIRPerformance *shared = [self sharedInstance];
164
+ shared.dataCollectionEnabled = NO;
165
+ shared.instrumentationEnabled = NO;
166
+ [sCreatedTraces removeAllObjects];
167
+ [sCreatedHttpMetrics removeAllObjects];
168
+ }
169
+
170
+ @end
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ * Enough of Firebase Performance for compiling RNFBPerfHelper.m and
4
+ * asserting SDK call wiring without linking the real SDK.
5
+ */
6
+ #import <Foundation/Foundation.h>
7
+
8
+ typedef NS_ENUM(NSInteger, FIRHTTPMethod) {
9
+ FIRHTTPMethodGET = 0,
10
+ FIRHTTPMethodPUT = 1,
11
+ FIRHTTPMethodPOST = 2,
12
+ FIRHTTPMethodDELETE = 3,
13
+ FIRHTTPMethodHEAD = 4,
14
+ FIRHTTPMethodPATCH = 5,
15
+ FIRHTTPMethodOPTIONS = 6,
16
+ FIRHTTPMethodTRACE = 7,
17
+ FIRHTTPMethodCONNECT = 8,
18
+ };
19
+
20
+ @interface FIRTrace : NSObject
21
+
22
+ @property(nonatomic, readonly, copy) NSString *name;
23
+ @property(nonatomic, assign) NSUInteger startCallCount;
24
+ @property(nonatomic, assign) NSUInteger stopCallCount;
25
+ @property(nonatomic, readonly, strong) NSMutableDictionary<NSString *, NSNumber *> *metrics;
26
+ @property(nonatomic, readonly, strong) NSMutableDictionary<NSString *, NSString *> *attributes;
27
+
28
+ - (instancetype)initWithName:(NSString *)name;
29
+ - (void)start;
30
+ - (void)stop;
31
+ - (void)setIntValue:(int64_t)value forMetric:(NSString *)metricName;
32
+ - (void)setValue:(NSString *)value forAttribute:(NSString *)attributeName;
33
+
34
+ @end
35
+
36
+ @interface FIRHTTPMetric : NSObject
37
+
38
+ @property(nonatomic, readonly, copy) NSURL *url;
39
+ @property(nonatomic, readonly, assign) FIRHTTPMethod HTTPMethod;
40
+ @property(nonatomic, assign) NSUInteger startCallCount;
41
+ @property(nonatomic, assign) NSUInteger stopCallCount;
42
+ @property(nonatomic, assign) NSInteger responseCode;
43
+ @property(nonatomic, assign) NSInteger requestPayloadSize;
44
+ @property(nonatomic, assign) NSInteger responsePayloadSize;
45
+ @property(nonatomic, copy, nullable) NSString *responseContentType;
46
+ @property(nonatomic, readonly, strong) NSMutableDictionary<NSString *, NSString *> *attributes;
47
+
48
+ - (instancetype)initWithURL:(NSURL *)url HTTPMethod:(FIRHTTPMethod)httpMethod;
49
+ - (void)start;
50
+ - (void)stop;
51
+ - (void)setValue:(NSString *)value forAttribute:(NSString *)attributeName;
52
+ - (void)setResponseCode:(NSInteger)responseCode;
53
+ - (void)setRequestPayloadSize:(NSInteger)bytes;
54
+ - (void)setResponsePayloadSize:(NSInteger)bytes;
55
+ - (void)setResponseContentType:(NSString *)contentType;
56
+
57
+ @end
58
+
59
+ @interface FIRPerformance : NSObject
60
+
61
+ @property(nonatomic, assign) BOOL dataCollectionEnabled;
62
+ @property(nonatomic, assign) BOOL instrumentationEnabled;
63
+
64
+ + (instancetype)sharedInstance;
65
+
66
+ - (FIRTrace *)traceWithName:(NSString *)name;
67
+
68
+ /** Test seams */
69
+ @property(class, nonatomic, copy, nullable) NSArray<FIRTrace *> *createdTraces;
70
+ @property(class, nonatomic, copy, nullable) NSArray<FIRHTTPMetric *> *createdHttpMetrics;
71
+
72
+ + (void)resetTestState;
73
+ + (void)recordCreatedHttpMetric:(FIRHTTPMetric *)metric;
74
+
75
+ @end
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ */
4
+ #import <Foundation/Foundation.h>
5
+ #import <React/RCTBridgeModule.h>
6
+
7
+ @interface RNFBSharedUtils : NSObject
8
+
9
+ + (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
10
+ userInfo:(NSMutableDictionary *)userInfo;
11
+
12
+ @end