react-native-macos/flow-typed/npm/ws_v7.x.x.js

344 строки
8.7 KiB
JavaScript
Исходник Обычный вид История

Migrate cli-plugin-metro into repo (#38795) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38795 ## Context RFC: Decoupling Flipper from React Native core: https://github.com/react-native-community/discussions-and-proposals/pull/641 ## Changes Inits new package `react-native/community-cli-plugin`. This migrates [`react-native-community/cli-plugin-metro`](https://github.com/react-native-community/cli/tree/main/packages/cli-plugin-metro) into the React Native repo, to enable faster iteration by the React Native core team. Specifically: - This package contains several `metro` dependencies, which when removed from CLI will no longer require us to ship new CLI releases to get Metro patches and features to users. - This package contains the `start`, `bundle`, and `ram-bundle` commands (central to the React Native development experience), for which we have incoming debugging-related changes. - This package now **only** exports commands to be attached via a RN CLI plugin. With this move, we're aiming to **internalise** the default implementations of these dev commands within React Native — other RN CLI plugins can continue to override these, but must do so wholesale. (See also the recent fix for this: https://github.com/react-native-community/cli/pull/1999.) In V15: - (Microsoft feedback) Re-export `unstable_buildBundleWithConfig`, marking as unstable. This gives us a time buffer to consider how we repackage this functionality in future. The package source has been converted from TypeScript to Flow, with a number of new `flow-typed/` defs added to meet type coverage requirements. ## To dos - For now, we aren't removing the existing [`react-native-community/cli-plugin-metro`](https://github.com/react-native-community/cli/tree/main/packages/cli-plugin-metro) source — until later PRs consolidate this move by changing dependencies in the `react-native` package. - **Exported API is reduced!**: I'm working with szymonrybczak to decouple references from RN CLI packages https://github.com/react-native-community/cli/pull/2021. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D46801501 fbshipit-source-id: 7f6b72941a69f487fb437768cdba125a9aa3418d
2023-08-10 21:34:36 +03:00
/**
* 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
* @format
* @oncall react_native
*/
declare type ws$PerMessageDeflateOptions = {
serverNoContextTakeover?: boolean,
clientNoContextTakeover?: boolean,
serverMaxWindowBits?: boolean | number,
clientMaxWindowBits?: boolean | number,
zlibDeflateOptions?: zlib$options,
zlibInflateOptions?: zlib$options,
threshold?: number,
concurrencyLimit?: number,
isServer?: boolean,
maxPayload?: number,
};
/* $FlowFixMe[incompatible-extend] - Found with Flow v0.143.1 upgrade
* "on" definition failing with string is incompatible with string literal */
declare class ws$WebSocketServer extends events$EventEmitter {
/**
* Create a `WebSocketServer` instance.
*/
constructor(
options: {
backlog?: number,
clientTracking?: boolean,
handleProtocols?: () => mixed,
host?: string,
maxPayload?: number,
noServer?: boolean,
path?: string,
perMessageDeflate?: boolean | ws$PerMessageDeflateOptions,
port?: number,
server?: http$Server | https$Server,
verifyClient?: () => mixed,
},
callback?: () => mixed,
): this;
/**
* Emitted when the server closes.
*/
on(event: 'close', () => mixed): this;
/**
* Emitted when the handshake is complete.
*/
on(
event: 'connection',
(socket: ws$WebSocket, request: http$IncomingMessage<>) => mixed,
): this;
/**
* Emitted when an error occurs on the underlying server.
*/
on(event: 'error', (error: Error) => mixed): this;
/**
* Emitted before the response headers are written to the socket as part of
* the handshake.
*/
on(
event: 'headers',
(headers: Array<string>, request: http$IncomingMessage<>) => mixed,
): this;
/**
* Emitted when the underlying server has been bound.
*/
on(event: 'listening', () => mixed): this;
/**
* Returns the bound address, the address family name, and port of the server
* as reported by the operating system if listening on an IP socket.
* If the server is listening on a pipe or UNIX domain socket, the name is
* returned as a string.
*/
address(): null | string | {port?: number, family?: string, address?: string};
/**
* A set that stores all connected clients. Please note that this property is
* only added when the `clientTracking` is truthy.
*/
clients: Set<ws$WebSocket>;
/**
* Close the server.
*/
close(callback?: () => mixed): void;
/**
* Handle a HTTP Upgrade request.
*/
handleUpgrade(
request: http$IncomingMessage<>,
socket: net$Socket,
head: Buffer,
callback: (?ws$WebSocket) => mixed,
): void;
/**
* See if a given request should be handled by this server instance.
*/
shouldHandle(request: http$IncomingMessage<>): boolean;
}
declare type ws$WebSocketOptions = {
followRedirects?: boolean,
handshakeTimeout?: number,
maxRedirects?: number,
perMessageDeflate?: boolean | ws$PerMessageDeflateOptions,
protocolVersion?: number,
origin?: string,
maxPayload?: number,
...requestOptions,
agent?: boolean | http$Agent<> | http$Agent<tls$TLSSocket>,
createConnection?:
| ((options: net$connectOptions, callback?: () => mixed) => net$Socket)
| ((options: tls$connectOptions, callback?: () => mixed) => tls$TLSSocket),
};
declare type ws$CloseListener = (code: number, reason: string) => mixed;
declare type ws$ErrorListener = (error: Error) => mixed;
declare type ws$MessageListener = (
data: string | Buffer | ArrayBuffer | Array<Buffer>,
) => mixed;
declare type ws$OpenListener = () => mixed;
declare type ws$PingListener = (Buffer) => mixed;
declare type ws$PongListener = (Buffer) => mixed;
declare type ws$UnexpectedResponseListener = (
request: http$ClientRequest<>,
response: http$IncomingMessage<>,
) => mixed;
declare type ws$UpgradeListener = (response: http$IncomingMessage<>) => mixed;
/* $FlowFixMe[incompatible-extend] - Found with Flow v0.143.1 upgrade
* "on" definition failing with string is incompatible with string literal */
declare class ws$WebSocket extends events$EventEmitter {
static Server: typeof ws$WebSocketServer;
static createWebSocketStream: (
WebSocket: ws$WebSocket,
options?: duplexStreamOptions,
) => stream$Duplex;
static CONNECTING: number;
static OPEN: number;
static CLOSING: number;
static CLOSED: number;
/**
* Create a `WebSocket` instance.
*/
constructor(
address: string | URL,
protocols?: string | Array<string>,
options?: ws$WebSocketOptions,
): this;
constructor(address: string | URL, options: ws$WebSocketOptions): this;
/*
* Emitted when the connection is closed.
*/
on('close', ws$CloseListener): this;
/*
* Emitted when an error occurs.
*/
on('error', ws$ErrorListener): this;
/*
* Emitted when a message is received from the server.
*/
on('message', ws$MessageListener): this;
/*
* Emitted when the connection is established.
*/
on('open', ws$OpenListener): this;
/*
* Emitted when a ping is received from the server.
*/
on('ping', ws$PingListener): this;
/*
* Emitted when a pong is received from the server.
*/
on('pong', ws$PongListener): this;
/*
* Emitted when the server response is not the expected one,
* for example a 401 response.
*/
on('unexpected-response', ws$UnexpectedResponseListener): this;
/*
* Emitted when response headers are received from the server as part of the
* handshake.
*/
on('upgrade', ws$UpgradeListener): this;
/**
* Register an event listener emulating the `EventTarget` interface.
*/
addEventListener(
type: 'close',
listener: ws$CloseListener,
options?: {once?: boolean},
): this;
addEventListener(
type: 'error',
listener: ws$ErrorListener,
options?: {once?: boolean},
): this;
addEventListener(
type: 'message',
listener: ws$MessageListener,
options?: {once?: boolean},
): this;
addEventListener(
type: 'open',
listener: ws$OpenListener,
options?: {once?: boolean},
): this;
addEventListener(
type: 'ping',
listener: ws$PingListener,
options?: {once?: boolean},
): this;
addEventListener(
type: 'pong',
listener: ws$PongListener,
options?: {once?: boolean},
): this;
addEventListener(
type: 'unexpected-response',
ws$UnexpectedResponseListener,
options?: {once?: boolean},
): this;
addEventListener(
type: 'upgrade',
listener: ws$UpgradeListener,
options?: {once?: boolean},
): this;
/**
* A string indicating the type of binary data being transmitted by the
* connection.
*/
binaryType: string;
/**
* The number of bytes of data that have been queued using calls to send()
* but not yet transmitted to the network.
*/
bufferedAmount: number;
/**
* Initiate a closing handshake.
*/
close(code?: number, reason?: string): void;
/**
* The negotiated extensions.
*/
extensions: string;
/**
* Send a ping.
*/
ping(data?: any, mask?: boolean, callback?: () => mixed): void;
ping(data: any, callback: () => mixed): void;
ping(callback: () => mixed): void;
/**
* Send a pong.
*/
pong(data?: any, mask?: boolean, callback?: () => mixed): void;
pong(data: any, callback: () => mixed): void;
pong(callback: () => mixed): void;
/**
* The subprotocol selected by the server.
*/
protocol: string;
/**
* The current state of the connection.
*/
readyState: number;
/**
* Removes an event listener emulating the `EventTarget` interface.
*/
removeEventListener(type: 'close', listener: ws$CloseListener): this;
removeEventListener(type: 'error', listener: ws$ErrorListener): this;
removeEventListener(type: 'message', listener: ws$MessageListener): this;
removeEventListener(type: 'open', listener: ws$OpenListener): this;
removeEventListener(type: 'ping', listener: ws$PingListener): this;
removeEventListener(type: 'pong', listener: ws$PongListener): this;
removeEventListener(
type: 'unexpected-response',
ws$UnexpectedResponseListener,
): this;
removeEventListener(type: 'upgrade', listener: ws$UpgradeListener): this;
/**
* Send a data message.
*/
send(
data?: any,
options?: {
compress?: boolean,
binary?: boolean,
mask?: boolean,
fin?: boolean,
},
callback?: () => mixed,
): void;
send(data: any, callback: () => mixed): void;
/**
* Forcibly close the connection.
*/
terminate(): void;
}
declare module 'ws' {
declare module.exports: typeof ws$WebSocket;
}
declare module 'ws/lib/websocket-server' {
declare module.exports: typeof ws$WebSocketServer;
}