prisma-mock 1.1.0-alpha.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/delegate.js +13 -0
  2. package/package.json +1 -1
package/lib/delegate.js CHANGED
@@ -629,6 +629,19 @@ const createDelegate = ({ ref, prisma, datamodel = prisma.dmmf.datamodel, caseIn
629
629
  return (0, fieldHelpers_1.getCamelCase)(model.name) === prop;
630
630
  });
631
631
  const d = nestedUpdate(args, true, null);
632
+ // Check compound @@unique constraint violations during creation
633
+ const compoundUniques = model.uniqueFields?.filter((uf) => uf.length > 1) || [];
634
+ for (const fields of compoundUniques) {
635
+ const hasAllValues = fields.every((f) => d[f] !== undefined && d[f] !== null);
636
+ if (hasAllValues) {
637
+ const whereKey = fields.join("_");
638
+ const whereClause = fields.reduce((acc, f) => ({ ...acc, [f]: d[f] }), {});
639
+ const existing = findOne({ where: { [whereKey]: whereClause } });
640
+ if (existing) {
641
+ (0, errors_1.throwKnownError)(prisma, `Unique constraint failed on the fields: (\`${fields.join("`, `")}\`)`, { code: "P2002", meta: { modelName: model.name, target: fields } });
642
+ }
643
+ }
644
+ }
632
645
  ref.data = {
633
646
  ...ref.data,
634
647
  [prop]: [...ref.data[prop] || [], d],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-mock",
3
- "version": "1.1.0-alpha.3",
3
+ "version": "1.1.0",
4
4
  "description": "Mock prisma for unit testing database",
5
5
  "main": "lib/index.js",
6
6
  "repository": {