*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:
parent
9768e2dc9d
commit
648c366b6d
|
@ -2,5 +2,10 @@
|
|||
"name": "@lumeweb/relay-types",
|
||||
"version": "0.1.0",
|
||||
"main": "dist",
|
||||
"type": "module"
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.7.16",
|
||||
"express": "^4.18.1",
|
||||
"loglevel": "^1.8.0"
|
||||
}
|
||||
}
|
||||
|
|
49
src/index.ts
49
src/index.ts
|
@ -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 {
|
||||
bypassCache?: boolean;
|
||||
module: string;
|
||||
|
@ -29,6 +34,20 @@ export interface PluginAPI {
|
|||
registerMethod: (methodName: string, method: RPCMethod) => void;
|
||||
loadPlugin: (moduleName: string) => Promise<Plugin>;
|
||||
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>;
|
||||
|
@ -43,3 +62,33 @@ export interface Plugin {
|
|||
export type RPCStreamHandler = (
|
||||
stream: AsyncIterable<Uint8Array>
|
||||
) => 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue