/** * @packageDocumentation Per-function typed client. * * Each property on the proxy returned by `createFunctionsApi` is a * `FunctionClient` whose `invoke()` signature is derived from the schema * entry for that function name. */ import { ApiClient } from '@microsoft/rayfin-lib'; /** * Response from a function invocation. */ export interface FunctionInvocationResponse { /** The name of the function that was invoked. */ functionName: string; /** A unique identifier for this invocation. */ invocationId: string; /** Status of the function invocation (Success, Failed, etc.) */ status: string; /** * The output from the function. * When the raw response contains a JSON-encoded string, `invoke()` auto-parses it * so the caller receives `TOutput` directly. */ output: TOutput; /** Any errors that occurred during the function invocation. */ errors: Array>; } /** * Options that can be supplied to a single `invoke()` call. */ export interface InvokeOptions { /** Extra headers to attach to the request. */ headers?: Record; /** * Per-call request timeout in milliseconds, overriding the default function * invocation timeout (`FUNCTIONS_INVOKE_TIMEOUT_MS`, 250s). Use this * for functions that should fail faster than the default. * * Capped at `FUNCTIONS_INVOKE_TIMEOUT_MS` (250s): the Fabric UDF host * aborts the invocation at that ceiling server-side, so a larger value is * silently clamped down. A non-positive value falls back to the default. * * For a no-input function, pass options in the second argument slot * (`invoke(undefined, { timeoutMs })`) rather than as the single * argument, so the option is never confused with a function's own input. * See the note on {@link FunctionClient.invoke}. */ timeoutMs?: number; } /** * A strongly-typed client for a single function. * * @typeParam TInput - The parameter object the function expects (`void` when none). * @typeParam TOutput - The type returned by the function. */ export declare class FunctionClient { private apiClient; private functionName; constructor(apiClient: ApiClient, functionName: string); /** * Invoke the function and return its typed output. * * @param args - Options always go in the **second** argument slot; the * first argument is always the function's input `params`. * * - Input functions: `invoke(params)` or `invoke(params, options)`. * - No-input functions: `invoke()` or `invoke(undefined, options)`. * * A lone argument is therefore always treated as `params`, never as * options — so a real input that happens to be shaped like an option * (for example `{ timeoutMs }`) is never misread. For a no-input function * the type forbids a lone object, so per-call options such as `timeoutMs` * must be passed in the second slot (`invoke(undefined, { timeoutMs })`). * @returns The function's success-path output, typed as `TOutput`. * * Failure modes throw — a non-empty `errors` array or a non-success * status on the wire response is surfaced as {@link FunctionsError}. * Network and unknown errors are wrapped in {@link NetworkError} and * {@link FunctionsError} respectively. By the time this method * resolves, the caller can use the value without defending against * `undefined`. * * The server-side `invocationId` from the underlying envelope is * emitted via `console.debug` (along with the function name) so the * value is available in the browser/Node console for correlation * without polluting the public return type. * * @throws {@link FunctionsError} - If the function invocation fails. * @throws `NetworkError` - For network-related issues. * @throws `SdkError` - For any other unexpected SDK errors. * * @example * ```typescript * const greeting = await client.functions.helloWorld.invoke({ * firstName: 'Ada', * lastName: 'Lovelace', * }); * console.log(greeting); // typed as string * * // Per-call timeout override (input function): * await client.functions.longRunning.invoke(params, { timeoutMs: 5_000 }); * * // No-input function with a per-call timeout override (second slot): * await client.functions.ping.invoke(undefined, { timeoutMs: 5_000 }); * ``` */ invoke(...args: TInput extends void | Record ? [params?: undefined, options?: InvokeOptions] : [params: TInput, options?: InvokeOptions]): Promise; } //# sourceMappingURL=FunctionClient.d.ts.map