*Add plugin api for ssl, approuter, and logger

*Move IndependentFile types to types repo as it will be used by plugins
This commit is contained in:
Derrick Hammer 2022-09-09 03:20:31 -04:00
parent 9768e2dc9d
commit 648c366b6d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 55 additions and 1 deletions

View File

@ -2,5 +2,10 @@
"name": "@lumeweb/relay-types", "name": "@lumeweb/relay-types",
"version": "0.1.0", "version": "0.1.0",
"main": "dist", "main": "dist",
"type": "module" "type": "module",
"devDependencies": {
"@types/node": "^18.7.16",
"express": "^4.18.1",
"loglevel": "^1.8.0"
}
} }

View File

@ -1,3 +1,8 @@
import tls from "tls";
import type { Logger } from "loglevel";
import type { Ed25519Keypair, Err } from "libskynet";
import type express from "express";
export interface RPCRequest { export interface RPCRequest {
bypassCache?: boolean; bypassCache?: boolean;
module: string; module: string;
@ -29,6 +34,20 @@ export interface PluginAPI {
registerMethod: (methodName: string, method: RPCMethod) => void; registerMethod: (methodName: string, method: RPCMethod) => void;
loadPlugin: (moduleName: string) => Promise<Plugin>; loadPlugin: (moduleName: string) => Promise<Plugin>;
getMethods: () => string[]; getMethods: () => string[];
ssl: {
setContext: (context: tls.SecureContext) => void;
getContext: () => tls.SecureContext;
getSaved: (retry: boolean) => Promise<boolean | SslData>;
set: (cert: IndependentFileSmall, key: IndependentFileSmall) => void;
get: () => SslData;
save: () => Promise<void>;
};
appRouter: {
get: () => express.Router;
set: (newRouter: express.Router) => void;
reset: () => void;
};
logger: Logger;
} }
export type PluginFunction = (api: PluginAPI) => Promise<void>; export type PluginFunction = (api: PluginAPI) => Promise<void>;
@ -43,3 +62,33 @@ export interface Plugin {
export type RPCStreamHandler = ( export type RPCStreamHandler = (
stream: AsyncIterable<Uint8Array> stream: AsyncIterable<Uint8Array>
) => Promise<RPCResponse>; ) => Promise<RPCResponse>;
export type OverwriteDataFn = (newData: Uint8Array) => Promise<Err>;
export type ReadDataFn = () => Promise<[Uint8Array, Err]>;
export interface IndependentFileSmallMetadata {
largestHistoricSize: bigint;
}
export interface IndependentFileSmall {
dataKey: Uint8Array;
fileData: Uint8Array;
inode: string;
keypair: Ed25519Keypair;
metadata: IndependentFileSmallMetadata;
revision: bigint;
seed: Uint8Array;
skylink: string;
viewKey: string;
overwriteData: OverwriteDataFn;
readData: ReadDataFn;
}
export interface SslData {
cert?: IndependentFileSmall;
key?: IndependentFileSmall;
}