Move server add-on interfaces to flipper-common
Reviewed By: antonk52 Differential Revision: D34169419 fbshipit-source-id: 69fcc8da7d98f59818fbb5b486a488f19830cd81
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b9294645d3
commit
04eab80c98
@@ -7,9 +7,45 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {FlipperServerCommands} from './server-types';
|
||||
import {
|
||||
FlipperServer,
|
||||
FlipperServerCommands,
|
||||
FlipperServerEvents,
|
||||
} from './server-types';
|
||||
|
||||
export interface ServerAddOnControls {
|
||||
start: FlipperServerCommands['plugins-server-add-on-start'];
|
||||
stop: FlipperServerCommands['plugins-server-add-on-stop'];
|
||||
}
|
||||
|
||||
// TODO: Share with js-flipper? Is it worth it?
|
||||
export type FlipperPluginReceiverRes =
|
||||
| object
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| undefined
|
||||
| void;
|
||||
|
||||
export type FlipperPluginReceiver = (
|
||||
data: any,
|
||||
) => FlipperPluginReceiverRes | Promise<FlipperPluginReceiverRes>;
|
||||
|
||||
export interface ServerAddOnPluginConnection {
|
||||
send(method: string, params: unknown): void;
|
||||
receive(method: string, receiver: FlipperPluginReceiver): void;
|
||||
}
|
||||
|
||||
export interface FlipperServerForServerAddOn extends FlipperServer {
|
||||
emit(
|
||||
event: 'plugins-server-add-on-message',
|
||||
payload: FlipperServerEvents['plugins-server-add-on-message'],
|
||||
): void;
|
||||
}
|
||||
|
||||
export type ServerAddOnCleanup = () => Promise<void>;
|
||||
export type ServerAddOn = (
|
||||
connection: ServerAddOnPluginConnection,
|
||||
{flipperServer}: {flipperServer: FlipperServerForServerAddOn},
|
||||
) => Promise<ServerAddOnCleanup>;
|
||||
|
||||
@@ -51,3 +51,4 @@ export * from './clientUtils';
|
||||
export * from './settings';
|
||||
export * from './PluginDetails';
|
||||
export * from './doctor';
|
||||
export * from './ServerAddOn';
|
||||
|
||||
@@ -109,6 +109,7 @@ test('Correct top level API exposed', () => {
|
||||
"FileDescriptor",
|
||||
"FileEncoding",
|
||||
"FlipperLib",
|
||||
"FlipperServerForServerAddOn",
|
||||
"HighlightManager",
|
||||
"Idler",
|
||||
"InteractionReport",
|
||||
@@ -119,6 +120,8 @@ test('Correct top level API exposed', () => {
|
||||
"Notification",
|
||||
"PluginClient",
|
||||
"RemoteServerContext",
|
||||
"ServerAddOn",
|
||||
"ServerAddOnPluginConnection",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
@@ -152,4 +152,7 @@ export {
|
||||
DeviceLogLevel,
|
||||
Logger,
|
||||
CrashLog,
|
||||
ServerAddOn,
|
||||
ServerAddOnPluginConnection,
|
||||
FlipperServerForServerAddOn,
|
||||
} from 'flipper-common';
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
BundledPluginDetails,
|
||||
DownloadablePluginDetails,
|
||||
ExecuteMessage,
|
||||
FlipperServerForServerAddOn,
|
||||
InstalledPluginDetails,
|
||||
} from 'flipper-common';
|
||||
import {getStaticPath} from '../utils/pathUtils';
|
||||
@@ -32,7 +33,6 @@ import {
|
||||
installPluginFromNpm,
|
||||
} from 'flipper-plugin-lib';
|
||||
import {ServerAddOn} from './ServerAddOn';
|
||||
import {FlipperServerForServerAddOn} from './ServerAddOnDesktopToModuleConnection';
|
||||
|
||||
const maxInstalledPluginVersionsToKeep = 2;
|
||||
|
||||
|
||||
@@ -10,20 +10,15 @@
|
||||
import assert from 'assert';
|
||||
import {assertNotNull} from '../comms/Utilities';
|
||||
import {
|
||||
ServerAddOnDesktopToModuleConnection,
|
||||
FlipperServerForServerAddOn,
|
||||
} from './ServerAddOnDesktopToModuleConnection';
|
||||
import {
|
||||
ServerAddOnModuleToDesktopConnection,
|
||||
ServerAddOnPluginConnection,
|
||||
} from './ServerAddOnModuleToDesktopConnection';
|
||||
ServerAddOnCleanup,
|
||||
ServerAddOn as ServerAddOnFn,
|
||||
} from 'flipper-common';
|
||||
import {ServerAddOnDesktopToModuleConnection} from './ServerAddOnDesktopToModuleConnection';
|
||||
import {ServerAddOnModuleToDesktopConnection} from './ServerAddOnModuleToDesktopConnection';
|
||||
|
||||
type ServerAddOnCleanup = () => Promise<void>;
|
||||
interface ServerAddOnModule {
|
||||
serverAddOn?: (
|
||||
connection: ServerAddOnPluginConnection,
|
||||
{flipperServer}: {flipperServer: FlipperServerForServerAddOn},
|
||||
) => Promise<ServerAddOnCleanup>;
|
||||
serverAddOn?: ServerAddOnFn;
|
||||
}
|
||||
|
||||
const loadPlugin = (_pluginName: string): ServerAddOnModule => {
|
||||
|
||||
@@ -11,27 +11,13 @@ import assert from 'assert';
|
||||
import {
|
||||
ClientResponseType,
|
||||
ExecuteMessage,
|
||||
FlipperServer,
|
||||
FlipperServerEvents,
|
||||
FlipperServerForServerAddOn,
|
||||
} from 'flipper-common';
|
||||
import {ServerDevice} from '../devices/ServerDevice';
|
||||
import {
|
||||
ServerAddOnModuleToDesktopConnection,
|
||||
ServerAddOnModuleToDesktopConnectionEvents,
|
||||
} from './ServerAddOnModuleToDesktopConnection';
|
||||
|
||||
export interface FlipperServerForServerAddOn extends FlipperServer {
|
||||
emit(
|
||||
event: 'plugins-server-add-on-message',
|
||||
payload: FlipperServerEvents['plugins-server-add-on-message'],
|
||||
): void;
|
||||
registerDevice(device: ServerDevice): void;
|
||||
unregisterDevice(serial: string): void;
|
||||
getDevice(serial: string): ServerDevice;
|
||||
getDeviceSerials(): string[];
|
||||
getDevices(): ServerDevice[];
|
||||
}
|
||||
|
||||
export class ServerAddOnDesktopToModuleConnection {
|
||||
constructor(
|
||||
private readonly moduleToDesktopConnection: ServerAddOnModuleToDesktopConnection,
|
||||
|
||||
@@ -8,32 +8,19 @@
|
||||
*/
|
||||
|
||||
import EventEmitter from 'events';
|
||||
import {ResponseMessage, ClientErrorType, ExecuteMessage} from 'flipper-common';
|
||||
import {
|
||||
ResponseMessage,
|
||||
ClientErrorType,
|
||||
ExecuteMessage,
|
||||
ServerAddOnPluginConnection,
|
||||
FlipperPluginReceiver,
|
||||
} from 'flipper-common';
|
||||
import {safeJSONStringify} from '../utils/safeJSONStringify';
|
||||
|
||||
// TODO: Share with js-flipper? Is it worth it?
|
||||
type FlipperPluginReceiverRes =
|
||||
| object
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| undefined
|
||||
| void;
|
||||
|
||||
type FlipperPluginReceiver = (
|
||||
data: any,
|
||||
) => FlipperPluginReceiverRes | Promise<FlipperPluginReceiverRes>;
|
||||
|
||||
export type ServerAddOnModuleToDesktopConnectionEvents = {
|
||||
message: ExecuteMessage;
|
||||
};
|
||||
|
||||
export interface ServerAddOnPluginConnection {
|
||||
send(method: string, params: unknown): void;
|
||||
receive(method: string, receiver: FlipperPluginReceiver): void;
|
||||
}
|
||||
|
||||
export class ServerAddOnModuleToDesktopConnection
|
||||
extends EventEmitter
|
||||
implements ServerAddOnPluginConnection
|
||||
|
||||
Reference in New Issue
Block a user