Releases: cloudflare/chanfana
v3.2.1
Patch Changes
-
#325
c182e59Thanks @G4brym! - ExportOrderByDirectiontype alias ("asc" | "desc") so consumers can import it directly instead of inlining literal unions -
#325
c182e59Thanks @G4brym! - AddpassthroughErrorsoption to bypass chanfana's error handling and let errors propagate raw to the framework's error handlerimport { Hono } from "hono"; import { fromHono, ApiException } from "chanfana"; import { ZodError } from "zod"; const app = new Hono(); app.onError((err, c) => { // Errors arrive as raw exceptions — no HTTPException wrapping if (err instanceof ApiException) { return c.json( { ok: false, code: err.code, message: err.message }, err.status as any ); } if (err instanceof ZodError) { return c.json({ ok: false, validationErrors: err.issues }, 400); } return c.json({ ok: false, message: "Internal Server Error" }, 500); }); const openapi = fromHono(app, { passthroughErrors: true });
v3.2.0
Minor Changes
-
#314
2408999Thanks @G4brym! - Addtagssupport to auto endpoint_metafor OpenAPI tag grouping -
#323
d9b7297Thanks @G4brym! - AddhandleErrorhook,defaultOrderByDirection, fix validation error format and D1 update with extra columns-
Add
handleError(error)protected method onOpenAPIRouteto transform errors before chanfana formats them. Enables custom error wrapping (e.g., bypassing chanfana's formatter to use Hono'sonError). -
Add
defaultOrderByDirectionproperty toListEndpoint(defaults to"asc"). Allows configuring the default sort direction whenorderByFieldsis used. -
Breaking: Validation errors from
validateRequest()now returnInputValidationExceptionformat instead of raw Zod issues. This makes the actual response match the OpenAPI schema that chanfana documents. If you parse validation error responses, update your code to use the new shape:Before:
{ "errors": [ { "code": "invalid_type", "expected": "string", "received": "number", "message": "Invalid input: expected string, received number", "path": ["body", "name"] } ], "success": false, "result": {} }After:
{ "errors": [ { "code": 7001, "message": "Invalid input: expected string, received number", "path": ["body", "name"] } ], "success": false, "result": {} }Key differences:
codeis now the numeric7001(was a string like"invalid_type"), and Zod-specific fields (expected,received) are no longer included. -
D1UpdateEndpoint.update()now automatically filtersupdatedDatato only include columns defined in the Zod schema. Previously, DB tables with extra columns not in the schema would causevalidateColumnName()to throw.
-
v3.1.0
[email protected]
Minor Changes
Breaking Changes
- Parameter helpers removed —
Str(),Num(),Int(),Bool(),DateTime(),DateOnly(),Email(),Uuid(),Hostname(),Ipv4(),Ipv6(),Ip(),Regex(),Enumeration(), andconvertParams()removed. Use native Zod schemas directly. - Legacy type support removed —
legacyTypeIntoZod,Arr(),Obj()no longer exported.contentJson()now requires a Zod schema. - D1 error messages sanitized — Database errors no longer expose internals. Use
constraintsMessagesfor user-friendly messages. - D1 delete/update restricted to primary key filters — Only
primaryKeysfilters used in WHERE clauses. - D1
per_pagecapped at 100 — Configurable viamaxPerPage. raiseUnknownParametersenforced — Was previously accepted but non-functional; now active.
New Features
- 10 new exception classes —
UnauthorizedException(401),ForbiddenException(403),MethodNotAllowedException(405),ConflictException(409),UnprocessableEntityException(422),TooManyRequestsException(429),InternalServerErrorException(500),BadGatewayException(502),ServiceUnavailableException(503),GatewayTimeoutException(504) - D1 SQL injection prevention —
validateSqlIdentifier(),validateTableName(),validateColumnName(),buildSafeFilters(),buildPrimaryKeyFilters(),getD1Binding(),handleDbError(), and query clause builders Retry-Afterheader — Automatically set forTooManyRequestsExceptionandServiceUnavailableExceptiongetUnvalidatedData()— Access raw request data before Zod defaults/transformations- Hono
basePath()auto-detection — Detected automatically; combiningbasePath()andbaseoption now throws a descriptive error - Hono error flow — Errors flow through Hono's
app.onErrorasHTTPExceptioninstances instead of being caught internally
Bug Fixes
- D1: Prevent unscoped DELETE/UPDATE via
buildPrimaryKeyFilters() - D1: Fix shared exception instances, empty update SQL, LIKE wildcard escaping
- D1: Column names validated against model schema
- D1: Read/Delete endpoints use consistent primary key filters and error handling
- Fixed: schema generation errors now propagate instead of being silently swallowed
- Fixed:
CreateEndpointresponse schema references 201 instead of 200 - Fixed: falsy defaults (
0,false,"") correctly applied - Fixed: BigInt coercion uses
BigInt()directly to avoid precision loss - Fixed: boolean coercion null guard, HEAD request body parsing, YAML URL generation
- Fixed:
ApiExceptionimport changed to value import forinstanceofchecks - Fixed:
ReadEndpoint/ListEndpointdocumentInputValidationExceptionin 400 responses
Improvements
- D1 parallel queries via
Promise.all()for list endpoint - Configurable
maxPerPageclass property - Normalized ORDER BY to lowercase
"asc"/"desc" sanitizeOperationId()removes special characters- Router constructor validation throws if router argument is missing
- Error responses include
result: {}for consistent shape - Comprehensive JSDoc across exception classes, D1 endpoints, and handler methods
Patch Changes
- Include source code, AI coding skills, and documentation in npm package. Added
llms.txtentry point.
v3.0.0
Major release v3.0.0
Migration guide here: https://chanfana.pages.dev/migration-to-chanfana-3#migration-steps
What's Changed
- Upgraded to Zod v4
- Improved Type Hints for Auto-Endpoint Lifecycle Methods
- New
getUnvalidatedData()Method
Full Changelog: v2.8.3...v3.0.0
v2.8.3
v2.8.2
What's Changed
- Fix chanfana cli not supporting writing schemas into folders
Full Changelog: v2.8.1...v2.8.2
v2.8.1
v2.8.0
v2.7.2
What's Changed
- Add more Examples and Recipes to docs by @G4brym in #251
- fix: use literal false for the success field in exceptions by @ratnaraj7 in #253
Full Changelog: v2.7.1...v2.7.2