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.
@@ -1277,7 +1277,14 @@ function createWhereBuilder(typeMap, enumMap, scalarBase) {
1277
1277
  let hasClientOps = false;
1278
1278
  let hasStringModeOp = false;
1279
1279
  const clientOpKeys = [];
1280
+ let modeConfigValue = void 0;
1281
+ let hasModeConfig = false;
1280
1282
  for (const [op, opValue] of Object.entries(operators)) {
1283
+ if (op === "mode") {
1284
+ hasModeConfig = true;
1285
+ modeConfigValue = opValue;
1286
+ continue;
1287
+ }
1281
1288
  if (opValue === true) {
1282
1289
  opSchemas[op] = createOperatorSchema(
1283
1290
  fieldMeta,
@@ -1307,14 +1314,43 @@ function createWhereBuilder(typeMap, enumMap, scalarBase) {
1307
1314
  );
1308
1315
  }
1309
1316
  fieldForced[op] = parsed;
1317
+ if (fieldMeta.type === "String" && !fieldMeta.isList && STRING_MODE_OPS.has(op)) {
1318
+ hasStringModeOp = true;
1319
+ }
1310
1320
  }
1311
1321
  }
1312
1322
  if (!hasClientOps && Object.keys(fieldForced).length === 0) {
1323
+ if (hasModeConfig) {
1324
+ throw new ShapeError(
1325
+ `Where field "${fieldName}" on model "${model}" has "mode" but no operators. Add at least one operator (contains, startsWith, endsWith, equals).`
1326
+ );
1327
+ }
1313
1328
  throw new ShapeError(
1314
1329
  `Empty operator config for where field "${fieldName}" on model "${model}". Define at least one operator.`
1315
1330
  );
1316
1331
  }
1317
- if (hasStringModeOp) {
1332
+ if (hasModeConfig) {
1333
+ if (!hasStringModeOp) {
1334
+ throw new ShapeError(
1335
+ `"mode" on where field "${fieldName}" on model "${model}" requires a compatible String operator (contains, startsWith, endsWith, equals)`
1336
+ );
1337
+ }
1338
+ if (modeConfigValue === true) {
1339
+ opSchemas["mode"] = import_zod4.z.enum(["default", "insensitive"]).optional();
1340
+ } else {
1341
+ const actualModeValue = isForcedValue(modeConfigValue) ? modeConfigValue.value : modeConfigValue;
1342
+ const modeSchema = import_zod4.z.enum(["default", "insensitive"]);
1343
+ let parsed;
1344
+ try {
1345
+ parsed = modeSchema.parse(actualModeValue);
1346
+ } catch (err) {
1347
+ throw new ShapeError(
1348
+ `Invalid forced value for "${model}.${fieldName}.mode": ${err.message}`
1349
+ );
1350
+ }
1351
+ fieldForced["mode"] = parsed;
1352
+ }
1353
+ } else if (hasStringModeOp) {
1318
1354
  opSchemas["mode"] = import_zod4.z.enum(["default", "insensitive"]).optional();
1319
1355
  }
1320
1356
  if (hasClientOps) {