Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
👋 Hi there! At Stackblitz we rely heavily on Comlink (as you might already be aware), and we're big fans, thanks for you work!
Recently, we've encountered a situation where one of our Comlink endpoints is not fully under our control (see @webcontainer/api). In this scenario, we would welcome some extra assurance that what we expose is exactly what we intend to, and nothing else. You could argue that Comlink, being about seamless RPC, might not 100% be the best fit for it, but we went ahead anyway because of its ergonomics 😅
This patch is more or less what we've added to a internal fork for the purposes of "hardening"
Comlink.expose()
. It is somewhat nice b/c it only affects the "server" side endpoint, while the "client" endpoint does not need any new codepath.I am not fully convinced this belongs in Comlink proper, but we wanted to show it to you anyway. We are actually considering moving this "hardening" to a external
Proxy
that wraps our exposed objects. One disadvantage of doing that is that, AFAICS, when Comlink traverses apath
for a exposed object, we would need to create proxies on the fly.This adds
ExposeOptions
toComlink.expose()
.options.spec
allows you to specify a "spec" of the object being exposed, a description of what the other side of the endpoint can do with the object. For instance, with the following spec:the other side of the endpoint cannot perform certain actions: