Skip to content

Conversation

@Lqm1
Copy link

@Lqm1 Lqm1 commented Sep 16, 2025

Resolves: #143 #142

This pull request refactors the codebase to use Prisma schema AST parsing instead of the Prisma DMMF format, simplifying model analysis and removing dependencies on Prisma internals. It introduces a new AST-based analysis module, updates dependencies, and migrates tests and core logic to use the new approach. The changes improve maintainability and compatibility with Prisma by relying on the open-source @mrleebo/prisma-ast library.

Migration to AST-based schema analysis:

  • Replaced the DMMF-based model analysis in src/dmmf.ts with a new AST-based implementation in src/ast.ts, using @mrleebo/prisma-ast for parsing Prisma schema files. The new analyseSchema and analyseSchemaFile functions provide model analysis based on schema comments and attributes, and the types were updated from DMMFModels to ASTModels. [1] [2] [3]

  • Updated all usages of the model analysis types and functions in src/encryption.ts and other modules to use the new AST-based types and functions (ASTModels instead of DMMFModels). [1] [2] [3]

Dependency updates and cleanup:

  • Removed the dependency on @prisma/internals and added @mrleebo/prisma-ast to package.json. Also updated the bin field for correct CLI usage. [1] [2]

  • Changed the Yarn node linker to node-modules for compatibility. (.yarnrc.yml)

Test migration and improvements:

  • Removed the old DMMF-based tests in src/dmmf.test.ts and added new, comprehensive AST-based tests in src/ast.test.ts, covering annotation parsing and schema analysis. [1] [2]

File renaming and code organization:

  • Renamed src/dmmf.ts to src/ast.ts to reflect the new AST-based approach.

References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

- Replaced DMMFModels with ASTModels in encryption and middleware logic.
- Updated schema analysis to use @mrleebo/prisma-ast for parsing Prisma schemas.
- Introduced new functions for parsing encrypted and hash annotations.
- Adjusted tests to reflect changes in schema parsing and model descriptors.
- Deprecated DMMFDocument in favor of schemaPath in Configuration.
- Enhanced error handling for cursor and field types in schema analysis.
@franky47
Copy link
Member

Looks like the GitHub Actions workflow needs a little update before we can run it..

@Lqm1
Copy link
Author

Lqm1 commented Sep 16, 2025

I don't know if it will be solved, but I upgraded it to v4 anyway.

@Lqm1 Lqm1 requested a review from franky47 September 16, 2025 10:55
@coveralls
Copy link

coveralls commented Sep 16, 2025

Pull Request Test Coverage Report for Build 17791208893

Details

  • 36 of 43 (83.72%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 79.65%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/extension.ts 3 4 75.0%
src/middleware.ts 3 4 75.0%
src/ast.ts 30 35 85.71%
Totals Coverage Status
Change from base Build 13069234660: 0.4%
Covered Lines: 277
Relevant Lines: 330

💛 - Coveralls

Copy link
Member

@franky47 franky47 left a comment

Choose a reason for hiding this comment

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

LGTM, this will be a breaking change though, could you add a migration step in the docs please?

I'll have to do a pass on the CI process separately, I recently hardened my NPM account due to the supply chain attacks and I need to update this project's settings accordingly.

@Lqm1
Copy link
Author

Lqm1 commented Sep 17, 2025

LGTM, this will be a breaking change though, could you add a migration step in the docs please?

I'll have to do a pass on the CI process separately, I recently hardened my NPM account due to the supply chain attacks and I need to update this project's settings accordingly.

Edited how to migrate from v1.x to v2.x and how to use it
If you release these changes as v1.x, please let me know as I will revise them again.

@Lqm1 Lqm1 requested a review from franky47 September 17, 2025 11:51
Copy link
Member

@franky47 franky47 left a comment

Choose a reason for hiding this comment

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

LGTM, I'll see if I can setup pkg.pr.new here to give you a preview build to play with.

@franky47 franky47 added the deploy:preview Deploy a preview version of this PR on pkg.pr.new label Sep 18, 2025
@franky47
Copy link
Member

franky47 commented Sep 18, 2025

The automatic comment from pkg.pr.new failed, but here is the preview build:

npm install https://pkg.pr.new/prisma-field-encryption@f84e373

Hopefully subsequent pushes will be enough to trigger it.

@bryan-hunter
Copy link

any updates on this?

@hrueger
Copy link

hrueger commented Oct 13, 2025

We recently tried this pull request, but we had some problem with it. I believe it didn't handle multi-file schemas correctly, I'll ask my colleague for futher info.

@bryan-hunter
Copy link

We recently tried this pull request, but we had some problem with it. I believe it didn't handle multi-file schemas correctly, I'll ask my colleague for futher info.

ahh, thanks for the response!

@hrueger
Copy link

hrueger commented Oct 14, 2025

Hi all,
I made a reproduction repository: https://github.com/hrueger/prisma-encrypted-fields-test
When trying to insert the user, it fails with

/home/me/source/prisma-encrypted-fields-test/node_modules/prisma-field-encryption/dist/encryption.js:93
    if (Object.keys(model.fields).length === 0 &&
                          ^

TypeError: Cannot read properties of undefined (reading 'fields')
    at decryptOnRead (/home/me/source/prisma-encrypted-fields-test/node_modules/prisma-field-encryption/dist/encryption.js:93:27)
    at Array.$allOperations (/home/me/source/prisma-encrypted-fields-test/node_modules/prisma-field-encryption/dist/extension.js:36:52)
    at async a (/home/me/source/prisma-encrypted-fields-test/node_modules/@prisma/client/src/runtime/getPrismaClient.ts:833:24)
    at async <anonymous> (/home/me/source/prisma-encrypted-fields-test/index.ts:19:5)

Node.js v22.20.0

Hope that helps!

@batkedev

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy:preview Deploy a preview version of this PR on pkg.pr.new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prisma 6.16.0 — dmmf shape changed: documentation missing and field-encryption breaks in prisma-client-js

6 participants