Minor Changes
-
#316
d30cc36Thanks @G4brym! - Add customizable pagination and ordering parameter names to ListEndpoint viapageFieldName,perPageFieldName,orderByFieldName, andorderByDirectionFieldNameclass properties.Breaking change for subclasses overriding
optionFields:optionFieldsis now a computed getter derived from the four*FieldNameproperties. Subclasses that previously overrodeoptionFieldsdirectly should instead override the individual field name properties. -
#317
39c89d2Thanks @G4brym! - AddvalidateResponserouter option to validate and sanitize response bodies against their Zod schemas at runtime.When enabled, responses are parsed through
z.object().parseAsync(), which strips unknown fields and validates required fields/types. This prevents accidental data leaks (e.g., internal fields likepasswordHashreaching the client) and catches handler bugs where the response doesn't match the declared schema.const router = fromHono(app, { validateResponse: true });
Behavior:
- Plain object responses are validated against the
200response schema Responseobjects withapplication/jsoncontent are cloned, validated, and reconstructed with corrected headers- Non-JSON responses and responses without a matching Zod schema are passed through unchanged
- Validation failures return
500 Internal Server Error(code7013) and log the full error viaconsole.error
New exports:
ResponseValidationException— thrown when a handler's response doesn't match its declared schema (status 500, code 7013,isVisible: false)
- Plain object responses are validated against the
-
#315
47d304aThanks @G4brym! - AddSerializerContextparameter to auto endpoint serializer function, providing access to filters and options for context-aware serialization.The serializer signature changes from
(obj: object) => objectto(obj: object, context?: SerializerContext) => object. TheSerializerContexttype contains:filters—Array<FilterCondition>: the active filter conditions for the current requestoptions— pagination and ordering options (page,per_page,order_by,order_by_direction)
Context passed per endpoint type:
Endpoint Context ListEndpoint/ReadEndpoint{ filters, options }UpdateEndpoint/DeleteEndpoint{ filters }CreateEndpoint{ filters: [] }const meta = { model: { schema: UserSchema, primaryKeys: ["id"], tableName: "users", serializer: (obj: any, context?: SerializerContext) => { const hasRoleFilter = context?.filters?.some((f) => f.field === "role"); // Conditionally include fields based on active filters return hasRoleFilter ? obj : omit(obj, ["role"]); }, }, };
New exports:
SerializerContext— type for the serializer's second parameter