nx-functions
v1.1.0
Published
Function registry + standard execution contract (boolean + baggage) for Node.js/TS/JS runtimes.
Maintainers
Readme
nx-functions
Function registry + standard execution contract (boolean + baggage) for Node.js/TS/JS runtimes.
Usage (TypeScript)
import { FunctionRegistry } from "nx-functions";
const reg = new FunctionRegistry();
reg.register("cond.existsContent", async (ctx) => {
const has = typeof ctx.content === "string" && ctx.content.trim().length > 0;
return { passed: has, baggage: { length: ctx.content?.length ?? 0 } };
});
const res = await reg.execute("cond.existsContent", {
input: { source: "email" },
content: "hello"
});
console.log(res.passed, res.baggage);Usage (JavaScript - CommonJS)
const { FunctionRegistry } = require("x-functions");
const reg = new FunctionRegistry();
reg.register("cond.eq", (ctx) => {
const { a, b } = ctx.args;
return { passed: a === b, baggage: { a, b } };
});
reg.execute("cond.eq", {
input: { tenantId: "t1" },
args: { a: 1, b: 1 }
}).then(console.log);Input Contract
ctx.inputis required and must be an object.ctx.contentis optional and must be a string if provided.
