Work on #508 (thin client)
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
import { KVStore } from "../../plugos/lib/kv_store.ts";
|
||||
import { storeSyscalls } from "../../plugos/syscalls/store.ts";
|
||||
import { proxySyscalls } from "../../plugos/syscalls/transport.ts";
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
|
||||
// DEPRECATED, use store directly
|
||||
export function clientStoreSyscalls(
|
||||
storeCalls: SysCallMapping,
|
||||
db: KVStore,
|
||||
): SysCallMapping {
|
||||
const localStoreCalls = storeSyscalls(db);
|
||||
return proxySyscalls(
|
||||
["clientStore.get", "clientStore.set", "clientStore.delete"],
|
||||
(ctx, name, ...args) => {
|
||||
return storeCalls[name.replace("clientStore.", "store.")](ctx, ...args);
|
||||
return localStoreCalls[name.replace("clientStore.", "store.")](
|
||||
ctx,
|
||||
...args,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { Client } from "../client.ts";
|
||||
import { proxySyscalls } from "./util.ts";
|
||||
|
||||
export function indexProxySyscalls(client: Client): SysCallMapping {
|
||||
return proxySyscalls(client, [
|
||||
"index.set",
|
||||
"index.batchSet",
|
||||
"index.delete",
|
||||
"index.get",
|
||||
"index.queryPrefix",
|
||||
"index.clearPageIndexForPage",
|
||||
"index.deletePrefixForPage",
|
||||
"index.clearPageIndex",
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { SysCallMapping } from "../../plugos/system.ts";
|
||||
import type { Client } from "../client.ts";
|
||||
import { proxySyscalls } from "./util.ts";
|
||||
|
||||
export function storeProxySyscalls(client: Client): SysCallMapping {
|
||||
return proxySyscalls(client, [
|
||||
"store.delete",
|
||||
"store.deletePrefix",
|
||||
"store.deleteAll",
|
||||
"store.set",
|
||||
"store.batchSet",
|
||||
"store.batchDelete",
|
||||
"store.batchGet",
|
||||
"store.get",
|
||||
"store.has",
|
||||
"store.queryPrefix",
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { SyscallResponse } from "../../server/rpc.ts";
|
||||
import { Client } from "../client.ts";
|
||||
|
||||
export function proxySyscalls(client: Client, names: string[]): SysCallMapping {
|
||||
const syscalls: SysCallMapping = {};
|
||||
for (const name of names) {
|
||||
syscalls[name] = async (_ctx, ...args: any[]) => {
|
||||
if (!client.remoteSpacePrimitives) {
|
||||
throw new Error("Not supported");
|
||||
}
|
||||
const resp = await client.remoteSpacePrimitives.authenticatedFetch(
|
||||
`${client.remoteSpacePrimitives.url}/.rpc`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
operation: "syscall",
|
||||
name,
|
||||
args,
|
||||
}),
|
||||
},
|
||||
);
|
||||
const result: SyscallResponse = await resp.json();
|
||||
if (result.error) {
|
||||
console.error("Remote syscall error", result.error);
|
||||
throw new Error(result.error);
|
||||
} else {
|
||||
return result.result;
|
||||
}
|
||||
};
|
||||
}
|
||||
return syscalls;
|
||||
}
|
||||
Reference in New Issue
Block a user