Remove WOS dependency from wshrpc (#329)

The frontend wshserver.ts had a weird circuitous dependency on wos.ts,
which was unnecessary. This moves the misplaced functions into wshrpc.ts
and updates the generation logic.
This commit is contained in:
Evan Simkowitz
2024-09-05 13:17:35 -07:00
committed by GitHub
parent 779d2d35b7
commit debbed7003
5 changed files with 96 additions and 95 deletions
-52
View File
@@ -3,7 +3,6 @@
// WaveObjectStore
import { sendRpcCommand } from "@/app/store/wshrpc";
import { getWebServerEndpoint } from "@/util/endpoints";
import { fetch } from "@/util/fetchutil";
import * as jotai from "jotai";
@@ -11,8 +10,6 @@ import * as React from "react";
import { atoms, globalStore } from "./global";
import * as services from "./services";
const IsElectron = true;
type WaveObjectDataItemType<T extends WaveObj> = {
value: T;
loading: boolean;
@@ -125,53 +122,6 @@ function callBackendService(service: string, method: string, args: any[], noUICo
return prtn;
}
function wshServerRpcHelper_responsestream(
command: string,
data: any,
opts: RpcOpts
): AsyncGenerator<any, void, boolean> {
if (opts?.noresponse) {
throw new Error("noresponse not supported for responsestream calls");
}
const msg: RpcMessage = {
command: command,
data: data,
reqid: crypto.randomUUID(),
};
if (opts?.timeout) {
msg.timeout = opts.timeout;
}
if (opts?.route) {
msg.route = opts.route;
}
const rpcGen = sendRpcCommand(msg);
return rpcGen;
}
function wshServerRpcHelper_call(command: string, data: any, opts: RpcOpts): Promise<any> {
const msg: RpcMessage = {
command: command,
data: data,
};
if (!opts?.noresponse) {
msg.reqid = crypto.randomUUID();
}
if (opts?.timeout) {
msg.timeout = opts.timeout;
}
if (opts?.route) {
msg.route = opts.route;
}
const rpcGen = sendRpcCommand(msg);
if (rpcGen == null) {
return null;
}
const respMsgPromise = rpcGen.next(true); // pass true to force termination of rpc after 1 response (not streaming)
return respMsgPromise.then((msg: IteratorResult<any, void>) => {
return msg.value;
});
}
const waveObjectValueCache = new Map<string, WaveObjectValue<any>>();
function clearWaveObjectCache() {
@@ -344,6 +294,4 @@ export {
updateWaveObject,
updateWaveObjects,
useWaveObjectValue,
wshServerRpcHelper_call,
wshServerRpcHelper_responsestream,
};