Delete unused opencode Zod helpers (#26793)
This commit is contained in:
@@ -36,7 +36,7 @@ export function zod<S extends Schema.Top>(schema: S): z.ZodType<Schema.Schema.Ty
|
|||||||
* mapped `.omit()` / `.extend()` surface triggers brand-intersection
|
* mapped `.omit()` / `.extend()` surface triggers brand-intersection
|
||||||
* explosions for branded primitives (`string & Brand<"SessionID">` extends
|
* explosions for branded primitives (`string & Brand<"SessionID">` extends
|
||||||
* `object` via the brand and gets walked into the prototype by `DeepPartial`,
|
* `object` via the brand and gets walked into the prototype by `DeepPartial`,
|
||||||
* `updateSchema`, etc.), and zod's inference through `z.ZodType<T | undefined>`
|
* mapped-schema helpers, and zod's inference through `z.ZodType<T | undefined>`
|
||||||
* wrappers also can't reconstruct `T` cleanly. Consumers that care about the
|
* wrappers also can't reconstruct `T` cleanly. Consumers that care about the
|
||||||
* post-`.omit()` shape should cast `c.req.valid(...)` to the expected type.
|
* post-`.omit()` shape should cast `c.req.valid(...)` to the expected type.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import { z } from "zod"
|
|
||||||
|
|
||||||
export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T>) => Result) {
|
|
||||||
const result = (input: z.infer<T>) => {
|
|
||||||
let parsed
|
|
||||||
try {
|
|
||||||
parsed = schema.parse(input)
|
|
||||||
} catch (e) {
|
|
||||||
console.trace("schema validation failure stack trace:")
|
|
||||||
if (e instanceof z.ZodError) {
|
|
||||||
console.error("schema validation issues:", JSON.stringify(e.issues, null, 2))
|
|
||||||
}
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
|
|
||||||
return cb(parsed)
|
|
||||||
}
|
|
||||||
result.force = (input: z.infer<T>) => cb(input)
|
|
||||||
result.schema = schema
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import z from "zod"
|
|
||||||
|
|
||||||
export function updateSchema<T extends z.ZodRawShape>(schema: z.ZodObject<T>) {
|
|
||||||
const next = {} as {
|
|
||||||
[K in keyof T]: z.ZodOptional<z.ZodNullable<T[K]>>
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(schema.required().shape) as [keyof T & string, z.ZodTypeAny][]) {
|
|
||||||
next[k] = v.nullable() as unknown as (typeof next)[typeof k]
|
|
||||||
}
|
|
||||||
|
|
||||||
return z.object(next)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user