TypeScript processes
A TypeScript Process is a serverless function whose
body you write as an execute(context) function. The platform runs it in an isolated
per-domain worker.
The shape
Section titled “The shape”async function execute(context: ProcessContext): Promise<any> { const { inputs, trigger } = context; // your logic here return { ok: true };}context.inputs— the resolved inputs (tag values, SQL results).context.trigger— information about what triggered this run.
The injected SDK
Section titled “The injected SDK”Inside a TypeScript process, the MACHHUB SDK is available as a global sdk — there
is no import and no initialization to do:
async function execute(context: ProcessContext): Promise<any> { // Read records directly — `sdk` is injected. const readings = await sdk.collection('myapp.readings').getAll();
const avg = readings.reduce((sum, r) => sum + Number(r.value), 0) / (readings.length || 1);
// You can also publish a tag, write records, etc. await sdk.tag.publish('myapp/readings/avg', avg);
return { count: readings.length, avg };}This is the main advantage of TypeScript processes over Python: full SDK access (collections, tags, historian) from inside the function.
HTTP triggers
Section titled “HTTP triggers”If the process has an http trigger, its JSON request body is merged into
context.inputs, and it is reachable at:
POST /process/<slug>Content-Type: application/json
{ "field": "value" }async function execute(context: ProcessContext): Promise<any> { const { field } = context.inputs; // came from the HTTP body return { received: field };}Tag-change triggers
Section titled “Tag-change triggers”A tag_change trigger does not automatically inject the new value. Add a tag
input so the value appears in context.inputs. See the Process model.
Deploy & invoke
Section titled “Deploy & invoke”Author and deploy from the MACHHUB Designer; invoke from an app
with sdk.processes.execute. See Invoking processes.