Skip to content

HoistNameContext

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

type HoistNameContext = object;

Naming information passed to the optional nameFn callback used by hoistAnonymousTypes.

The callback is invoked once for every anonymous inline object that is about to become a generated top-level type.

You can think of this object as the "naming explanation" for a single hoist operation: it tells you where the anonymous object came from, what its parent named type is, and which name the SDK would use if you do nothing.

The callback runs before the SDK resolves collisions. This means:

  • return defaultName to keep the built-in behavior
  • return a custom base name to override it
  • if the returned name already exists, the SDK will still make it unique by appending 2, 3, and so on
  • if the returned name is blank after trimming, hoistAnonymousTypes throws

This type is intentionally small so plugin authors can understand it quickly from the docs alone.

Examples

const flatSchema = ir.hoistAnonymousTypes(schema, ({ defaultName }) => {
  return `${defaultName}Dto`;
});
const flatSchema = ir.hoistAnonymousTypes(schema, ({ parts, defaultName }) => {
  if (parts.at(-1) === "input") return `${defaultName}Request`;
  if (parts.at(-1) === "output") return `${defaultName}Response`;
  return defaultName;
});

Properties

Property Type Description
defaultName string Name the SDK would use if no custom nameFn were provided. This is usually the best starting point for custom naming. Most callbacks only need to add a prefix/suffix or swap a few special cases.
parentName string Name of the nearest named parent type being traversed. For a direct child of an existing top-level type, this is that top-level type name. For an anonymous object nested inside another anonymous object that was already hoisted, this becomes the generated name of that synthetic parent type.
parts string[] Source path used to derive the generated type name. Each item represents one naming segment. For regular nested object fields, parts follows the field path. For anonymous objects inside arrays or maps, the SDK appends a synthetic segment so the generated name stays readable and deterministic: - array item objects append Item - map value objects append Value Examples: - MyRpc.barProc.input -> ['MyRpc', 'barProc', 'input'] - Response.items[] -> ['Response', 'items', 'Item'] - Response.meta{} -> ['Response', 'meta', 'Value']