You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pretty new to open source world, but I can't help but wonder if it would be possible to leverage zod to build a system for efficient / flexible / ergonomic equality comparison and not just schema validation.
I for example have a use case where I have to check if a restaurant from a json string has been changed or not, and I could imagine something like this being buildable.
constrestaurantSchema=z.object({id: z.string(),name: z.string(),createdAt: z.string(),updatedAt: z.string()})constrestaurant1={id: "12345",name: "Restaurant 1",createdAt: "1/1/2021",updatedAt: "1/1/2022",}constrestaurant1Copy=structuredClone(restaurant1)consteditedRestaurant1={id: "12345",name: "Restaurant 1",createdAt: "1/1/2021",updatedAt: "1/1/2023",}consthasRestaurantChangedAtAll=!restaurantSchema.compare(restaurant1,restaurant1Copy)// falseconsthasRestaurantChangedAtAll=!restaurantSchema.compare(restaurant1,editedRestaurant1)// true// you could be explicit about ignoring some fieldsconsthasRestaurantChangedShape=!restaurantSchema.compare(restaurant1,editedRestaurant1,{ignoreSchema: {updatedAt: true}})// false// or you could alternatively provide an "only check these fields" consthasRestaurantChangedShape=!restaurantSchema.compare(restaurant1,editedRestaurant1,{onlyCheck: {id: true}})// false
I took a look at This Discussion, saw how old it was and figured it was worth maybe revisiting with some more thought. I'm mainly just curious if under the hood zod has the internals to support something like this
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Pretty new to open source world, but I can't help but wonder if it would be possible to leverage zod to build a system for efficient / flexible / ergonomic equality comparison and not just schema validation.
I for example have a use case where I have to check if a restaurant from a json string has been changed or not, and I could imagine something like this being buildable.
I took a look at This Discussion, saw how old it was and figured it was worth maybe revisiting with some more thought. I'm mainly just curious if under the hood zod has the internals to support something like this
Beta Was this translation helpful? Give feedback.
All reactions