@chrisjeg/compute-module
TypeScript icon, indicating that this package has built-in type declarations

0.3.4 • Public • Published

@chrisjeg/compute-module

npm version

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.

Basic usage

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" }));

Readme

Keywords

none

Package Sidebar

Install

npm i @chrisjeg/compute-module

Weekly Downloads

28

Version

0.3.4

License

MIT

Unpacked Size

34.4 kB

Total Files

29

Last publish

Collaborators

  • chrisjeg