Releases: Quramy/prisma-fabbrica
Releases · Quramy/prisma-fabbrica
v2.2.1
What's Changed
- docs: fix typo in README.md by @mochizukikotaro in #348
- fix: Check indexing access by @Quramy in #350
New Contributors
- @mochizukikotaro made their first contribution in #348
Full Changelog: v2.2.0...v2.2.1
v2.2.0
New Features
Transient fields
Transient fields allows to define arbitrary parameters to factories.
const UserFactory = defineUserFactory.withTransientFields({
loginCount: 0,
})({
defaultData: async ({ loginCount }) => ({
/* Do something using `loginCount` parameter */
}),
});
await UserFactory.create({
name: "Bob", // `name` field is defined in scehma.primsma
loginCount: 100, // `loginCount` field is NOT defined in schema but defined in factory
});
If you want more details, See docs
Callback functions
Allow to define callback functions when to define factories like this:
const UserFactory = defineUserFactory({
onAfterCreate: async (user) => {
await PostFactory.craete({
author: { connect: uesr },
});
},
});
await UserFactory.create();
Available callback functions are onAfterBuild
, onBeforeCreate
, and onAfterCreate
.
If you want more details, See docs
Improve createList
signature
createList
(or buildList
) method in factory interface accepts the 2nd argument.
The 2nd argument can be an object assignable to Partial<Prisma.MODEL.CreateInput>
.
// Insert 10 LoginHistory model records with the same `userId` field.
await LoginHistoryFactory.createList(10, { userId: "user001" });
Full Changelog: v2.1.5...v2.2.0