-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
Hi there, thanks for providing this library. I have a feature request for supporting custom options. Let imagine we have a User and also a paginated response of users. It might look something like this:
type User = {
id: string
}
type Paginated<T> = {
data: T[],
pagination_data: any
}
export const userBuilder = build<User>('User', {
fields: {
id: perBuild(() => faker.string.uuid()),
},
})
export const paginatedUsersBuilder = build<Paginated<User>>('PaginatedUsers', {
fields: {
data: perBuild(() => userBuilder.many(10)),
pagination_data: {},
},
})
const users = paginatedUsersBuilder()You can see we are generating 10 users using many. However, what if we wanted to change the number of users created in the paginated response? Custom options could accomplish this.
The API could look something like this:
type User = {
id: string
}
type Paginated<T> = {
data: T[],
pagination_data: any
}
export const userBuilder = build<User>('User', {
fields: {
id: perBuild(() => faker.string.uuid()),
},
})
type PaginatedUsersOptions = {
count?: number
}
export const paginatedUsersBuilder = build<Paginated<User>, PaginatedUsersOptions>('PaginatedUsers', {
fields: {
data: perBuild((options) => userBuilder.many(options.count ?? 10)),
pagination_data: {},
},
})
const users = paginatedUsersBuilder({
options: {
count: 20
}
})Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels