Skip to content

feat(zod): add json primitive to @vlandoss/env/zod#24

Merged
rqbazan merged 1 commit into
mainfrom
feat/json-zod-primitive
Jun 9, 2026
Merged

feat(zod): add json primitive to @vlandoss/env/zod#24
rqbazan merged 1 commit into
mainfrom
feat/json-zod-primitive

Conversation

@rqbazan

@rqbazan rqbazan commented Jun 9, 2026

Copy link
Copy Markdown
Member

What

Adds a single-purpose Zod primitive json to the @vlandoss/env/zod entrypoint.

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/.json config file or from defaults.

Why the union (.or)

defineEnv feeds every leaf through the same schema via defu(envOverride, config, defaults) → validate(), so a leaf can receive either a string (from process.env) or a real JS value (from a config file / defaults). A bare z.codec(z.string(), …) only accepts a string and throws on the config-file path. json mirrors the existing bool primitive (z.stringbool().or(z.boolean())): codec .or(schema). InferOutput of the union collapses to the inner schema's output, so Config<S>/Env<S> infer the clean object type — never string.

Changes

  • package/src/zod.ts — new json factory.
  • Testsdescribe("json …") covering all three paths: env-var JSON string decodes, decoded config object passes through, invalid JSON throws with the dotpath (rateLimit.CONFIG).
  • Docs (docsite/.../zod.mdx) — Exports table row + a json section showing the dual source (env-var string vs config-file object), using a rate-limit config example.
  • Landing (docsite/.../landing/data.ts) — bump displayed version v0.3.0 → v0.4.0 (the release this changeset cuts).
  • Changesetminor bump (new public API).

Verification

  • pnpm test → 89/89 green (3 new).
  • tsc --noEmit clean for @vlandoss/env and docsite (pre-commit hooks).

Follow-up (out of scope, blocked on release)

Once @vlandoss/env@0.4.0 is published, migrate yoppy/apps/api to replace its local jsonCodec(SeedConfig) with e.json(SeedConfig) and delete src/env/json-codec.ts.

🤖 Generated with Claude Code

`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>
@vland-bot

vland-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Preview release

Latest commit: 1994008

Some packages have been released:

Package Version Install
@vlandoss/env 0.3.1-git-1994008.0 @vlandoss/env@0.3.1-git-1994008.0

Note

Use the PR number as tag to install any package. For instance:

pnpm add @vlandoss/env@pr-24

@rqbazan rqbazan merged commit e814bfa into main Jun 9, 2026
12 checks passed
@rqbazan rqbazan deleted the feat/json-zod-primitive branch June 9, 2026 00:02
@vland-bot vland-bot Bot mentioned this pull request Jun 9, 2026
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