prisma-guard 1.4.1 → 1.5.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.
@@ -1247,7 +1247,14 @@ function createWhereBuilder(typeMap, enumMap, scalarBase) {
1247
1247
  let hasClientOps = false;
1248
1248
  let hasStringModeOp = false;
1249
1249
  const clientOpKeys = [];
1250
+ let modeConfigValue = void 0;
1251
+ let hasModeConfig = false;
1250
1252
  for (const [op, opValue] of Object.entries(operators)) {
1253
+ if (op === "mode") {
1254
+ hasModeConfig = true;
1255
+ modeConfigValue = opValue;
1256
+ continue;
1257
+ }
1251
1258
  if (opValue === true) {
1252
1259
  opSchemas[op] = createOperatorSchema(
1253
1260
  fieldMeta,
@@ -1277,14 +1284,43 @@ function createWhereBuilder(typeMap, enumMap, scalarBase) {
1277
1284
  );
1278
1285
  }
1279
1286
  fieldForced[op] = parsed;
1287
+ if (fieldMeta.type === "String" && !fieldMeta.isList && STRING_MODE_OPS.has(op)) {
1288
+ hasStringModeOp = true;
1289
+ }
1280
1290
  }
1281
1291
  }
1282
1292
  if (!hasClientOps && Object.keys(fieldForced).length === 0) {
1293
+ if (hasModeConfig) {
1294
+ throw new ShapeError(
1295
+ `Where field "${fieldName}" on model "${model}" has "mode" but no operators. Add at least one operator (contains, startsWith, endsWith, equals).`
1296
+ );
1297
+ }
1283
1298
  throw new ShapeError(
1284
1299
  `Empty operator config for where field "${fieldName}" on model "${model}". Define at least one operator.`
1285
1300
  );
1286
1301
  }
1287
- if (hasStringModeOp) {
1302
+ if (hasModeConfig) {
1303
+ if (!hasStringModeOp) {
1304
+ throw new ShapeError(
1305
+ `"mode" on where field "${fieldName}" on model "${model}" requires a compatible String operator (contains, startsWith, endsWith, equals)`
1306
+ );
1307
+ }
1308
+ if (modeConfigValue === true) {
1309
+ opSchemas["mode"] = z4.enum(["default", "insensitive"]).optional();
1310
+ } else {
1311
+ const actualModeValue = isForcedValue(modeConfigValue) ? modeConfigValue.value : modeConfigValue;
1312
+ const modeSchema = z4.enum(["default", "insensitive"]);
1313
+ let parsed;
1314
+ try {
1315
+ parsed = modeSchema.parse(actualModeValue);
1316
+ } catch (err) {
1317
+ throw new ShapeError(
1318
+ `Invalid forced value for "${model}.${fieldName}.mode": ${err.message}`
1319
+ );
1320
+ }
1321
+ fieldForced["mode"] = parsed;
1322
+ }
1323
+ } else if (hasStringModeOp) {
1288
1324
  opSchemas["mode"] = z4.enum(["default", "insensitive"]).optional();
1289
1325
  }
1290
1326
  if (hasClientOps) {