Deno/typescript
Deno runtime
The DenoRuntime allows you to run lightweight and short-lived typescript function in a sandboxed environment. Permissions can be customized per typegraph and by default only include some HTTPs domains. It's a great way to implement custom logic and functions. All typegraphs can lazily spawn a web worker and get an incredible cold-start and continuous performance thanks to the V8 engine powering Deno.
Loading...
Instead of providing the typescript code inline, we can also point to a file on disk:
# my_typegraph.py
from typegraph import typegraph, Policy, t, Graph
from typegraph.runtimes.deno import DenoRuntime
@typegraph()
def deno(g: Graph):
public = Policy.public()
deno = DenoRuntime()
g.expose(
public,
add=deno.import_(
t.struct({"a": t.number(), "b": t.number()}),
t.number(),
module="main.ts", # path to ts file
name="doAddition", # function export from ts file to use
),
)
Where main.ts looks like:
// main.ts
interface AddInput {
a: number;
b: number;
}
export function doAddition({ a, b }: AddInput) {
return a + b;
}