-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Added prisma extension to convert "path" in array format (postgresql) to string format (mysql) #1535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Added prisma extension to convert "path" from array format (postgresql) to string format (mysql)
Reviewer's GuideIntroduces a Prisma Client extension that converts PostgreSQL-style JSON path arrays into MySQL-compatible string paths at runtime via a proxy wrapper for the MySQL provider, adds a fallback for missing message status in the WhatsApp service, and enables JS support to compile the new extension. Sequence Diagram for JSON Path Conversion in Prisma QueriessequenceDiagram
actor ClientCode as "Application Code"
participant PR_Proxy as "PrismaRepository (MySQL Proxy)"
participant Ext as "pgPathToMysql Extension"
participant PrismaCore as "Prisma Client Core"
participant DB as "MySQL Database"
ClientCode->>PR_Proxy: Query with JSON array path (e.g., findFirst({ where: { data: { path: ['field'] } } }))
PR_Proxy->>Ext: overriddenOperation(args)
Ext->>Ext: processWhere(args.where)
Ext->>Ext: convertPgPathToMysql(['field'])
Note right of Ext: Converts ['field'] to '$.field'
Ext-->>PR_Proxy: Modified args with string path
PR_Proxy->>PrismaCore: query(modifiedArgs)
PrismaCore->>DB: Execute SQL with '$.field'
DB-->>PrismaCore: Query Result
PrismaCore-->>PR_Proxy: Query Result
PR_Proxy-->>ClientCode: Query Result
Sequence Diagram for Message Status Fallback LogicsequenceDiagram
participant WhatsApp as "WhatsApp Event Source"
participant BSS as "BaileysStartupService"
participant Repo as "PrismaRepository"
WhatsApp->>BSS: Message Update (e.g., edited, status undefined)
BSS->>BSS: Process update: update.status is undefined
BSS->>BSS: Use findMessage.status as fallback for message.status
Note right of BSS: new_status = status[update.status] // undefined<br/> || findMessage.status // used
BSS->>BSS: Prepare message data with resolved status
BSS->>Repo: Save/Update message data
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @w35l3y - I've reviewed your changes - here's some feedback:
- The processWhere function mutates the original args.where object in place—consider cloning it first to avoid unexpected side-effects on shared objects.
- The extendsWithProxy Proxy wrapper adds complexity to the Prisma client—consider using PrismaClient.$extends directly to simplify typing and client behavior.
- You’re logging full query args and results on every operation—restrict or sanitize these debug logs in production to avoid performance hits and leaking sensitive data.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Outdated
Show resolved
Hide resolved
@DavidsonGomes , resolvi a situação do lint, mas o conflito... no meu caso, aconteceu quando a mensagem foi editada. Para mim, não faria sentido ficar com o status de DELETED. Vocês entendem melhor o projeto como um todo e podem ter uma ideia diferente da minha. |
Este PR deve resolver os seguintes erros:
path
: Invalid value provided. Expected String, provided (String).this.cache.delete()
invocation - Argumentpath
: Invalid value provided. Expected String, provided (String). #1158status
is missing.status
is missing #1266O 1o erro ocorre sempre que há alguma consulta que envolve buscar algo em um campo JSON.
Por exemplo:
De acordo com a documentação do Prisma, o formato esperado para trabalhar com MySQL é o seguinte:
A solução proposta foi criar uma extensão que é aplicada em tempo de execução quando se está usando o provider "mysql".
Ou seja, a aplicação continua usando o formato de array (postgresql) e a extensão processa a cláusula where de forma recursiva e converte o "path" em string.
Para maiores detalhes, segue links da documentação:
O 2o erro aconteceu comigo quando recebi uma mensagem editada.
Mensagens editadas não possuem status.
Então, o campo "status" terminava ficando indefinido.
Como "status" é um campo obrigatório no banco, lança o erro.
A solução proposta para este caso foi atribuir o status da mensagem original quando este for indefinido.
Summary by Sourcery
Add runtime Prisma extension to convert PostgreSQL-style JSON path arrays into MySQL JSON path strings and apply it via a proxy when using the MySQL provider, fix missing message status fallback, and enable JavaScript support in tsconfig.
New Features:
extendsWithProxy
wrapper when the MySQL provider is used.Bug Fixes:
update.status
is undefined to prevent missing status errors.Build:
allowJs
in tsconfig to include the new JavaScript Prisma extension file.