-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci] Improve CDP Flow types (#42816)
Summary: Some refactoring to formalise CDP protocol types (`protocol.js` is aligned with [Chrome's `protocol.d.ts` source](https://github.com/ChromeDevTools/devtools-protocol/blob/master/types/protocol.d.ts)), and to demarcate these from other types in the Inspector Proxy prototol. Changelog: [Internal] Reviewed By: robhogan Differential Revision: D53352243
- Loading branch information
1 parent
608029a
commit d325e19
Showing
5 changed files
with
168 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/dev-middleware/src/inspector-proxy/cdp-types/messages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import type {Commands, Events} from './protocol'; | ||
|
||
// Note: A CDP event is a JSON-RPC notification with no `id` member. | ||
export type CDPEvent<TEvent: $Keys<Events> = 'unknown'> = $ReadOnly<{ | ||
method: TEvent, | ||
params: Events[TEvent], | ||
}>; | ||
|
||
export type CDPRequest<TCommand: $Keys<Commands> = 'unknown'> = $ReadOnly<{ | ||
method: TCommand, | ||
params: Commands[TCommand]['paramsType'], | ||
id: number, | ||
}>; | ||
|
||
export type CDPResponse<TCommand: $Keys<Commands> = 'unknown'> = | ||
| $ReadOnly<{ | ||
result: Commands[TCommand]['resultType'], | ||
id: number, | ||
}> | ||
| $ReadOnly<{ | ||
error: CDPRequestError, | ||
id: number, | ||
}>; | ||
|
||
export type CDPRequestError = $ReadOnly<{ | ||
code: number, | ||
message: string, | ||
data?: mixed, | ||
}>; | ||
|
||
export type CDPClientMessage = | ||
| CDPRequest<'Debugger.getScriptSource'> | ||
| CDPRequest<'Debugger.setBreakpointByUrl'> | ||
| CDPRequest<>; |
88 changes: 88 additions & 0 deletions
88
packages/dev-middleware/src/inspector-proxy/cdp-types/protocol.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
// Adapted from https://github.com/ChromeDevTools/devtools-protocol/blob/master/types/protocol.d.ts | ||
|
||
export interface Debugger { | ||
GetScriptSourceParams: $ReadOnly<{ | ||
/** | ||
* Id of the script to get source for. | ||
*/ | ||
scriptId: string, | ||
}>; | ||
|
||
GetScriptSourceResult: $ReadOnly<{ | ||
/** | ||
* Script source (empty in case of Wasm bytecode). | ||
*/ | ||
scriptSource: string, | ||
|
||
/** | ||
* Wasm bytecode. (Encoded as a base64 string when passed over JSON) | ||
*/ | ||
bytecode?: string, | ||
}>; | ||
|
||
SetBreakpointByUrlParams: $ReadOnly<{ | ||
/** | ||
* Line number to set breakpoint at. | ||
*/ | ||
lineNumber: number, | ||
|
||
/** | ||
* URL of the resources to set breakpoint on. | ||
*/ | ||
url?: string, | ||
|
||
/** | ||
* Regex pattern for the URLs of the resources to set breakpoints on. Either `url` or | ||
* `urlRegex` must be specified. | ||
*/ | ||
urlRegex?: string, | ||
|
||
/** | ||
* Script hash of the resources to set breakpoint on. | ||
*/ | ||
scriptHash?: string, | ||
|
||
/** | ||
* Offset in the line to set breakpoint at. | ||
*/ | ||
columnNumber?: number, | ||
|
||
/** | ||
* Expression to use as a breakpoint condition. When specified, debugger will only stop on the | ||
* breakpoint if this expression evaluates to true. | ||
*/ | ||
condition?: string, | ||
}>; | ||
} | ||
|
||
export type Events = { | ||
[method: string]: mixed, | ||
}; | ||
|
||
export type Commands = { | ||
'Debugger.getScriptSource': { | ||
paramsType: Debugger['GetScriptSourceParams'], | ||
resultType: Debugger['GetScriptSourceResult'], | ||
}, | ||
|
||
'Debugger.setBreakpointByUrl': { | ||
paramsType: Debugger['SetBreakpointByUrlParams'], | ||
resultType: void, | ||
}, | ||
|
||
[method: string]: { | ||
paramsType: mixed, | ||
resultType: mixed, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters