-
-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add additional Imports config for flexible import sections #140
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: main
Are you sure you want to change the base?
feat: add additional Imports config for flexible import sections #140
Conversation
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
Thanks for the contrib! This makes sense, I'm often doing something like: /// @kyselyType(import('module').TheThing)
prop StringI'll have a feel with this on the weekend and think it through a little. My gut feeling is that there might be a better, more generic way we could enable this. Perhaps naming it something else like "filePrefix" even, since this is, in theory, unrelated to just imports. |
|
Thanks for the quick feedback! I completely agree that filePrefix is a better, more generic name. It makes the feature more flexible and not limited to just imports - users could add comments, pragma directives, or any other content they need at the top of the file. I'm happy to update the PR to use filePrefix instead of additionalImports if you'd like, or I can wait for your thoughts after you've had more time to think it through over the weekend. Let me know what you prefer! |
|
Feel free to iterate/update it some more, but will be able to provide something more concrete this weekend. Thanks again 🙂 |
|
Hi, I just wanted to check if you’ve had a chance to take a look at it. Thanks! |
|
Sorry! I did not get a chance to unfortunately, have had a busy week/weekend. Will aim to do so next weekend. I will soon upgrade the prisma version to be compatible with 6.17. |
|
This is exactly what we were looking for! Thanks! |
|
I've gone ahead and implemented the Have you had a chance to think through the feature further? Happy to make any additional changes you'd like! Thanks for your feedback 🙂 |
|
Any word on when this will be merged? |
Add
additionalImportsConfiguration Option for Flexible Import SectionsProblem
Currently, when using
prisma-kyselyto generate Kysely types, users have no way to import additional libraries that they might need in their generated TypeScript files. This is particularly problematic when:decimal.jsorbig.jsto handle precise decimal calculationsWithout this feature, users have to manually edit the generated files after each regeneration, which is error-prone and not maintainable.
Solution
This PR introduces a new optional configuration option
additionalImportsthat allows users to specify custom import sections in their generated Kysely type files.Key Features
Flexible Import Syntax: Supports all TypeScript import patterns:
import Decimal from 'decimal.js'import { Big } from 'big.js'import * as moment from 'moment'import { v4 as uuid } from 'uuid'import type { SomeType } from './custom-types'Multiple Imports: Support for importing multiple libraries in a single configuration
Optional: Completely backward compatible - feature is disabled by default
Full Control: Users can write exactly the import statements they need
Configuration
Generated Output
The generated file will start with the custom imports followed by the standard Kysely imports:
Implementation Details
Files Modified
src/utils/validateConfig.ts: AddedadditionalImportsto the configuration schemasrc/helpers/generateFile.ts: Updated to conditionally include custom import sectionssrc/helpers/generateFiles.ts: Pass theadditionalImportsconfig togenerateFilesrc/generator.ts: Pass theadditionalImportsconfig through the generation pipelineREADME.md: Added comprehensive documentation and examplessrc/helpers/generateFile.test.ts: Added tests for all import scenariosUse Cases
Financial Applications
Applications with Custom Types
Multi-library Applications
Backward Compatibility
This feature is completely backward compatible:
Benefits
Future Considerations
This implementation provides a solid foundation that could be extended in the future with:
However, the current implementation provides maximum flexibility while keeping the feature simple and maintainable.