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:
- If no type is annotated with
@httpRpc, validation is skipped. - Every
@httpRpcannotation must not have arguments. - Every
@httpRpctype must be an object type. - Inside each
@httpRpcobject, only fields annotated with@procare validated as procedures. Orphan@procfields outside@httpRpcare ignored. - Every
@procannotation must not have arguments. - Every
@procfield must be an inline object type. - If an operation declares
inputoroutputfields, each one must be an inline object type. - The contents inside valid
input/outputobjects are intentionally not validated by this helper and can be anything.
The function is fail-fast and non-returning for invalid input:
- It returns
voidwhen HTTP-RPC structures are valid. - It throws
PluginErroron the first violation. definePlugincatches 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 { assertValidIrForHttpRpc } from "@varavel/vdl-plugin-sdk/utils/rpc";
export const generate = definePlugin((input) => {
assertValidIrForHttpRpc(input.ir);
return {
files: [{ path: "rpc.ts", content: "// ..." }],
};
});