Skip to content

Commit ac7d541

Browse files
committed
chore: clean up extra function and types in compat layer
1 parent 2cef25b commit ac7d541

File tree

2 files changed

+2
-30
lines changed

2 files changed

+2
-30
lines changed

src/server/zod-compat.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ export type SchemaOutput<S> = S extends z3.ZodTypeAny ? z3.infer<S> : S extends
4646

4747
export type SchemaInput<S> = S extends z3.ZodTypeAny ? z3.input<S> : S extends z4.$ZodType ? z4.input<S> : never;
4848

49-
export type ObjectOutput<S extends AnyObjectSchema> = SchemaOutput<S>;
50-
5149
/**
5250
* Infers the output type from a ZodRawShapeCompat (raw shape object).
5351
* Maps over each key in the shape and infers the output type from each schema.

src/server/zod-json-schema-compat.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import type * as z4c from 'zod/v4/core';
99

1010
import * 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';
1313
import { zodToJsonSchema } from 'zod-to-json-schema';
1414

1515
type 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-
8862
export function parseWithCompat(schema: AnySchema, data: unknown): unknown {
8963
const result = safeParse(schema, data);
9064
if (!result.success) {

0 commit comments

Comments
 (0)