Skip to content

Commit

Permalink
Merge pull request #10 from iway1/zod-nullable
Browse files Browse the repository at this point in the history
Adds nullish support to zod parser
  • Loading branch information
iway1 authored Dec 15, 2022
2 parents 26fab7c + b8f82ea commit caacd3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { zodSelectorFunction } from "src/parse/input-mappers/zod/selector";
import { ParsedInputNode, ParseReferences } from "src/parse/parsed-node-types";
import { ZodNullableDef } from "zod";

export function parseZodNullableDef(
def: ZodNullableDef,
refs: ParseReferences
): ParsedInputNode {
return zodSelectorFunction(def.innerType._def, refs);
}
4 changes: 4 additions & 0 deletions packages/trpc-panel/src/parse/input-mappers/zod/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ZodEnumDef,
ZodFirstPartyTypeKind,
ZodLiteralDef,
ZodNullableDef,
ZodNumberDef,
ZodObjectDef,
ZodOptionalDef,
Expand All @@ -25,6 +26,7 @@ import { parseZodLiteralDef } from "./parsers/parseZodLiteralDef";
import { parseZodNumberDef } from "./parsers/parseZodNumberDef";
import { parseZodObjectDef } from "./parsers/parseZodObjectDef";
import { parseZodOptionalDef } from "src/parse/input-mappers/zod/parsers/parseZodOptionalDef";
import { parseZodNullableDef } from "src/parse/input-mappers/zod/parsers/parseZodNullableDef";

export const zodSelectorFunction: ParserSelectorFunction<ZodDefWithType> = (
def,
Expand Down Expand Up @@ -57,6 +59,8 @@ export const zodSelectorFunction: ParserSelectorFunction<ZodDefWithType> = (
return parseZodOptionalDef(def as ZodOptionalDef, references);
case ZodFirstPartyTypeKind.ZodString:
return parseZodStringDef(def as ZodStringDef, references);
case ZodFirstPartyTypeKind.ZodNullable:
return parseZodNullableDef(def as ZodNullableDef, references);
}
return { type: "unsupported", path: references.path, optional: false };
};
Expand Down

0 comments on commit caacd3f

Please sign in to comment.