@react-native-firebase/perf 24.1.1 → 25.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 (67) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/module/HttpMetric.js +91 -0
  3. package/dist/module/HttpMetric.js.map +1 -0
  4. package/dist/module/MetricWithAttributes.js +51 -0
  5. package/dist/module/MetricWithAttributes.js.map +1 -0
  6. package/{lib → dist/module}/ScreenTrace.js +3 -6
  7. package/dist/module/ScreenTrace.js.map +1 -0
  8. package/{lib → dist/module}/Trace.js +8 -23
  9. package/dist/module/Trace.js.map +1 -0
  10. package/dist/module/index.js +23 -0
  11. package/dist/module/index.js.map +1 -0
  12. package/dist/module/modular.js +93 -0
  13. package/dist/module/modular.js.map +1 -0
  14. package/{lib/index.js → dist/module/namespaced.js} +28 -72
  15. package/dist/module/namespaced.js.map +1 -0
  16. package/dist/module/package.json +1 -0
  17. package/dist/module/types/internal.js +4 -0
  18. package/dist/module/types/internal.js.map +1 -0
  19. package/dist/module/types/namespaced.js +65 -0
  20. package/dist/module/types/namespaced.js.map +1 -0
  21. package/dist/module/types/perf.js +4 -0
  22. package/dist/module/types/perf.js.map +1 -0
  23. package/dist/module/version.js +5 -0
  24. package/dist/module/version.js.map +1 -0
  25. package/dist/typescript/lib/HttpMetric.d.ts +21 -0
  26. package/dist/typescript/lib/HttpMetric.d.ts.map +1 -0
  27. package/dist/typescript/lib/MetricWithAttributes.d.ts +11 -0
  28. package/dist/typescript/lib/MetricWithAttributes.d.ts.map +1 -0
  29. package/dist/typescript/lib/ScreenTrace.d.ts +12 -0
  30. package/dist/typescript/lib/ScreenTrace.d.ts.map +1 -0
  31. package/dist/typescript/lib/Trace.d.ts +17 -0
  32. package/dist/typescript/lib/Trace.d.ts.map +1 -0
  33. package/dist/typescript/lib/index.d.ts +6 -0
  34. package/dist/typescript/lib/index.d.ts.map +1 -0
  35. package/dist/typescript/lib/modular.d.ts +43 -0
  36. package/dist/typescript/lib/modular.d.ts.map +1 -0
  37. package/dist/typescript/lib/namespaced.d.ts +11 -0
  38. package/dist/typescript/lib/namespaced.d.ts.map +1 -0
  39. package/dist/typescript/lib/types/internal.d.ts +45 -0
  40. package/dist/typescript/lib/types/internal.d.ts.map +1 -0
  41. package/dist/typescript/lib/types/namespaced.d.ts +128 -0
  42. package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
  43. package/dist/typescript/lib/types/perf.d.ts +72 -0
  44. package/dist/typescript/lib/types/perf.d.ts.map +1 -0
  45. package/dist/typescript/lib/version.d.ts +2 -0
  46. package/dist/typescript/lib/version.d.ts.map +1 -0
  47. package/dist/typescript/package.json +1 -0
  48. package/lib/{HttpMetric.js → HttpMetric.ts} +21 -8
  49. package/lib/{MetricWithAttributes.js → MetricWithAttributes.ts} +14 -4
  50. package/lib/ScreenTrace.ts +59 -0
  51. package/lib/Trace.ts +112 -0
  52. package/lib/index.ts +25 -0
  53. package/lib/modular.ts +116 -0
  54. package/lib/namespaced.ts +200 -0
  55. package/lib/types/internal.ts +80 -0
  56. package/lib/types/namespaced.ts +162 -0
  57. package/lib/types/perf.ts +99 -0
  58. package/lib/version.ts +2 -0
  59. package/package.json +40 -8
  60. package/plugin/tsconfig.json +2 -1
  61. package/plugin/tsconfig.tsbuildinfo +1 -1
  62. package/tsconfig.json +20 -0
  63. package/typedoc.json +2 -2
  64. package/lib/index.d.ts +0 -583
  65. package/lib/modular/index.d.ts +0 -89
  66. package/lib/modular/index.js +0 -103
  67. package/lib/version.js +0 -2
@@ -17,23 +17,33 @@
17
17
 
18
18
  import { hasOwnProperty, isString } from '@react-native-firebase/app/dist/module/common';
19
19
 
20
+ import type { RNFBPerfNativeModule } from './types/internal';
21
+
20
22
  let id = 0;
21
23
 
