Skip to content

FluxbaseRPC

FluxbaseRPC provides methods for invoking RPC procedures

// Invoke a procedure synchronously
const { data, error } = await fluxbase.rpc.invoke('get-user-orders', {
user_id: '123',
limit: 10
});
// Invoke asynchronously
const { data: asyncResult } = await fluxbase.rpc.invoke('long-running-report', {
start_date: '2024-01-01'
}, { async: true });
// Poll for status
const { data: status } = await fluxbase.rpc.getStatus(asyncResult.execution_id);

new FluxbaseRPC(fetch): FluxbaseRPC

Parameter Type
fetch RPCFetch

FluxbaseRPC

getLogs(executionId, afterLine?): Promise<{ data: ExecutionLog[] | null; error: Error | null; }>

Get execution logs (for debugging and monitoring)

Parameter Type Description
executionId string The execution ID
afterLine? number Optional line number to get logs after (for polling)

Promise<{ data: ExecutionLog[] | null; error: Error | null; }>

Promise resolving to { data, error } tuple with execution logs

const { data: logs } = await fluxbase.rpc.getLogs('execution-uuid');
for (const log of logs) {
console.log(`[${log.level}] ${log.message}`);
}

getStatus(executionId): Promise<{ data: RPCExecution | null; error: Error | null; }>

Get execution status (for async invocations or checking history)

Parameter Type Description
executionId string The execution ID returned from async invoke

Promise<{ data: RPCExecution | null; error: Error | null; }>

Promise resolving to { data, error } tuple with execution details

const { data, error } = await fluxbase.rpc.getStatus('execution-uuid');
if (data.status === 'completed') {
console.log('Result:', data.result);
} else if (data.status === 'running') {
console.log('Still running...');
}

invoke<T>(name, params?, options?): Promise<{ data: RPCInvokeResponse<T> | null; error: Error | null; }>

Invoke an RPC procedure

Type Parameter Default type
T unknown
Parameter Type Description
name string Procedure name
params? Record<string, unknown> Optional parameters to pass to the procedure
options? RPCInvokeOptions Optional invocation options

Promise<{ data: RPCInvokeResponse<T> | null; error: Error | null; }>

Promise resolving to { data, error } tuple with invocation response

// Synchronous invocation
const { data, error } = await fluxbase.rpc.invoke('get-user-orders', {
user_id: '123',
limit: 10
});
console.log(data.result); // Query results
// Asynchronous invocation
const { data: asyncData } = await fluxbase.rpc.invoke('generate-report', {
year: 2024
}, { async: true });
console.log(asyncData.execution_id); // Use to poll status

list(namespace?): Promise<{ data: RPCProcedureSummary[] | null; error: Error | null; }>

List available RPC procedures (public, enabled)

Parameter Type Description
namespace? string Optional namespace filter

Promise<{ data: RPCProcedureSummary[] | null; error: Error | null; }>

Promise resolving to { data, error } tuple with array of procedure summaries


waitForCompletion(executionId, options?): Promise<{ data: RPCExecution | null; error: Error | null; }>

Poll for execution completion with exponential backoff

Parameter Type Description
executionId string The execution ID to poll
options? { initialIntervalMs?: number; maxIntervalMs?: number; maxWaitMs?: number; onProgress?: (execution) => void; } Polling options
options.initialIntervalMs? number Initial polling interval in milliseconds (default: 500)
options.maxIntervalMs? number Maximum polling interval in milliseconds (default: 5000)
options.maxWaitMs? number Maximum time to wait in milliseconds (default: 30000)
options.onProgress? (execution) => void Callback for progress updates

Promise<{ data: RPCExecution | null; error: Error | null; }>

Promise resolving to final execution state

const { data: result } = await fluxbase.rpc.invoke('long-task', {}, { async: true });
const { data: final } = await fluxbase.rpc.waitForCompletion(result.execution_id, {
maxWaitMs: 60000, // Wait up to 1 minute
onProgress: (exec) => console.log(`Status: ${exec.status}`)
});
console.log('Final result:', final.result);