Skip to content
Discussion options

You must be logged in to vote

Update

Since v1.0, Data no longer provides any object modeling capabilities. You can use any Standard Schema-compliant library (Zod, ArkType, etc) to describe a schema where some properties are derived from other properties.

Here's an example of deriving the email field from the firstsName and lastName fields:

const users = new Collection({
schema: z
.object({
firstName: z.string(),
lastName: z.string(),
email: z.email().optional(),
})
.transform((user) => {
user.email = `${user.firstName.toLowerCase()}.${user.lastName.toLowerCase()}@email.com`
return user
}),

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants