[perm][ts] Create performance monitoring types

This commit is contained in:
Elliot Hesp 2018-07-18 12:08:04 +01:00
parent 2c776a60e8
commit 2ba6e15ea7
1 changed files with 131 additions and 1 deletions

132
lib/index.d.ts vendored
View File

@ -54,7 +54,7 @@ declare module 'react-native-firebase' {
RNFirebase.notifications.Notifications,
RNFirebase.notifications.NotificationsStatics
>;
// perf: FirebaseModuleAndStatics<RNFirebase.perf.Perf>;
perf: FirebaseModuleAndStatics<RNFirebase.perf.Perf>;
storage: FirebaseModuleAndStatics<RNFirebase.storage.Storage>;
// utils: FirebaseModuleAndStatics<RNFirebase.utils.Utils>;
initializeApp(options: Firebase.Options, name: string): App;
@ -1567,6 +1567,136 @@ declare module 'react-native-firebase' {
}
}
namespace perf {
type HttpMethod =
| 'CONNECT'
| 'DELETE'
| 'GET'
| 'HEAD'
| 'OPTIONS'
| 'PATCH'
| 'POST'
| 'PUT'
| 'TRACE';
interface Perf {
/**
* Globally enable or disable performance monitoring.
*/
setPerformanceCollectionEnabled(enabled: boolean): void;
/**
* Returns a new Trace instance.
*/
newTrace(trace: string): Trace;
/**
* Returns a new HTTP Metric instance.
*/
newHttpMetric(url: string, httpMethod: HttpMethod): HttpMetric;
}
interface Trace {
/**
* Return an attribute by name, or null if it does not exist.
*/
getAttribute(attribute: string): Promise<string | null>;
/**
* Return an object of key-value attributes.
*/
getAttributes(): Promise<Object>;
/**
* Get a metric by name. Returns 0 if it does not exist.
*/
getMetric(metricName: string): Promise<number>;
/**
* Increment a metric by name and value.
*/
incrementMetric(metricName: string, incrementBy: number): Promise<null>;
/**
* Set an attribute. Returns true if it was set, false if it was not.
*/
putAttribute(attribute: string, value: string): Promise<true | false>;
/**
* Set a metric.
*/
putMetric(metricName: string, value: number): Promise<null>;
/**
* Remove an attribute by name.
*/
removeAttribute(attribute: string): Promise<null>;
/**
* Start a Trace instance.
*/
start(): Promise<null>;
/**
* Stop a Trace instance.
*/
stop(): Promise<null>;
}
interface HttpMetric {
/**
* Return an attribute by name, or null if it does not exist.
*/
getAttribute(attribute: string): Promise<string | null>;
/**
* Return an object of key-value attributes.
*/
getAttributes(): Promise<Object>
/**
* Set an attribute. Returns true if it was set, false if it was not.
*/
putAttribute(attribute: string, value: string): Promise<true | false>;
/**
* Remove an attribute by name.
*/
removeAttribute(attribute: string): Promise<null>;
/**
* Set the request HTTP response code.
*/
setHttpResponseCode(code: number): Promise<null>;
/**
* Set the request payload size, in bytes.
*/
setRequestPayloadSize(bytes: number): Promise<null>;
/**
* Set the response content type.
*/
setResponseContentType(type: string): Promise<null>;
/**
* Set the response payload size, in bytes.
*/
setResponsePayloadSize(bytes: number): Promise<null>;
/**
* Start a HttpMetric instance.
*/
start(): Promise<null>;
/**
* Stop a HttpMetric instance.
*/
stop(): Promise<null>;
}
}
namespace crashlytics {
interface Crashlytics {
/**