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
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {FlipperServerCommands} from './server-types';
|
import {
|
||||||
|
FlipperServer,
|
||||||
|
FlipperServerCommands,
|
||||||
|
FlipperServerEvents,
|
||||||
|
} from './server-types';
|
||||||
|
|
||||||
export interface ServerAddOnControls {
|
export interface ServerAddOnControls {
|
||||||
start: FlipperServerCommands['plugins-server-add-on-start'];
|
start: FlipperServerCommands['plugins-server-add-on-start'];
|
||||||
stop: FlipperServerCommands['plugins-server-add-on-stop'];
|
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 './settings';
|
||||||
export * from './PluginDetails';
|
export * from './PluginDetails';
|
||||||
export * from './doctor';
|
export * from './doctor';
|
||||||
|
export * from './ServerAddOn';
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ test('Correct top level API exposed', () => {
|
|||||||
"FileDescriptor",
|
"FileDescriptor",
|
||||||
"FileEncoding",
|
"FileEncoding",
|
||||||
"FlipperLib",
|
"FlipperLib",
|
||||||
|
"FlipperServerForServerAddOn",
|
||||||
"HighlightManager",
|
"HighlightManager",
|
||||||
"Idler",
|
"Idler",
|
||||||
"InteractionReport",
|
"InteractionReport",
|
||||||
@@ -119,6 +120,8 @@ test('Correct top level API exposed', () => {
|
|||||||
"Notification",
|
"Notification",
|
||||||
"PluginClient",
|
"PluginClient",
|
||||||
"RemoteServerContext",
|
"RemoteServerContext",
|
||||||
|
"ServerAddOn",
|
||||||
|
"ServerAddOnPluginConnection",
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -152,4 +152,7 @@ export {
|
|||||||
DeviceLogLevel,
|
DeviceLogLevel,
|
||||||
Logger,
|
Logger,
|
||||||
CrashLog,
|
CrashLog,
|
||||||
|
ServerAddOn,
|
||||||
|
ServerAddOnPluginConnection,
|
||||||
|
FlipperServerForServerAddOn,
|
||||||
} from 'flipper-common';
|
} from 'flipper-common';
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
BundledPluginDetails,
|
BundledPluginDetails,
|
||||||
DownloadablePluginDetails,
|
DownloadablePluginDetails,
|
||||||
ExecuteMessage,
|
ExecuteMessage,
|
||||||
|
FlipperServerForServerAddOn,
|
||||||
InstalledPluginDetails,
|
InstalledPluginDetails,
|
||||||
} from 'flipper-common';
|
} from 'flipper-common';
|
||||||
import {getStaticPath} from '../utils/pathUtils';
|
import {getStaticPath} from '../utils/pathUtils';
|
||||||
@@ -32,7 +33,6 @@ import {
|
|||||||
installPluginFromNpm,
|
installPluginFromNpm,
|
||||||
} from 'flipper-plugin-lib';
|
} from 'flipper-plugin-lib';
|
||||||
import {ServerAddOn} from './ServerAddOn';
|
import {ServerAddOn} from './ServerAddOn';
|
||||||
import {FlipperServerForServerAddOn} from './ServerAddOnDesktopToModuleConnection';
|
|
||||||
|
|
||||||
const maxInstalledPluginVersionsToKeep = 2;
|
const maxInstalledPluginVersionsToKeep = 2;
|
||||||
|
|
||||||
|
|||||||
@@ -10,20 +10,15 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import {assertNotNull} from '../comms/Utilities';
|
import {assertNotNull} from '../comms/Utilities';
|
||||||
import {
|
import {
|
||||||
ServerAddOnDesktopToModuleConnection,
|
|
||||||
FlipperServerForServerAddOn,
|
FlipperServerForServerAddOn,
|
||||||
} from './ServerAddOnDesktopToModuleConnection';
|
ServerAddOnCleanup,
|
||||||
import {
|
ServerAddOn as ServerAddOnFn,
|
||||||
ServerAddOnModuleToDesktopConnection,
|
} from 'flipper-common';
|
||||||
ServerAddOnPluginConnection,
|
import {ServerAddOnDesktopToModuleConnection} from './ServerAddOnDesktopToModuleConnection';
|
||||||
} from './ServerAddOnModuleToDesktopConnection';
|
import {ServerAddOnModuleToDesktopConnection} from './ServerAddOnModuleToDesktopConnection';
|
||||||
|
|
||||||
type ServerAddOnCleanup = () => Promise<void>;
|
|
||||||
interface ServerAddOnModule {
|
interface ServerAddOnModule {
|
||||||
serverAddOn?: (
|
serverAddOn?: ServerAddOnFn;
|
||||||
connection: ServerAddOnPluginConnection,
|
|
||||||
{flipperServer}: {flipperServer: FlipperServerForServerAddOn},
|
|
||||||
) => Promise<ServerAddOnCleanup>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadPlugin = (_pluginName: string): ServerAddOnModule => {
|
const loadPlugin = (_pluginName: string): ServerAddOnModule => {
|
||||||
|
|||||||
@@ -11,27 +11,13 @@ import assert from 'assert';
|
|||||||
import {
|
import {
|
||||||
ClientResponseType,
|
ClientResponseType,
|
||||||
ExecuteMessage,
|
ExecuteMessage,
|
||||||
FlipperServer,
|
FlipperServerForServerAddOn,
|
||||||
FlipperServerEvents,
|
|
||||||
} from 'flipper-common';
|
} from 'flipper-common';
|
||||||
import {ServerDevice} from '../devices/ServerDevice';
|
|
||||||
import {
|
import {
|
||||||
ServerAddOnModuleToDesktopConnection,
|
ServerAddOnModuleToDesktopConnection,
|
||||||
ServerAddOnModuleToDesktopConnectionEvents,
|
ServerAddOnModuleToDesktopConnectionEvents,
|
||||||
} from './ServerAddOnModuleToDesktopConnection';
|
} 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 {
|
export class ServerAddOnDesktopToModuleConnection {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly moduleToDesktopConnection: ServerAddOnModuleToDesktopConnection,
|
private readonly moduleToDesktopConnection: ServerAddOnModuleToDesktopConnection,
|
||||||
|
|||||||
@@ -8,32 +8,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import EventEmitter from 'events';
|
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';
|
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 = {
|
export type ServerAddOnModuleToDesktopConnectionEvents = {
|
||||||
message: ExecuteMessage;
|
message: ExecuteMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ServerAddOnPluginConnection {
|
|
||||||
send(method: string, params: unknown): void;
|
|
||||||
receive(method: string, receiver: FlipperPluginReceiver): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ServerAddOnModuleToDesktopConnection
|
export class ServerAddOnModuleToDesktopConnection
|
||||||
extends EventEmitter
|
extends EventEmitter
|
||||||
implements ServerAddOnPluginConnection
|
implements ServerAddOnPluginConnection
|
||||||
|
|||||||
Reference in New Issue
Block a user