Skip to content

Commit

Permalink
🪲 Fix silly cases for UIntNumberSchema (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored May 9, 2024
1 parent 1e9b652 commit f3ab6c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slow-walls-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/devtools": patch
---

Update UIntNumberSchema to handle silly cases (like invalid toString() implementation)
16 changes: 15 additions & 1 deletion packages/devtools/src/omnigraph/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,21 @@ export const UIntBigIntSchema = z
})
.pipe(z.bigint().nonnegative())

export const UIntNumberSchema = z.coerce.number().nonnegative().int()
export const UIntNumberSchema = z
.unknown()
.transform((value, ctx): number => {
try {
return Number(value)
} catch {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Invalid Number-like value`,
})

return z.NEVER
}
})
.pipe(z.number().nonnegative().int())

export const AddressSchema = z.string()

Expand Down

0 comments on commit f3ab6c6

Please sign in to comment.