feat(zod): add json primitive to @vlandoss/env/zod#24
Merged
Conversation
`e.json(schema)` decodes a JSON-string env var into a validated object and also accepts the already-decoded object coming from a config file / defaults (codec `.or(schema)`, the same dual-source pattern as `e.bool`). This lets a single leaf back a structured value whether it arrives as a `process.env` string or as a real object from a `.ts`/`.json` config. - package/src/zod.ts: new `json` factory - tests: env-var string decode, decoded-config passthrough, invalid-JSON dotpath - docs: Exports row + `json` section (rate-limit config example) - landing: bump displayed version to v0.4.0 (the release this changeset cuts) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Preview releaseLatest commit: Some packages have been released:
Note Use the PR number as tag to install any package. For instance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a single-purpose Zod primitive
jsonto the@vlandoss/env/zodentrypoint.e.json(schema)decodes a JSON-string env var into a validated object and also accepts the already-decoded object when it arrives from a.ts/.jsonconfig file or fromdefaults.Why the union (
.or)defineEnvfeeds every leaf through the same schema viadefu(envOverride, config, defaults) → validate(), so a leaf can receive either a string (fromprocess.env) or a real JS value (from a config file / defaults). A barez.codec(z.string(), …)only accepts a string and throws on the config-file path.jsonmirrors the existingboolprimitive (z.stringbool().or(z.boolean())): codec.or(schema).InferOutputof the union collapses to the inner schema's output, soConfig<S>/Env<S>infer the clean object type — neverstring.Changes
package/src/zod.ts— newjsonfactory.describe("json …")covering all three paths: env-var JSON string decodes, decoded config object passes through, invalid JSON throws with the dotpath (rateLimit.CONFIG).docsite/.../zod.mdx) — Exports table row + ajsonsection showing the dual source (env-var string vs config-file object), using a rate-limit config example.docsite/.../landing/data.ts) — bump displayed versionv0.3.0 → v0.4.0(the release this changeset cuts).minorbump (new public API).Verification
pnpm test→ 89/89 green (3 new).tsc --noEmitclean for@vlandoss/envanddocsite(pre-commit hooks).Follow-up (out of scope, blocked on release)
Once
@vlandoss/env@0.4.0is published, migrateyoppy/apps/apito replace its localjsonCodec(SeedConfig)withe.json(SeedConfig)and deletesrc/env/json-codec.ts.🤖 Generated with Claude Code