Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remote module runner proxy #22

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
hi-ogawa committed Apr 14, 2024
commit f42c6460692ac5453d56cac6b6151116c38efc61
54 changes: 50 additions & 4 deletions packages/remote-runner/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// https://github.com/cloudflare/workers-sdk/blame/ad1d056cb2710b790ff5d4532e9f694e099c27e2/packages/miniflare/src/plugins/core/proxy/client.ts

export class ProxyClient {
constructor() {}
}

// proxy only get/apply?
// everything async

@@ -12,3 +8,53 @@ export class ProxyClient {
// import
// primitives
// function

// const client = new ProxyClient({ post });
// const proxy = client.getRootProxy();
// (await (await proxy.runner).import)
// const mod = await proxy.runner.import("/src/entry");
// const res = await mod.default(req);

// const server = new ProxyServer({ on, root: { runner } });

export type ProxyTarget = {
address: number;
};

// direct value to return
export type ProxyResult =
| {
type: "value";
value: unknown;
}
| {
type: "proxy";
address: number;
};

export class ProxyClient {
constructor() {}

async invokeCall(t: ProxyTarget, args: unknown[]) {
t;
args;
}

// sync fetch...?
async invokeGet(t: ProxyTarget, p: keyof any) {
t;
p;
}

createProxy(t: ProxyTarget) {
const client = this;
return new Proxy(() => {}, {
apply(_target, _thisArg, argArray) {
return client.invokeCall(t, argArray);
},
get(_target, p, _receiver) {
return client.invokeGet(t, p);
},
});
}
}
16 changes: 16 additions & 0 deletions packages/remote-runner/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
// https://github.com/cloudflare/workers-sdk/blame/ad1d056cb2710b790ff5d4532e9f694e099c27e2/packages/miniflare/src/workers/core/proxy.worker.ts#

import type { ProxyTarget } from "./client";

export class ProxyServer {
heap = new Map<number, unknown>();
heapInv = new WeakMap<object, number>();

constructor() {}

async handleCall(t: ProxyTarget, args: unknown[]) {
t;
args;
t.address;
this.heap.get(t.address);
}

async handleGet(t: ProxyTarget, p: keyof any) {
this.heap.get(t.address);
t;
p;
}
}