Convert Flipper plugin "Network" to TypeScript

Summary: _typescript_

Reviewed By: danielbuechele

Differential Revision: D17053118

fbshipit-source-id: 1ad6e9db7e6338165070c782ab9e7d2d600a62b7
This commit is contained in:
Chaiwat Ekkaewnumchai
2019-09-05 02:46:27 -07:00
committed by Facebook Github Bot
parent 4f671847ba
commit 4781f04ca4
6 changed files with 57 additions and 58 deletions

View File

@@ -11,7 +11,7 @@ import type {
Header, Header,
Insights, Insights,
RetryInsights, RetryInsights,
} from './types.js'; } from './types.tsx';
import { import {
Component, Component,

View File

@@ -6,7 +6,7 @@
*/ */
import {convertRequestToCurlCommand} from '../utils.js'; import {convertRequestToCurlCommand} from '../utils.js';
import type {Request} from '../types.js'; import type {Request} from '../types.tsx';
test('convertRequestToCurlCommand: simple GET', () => { test('convertRequestToCurlCommand: simple GET', () => {
const request: Request = { const request: Request = {

View File

@@ -26,7 +26,7 @@ import {
SearchableTable, SearchableTable,
FlipperPlugin, FlipperPlugin,
} from 'flipper'; } from 'flipper';
import type {Request, RequestId, Response} from './types.js'; import type {Request, RequestId, Response} from './types.tsx';
import { import {
convertRequestToCurlCommand, convertRequestToCurlCommand,
getHeaderValue, getHeaderValue,
@@ -150,7 +150,6 @@ export default class extends FlipperPlugin<State, *, PersistedState> {
persistedState: PersistedState, persistedState: PersistedState,
): Array<Notification> => { ): Array<Notification> => {
const responses = persistedState ? persistedState.responses || [] : []; const responses = persistedState ? persistedState.responses || [] : [];
// $FlowFixMe Object.values returns Array<mixed>, but we know it is Array<Response>
const r: Array<Response> = Object.values(responses); const r: Array<Response> = Object.values(responses);
return ( return (

View File

@@ -1,53 +0,0 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
export type RequestId = string;
export type Request = {|
id: RequestId,
timestamp: number,
method: string,
url: string,
headers: Array<Header>,
data: ?string,
|};
export type Response = {|
id: RequestId,
timestamp: number,
status: number,
reason: string,
headers: Array<Header>,
data: ?string,
insights: ?Insights,
|};
export type Header = {|
key: string,
value: string,
|};
export type RetryInsights = {|
count: number,
limit: number,
timeSpent: number,
|};
export type Insights = {|
dnsLookupTime: ?number,
connectTime: ?number,
sslHandshakeTime: ?number,
preTransferTime: ?number,
redirectsTime: ?number,
timeToFirstByte: ?number,
transferTime: ?number,
postProcessingTime: ?number,
// Amount of transferred data can be different from total size of payload.
bytesTransfered: ?number,
transferSpeed: ?number,
retries: ?RetryInsights,
|};

View File

@@ -0,0 +1,53 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
export type RequestId = string;
export type Request = {
id: RequestId;
timestamp: number;
method: string;
url: string;
headers: Array<Header>;
data: string | null | undefined;
};
export type Response = {
id: RequestId;
timestamp: number;
status: number;
reason: string;
headers: Array<Header>;
data: string | null | undefined;
insights: Insights | null | undefined;
};
export type Header = {
key: string;
value: string;
};
export type RetryInsights = {
count: number;
limit: number;
timeSpent: number;
};
export type Insights = {
dnsLookupTime: number | null | undefined;
connectTime: number | null | undefined;
sslHandshakeTime: number | null | undefined;
preTransferTime: number | null | undefined;
redirectsTime: number | null | undefined;
timeToFirstByte: number | null | undefined;
transferTime: number | null | undefined;
postProcessingTime: number | null | undefined;
// Amount of transferred data can be different from total size of payload.
bytesTransfered: number | null | undefined;
transferSpeed: number | null | undefined;
retries: RetryInsights | null | undefined;
};

View File

@@ -7,7 +7,7 @@
// $FlowFixMe // $FlowFixMe
import pako from 'pako'; import pako from 'pako';
import type {Request, Response, Header} from './types.js'; import type {Request, Response, Header} from './types.tsx';
export function getHeaderValue(headers: Array<Header>, key: string): string { export function getHeaderValue(headers: Array<Header>, key: string): string {
for (const header of headers) { for (const header of headers) {