zod icon indicating copy to clipboard operation
zod copied to clipboard

Validate array uniqueness

Open joaoGabriel55 opened this issue 2 years ago • 7 comments

From discussion: #2316

TODO

  • [x] Implement array of primitives uniqueness
  • [x] Implement array of complex objects uniqueness

Thanks for the help: @ramos-ph and @fwoelffel

joaoGabriel55 avatar Aug 21 '23 13:08 joaoGabriel55

Deploy Preview for guileless-rolypoly-866f8a ready!

Name Link
Latest commit 68d83b74f0cd9e8b4dbe8b9753706bfe89af2dbc
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/66283b3cf8e5c5000892af19
Deploy Preview https://deploy-preview-2672--guileless-rolypoly-866f8a.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Aug 21 '23 13:08 netlify[bot]

What suggestions do you have for array of complex objects uniqueness? I have one that would be make the objects elements from array flatten to simplifies the comparison between.

joaoGabriel55 avatar Aug 21 '23 14:08 joaoGabriel55

What suggestions do you have for array of complex objects uniqueness? I have one that would be make the objects elements from array flatten to simplifies the comparison between.

Class-validator seems to be doing a simple comparison

https://github.com/typestack/class-validator/blob/262a3c6369b9a9fc81846a39b62b6a2a21bd8fab/src/decorator/array/ArrayUnique.ts#L7-L20

aarontravass avatar Aug 21 '23 16:08 aarontravass

@colinhacks could you take a look, when you have a free time?

joaoGabriel55 avatar Aug 31 '23 20:08 joaoGabriel55

@joaoGabriel55 As discussed here, https://github.com/colinhacks/zod/discussions/2316#discussioncomment-6979061, would it be possible to add an options which would display duplicate items?

aarontravass avatar Sep 14 '23 22:09 aarontravass

@joaoGabriel55 As discussed here, #2316 (reply in thread), would it be possible to add an options which would display duplicate items?

yeah!

joaoGabriel55 avatar Sep 15 '23 11:09 joaoGabriel55

@colinhacks any thoughts about this?

fwoelffel avatar Feb 14 '24 09:02 fwoelffel

Thanks! I like this a lot, especially identifier. I'm merging this into the v4 branch. Some version of this will land in Zod 4, but — as a heads up — it may be a while, and this feature/API will likely undergo some changes in the interim.

colinhacks avatar Apr 23 '24 22:04 colinhacks