22
24
  export default class MetricWithAttributes {
23
- constructor(native) {
25
+ protected readonly native: RNFBPerfNativeModule;
26
+ protected readonly _id: number;
27
+ protected _attributes: Record<string, string>;
28
+
29
+ constructor(native: RNFBPerfNativeModule) {
24
30
  this._id = id++;
25
31
  this.native = native;
26
32
  this._attributes = {};
27
33
  }
28
34
 
29
- getAttribute(attribute) {
35
+ getAttribute(attribute: string): string | null {
30
36
  if (!isString(attribute)) {
31
37
  throw new Error("firebase.perf.*.getAttribute(*) 'attribute' must be a string.");
32
38
  }
33
- return this._attributes[attribute] || null;
39
+ return hasOwnProperty(this._attributes, attribute) ? this._attributes[attribute]! : null;
40
+ }
41
+
42
+ getAttributes(): Record<string, string> {
43
+ return Object.assign({}, this._attributes);
34
44
  }
35
45
 
36
- putAttribute(attribute, value) {
46
+ putAttribute(attribute: string, value: string): void {
37
47
  // TODO(VALIDATION): attribute: no leading or trailing whitespace, no leading underscore '_'
38
48
  if (!isString(attribute) || attribute.length > 40) {
39
49
  throw new Error(
@@ -0,0 +1,59 @@
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 { isIOS } from '@react-native-firebase/app/dist/module/common';
19
+
20
+ import type { RNFBPerfNativeModule } from './types/internal';
21
+
22
+ let id = 0;
23
+
24
+ export default class ScreenTrace {
25
+ readonly native: RNFBPerfNativeModule;
26
+ private readonly _identifier: string;
27
+ private readonly _id: number;
28
+ private _started: boolean;
29
+ private _stopped: boolean;
30
+
31
+ constructor(native: RNFBPerfNativeModule, identifier: string) {
32
+ this.native = native;
33
+ this._identifier = identifier;
34
+ this._id = id++;
35
+ this._started = false;
36
+ this._stopped = false;
37
+ }
38
+
39
+ start(): Promise<null> {
40
+ if (isIOS) {
41
+ return Promise.reject(new Error('Custom screentraces are currently not supported on iOS.'));
42
+ }
43
+ if (this._started) {
44
+ return Promise.resolve(null);
45
+ }
46
+ this._started = true;
47
+
48
+ return this.native.startScreenTrace(this._id, this._identifier);
49
+ }
50
+
51
+ stop(): Promise<null> {
52
+ if (!this._started || this._stopped) {
53
+ return Promise.resolve(null);
54
+ }
55
+ this._stopped = true;
56
+
57
+ return this.native.stopScreenTrace(this._id);
58
+ }
59
+ }
package/lib/Trace.ts ADDED
@@ -0,0 +1,112 @@
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 { hasOwnProperty, isNumber, isString } from '@react-native-firebase/app/dist/module/common';
19
+
20
+ import MetricWithAttributes from './MetricWithAttributes';
21
+
22
+ import type { RNFBPerfNativeModule } from './types/internal';
23
+
24
+ export default class Trace extends MetricWithAttributes {
25
+ private readonly _identifier: string;
26
+ private readonly _metrics: Record<string, number>;
27
+ private _started: boolean;
28
+ private _stopped: boolean;
29
+
30
+ constructor(native: RNFBPerfNativeModule, identifier: string) {
31
+ super(native);
32
+ this._identifier = identifier;
33
+
34
+ this._metrics = {};
35
+
36
+ this._started = false;
37
+ this._stopped = false;
38
+ }
39
+
40
+ getMetric(metricName: string): number {
41
+ if (!isString(metricName)) {
42
+ throw new Error("firebase.perf.Trace.getMetric(*) 'metricName' must be a string.");
43
+ }
44
+
45
+ return hasOwnProperty(this._metrics, metricName) ? this._metrics[metricName]! : 0;
46
+ }
47
+
48
+ getMetrics(): Record<string, number> {
49
+ return Object.assign({}, this._metrics);
50
+ }
51
+
52
+ putMetric(metricName: string, value: number): void {
53
+ // TODO(VALIDATION): metricName: no leading or trailing whitespace, no leading underscore '_' character, max length is 32 characters
54
+ // TODO(VALIDATION): value: >= 0
55
+ if (!isString(metricName)) {
56
+ throw new Error("firebase.perf.Trace.putMetric(*, _) 'metricName' must be a string.");
57
+ }
58
+
59
+ if (!isNumber(value)) {
60
+ throw new Error("firebase.perf.Trace.putMetric(_, *) 'value' must be a number.");
61
+ }
62
+
63
+ this._metrics[metricName] = value;
64
+ }
65
+
66
+ incrementMetric(metricName: string, num?: number): void {
67
+ // TODO(VALIDATION): metricName: no leading or trailing whitespace, no leading underscore '_' character, max length is 32 characters
68
+ // TODO(VALIDATION): value: >= 0
69
+ if (!isString(metricName)) {
70
+ throw new Error("firebase.perf.Trace.incrementMetric(*, _) 'metricName' must be a string.");
71
+ }
72
+
73
+ const incrementBy = num ?? 1;
74
+
75
+ if (!isNumber(incrementBy)) {
76
+ throw new Error("firebase.perf.Trace.incrementMetric(_, *) 'num' must be a number.");
77
+ }
78
+
79
+ this._metrics[metricName] = this.getMetric(metricName) + incrementBy;
80
+ }
81
+
82
+ removeMetric(metric: string): void {
83
+ if (!isString(metric)) {
84
+ throw new Error("firebase.perf.Trace.removeMetric(*) 'metric' must be a string.");
85
+ }
86
+
87
+ delete this._metrics[metric];
88
+ }
89
+
90
+ start(): Promise<null> {
91
+ if (this._started) {
92
+ return Promise.resolve(null);
93
+ }
94
+ this._started = true;
95
+
96
+ return this.native.startTrace(this._id, this._identifier);
97
+ }
98
+
99
+ stop(): Promise<null> {
100
+ if (this._stopped) {
101
+ return Promise.resolve(null);
102
+ }
103
+ this._stopped = true;
104
+
105
+ const traceData = {
106
+ metrics: Object.assign({}, this._metrics),
107
+ attributes: Object.assign({}, this._attributes),
108
+ };
109
+
110
+ return this.native.stopTrace(this._id, traceData);
111
+ }
112
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,25 @@
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
+ export type * from './types/perf';
19
+
20
+ export * from './modular';
21
+
22
+ export type { FirebasePerformanceTypes } from './types/namespaced';
23
+
24
+ export * from './namespaced';
25
+ export { default } from './namespaced';
package/lib/modular.ts ADDED
@@ -0,0 +1,116 @@
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
+ }
@@ -0,0 +1,200 @@
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
+ >;
@@ -0,0 +1,80 @@
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 {
19
+ FirebasePerformance,
20
+ HttpMetric,
21
+ HttpMethod,
22
+ PerformanceTrace,
23
+ ScreenTrace,
24
+ } from './perf';
25
+
26
+ export type PerfModularDeprecationArg = string;
27
+
28
+ /**
29
+ * Namespaced perf instance used by modular entrypoints; methods accept an optional modular deprecation token.
30
+ */
31
+ export interface PerfInternal extends FirebasePerformance {
32
+ /**
33
+ * @deprecated Prefer assigning {@link FirebasePerformance.dataCollectionEnabled}.
34
+ */
35
+ setPerformanceCollectionEnabled(enabled: boolean): Promise<null>;
36
+ newTrace(name: string, deprecationArg?: PerfModularDeprecationArg): PerformanceTrace;
37
+ startTrace(name: string, deprecationArg?: PerfModularDeprecationArg): Promise<PerformanceTrace>;
38
+ newScreenTrace(screenName: string, deprecationArg?: PerfModularDeprecationArg): ScreenTrace;
39
+ startScreenTrace(
40
+ screenName: string,
41
+ deprecationArg?: PerfModularDeprecationArg,
42
+ ): Promise<ScreenTrace>;
43
+ newHttpMetric(
44
+ url: string,
45
+ httpMethod: HttpMethod,
46
+ deprecationArg?: PerfModularDeprecationArg,
47
+ ): HttpMetric;
48
+ }
49
+
50
+ export interface RNFBPerfTraceData {
51
+ metrics: Record<string, number>;
52
+ attributes: Record<string, string>;
53
+ }
54
+
55
+ export interface RNFBPerfHttpMetricData {
56
+ attributes: Record<string, string>;
57
+ httpResponseCode?: number;
58
+ requestPayloadSize?: number;
59
+ responsePayloadSize?: number;
60
+ responseContentType?: string;
61
+ }
62
+
63
+ export interface RNFBPerfNativeModule {
64
+ isPerformanceCollectionEnabled: boolean;
65
+ isInstrumentationEnabled: boolean;
66
+ setPerformanceCollectionEnabled(enabled: boolean): Promise<null>;
67
+ instrumentationEnabled(enabled: boolean): Promise<null>;
68
+ startTrace(id: number, identifier: string): Promise<null>;
69
+ stopTrace(id: number, traceData: RNFBPerfTraceData): Promise<null>;
70
+ startHttpMetric(id: number, url: string, httpMethod: HttpMethod): Promise<null>;
71
+ stopHttpMetric(id: number, metricData: RNFBPerfHttpMetricData): Promise<null>;
72
+ startScreenTrace(id: number, identifier: string): Promise<null>;
73
+ stopScreenTrace(id: number): Promise<null>;
74
+ }
75
+
76
+ declare module '@react-native-firebase/app/dist/module/internal/NativeModules' {
77
+ interface ReactNativeFirebaseNativeModules {
78
+ RNFBPerfModule: RNFBPerfNativeModule;
79
+ }
80
+ }