prisma-guard 1.30.0 → 1.31.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.
@@ -4141,12 +4141,39 @@ function validateAllowedKeys(value, allowed, method, kind) {
4141
4141
  return `Shape key "${key}" not valid for ${method}. Allowed: ${[...allowed].join(", ")}`;
4142
4142
  });
4143
4143
  }
4144
+ var RELATION_OPS_COVERING_FK = /* @__PURE__ */ new Set([
4145
+ "connect",
4146
+ "connectOrCreate",
4147
+ "create"
4148
+ ]);
4149
+ function collectRelationCoveredFks(modelFields, dataConfig) {
4150
+ const covered = /* @__PURE__ */ new Set();
4151
+ for (const [fieldName, value] of Object.entries(dataConfig)) {
4152
+ const meta = modelFields[fieldName];
4153
+ if (!meta || !meta.isRelation)
4154
+ continue;
4155
+ const fks = meta.relationFromFields;
4156
+ if (!fks || fks.length === 0)
4157
+ continue;
4158
+ if (!isPlainObject(value))
4159
+ continue;
4160
+ const covers = Object.keys(value).some(
4161
+ (op) => RELATION_OPS_COVERING_FK.has(op)
4162
+ );
4163
+ if (!covers)
4164
+ continue;
4165
+ for (const fk of fks)
4166
+ covered.add(fk);
4167
+ }
4168
+ return covered;
4169
+ }
4144
4170
  function validateCreateCompleteness(modelName, dataConfig, typeMap, scopeFks, zodDefaults) {
4145
4171
  const modelFields = typeMap[modelName];
4146
4172
  if (!modelFields)
4147
4173
  return;
4148
4174
  const zodDefaultFields = zodDefaults[modelName];
4149
4175
  const zodDefaultSet = zodDefaultFields ? new Set(zodDefaultFields) : void 0;
4176
+ const relationCoveredFks = collectRelationCoveredFks(modelFields, dataConfig);
4150
4177
  for (const [fieldName, meta] of Object.entries(modelFields)) {
4151
4178
  if (meta.isRelation)
4152
4179
  continue;
@@ -4160,10 +4187,12 @@ function validateCreateCompleteness(modelName, dataConfig, typeMap, scopeFks, zo
4160
4187
  continue;
4161
4188
  if (scopeFks.has(fieldName))
4162
4189
  continue;
4190
+ if (relationCoveredFks.has(fieldName))
4191
+ continue;
4163
4192
  if (zodDefaultSet && zodDefaultSet.has(fieldName))
4164
4193
  continue;
4165
4194
  throw new ShapeError(
4166
- `Required field "${fieldName}" on model "${modelName}" is missing from create data shape, has no default, and is not a scope FK`
4195
+ `Required field "${fieldName}" on model "${modelName}" is missing from create data shape, has no default, is not a scope FK, and is not covered by a relation write in the shape`
4167
4196
  );
4168
4197
  }
4169
4198
  }