commontoolsinc / system

A constellation of Common tools
3 stars 0 forks source link

feat: Implement host callbacks in basic world, and remove async handling #241

Closed jsantell closed 4 days ago

jsantell commented 4 days ago

Introduces a generic globalThis.hostCallback() in the JS VM that executes a function on the host with the signature host_callback(String) -> Result<String, String>, marshalling JS in and out. This would allow us to implement https://github.com/commontoolsinc/labs/issues/217.

   export const run = (input) => {
      input.foo = input.foo + 1;

      input.reflect = globalThis.hostCallback({
        test: 123,
      });
      return input;
    }

Given the default, reflecting callback host_callback(input: String) -> Result<String, String> { Ok(input) }, calling with {"foo":9} would result in the response {"foo":10,"reflect":{"test":123}}