Open soullivaneuh opened 2 years ago
There is no way to do that in v1.
In v2, you can derive a value from another value by using a new derivative()
API:
import { id, factory, derivative } from '@mswjs/data'
factory({
user: {
id: id(String),
age: Number,
isAdult: derivative(({ age }) => age >= 18),
}
})
I have a modeling like this:
On the production API, the
slug
property has a generated value that depends to thename
property.However, I have no way to reproduce that with the fake data factory, as I don't have the information on the getter, so I have to generate a random one.
Ideally, the simplest implementation way would be this:
Or maybe a way to define a custom function to process the given data on each
.create
and.update
call.What do you think?