Skip to content

Commit

Permalink
fix: update filter types to conditionally include Prisma filters base…
Browse files Browse the repository at this point in the history
…d on field requirements
  • Loading branch information
WhyAsh5114 committed Dec 30, 2024
1 parent 81aa5c0 commit 10f969a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ export function addBigIntFilter(utilsFile: SourceFile, models: readonly Model[])
const bigIntFields = models.flatMap(({ fields }) => fields).filter((field) => field.type === "BigInt");
if (bigIntFields.length === 0) return;

const nonNullableBigIntFieldPresent = bigIntFields.some(({ isRequired }) => isRequired);
const nullableBigIntFieldPresent = bigIntFields.some(({ isRequired }) => !isRequired);
let filterType = "undefined | number | bigint | Prisma.BigIntFilter<unknown>";

let filterType = "undefined | number | bigint";
if (nonNullableBigIntFieldPresent) {
filterType += " | Prisma.BigIntFilter<unknown>";
}
if (nullableBigIntFieldPresent) {
filterType += " | null | Prisma.BigIntNullableFilter<unknown>";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ export function addBoolFilter(utilsFile: SourceFile, models: readonly Model[]) {
const booleanFields = models.flatMap(({ fields }) => fields).filter((field) => field.type === "Boolean");
if (booleanFields.length === 0) return;

const nonNullableBooleanFieldPresent = booleanFields.some(({ isRequired }) => isRequired);
const nullableBooleanFieldPresent = booleanFields.some(({ isRequired }) => !isRequired);
let filterType = "undefined | boolean | Prisma.BoolFilter<unknown>";

let filterType = "undefined | boolean";
if (nonNullableBooleanFieldPresent) {
filterType += " | Prisma.BoolFilter<unknown>";
}
if (nullableBooleanFieldPresent) {
filterType += " | null | Prisma.BoolNullableFilter<unknown>";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ export function addBytesFilter(utilsFile: SourceFile, models: readonly Model[])
const bytesFields = models.flatMap(({ fields }) => fields).filter((field) => field.type === "Bytes");
if (bytesFields.length === 0) return;

const nonNullableBytesFieldPresent = bytesFields.some(({ isRequired }) => isRequired);
const nullableBytesFieldPresent = bytesFields.some(({ isRequired }) => !isRequired);
let filterType = "undefined | Uint8Array | Prisma.BytesFilter<unknown>";

let filterType = "undefined | Uint8Array";
if (nonNullableBytesFieldPresent) {
filterType += " | Prisma.BytesFilter<unknown>";
}
if (nullableBytesFieldPresent) {
filterType += " | null | Prisma.BytesNullableFilter<unknown>";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ export function addDateTimeFilter(utilsFile: SourceFile, models: readonly Model[
const dateTimeFields = models.flatMap(({ fields }) => fields).filter((field) => field.type === "DateTime");
if (dateTimeFields.length === 0) return;

const nonNullableDateTimeFieldPresent = dateTimeFields.some(({ isRequired }) => isRequired);
const nullableDateTimeFieldPresent = dateTimeFields.some(({ isRequired }) => !isRequired);
let filterType = "undefined | Date | string | Prisma.DateTimeFilter<unknown>";

let filterType = "undefined | Date | string";
if (nonNullableDateTimeFieldPresent) {
filterType += " | Prisma.DateTimeFilter<unknown>";
}
if (nullableDateTimeFieldPresent) {
filterType += " | null | Prisma.DateTimeNullableFilter<unknown>";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export function addNumberFilter(utilsFile: SourceFile, models: readonly Model[])
if (intFields.length + floatFields.length === 0) return;
let filterType = "undefined | number";

if (intFields.length) filterType += "| Prisma.IntFilter<unknown>";
if (floatFields.length) filterType += "| Prisma.FloatFilter<unknown>";
if (intFields.some(({ isRequired }) => isRequired)) filterType += "| Prisma.IntFilter<unknown>";
if (floatFields.some(({ isRequired }) => isRequired)) filterType += "| Prisma.FloatFilter<unknown>";

if (intFields.some(({ isRequired }) => !isRequired)) filterType += "| Prisma.IntNullableFilter<unknown>";
if (floatFields.some(({ isRequired }) => !isRequired)) filterType += "| Prisma.FloatNullableFilter<unknown>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ export function addStringFilter(utilsFile: SourceFile, models: readonly Model[])
const stringFields = models.flatMap(({ fields }) => fields).filter((field) => field.type === "String");
if (stringFields.length === 0) return;

const nonNullableStringFieldPresent = stringFields.some(({ isRequired }) => isRequired);
const nullableStringFieldPresent = stringFields.some(({ isRequired }) => !isRequired);
let filterType = "undefined | string | Prisma.StringFilter<unknown>";

let filterType = "undefined | string";
if (nonNullableStringFieldPresent) {
filterType += " | Prisma.StringFilter<unknown>";
}
if (nullableStringFieldPresent) {
filterType += " | null | Prisma.StringNullableFilter<unknown>";
}
Expand Down

0 comments on commit 10f969a

Please sign in to comment.