Skip to content

assertValidIrForRpc

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

function assertValidIrForRpc(ir): void;

Asserts that RPC-annotated IR structures follow SDK RPC conventions.

This helper is intended for RPC-oriented plugins that want a single fail-fast validation call before generation starts.

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 fail-fast and non-returning for invalid input:

  • It returns void when RPC structures are valid.
  • It throws PluginError on the first violation.
  • definePlugin catches that error and turns it into plugin diagnostics.

Parameters

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

Returns

void

Example

import { definePlugin } from "@varavel/vdl-plugin-sdk";
import { assertValidIrForRpc } from "@varavel/vdl-plugin-sdk/utils/rpc";

export const generate = definePlugin((input) => {
  assertValidIrForRpc(input.ir);

  return {
    files: [{ path: "rpc.ts", content: "// ..." }],
  };
});