Skip to content

refactor(ensnode-sdk) Duration schema#1630

Open
tk-o wants to merge 3 commits intomainfrom
refactor/ensnode-sdk-duration-schema
Open

refactor(ensnode-sdk) Duration schema#1630
tk-o wants to merge 3 commits intomainfrom
refactor/ensnode-sdk-duration-schema

Conversation

@tk-o
Copy link
Contributor

@tk-o tk-o commented Feb 13, 2026

Lite PR

Tip: Review docs on the ENSNode PR process

Summary

  • Updates makeDurationSchema to work only for business-layer objects.
  • Updates deserializeDuration to work for serialization-layer objects.
  • Updates maxWorstCaseDistance request search param schema to properly coerce string input into number (required after makeDurationSchema started to work with numbers only).

Why


Testing

  • Ran lint, typecheck, and test commands
  • Tested endpoints:
    • ENSIndexer
      • GET /api/indexing-status
    • ENSApi
      • GET /api/indexing-status
      • GET /ensanalytics/referrers
      • GET /amirealtime?maxWorstCaseDistance=12
      • GET /amirealtime?maxWorstCaseDistance=nan

Notes for Reviewer (Optional)

  • No public ENSNode SDK public API changes were aimed in this PR.

Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

tk-o added 3 commits February 13, 2026 14:38
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.
Copilot AI review requested due to automatic review settings February 13, 2026 14:04
@changeset-bot
Copy link

changeset-bot bot commented Feb 13, 2026

⚠️ No Changeset found

Latest commit: 51cbf2b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Feb 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
admin.ensnode.io Ready Ready Preview, Comment Feb 13, 2026 2:04pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
ensnode.io Skipped Skipped Feb 13, 2026 2:04pm
ensrainbow.io Skipped Skipped Feb 13, 2026 2:04pm

@tk-o tk-o marked this pull request as ready for review February 13, 2026 14:04
@tk-o tk-o requested a review from a team as a code owner February 13, 2026 14:04
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

The changes reorganize duration validation by removing number coercion from the makeDurationSchema core schema function and adding explicit coercion at individual call sites in the API handler and deserializer, consolidating validation responsibility.

Changes

Cohort / File(s) Summary
Schema Definition
packages/ensnode-sdk/src/shared/zod-schemas.ts
Modified makeDurationSchema to use z.number() instead of z.coerce.number(), narrowing input acceptance to strictly numeric values.
Coercion at Call Sites
apps/ensapi/src/handlers/amirealtime-api.ts, packages/ensnode-sdk/src/shared/deserialize.ts
Added explicit z.coerce.number() wrapping before duration schema application to handle numeric string coercion at the point of consumption.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰✨ Validation springs from schema and form,
Where numbers must coerce to transform,
We hop through the pipes with grace,
Each call site finds its rightful place—
Duration flows true, no need to ask,
One schema, one truth, one noble task! 🎯

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: a refactor of the Duration schema in the ensnode-sdk package.
Description check ✅ Passed The description follows the template structure with all required sections complete: Summary (3 bullets), Why (linked to PR #1629), Testing (multiple endpoints tested), and Pre-Review Checklist fully checked.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/ensnode-sdk-duration-schema

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

This PR refactors the Duration schema to properly separate concerns between business-layer and serialization-layer validation:

  • makeDurationSchema now expects numeric input (business-layer objects)
  • deserializeDuration handles string-to-number coercion (serialization-layer objects)
  • Query parameter handling explicitly coerces strings to numbers before validation

The refactoring is well-structured and maintains backward compatibility. All existing usages were reviewed:

  • Business-layer usages (indexing status, registrar actions, referral metrics) correctly work with numeric values
  • Serialization-layer usages (query params, database results) properly handle coercion
  • The change aligns with the stated goal of supporting PR feat(ensnode-sdk): Indexing Status validation #1629's indexing status improvements

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring is well-executed with clear separation of concerns. All call sites were verified to work correctly with the changes. The PR properly handles both business-layer numeric values and serialization-layer string coercion. Testing was thorough and covered all affected endpoints.
  • No files require special attention

Important Files Changed

Filename Overview
packages/ensnode-sdk/src/shared/zod-schemas.ts Removed z.coerce from makeDurationSchema to ensure it only works with numeric business-layer values
packages/ensnode-sdk/src/shared/deserialize.ts Added z.coerce.number() to deserializeDuration to handle string-to-number conversion at serialization layer
apps/ensapi/src/handlers/amirealtime-api.ts Added explicit z.coerce.number() for query param coercion before makeDurationSchema validation

Sequence Diagram

sequenceDiagram
    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
Loading

Last reviewed commit: 51cbf2b

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.coerce from makeDurationSchema to make it a pure business-layer schema that expects number inputs
  • Updated deserializeDuration to handle coercion from unknown/serialized types by adding z.coerce.number().pipe()
  • Fixed query parameter handling in the /amirealtime endpoint 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant