sor4chi / hono-storage

A storage helper for Hono. Support disk, memory, S3, etc.
MIT License
101 stars 3 forks source link

fix: change `stoarage.field` schema to `Recode<string, FieldSchema>` instead of `FieldSchema[]` #23

Closed sor4chi closed 10 months ago

sor4chi commented 10 months ago

The concept so far has been to define the schema of storage.fields in an array to follow the Multer.

However, I believe that arrays are difficult to infer strictly using generics, and that having fields inferred in object form is better for future extensions and for DX.

Before

app.post(
  "/upload/field", 
  storage.fields([
    { name: "image", maxCount: 1 },
    { name: "pictures", maxCount: 2 },
  ]),
  (c) => c.text("OK"),
);

After

app.post(
  "/upload/field", 
  storage.fields({
    image: { type: "multiple", maxCount: 1 },
    pictures: { type: "multiple", maxCount: 2 },
  }),
  (c) => c.text("OK"),
);

Applying this changes, I think c.var.files could easily be type-safe.