HoistNameContext
Import from @varavel/vdl-plugin-sdk/utils/ir.
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
defaultNameto 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,
hoistAnonymousTypesthrows
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;
});