Skip to content

validateIrForRpc

Import from @varavel/vdl-plugin-sdk/utils/rpc.

function validateIrForRpc(ir): 
  | PluginOutputError[]
  | undefined;

Validates IR types annotated for RPC conventions and returns plugin-friendly diagnostics.

This helper enforces the SDK-level RPC structural rules used by RPC-oriented plugins and returns errors in the same shape expected by plugin outputs.

Validation rules:

  1. If no type is annotated with @rpc, validation is skipped.
  2. Every @rpc type must be an object type.
  3. Inside each @rpc object, only fields annotated with @proc or @stream are validated as RPC operations.
  4. An operation field cannot have both @proc and @stream.
  5. Every @proc or @stream field must be an object type.
  6. If an operation declares input or output fields, each one must be an object type.
  7. The contents inside valid input/output objects are intentionally not validated by this helper and can be anything.

The function is non-throwing: it always returns either a diagnostics array or undefined when no RPC-related issues were found.

Parameters

Parameter Type Description
ir IrSchema Fully resolved VDL IR schema to validate.

Returns

| PluginOutputError[] | undefined

A list of PluginOutputError diagnostics, or undefined when valid.

Example

const errors = validateIrForRpc(input.ir);
if (errors) {
  return { errors };
}