-
-
Notifications
You must be signed in to change notification settings - Fork 919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-add simplified implementation of helpers.unique #2774
Comments
Thank you for your feature proposal. We marked it as "waiting for user interest" for now to gather some feedback from our community:
We would also like to hear about other community members' use cases for the feature to give us a better understanding of their potential implicit or explicit requirements. We will start the implementation based on:
We do this because:
|
Please add to the description how the "faker-seed" is used inside that re-implementation. |
I think the reason the removal issue got so many downvotes is because it was linked from the deprecation message without showing any alternative ways of generating unique values. So my feeling is that improving the documentation is more important than rushing to restore this. |
Upon reflection, the initial reason for removing the "unique" feature was its lack of dependency on Faker's seed. This remains a valid point, IMO. However, it has come to my attention that we currently have a function within our codebase, namely In light of this, it may be valid to consider expanding the A complete alternative might be to create a new package under our name space: |
Would it be possible to add the unique helper as a wrapper around other methods? Or as an option in each factory? Given that I usually use a sequence to get locally unique values when using "fishery", the code might look like: `${faker.company.name()}-${sequence}` e.g. import { faker } from "@faker-js/faker"
import { DeepPartial, Factory } from "fishery"
import { Team } from "@/models"
function assertParamsHasOrganizationId(
params: DeepPartial<Team>
): asserts params is DeepPartial<Team> & { organizationId: number } {
if (typeof params.organizationId !== "number") {
throw new Error("organizationId is must be a number")
}
}
export const teamFactory = Factory.define<Team>(({ sequence, params, onCreate }) => {
onCreate((team) => team.save())
assertParamsHasOrganizationId(params)
return Team.build({
id: sequence,
organizationId: params.organizationId,
name: `${faker.company.name()}-${sequence}`,
})
})
export default teamFactory So if Faker where to implement something like this it could look like
or
The The advantage of the first option would be that all uniqueness code would be centralized; the disadvantage is that it would be complicated and need to handle each data type. The advantage of the second option is that it would help keep the complexity low by handling uniqueness on a per-factory level; the disadvantage is that it would require adding a new option to all factories. |
Clear and concise description of the problem
The removal/deprecation of unique has an overwhelmingly negative feedback.
The other packages that provide the unique feature outside of faker got 12 hearts.
Suggested solution
Re-add a simplified implementation of the unique method, that requires providing dedicated a unique store option.
TBD: If there should be a default uniqueStore, potentially per faker instance.
Alternative
Keep using
const values = helpers.uniqueArray
and increment theoffset
manually.Additional context
The text was updated successfully, but these errors were encountered: