Conversation
Maintain the `unknown` input type by enforcing corercion before calling the business-layer schema.
Maintain the `unknown` input type by enforcing corercion before calling the business-layer schema.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
📝 WalkthroughWalkthroughThe changes reorganize duration validation by removing number coercion from the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile OverviewGreptile SummaryThis PR refactors the
The refactoring is well-structured and maintains backward compatibility. All existing usages were reviewed:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant API as amirealtime-api
participant QueryParam as params.queryParam
participant Coerce as z.coerce.number()
participant DurationSchema as makeDurationSchema
participant Deserialize as deserializeDuration
participant DB as Database
Note over Client,DurationSchema: Query Parameter Flow (String Input)
Client->>API: GET /amirealtime?maxWorstCaseDistance=12
API->>QueryParam: Process query param (string "12")
QueryParam->>Coerce: Coerce string to number
Coerce->>DurationSchema: Validate as Duration (number)
DurationSchema-->>API: Valid Duration value
Note over Deserialize,DB: Database Deserialization Flow
DB->>Deserialize: totalIncrementalDuration (string from DB)
Deserialize->>Coerce: Coerce string to number
Coerce->>DurationSchema: Validate as Duration (number)
DurationSchema-->>Deserialize: Valid Duration value
Last reviewed commit: 51cbf2b |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/ensnode-sdk/src/shared/deserialize.ts`:
- Line 110: The current schema uses z.coerce.number() without a custom coercion
error so non-numeric inputs produce generic Zod messages; update the call in
deserialize.ts to pass a descriptive error that uses valueLabel (same pattern as
amirealtime-api.ts) before piping into makeDurationSchema — e.g., supply an {
error: `...${valueLabel}...` } to z.coerce.number() so the resulting schema
(variable schema) returns consistent, contextual coercion errors when valueLabel
is provided.
There was a problem hiding this comment.
Pull request overview
This PR refactors the Duration schema to separate business-layer validation from serialization-layer coercion, supporting improved data model validation patterns introduced in PR #1629.
Changes:
- Removed
z.coercefrommakeDurationSchemato make it a pure business-layer schema that expects number inputs - Updated
deserializeDurationto handle coercion from unknown/serialized types by addingz.coerce.number().pipe() - Fixed query parameter handling in the
/amirealtimeendpoint to explicitly coerce string inputs to numbers before Duration validation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/ensnode-sdk/src/shared/zod-schemas.ts | Removes z.coerce from makeDurationSchema to make it business-layer only |
| packages/ensnode-sdk/src/shared/deserialize.ts | Adds z.coerce.number().pipe() pattern to deserializeDuration for serialization-layer coercion |
| apps/ensapi/src/handlers/amirealtime-api.ts | Adds explicit z.coerce.number() step for query param before piping to makeDurationSchema |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Lite PR
Tip: Review docs on the ENSNode PR process
Summary
makeDurationSchemato work only for business-layer objects.deserializeDurationto work for serialization-layer objects.maxWorstCaseDistancerequest search param schema to properly coerce string input into number (required aftermakeDurationSchemastarted to work with numbers only).Why
Testing
GET /api/indexing-statusGET /api/indexing-statusGET /ensanalytics/referrersGET /amirealtime?maxWorstCaseDistance=12GET /amirealtime?maxWorstCaseDistance=nanNotes for Reviewer (Optional)
Pre-Review Checklist (Blocking)