Replies: 1 comment 2 replies
-
|
Indeed a nice proposal, although the lack of a standardized Each validation library needs its own implementation of |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR
Build fails if config invalid. Types auto-generated for
useRuntimeConfig().What Changed
The main blocker raised by @sandros94 ("lack of standardized JSON Schema conversion") is now resolved:
z.toJSONSchema()via~standard.jsonSchema@valibot/to-json-schemaor fallback@standard-community/standard-jsonNew in Standard Schema spec:
StandardJSONSchemaV1interface with targetsdraft-2020-12,draft-07,openapi-3.0.Proof of concept: nuxt-safe-runtime-config implements this pattern today.
Proposal
runtimeConfig.$schemaAccept a Standard Schema object that:
nuxi dev/build) after env vars mergeuseRuntimeConfig()automaticallyDetection Logic
Type Generation
Convert schema to JSON Schema, then to TypeScript:
JSON Schema Fallback
Error Output
Scope
In scope:
runtimeConfig.$schemawith Standard SchemauseRuntimeConfig()Out of scope (can be added later):
nuxt.configvalidationImplementation
~150 LOC in core:
packages/schema/src/types/config.ts- Add$schema?: StandardSchemaV1to RuntimeConfigInputpackages/nuxt/src/core/nuxt.ts- Validate onnuxt:ready+build:donepackages/nuxt/src/core/templates.ts- Generate types from schemaDependencies:
@standard-schema/spec(types only)@standard-community/standard-json(~5KB, fallback)Questions for Team
$schema(matches existing pattern) or$standardSchema(explicit)?schema:runtimeConfighook?References
Beta Was this translation helpful? Give feedback.
All reactions