fix: Simplify coercion: unify ArkType and Standard Schema paths with pre-coercion model#1193
Conversation
🦋 Changeset detectedLatest commit: 1fbfeaf The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
arkenv
@arkenv/bun-plugin
@arkenv/cli
@arkenv/fumadocs-ui
@arkenv/nextjs
@arkenv/vite-plugin
commit: |
📦 Bundle Size Report
✅ All size limits passed! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — removes the .pipe()-based coercion wrapper with its unsafe type cast and unifies the ArkType path with the Standard Schema pre-coercion model.
- Delete
coerce()wrapper — removespackages/arkenv/src/arktype/coercion/coerce.tsand its barrel re-export, eliminating theat("unknown").pipe(...).pipe(schema) as BaseType<t, $>pattern. - Inline coercion in
parse()—packages/arkenv/src/arktype/index.tsnow callsfindCoercionPaths+applyCoerciondirectly, matching the existing flow inparse-standard.ts. - Update coercion tests —
coerce.test.tsreplaces the deleted import with a local helper that mirrors the production pre-coercion flow. - Update documentation — coercion.mdx, faq.mdx, and ADR-0002 all reflect the unified model.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
yamcodes
left a comment
There was a problem hiding this comment.
Just a few /typescript questions but it's good
I'd also ensure a /jsdoc pass and double check the /changeset although that looked good to me
- Refactor to use strictly typed JsonSchemaNode for coercion traversal without 'any' - Simplify internal coercion path imports using barrel file - Fix JSDoc annotations across ArkType parse and internal utilities
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — addresses all four TypeScript review comments from the prior review with type narrowing, import simplification, JSDoc, and a generic return type on applyCoercion.
- Narrowed
fallbackcontext type — changed from(ctx: any)to(ctx: { base: unknown })in bothparse()and the test helper. - Removed
as any/as Record<string, unknown>casts — changedfindCoercionPathsparameter fromRecord<string, any>tounknown, and added a generic<T>toapplyCoercionso coercion preserves the input type. - Added
JsonSchemaNodeinterface incoercion/shared.ts— replaces ad-hocRecord<string, any>property access with a single internal cast, plus anArray.isArray(node)guard on the early return. - Simplified imports — new
coercion/index.tsbarrel re-exports./morphsand./shared; callers now import from@/coercioninstead of@/coercion/shared. - Added JSDoc —
@param,@returns, and@throwsforarkErrorsToIssuesandparse.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…pre-coercion model (#1193) Fixes #1178 Unifies the coercion execution model between the default `arkenv` and `arkenv/standard` entry points. Uses a pre-coercion flow that shallow-copies the env object and applies coercion prior to validation against the unmodified schema. - Replace ArkType's `.pipe()` coercion wrapper with pre-coercion flow using `findCoercionPaths` + `applyCoercion` directly in `packages/arkenv/src/arktype/index.ts` - Delete the redundant wrapper file `packages/arkenv/src/arktype/coercion/coerce.ts` and its re-export - Update `coerce.test.ts` unit tests to use a local helper mapping the pre-coercion flow - Update coercion documentation, FAQ, Standard Schema docs, and ADR-0002

Fixes #1178
Unifies the coercion execution model between the default
arkenvandarkenv/standardentry points. Uses a pre-coercion flow that shallow-copies the env object and applies coercion prior to validation against the unmodified schema.Changes
.pipe()coercion wrapper with pre-coercion flow usingfindCoercionPaths+applyCoerciondirectly inpackages/arkenv/src/arktype/index.tspackages/arkenv/src/arktype/coercion/coerce.tsand its re-exportcoerce.test.tsunit tests to use a local helper mapping the pre-coercion flow