2.6 KiB
2.6 KiB
options.ts
(no submodules)
Purpose
Defines the Zod schema validating caller-supplied FileUploadPluginOptions. Invalid input — wrong type, malformed basePath, non-positive limits, non-conforming storage/sessionStore shapes — throws FileUploadError(UPLOAD.INVALID_INPUT) at the createFileUploadPlugin boundary so misconfiguration fails fast at boot rather than at first request.
Features
basePathregex matches Hono's mount rules: starts with/, never ends with/except the root.- Default
singleShotLimitBytesof 10 MiB,maxFileSizeBytesof 1 GiB,defaultChunkSizeof 5 MiB,sessionTtlMsof 24 h. - Default MIME denylist covers common native-executable formats so a default-configured deployment refuses obvious malware delivery vectors.
storage,sessionStore, andloggervalidated structurally viaz.custom(they are runtime objects).- Exports both the input shape (what callers pass) and the resolved shape (what the descriptor stores).
Usage: Basic
import { FileUploadPluginOptionsSchema } from "@suaveplan/api-plugin-file-upload/schemas/options";
const config = FileUploadPluginOptionsSchema.parse({ basePath: "/files" });
Usage: Advanced
import { FileUploadPluginOptionsSchema } from "@suaveplan/api-plugin-file-upload";
import { MemoryUploadStorage } from "@suaveplan/api-plugin-file-upload/storage/memory";
const config = FileUploadPluginOptionsSchema.parse({
basePath: "/api/v1/uploads",
singleShotLimitBytes: 5 * 1024 * 1024,
allowedMimeTypes: ["image/png", "image/jpeg", "application/pdf"],
storage: new MemoryUploadStorage(),
});
API Reference
FileUploadPluginOptionsSchema— Zod object schema.FileUploadPluginOptionsInput—z.inputtype, what callers may pass.FileUploadPluginOptionsResolved—z.outputtype, post-default shape.
Implementation Notes
- The schema applies defaults rather than rejecting missing fields — calling
createFileUploadPlugin({})is a valid (development) configuration. The defaults match the hardening baseline (executable denylist on, generous size caps, 24 h TTL). allowedMimeTypesempty defaults to "no allow-list" (everything except the denylist). Setting any value flips to "exclusive allow" semantics — the validator rejects anything not in the array.- The
z.customstructural checks forstorage/sessionStore/loggeraccept any object exposing the expected duck-typed methods; full interface conformance is enforced at the consumer call site by TypeScript when the package's exported types are imported.