Skip to content

Conversation

herberthobregon
Copy link
Contributor

@herberthobregon herberthobregon commented Aug 6, 2025

Fixed if one type a string, the other json stop working.

This is because I need to use an enum or string constants like 'hello' | 'word'
Example:

Doesn't Work

model pages {
  id         String   @id
  /// [pay_provider] 
  pay_provider    String 
  /// [ats_config] 
  ats_config          Json?
}

I dont know why Work???

model pages {
  id         String   @id
  d1    Json
  d2    String

  /// [pages.pay_provider] 
  pay_provider    String 
  /// [pages.ats_config] 
  ats_config          Json?
}

@arthurfiorette
Copy link
Owner

Hi! please add tests ensuring your change works and fixes your specific problem :)

@herberthobregon
Copy link
Contributor Author

Perfect. I’ll work on the weekend✅

@arthurfiorette arthurfiorette added help wanted Extra attention is needed good first issue Good for newcomers labels Aug 19, 2025
@arthurfiorette arthurfiorette self-assigned this Aug 19, 2025
@arthurfiorette arthurfiorette marked this pull request as draft August 19, 2025 15:11
case 'number':
case 'Prisma.IntFieldUpdateOperationsInput | number':
case 'Prisma.FloatFieldUpdateOperationsInput | number':
if (!shouldReplaceStrings) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you've added types to number and reusing this flag, maybe we should rename this variable to somewhat like replacePrimitive?

result = typeToChange;
break;

case `Prisma.${model}Update${field}Input | string[]`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should move these lines after L65

result = `(${typeToChange})[]`;
break;

case `Prisma.NullableIntFieldUpdateOperationsInput | number | null`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether these lines can be merged with the case on L104

@Yesterday17
Copy link
Contributor

Thank you for the solution! I encountered the same problem recently and found this PR which fixed the problem. I left several comments and hoping to improve the code quality :)

And I have a question about the error handling logic, which might not be directly related to this PR, but I did not find a good place to ask about it. I wonder why throwOnNotFound is false only if the type is unknown? Because if findNewSignaturn does not throw, everything seems to be working too without any problem.

@herberthobregon
Copy link
Contributor Author

Nice! At the moment I haven’t had time to finish the tests, but I find your observations valuable and I’ll review them tomorrow after work.

For now, I’m using it from my GitHub and it’s working quite well for me:

pnpm i github:herberthobregon/prisma-json-types-generator#npm

I hope to get it working as soon as possible to merge in main.

@herberthobregon herberthobregon changed the title fix: Add type on string fix: Add type/enum on string or number Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants