@@ -9,13 +9,13 @@ import type * as z4c from 'zod/v4/core';
99
1010import * as z4mini from 'zod/v4-mini' ;
1111
12- import { AnySchema , AnyObjectSchema , getObjectShape , safeParse , isZ4Schema , type ZodV3Internal , type ZodV4Internal } from './zod-compat.js' ;
12+ import { AnySchema , AnyObjectSchema , getObjectShape , safeParse , isZ4Schema , getLiteralValue } from './zod-compat.js' ;
1313import { zodToJsonSchema } from 'zod-to-json-schema' ;
1414
1515type JsonSchema = Record < string , unknown > ;
1616
1717// Options accepted by call sites; we map them appropriately
18- export type CommonOpts = {
18+ type CommonOpts = {
1919 strictUnions ?: boolean ;
2020 pipeStrategy ?: 'input' | 'output' ;
2121 target ?: 'jsonSchema7' | 'draft-7' | 'jsonSchema2019-09' | 'draft-2020-12' ;
@@ -59,32 +59,6 @@ export function getMethodLiteral(schema: AnyObjectSchema): string {
5959 return value ;
6060}
6161
62- export function getLiteralValue ( schema : AnySchema ) : unknown {
63- if ( isZ4Schema ( schema ) ) {
64- const v4Schema = schema as unknown as ZodV4Internal ;
65- const v4Def = v4Schema . _zod ?. def ;
66- const candidates = [ v4Def ?. value , Array . isArray ( v4Def ?. values ) ? v4Def . values [ 0 ] : undefined , v4Schema . value ] ;
67-
68- for ( const candidate of candidates ) {
69- if ( typeof candidate !== 'undefined' ) {
70- return candidate ;
71- }
72- }
73- } else {
74- const v3Schema = schema as unknown as ZodV3Internal ;
75- const legacyDef = v3Schema . _def ;
76- const candidates = [ legacyDef ?. value , Array . isArray ( legacyDef ?. values ) ? legacyDef . values [ 0 ] : undefined , v3Schema . value ] ;
77-
78- for ( const candidate of candidates ) {
79- if ( typeof candidate !== 'undefined' ) {
80- return candidate ;
81- }
82- }
83- }
84-
85- return undefined ;
86- }
87-
8862export function parseWithCompat ( schema : AnySchema , data : unknown ) : unknown {
8963 const result = safeParse ( schema , data ) ;
9064 if ( ! result . success ) {
0 commit comments