Chainbox

Capability Reference

Client

Call()

The primary entry point for executing capabilities from the client side.

Signature

function Call(
  fnName: string,
  input?: any,
  options?: CallOptions,
): Promise<any>;

Parameters

Parameter Type Required Description
fnName string Yes The dot-notation path to the capability (e.g., 'user.create').
input any No The input data payload passed to the capability as the first argument.
options CallOptions No Configuration options for the execution.

Server

Ctx (Execution Context)

The execution context passed to every capability as the second argument. It provides access to the request identity, environment, and storage.

type Ctx = {
  input: any;
  identity?: Identity;
  env: Record<string, string | undefined>;

  // Storage
  kv: StorageAdapter;
  blob: StorageAdapter;
  db?: any; // Auto-injected if configured

  // Composition
  call: (fnName: string, input?: any) => Promise<any>;
  parallel: (calls: { fn: string; input?: any }[]) => Promise<any[]>;
};

ctx.identity

Represents the authenticated user or service.

ctx.kv & ctx.blob

Both kv and blob implement the StorageAdapter interface for persistent storage.

Method Signature Description
get get(key: string): Promise<any> Retrieve a value/object.
set set(key: string, value: any): Promise<void> Store a value/object.
delete delete(key: string): Promise<void> Remove a key.
list list(prefix?: string): Promise<string[]> List keys starting with prefix.