X Enterprises
fastify-ximagepipeline

getVariantPresets / getSourceTypes / getVariants

Inspect the active variant and source type configuration at runtime.

getVariantPresets / getSourceTypes / getVariants

Three synchronous accessors that expose the active configuration built at registration time. Useful for building admin UIs, validation logic, or dynamic upload forms.

Signatures

fastify.xImagePipeline.getVariantPresets(): Record<string, string[]>
fastify.xImagePipeline.getSourceTypes(): Record<string, SourceTypeConfig>
fastify.xImagePipeline.getVariants(): Record<string, VariantSpec>

interface SourceTypeConfig {
  variants: string[]       // variant names to generate
  formats: string[]        // output formats (always ["webp"])
  quality: number          // WebP quality 0–100
  storeOriginal: boolean   // whether to keep the original file
}

interface VariantSpec {
  width: number
  height: number | null    // null = auto (maintain aspect ratio)
  fit: "cover" | "inside"
}

Methods

MethodReturnsDescription
getVariantPresets()Record<string, string[]>Maps each source type to the variant names it produces
getSourceTypes()Record<string, SourceTypeConfig>Full configuration per source type including quality and storeOriginal
getVariants()Record<string, VariantSpec>Dimension specs for every variant name

All three methods are synchronous and return the resolved configuration (merged defaults + any overrides passed at registration).

Examples

Expose config for a frontend upload form

fastify.get("/api/image-config", async (request, reply) => {
  return {
    sourceTypes: Object.keys(fastify.xImagePipeline.getSourceTypes()),
    variantPresets: fastify.xImagePipeline.getVariantPresets(),
  };
});

// Response:
// {
//   sourceTypes: ["avatar", "member_photo", "gallery", "hero", "content"],
//   variantPresets: {
//     avatar: ["xs", "sm"],
//     gallery: ["md", "lg", "xl"],
//     ...
//   }
// }

Validate a sourceType before proxying an upload

fastify.post("/upload", async (request, reply) => {
  const { sourceType } = request.body;
  const validTypes = Object.keys(fastify.xImagePipeline.getSourceTypes());

  if (!validTypes.includes(sourceType)) {
    return reply.code(400).send({
      error: `Invalid sourceType. Must be one of: ${validTypes.join(", ")}`,
    });
  }

  // forward to image pipeline...
});

See Also

AI Context

package: "@xenterprises/fastify-ximagepipeline"
methods: fastify.xImagePipeline.getVariantPresets() | fastify.xImagePipeline.getSourceTypes() | fastify.xImagePipeline.getVariants(sourceType)
use-when: Inspect the active variant specs and source type configuration at runtime
Copyright © 2026