*Move code to types package
This commit is contained in:
parent
744ab44af8
commit
c347692490
48
src/types.ts
48
src/types.ts
|
@ -1,27 +1,4 @@
|
||||||
import { JSONSchemaType } from "ajv";
|
import { JSONSchemaType } from "ajv";
|
||||||
import { PluginApiManager } from "./plugin.js";
|
|
||||||
import { RPCServer } from "./rpc/server.js";
|
|
||||||
|
|
||||||
export interface RPCRequest {
|
|
||||||
bypassCache?: boolean;
|
|
||||||
module: string;
|
|
||||||
method: string;
|
|
||||||
data: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RPCResponse {
|
|
||||||
updated?: number;
|
|
||||||
data?: any;
|
|
||||||
error?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RPCMethod {
|
|
||||||
cacheable: boolean;
|
|
||||||
handler: (
|
|
||||||
request: RPCRequest,
|
|
||||||
sendStream: (stream: AsyncIterable<Uint8Array>) => void
|
|
||||||
) => Promise<RPCResponse | null>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const RPC_REQUEST_SCHEMA: JSONSchemaType<RPCRequest> = {
|
export const RPC_REQUEST_SCHEMA: JSONSchemaType<RPCRequest> = {
|
||||||
|
@ -42,28 +19,3 @@ export const RPC_REQUEST_SCHEMA: JSONSchemaType<RPCRequest> = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface StreamFileResponse {
|
|
||||||
data?: Uint8Array;
|
|
||||||
done: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PluginAPI {
|
|
||||||
config: any;
|
|
||||||
registerMethod: (methodName: string, method: RPCMethod) => void;
|
|
||||||
loadPlugin: PluginApiManager["loadPlugin"];
|
|
||||||
getMethods: RPCServer["getMethods"];
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PluginFunction = (api: PluginAPI) => Promise<void>;
|
|
||||||
|
|
||||||
export interface Plugin {
|
|
||||||
name: string;
|
|
||||||
plugin: PluginFunction;
|
|
||||||
exports?: any;
|
|
||||||
default?: Plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type RPCStreamHandler = (
|
|
||||||
stream: AsyncIterable<Uint8Array>
|
|
||||||
) => Promise<RPCResponse>;
|
|
||||||
|
|
Loading…
Reference in New Issue