Skip to content

feat(loader): support validate with standard schema#237

Open
ysknsid25 wants to merge 18 commits intounjs:mainfrom
ysknsid25:feature/impl-standard-schema
Open

feat(loader): support validate with standard schema#237
ysknsid25 wants to merge 18 commits intounjs:mainfrom
ysknsid25:feature/impl-standard-schema

Conversation

@ysknsid25
Copy link
Contributor

@ysknsid25 ysknsid25 commented Mar 24, 2025

attempts to resolve #228

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@pi0 pi0 changed the title feat(loader): implements validation by standard schema feat(loader): support validate with standard schema Mar 26, 2025
Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 requested a review from pi0 March 26, 2025 13:31
@pi0
Copy link
Member

pi0 commented Jul 30, 2025

@ysknsid25 i will put more time on this PR before releasing in next minor releases. It is a big feature!

ysknsid25 and others added 6 commits November 23, 2025 15:16
Signed-off-by: ysknsid25 <kengo071225@gmail.com>
define StandardSchema

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
define StandardSchema

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
define StandardSchema

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.74%. Comparing base (42d9697) to head (1ebb06c).
⚠️ Report is 209 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #237      +/-   ##
==========================================
+ Coverage   76.92%   77.74%   +0.82%     
==========================================
  Files           7        5       -2     
  Lines         806      364     -442     
  Branches       80      147      +67     
==========================================
- Hits          620      283     -337     
+ Misses        184       67     -117     
- Partials        2       14      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ysknsid25 ysknsid25 force-pushed the feature/impl-standard-schema branch 2 times, most recently from 9b10eda to cfdf5fa Compare December 8, 2025 12:12
implement validate and transform

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 force-pushed the feature/impl-standard-schema branch from cfdf5fa to f1758fa Compare December 8, 2025 12:27
@ysknsid25
Copy link
Contributor Author

ysknsid25 commented Dec 8, 2025

Hello @pi0 . I have a consultation 🙇

Can you make feature branch for this issue?
I think I must writing test for all library complied Standard Schema, but there are 22 libraries.
In order to decrease your review workload, I think it would be better split sevral branch.

In this branch, write test for Zod and valibot and marge to new feature branch. remaning test code will be written another each branch.

How about? 👀

@pi0
Copy link
Member

pi0 commented Feb 6, 2026

Hi dear @ysknsid25 i have updated changes little bit also simplified tests (to add again), fortunatly, since standard schema is unified, we only need to test against one library not all.

TODO:

  • We need to infer return types when schema: { config } is provided
  • We need better error formatting

ysknsid25 and others added 2 commits February 26, 2026 15:17
add infer return type & error format

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25
Copy link
Contributor Author

ysknsid25 commented Feb 26, 2026

Hi dear @pi0 . Thank you for your helping :)

I changed code like below.

1. Return type inference from schema (src/types.ts + src/loader.ts)

Added function overloads to loadConfig so that when schema is provided, the return type of config is inferred from the schema's output type instead of falling back to Record<string, any>.

  • With schema: Uses StandardSchemaV1.InferConfigOutput<S> to extract the config property type from the schema output
  • Without schema: Behaves as before, using the explicit type parameter T

A new utility type InferConfigOutput was added to StandardSchemaV1 namespace to extract the config property from the schema output via conditional type inference.

2. Better error formatting (src/loader.ts)

Replaced raw JSON.stringify output with a human-readable format that combines each issue's path and message:

// Before 
[{"message":"Expected string, received number","path":["config","port"]}]

// After
Config validation failed:
  - config.port: Expected string, received number

3. Tests (test/loader.test.ts)

  • Removed the now-unnecessary <UserConfig> type parameter from the existing test (inferred from schema)
  • Added "schema validation formats errors" — verifies the error message starts with "Config validation failed:"
  • Added "schema infers config type" — compile-time verification that config.configFile is correctly typed as string | boolean | undefined based on the schema.

@ysknsid25 ysknsid25 requested a review from pi0 February 26, 2026 06:42
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.

Support validation

2 participants