diff --git a/packages/generator/src/fileCreators/idb-utils/filters/BigIntFilter.ts b/packages/generator/src/fileCreators/idb-utils/filters/BigIntFilter.ts index ce46035..0568fb0 100644 --- a/packages/generator/src/fileCreators/idb-utils/filters/BigIntFilter.ts +++ b/packages/generator/src/fileCreators/idb-utils/filters/BigIntFilter.ts @@ -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"; + + let filterType = "undefined | number | bigint"; + if (nonNullableBigIntFieldPresent) { + filterType += " | Prisma.BigIntFilter"; + } if (nullableBigIntFieldPresent) { filterType += " | null | Prisma.BigIntNullableFilter"; } diff --git a/packages/generator/src/fileCreators/idb-utils/filters/BoolFilter.ts b/packages/generator/src/fileCreators/idb-utils/filters/BoolFilter.ts index 5f729af..cef88b6 100644 --- a/packages/generator/src/fileCreators/idb-utils/filters/BoolFilter.ts +++ b/packages/generator/src/fileCreators/idb-utils/filters/BoolFilter.ts @@ -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"; + + let filterType = "undefined | boolean"; + if (nonNullableBooleanFieldPresent) { + filterType += " | Prisma.BoolFilter"; + } if (nullableBooleanFieldPresent) { filterType += " | null | Prisma.BoolNullableFilter"; } diff --git a/packages/generator/src/fileCreators/idb-utils/filters/BytesFilter.ts b/packages/generator/src/fileCreators/idb-utils/filters/BytesFilter.ts index 192b00e..c683e32 100644 --- a/packages/generator/src/fileCreators/idb-utils/filters/BytesFilter.ts +++ b/packages/generator/src/fileCreators/idb-utils/filters/BytesFilter.ts @@ -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"; + + let filterType = "undefined | Uint8Array"; + if (nonNullableBytesFieldPresent) { + filterType += " | Prisma.BytesFilter"; + } if (nullableBytesFieldPresent) { filterType += " | null | Prisma.BytesNullableFilter"; } diff --git a/packages/generator/src/fileCreators/idb-utils/filters/DateTimeFilter.ts b/packages/generator/src/fileCreators/idb-utils/filters/DateTimeFilter.ts index cb35396..7b243f9 100644 --- a/packages/generator/src/fileCreators/idb-utils/filters/DateTimeFilter.ts +++ b/packages/generator/src/fileCreators/idb-utils/filters/DateTimeFilter.ts @@ -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"; + + let filterType = "undefined | Date | string"; + if (nonNullableDateTimeFieldPresent) { + filterType += " | Prisma.DateTimeFilter"; + } if (nullableDateTimeFieldPresent) { filterType += " | null | Prisma.DateTimeNullableFilter"; } diff --git a/packages/generator/src/fileCreators/idb-utils/filters/NumberFilter.ts b/packages/generator/src/fileCreators/idb-utils/filters/NumberFilter.ts index efb46ce..e387036 100644 --- a/packages/generator/src/fileCreators/idb-utils/filters/NumberFilter.ts +++ b/packages/generator/src/fileCreators/idb-utils/filters/NumberFilter.ts @@ -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"; - if (floatFields.length) filterType += "| Prisma.FloatFilter"; + if (intFields.some(({ isRequired }) => isRequired)) filterType += "| Prisma.IntFilter"; + if (floatFields.some(({ isRequired }) => isRequired)) filterType += "| Prisma.FloatFilter"; if (intFields.some(({ isRequired }) => !isRequired)) filterType += "| Prisma.IntNullableFilter"; if (floatFields.some(({ isRequired }) => !isRequired)) filterType += "| Prisma.FloatNullableFilter"; diff --git a/packages/generator/src/fileCreators/idb-utils/filters/StringFilter.ts b/packages/generator/src/fileCreators/idb-utils/filters/StringFilter.ts index bccb51d..297011e 100644 --- a/packages/generator/src/fileCreators/idb-utils/filters/StringFilter.ts +++ b/packages/generator/src/fileCreators/idb-utils/filters/StringFilter.ts @@ -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"; + + let filterType = "undefined | string"; + if (nonNullableStringFieldPresent) { + filterType += " | Prisma.StringFilter"; + } if (nullableStringFieldPresent) { filterType += " | null | Prisma.StringNullableFilter"; }