| 3684 | } |
| 3685 | |
| 3686 | export class ZodSet<Value extends ZodTypeAny = ZodTypeAny> extends ZodType< |
| 3687 | Set<Value["_output"]>, |
| 3688 | ZodSetDef<Value>, |
| 3689 | Set<Value["_input"]> |
| 3690 | > { |
| 3691 | _parse(input: ParseInput): ParseReturnType<this["_output"]> { |
| 3692 | const { status, ctx } = this._processInputParams(input); |
| 3693 | if (ctx.parsedType !== ZodParsedType.set) { |
| 3694 | addIssueToContext(ctx, { |
| 3695 | code: ZodIssueCode.invalid_type, |
| 3696 | expected: ZodParsedType.set, |
| 3697 | received: ctx.parsedType, |
| 3698 | }); |
| 3699 | return INVALID; |
| 3700 | } |
| 3701 | |
| 3702 | const def = this._def; |
| 3703 | |
| 3704 | if (def.minSize !== null) { |
| 3705 | if (ctx.data.size < def.minSize.value) { |
| 3706 | addIssueToContext(ctx, { |
| 3707 | code: ZodIssueCode.too_small, |
| 3708 | minimum: def.minSize.value, |
| 3709 | type: "set", |
| 3710 | inclusive: true, |
| 3711 | exact: false, |
| 3712 | message: def.minSize.message, |
| 3713 | }); |
| 3714 | status.dirty(); |
| 3715 | } |
| 3716 | } |
| 3717 | |
| 3718 | if (def.maxSize !== null) { |
| 3719 | if (ctx.data.size > def.maxSize.value) { |
| 3720 | addIssueToContext(ctx, { |
| 3721 | code: ZodIssueCode.too_big, |
| 3722 | maximum: def.maxSize.value, |
| 3723 | type: "set", |
| 3724 | inclusive: true, |
| 3725 | exact: false, |
| 3726 | message: def.maxSize.message, |
| 3727 | }); |
| 3728 | status.dirty(); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | const valueType = this._def.valueType; |
| 3733 | |
| 3734 | function finalizeSet(elements: SyncParseReturnType<any>[]) { |
| 3735 | const parsedSet = new Set(); |
| 3736 | for (const element of elements) { |
| 3737 | if (element.status === "aborted") return INVALID; |
| 3738 | if (element.status === "dirty") status.dirty(); |
| 3739 | parsedSet.add(element.value); |
| 3740 | } |
| 3741 | return { status: status.value, value: parsedSet }; |
| 3742 | } |
| 3743 |
nothing calls this directly
no test coverage detected