| 1633 | } |
| 1634 | |
| 1635 | export class ZodBigInt extends ZodType<bigint, ZodBigIntDef, bigint> { |
| 1636 | _parse(input: ParseInput): ParseReturnType<bigint> { |
| 1637 | if (this._def.coerce) { |
| 1638 | try { |
| 1639 | input.data = BigInt(input.data); |
| 1640 | } catch { |
| 1641 | return this._getInvalidInput(input); |
| 1642 | } |
| 1643 | } |
| 1644 | const parsedType = this._getType(input); |
| 1645 | if (parsedType !== ZodParsedType.bigint) { |
| 1646 | return this._getInvalidInput(input); |
| 1647 | } |
| 1648 | |
| 1649 | let ctx: undefined | ParseContext = undefined; |
| 1650 | const status = new ParseStatus(); |
| 1651 | |
| 1652 | for (const check of this._def.checks) { |
| 1653 | if (check.kind === "min") { |
| 1654 | const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value; |
| 1655 | if (tooSmall) { |
| 1656 | ctx = this._getOrReturnCtx(input, ctx); |
| 1657 | addIssueToContext(ctx, { |
| 1658 | code: ZodIssueCode.too_small, |
| 1659 | type: "bigint", |
| 1660 | minimum: check.value, |
| 1661 | inclusive: check.inclusive, |
| 1662 | message: check.message, |
| 1663 | }); |
| 1664 | status.dirty(); |
| 1665 | } |
| 1666 | } else if (check.kind === "max") { |
| 1667 | const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value; |
| 1668 | if (tooBig) { |
| 1669 | ctx = this._getOrReturnCtx(input, ctx); |
| 1670 | addIssueToContext(ctx, { |
| 1671 | code: ZodIssueCode.too_big, |
| 1672 | type: "bigint", |
| 1673 | maximum: check.value, |
| 1674 | inclusive: check.inclusive, |
| 1675 | message: check.message, |
| 1676 | }); |
| 1677 | status.dirty(); |
| 1678 | } |
| 1679 | } else if (check.kind === "multipleOf") { |
| 1680 | if (input.data % check.value !== BigInt(0)) { |
| 1681 | ctx = this._getOrReturnCtx(input, ctx); |
| 1682 | addIssueToContext(ctx, { |
| 1683 | code: ZodIssueCode.not_multiple_of, |
| 1684 | multipleOf: check.value, |
| 1685 | message: check.message, |
| 1686 | }); |
| 1687 | status.dirty(); |
| 1688 | } |
| 1689 | } else { |
| 1690 | util.assertNever(check); |
| 1691 | } |
| 1692 | } |
nothing calls this directly
no test coverage detected