Functions

Functions overview

TypeScript and JavaScript functions that run in an isolated managed runtime — never inside the CubiBase engine. Four trigger types, one execution pipeline, one set of quotas and logs.

What CubiBase Functions are

A CubiBase Function is your code, deployed as an immutable version to a managed Node.js 22 runtime (AWS Lambda in production; an isolated child process in local development). The engine manages deployments, triggers, secrets and metering, but never executes your code in its own process.

TriggerWhen it runsDelivery
HTTPA request hits https://{slug}.api.cubibase.com/functions/{name}Synchronous request/response
DatabaseAfter an INSERT, UPDATE or DELETE commits on a subscribed tableAsync, at-least-once, retried
StorageAfter an object is created, updated or deleted in a subscribed bucketAsync, at-least-once, retried
ScheduledA cron expression fires (UTC or a configured timezone)Async, at-least-once, retried

All four categories produce the same invocation envelope and pass through the same authorization, quota reservation, concurrency control, metering and logging. There is no per-trigger side channel that skips enforcement.

The programming model

Default-export an async handler (request, ctx). Return a web Response, a { status, headers, body } object, a plain object (serialized as JSON), a string, or nothing (204).

index.ts
// index.ts — default-export an async (request, ctx) handler.
export default async function handler(request: any, ctx: any) {
  const name = request.query.name ?? 'world';
  console.log('Saying hello to', name);
  return new Response(JSON.stringify({
    message: `Hello, ${name}!`,
    invocationId: ctx.invocationId,
  }), { status: 200, headers: { 'content-type': 'application/json' } });
}
On requestMeaning
method, url, headers, queryThe HTTP request as received by the gateway
bodyA Buffer with the EXACT raw request bytes (HTTP triggers) — safe for signature verification
json() / text()Parse helpers over the raw body
eventThe structured payload for database, storage and scheduled triggers
triggerhttp, database, storage, schedule or test
authThe verified caller context (kind and user id, when authenticated)
invocationId, correlationIdIdentifiers that appear in Executions & Logs
On ctxMeaning
ctx.db.from(table)Scoped select / insert / update / delete with equality filters, through the project’s own roles and policies. JWT-authenticated HTTP calls run under the caller’s row-level security; trusted database, storage and scheduled invocations run with the project’s developer-level access
ctx.db.query(sql, params)Read-only parameterized SQL through the project’s SQL role
ctx.storage.from(bucket)upload, download, getMetadata, remove, list — through the same Storage quotas and events
ctx.envYour environment variables and secrets for this deployment (frozen snapshot)
ctx.log, console.*Captured into the bounded, redacted execution log
ctx.waitUntil(promise)Background work with at most 5 extra seconds after the response

Deployments and versions

  • Editing source in the Console changes the working copy only. Deploy builds and publishes an immutable version.
  • Bundling uses esbuild to transform your code — build scripts are never executed and no per-deploy npm install runs.
  • Imports are limited to Node built-ins and a pinned dependency allowlist (currently the official Stripe SDK). Other imports fail the build with a clear error.
  • Artifacts are stored in a private S3 bucket; the database keeps only references and checksums.
  • A successful deploy atomically switches the active pointer. A failed deploy never interrupts the version that is serving.
  • Activate any earlier ready version to roll back.

In the Console

Open a project and choose Functions. My Functions lists every function with its triggers, deployment state and error rate. The editor has tabs for Source, Triggers, Security & Config, Secrets & Env, Deployments, Test and Logs. Executions & Logs shows every invocation across all trigger types; Usage & Quotas shows consumption against your plan.

Additional resources