Simple implementation of the Compute Module interface. Definitions are generated using typebox allowing the Compute Module to register functions at runtime, while maintaining typesafety at compile time.
This library is dependent on "Runtime V1", if not provided this will not work.
import { ComputeModule } from "@chrisjeg/compute-module";
import { Type } from "@sinclair/typebox";
const myModule = new ComputeModule({
logger: console,
definitions: {
addOne: {
input: Type.Object({
value: Type.Number(),
}),
output: Type.Object({ value: Type.Number() }),
},
stringify: {
input: Type.Object({
value: Type.Any(),
}),
output: Type.String(),
},
},
});
myModule
.on("addOne", async (n) => n + 1)
.on("stringify", async (n) => "" + n)
.default(() => ({ error: "Unsupported query name" }));