VDL Plugin SDK

assertValidIrForHttpRpc

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

function assertValidIrForHttpRpc(ir): void;

Asserts that HTTP-RPC IR structures follow VPP-2 conventions.

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

Validation rules:

  1. If no type is annotated with @httpRpc, validation is skipped.
  2. Every @httpRpc annotation must not have arguments.
  3. Every @httpRpc type must be an object type.
  4. Inside each @httpRpc object, only fields annotated with @proc are validated as procedures. Orphan @proc fields outside @httpRpc are ignored.
  5. Every @proc annotation must not have arguments.
  6. Every @proc field must be an inline object type.
  7. If an operation declares input or output fields, each one must be an inline object type.
  8. 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 HTTP-RPC structures are valid.
  • It throws PluginError on the first violation.
  • definePlugin catches that error and turns it into plugin diagnostics.

Parameters

ParameterTypeDescription
irIrSchemaFully resolved VDL IR schema to validate.

Returns

void

Example

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

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

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