From d0782f7fac8a9215414d3e17c44ec85da8df36d0 Mon Sep 17 00:00:00 2001 From: Adam Varga Date: Tue, 7 Oct 2025 14:14:26 +0200 Subject: [PATCH 1/8] feat: add additionalImports config for flexible import sections --- README.md | 37 ++++++++++++++++++++++++++++++++ src/generator.ts | 1 + src/helpers/generateFile.test.ts | 34 +++++++++++++++++++++++++++++ src/helpers/generateFile.ts | 5 +++-- src/helpers/generateFiles.ts | 4 ++++ src/utils/validateConfig.ts | 3 +++ 6 files changed, 82 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00e4dad..145ccbc 100644 --- a/README.md +++ b/README.md @@ -39,12 +39,48 @@ without losing the safety of the TypeScript type system? fileName = "types.ts" // Optionally generate runtime enums to a separate file enumFileName = "enums.ts" + // Optionally import any additional libraries + additionalImports = "import Decimal from 'decimal.js';" } ``` 3. Run `prisma migrate dev` or `prisma generate` and use your freshly generated types when instantiating Kysely! +### Advanced Import Configuration + +The `additionalImports` option supports full import sections, allowing you to import multiple libraries with different syntaxes: + +```prisma +generator kysely { + provider = "prisma-kysely" + output = "../src/db" + fileName = "types.ts" + + // Import multiple libraries with different syntaxes + additionalImports = """ +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'; +""" +} +``` + +This will generate a file that starts with: + +```typescript +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'; + +import type { ColumnType } from "kysely"; +// ... rest of generated types +``` + ### Motivation Prisma's migration and schema definition workflow is undeniably great, and the @@ -81,6 +117,7 @@ hope it's just as useful for you! 😎 | `enumFileName` | The filename for the generated enums. Omitting this will generate enums and files in the same file. | | | `camelCase` | Enable support for Kysely's camelCase plugin | `false` | | `exportWrappedTypes` | Kysely wrapped types such as `Selectable` are also exported as described in the [Kysely documentation](https://kysely.dev/docs/getting-started#types). The exported types follow the naming conventions of the document. | `false` | +| `additionalImports` | Import any additional libraries. Set to the full import section you want (e.g., `"import Decimal from 'decimal.js';"`, `"import { Big } from 'big.js';"`, multiple imports separated by newlines, etc.). When set, adds the import section to the generated file. | | | `readOnlyIds` | Use Kysely's `GeneratedAlways` for `@id` fields with default values, preventing insert and update. | `false` | | `[typename]TypeOverride` | Allows you to override the resulting TypeScript type for any Prisma type. Useful when targeting a different environment than Node (e.g. WinterCG compatible runtimes that use UInt8Arrays instead of Buffers for binary types etc.) Check out the [config validator](https://github.com/valtyr/prisma-kysely/blob/main/src/utils/validateConfig.ts) for a complete list of options. | | | `dbTypeName` | Allows you to override the exported type with all tables | `DB` | diff --git a/src/generator.ts b/src/generator.ts index 80d89a4..9e21db1 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -123,6 +123,7 @@ generatorHandler({ defaultSchema: config.defaultSchema, importExtension: config.importExtension, exportWrappedTypes: config.exportWrappedTypes, + additionalImports: config.additionalImports, }); // And write it to a file! diff --git a/src/helpers/generateFile.test.ts b/src/helpers/generateFile.test.ts index c3955c0..373a96e 100644 --- a/src/helpers/generateFile.test.ts +++ b/src/helpers/generateFile.test.ts @@ -36,3 +36,37 @@ test("generates a file which imports Kysely wrapper types.", () => { ', Insertable, Selectable, Updateable } from "kysely";' ); }); + +test("generates a file with single additional import when additionalImports is specified.", () => { + const result = generateFile([], { + withEnumImport: false, + withLeader: true, + exportWrappedTypes: false, + additionalImports: "import Decimal from 'decimal.js';", + }); + expect(result).toContain("import Decimal from 'decimal.js';"); +}); + +test("generates a file with multiple additional imports when additionalImports is specified.", () => { + const result = generateFile([], { + withEnumImport: false, + withLeader: true, + exportWrappedTypes: false, + additionalImports: `import Decimal from 'decimal.js'; +import { Big } from 'big.js'; +import * as moment from 'moment';`, + }); + expect(result).toContain("import Decimal from 'decimal.js';"); + expect(result).toContain("import { Big } from 'big.js';"); + expect(result).toContain("import * as moment from 'moment';"); +}); + +test("generates a file with named additional import when additionalImports is specified.", () => { + const result = generateFile([], { + withEnumImport: false, + withLeader: true, + exportWrappedTypes: false, + additionalImports: "import { v4 as uuid } from 'uuid';", + }); + expect(result).toContain("import { v4 as uuid } from 'uuid';"); +}); diff --git a/src/helpers/generateFile.ts b/src/helpers/generateFile.ts index 28aca8e..72dfce4 100644 --- a/src/helpers/generateFile.ts +++ b/src/helpers/generateFile.ts @@ -6,11 +6,12 @@ type Options = { withEnumImport: false | { importPath: string; names: string[] }; withLeader: boolean; exportWrappedTypes: boolean; + additionalImports?: string; }; export const generateFile = ( statements: readonly ts.Statement[], - { withEnumImport, withLeader, exportWrappedTypes }: Options + { withEnumImport, withLeader, exportWrappedTypes, additionalImports }: Options ) => { const file = ts.factory.createSourceFile( statements, @@ -20,7 +21,7 @@ export const generateFile = ( const result = printer.printFile(file); - const leader = `import type { ColumnType${ + const leader = `${additionalImports ? `${additionalImports}\n` : ""}import type { ColumnType${ result.includes("GeneratedAlways") ? ", GeneratedAlways" : "" }${ exportWrappedTypes ? ", Insertable, Selectable, Updateable" : "" diff --git a/src/helpers/generateFiles.ts b/src/helpers/generateFiles.ts index 42d5af4..a7fad82 100644 --- a/src/helpers/generateFiles.ts +++ b/src/helpers/generateFiles.ts @@ -24,6 +24,7 @@ export function generateFiles(opts: { defaultSchema: string; importExtension: string; exportWrappedTypes: boolean; + additionalImports?: string; }) { const models = opts.models.map( ({ definition, ...rest }: ModelType): MultiDefsModelType => ({ @@ -53,6 +54,7 @@ export function generateFiles(opts: { withEnumImport: false, withLeader: true, exportWrappedTypes: opts.exportWrappedTypes, + additionalImports: opts.additionalImports, }), }; @@ -70,6 +72,7 @@ export function generateFiles(opts: { }, withLeader: true, exportWrappedTypes: opts.exportWrappedTypes, + additionalImports: opts.additionalImports, } ), }; @@ -84,6 +87,7 @@ export function generateFiles(opts: { withEnumImport: false, withLeader: false, exportWrappedTypes: opts.exportWrappedTypes, + additionalImports: opts.additionalImports, } ), }; diff --git a/src/utils/validateConfig.ts b/src/utils/validateConfig.ts index 6068527..af89d65 100644 --- a/src/utils/validateConfig.ts +++ b/src/utils/validateConfig.ts @@ -58,6 +58,9 @@ export const configValidator = z // Export Kysely wrapped types such as `Selectable` exportWrappedTypes: booleanStringLiteral.default(false), + + // Import any additional libraries. Set to the full import section you want (e.g., "import Decimal from 'decimal.js';", "import { Big } from 'big.js';", multiple imports separated by newlines, etc.) + additionalImports: z.string().optional(), }) .strict() .transform((config) => { From 9d6eb5771e6467d9d727b1eaa7dac6df8e49601f Mon Sep 17 00:00:00 2001 From: Adam Varga Date: Tue, 7 Oct 2025 14:20:19 +0200 Subject: [PATCH 2/8] fix: prettier formatting --- README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 145ccbc..b5f0a73 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ generator kysely { provider = "prisma-kysely" output = "../src/db" fileName = "types.ts" - + // Import multiple libraries with different syntaxes additionalImports = """ import Decimal from 'decimal.js'; @@ -71,13 +71,14 @@ import type { SomeType } from './custom-types'; This will generate a file that starts with: ```typescript -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'; - +import { Big } from "big.js"; +import Decimal from "decimal.js"; import type { ColumnType } from "kysely"; +import * as moment from "moment"; +import { v4 as uuid } from "uuid"; + +import type { SomeType } from "./custom-types"; + // ... rest of generated types ``` @@ -117,7 +118,7 @@ hope it's just as useful for you! 😎 | `enumFileName` | The filename for the generated enums. Omitting this will generate enums and files in the same file. | | | `camelCase` | Enable support for Kysely's camelCase plugin | `false` | | `exportWrappedTypes` | Kysely wrapped types such as `Selectable` are also exported as described in the [Kysely documentation](https://kysely.dev/docs/getting-started#types). The exported types follow the naming conventions of the document. | `false` | -| `additionalImports` | Import any additional libraries. Set to the full import section you want (e.g., `"import Decimal from 'decimal.js';"`, `"import { Big } from 'big.js';"`, multiple imports separated by newlines, etc.). When set, adds the import section to the generated file. | | +| `additionalImports` | Import any additional libraries. Set to the full import section you want (e.g., `"import Decimal from 'decimal.js';"`, `"import { Big } from 'big.js';"`, multiple imports separated by newlines, etc.). When set, adds the import section to the generated file. | | | `readOnlyIds` | Use Kysely's `GeneratedAlways` for `@id` fields with default values, preventing insert and update. | `false` | | `[typename]TypeOverride` | Allows you to override the resulting TypeScript type for any Prisma type. Useful when targeting a different environment than Node (e.g. WinterCG compatible runtimes that use UInt8Arrays instead of Buffers for binary types etc.) Check out the [config validator](https://github.com/valtyr/prisma-kysely/blob/main/src/utils/validateConfig.ts) for a complete list of options. | | | `dbTypeName` | Allows you to override the exported type with all tables | `DB` | From 34b2f6b96e1b8ab669932946a87b362462fbcdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Varga=20=C3=81d=C3=A1m?= <44025816+vargaadam@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:34:36 +0200 Subject: [PATCH 3/8] Update README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b5f0a73..62531d3 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,9 @@ without losing the safety of the TypeScript type system? fileName = "types.ts" // Optionally generate runtime enums to a separate file enumFileName = "enums.ts" - // Optionally import any additional libraries + // Optionally include a custom import section (single or multi-line) additionalImports = "import Decimal from 'decimal.js';" + // For multi-line, use Prisma's triple-quoted string syntax (see below) } ``` From 170c99454b308e52f628a523b854113c7c7e105c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Varga=20=C3=81d=C3=A1m?= <44025816+vargaadam@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:34:45 +0200 Subject: [PATCH 4/8] Update README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62531d3..6ff02f6 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ hope it's just as useful for you! 😎 | `enumFileName` | The filename for the generated enums. Omitting this will generate enums and files in the same file. | | | `camelCase` | Enable support for Kysely's camelCase plugin | `false` | | `exportWrappedTypes` | Kysely wrapped types such as `Selectable` are also exported as described in the [Kysely documentation](https://kysely.dev/docs/getting-started#types). The exported types follow the naming conventions of the document. | `false` | -| `additionalImports` | Import any additional libraries. Set to the full import section you want (e.g., `"import Decimal from 'decimal.js';"`, `"import { Big } from 'big.js';"`, multiple imports separated by newlines, etc.). When set, adds the import section to the generated file. | | +| `additionalImports` | A full import section to prepend to the generated file. Supports any TS import syntax (default, named, namespace, renamed, and `import type`). Single-line strings or multi-line via Prisma triple-quoted strings (`""" ... """`). The content is inserted verbatim; no sorting or deduplication is performed. | | | `readOnlyIds` | Use Kysely's `GeneratedAlways` for `@id` fields with default values, preventing insert and update. | `false` | | `[typename]TypeOverride` | Allows you to override the resulting TypeScript type for any Prisma type. Useful when targeting a different environment than Node (e.g. WinterCG compatible runtimes that use UInt8Arrays instead of Buffers for binary types etc.) Check out the [config validator](https://github.com/valtyr/prisma-kysely/blob/main/src/utils/validateConfig.ts) for a complete list of options. | | | `dbTypeName` | Allows you to override the exported type with all tables | `DB` | From 0e249559e5ad134c0aade0f565f375eb3d952f44 Mon Sep 17 00:00:00 2001 From: Adam Varga Date: Tue, 7 Oct 2025 14:42:18 +0200 Subject: [PATCH 5/8] fix: prettier table formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ff02f6..a112f32 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ hope it's just as useful for you! 😎 | `enumFileName` | The filename for the generated enums. Omitting this will generate enums and files in the same file. | | | `camelCase` | Enable support for Kysely's camelCase plugin | `false` | | `exportWrappedTypes` | Kysely wrapped types such as `Selectable` are also exported as described in the [Kysely documentation](https://kysely.dev/docs/getting-started#types). The exported types follow the naming conventions of the document. | `false` | -| `additionalImports` | A full import section to prepend to the generated file. Supports any TS import syntax (default, named, namespace, renamed, and `import type`). Single-line strings or multi-line via Prisma triple-quoted strings (`""" ... """`). The content is inserted verbatim; no sorting or deduplication is performed. | | +| `additionalImports` | A full import section to prepend to the generated file. Supports any TS import syntax (default, named, namespace, renamed, and `import type`). Single-line strings or multi-line via Prisma triple-quoted strings (`""" ... """`). The content is inserted verbatim; no sorting or deduplication is performed. | | | `readOnlyIds` | Use Kysely's `GeneratedAlways` for `@id` fields with default values, preventing insert and update. | `false` | | `[typename]TypeOverride` | Allows you to override the resulting TypeScript type for any Prisma type. Useful when targeting a different environment than Node (e.g. WinterCG compatible runtimes that use UInt8Arrays instead of Buffers for binary types etc.) Check out the [config validator](https://github.com/valtyr/prisma-kysely/blob/main/src/utils/validateConfig.ts) for a complete list of options. | | | `dbTypeName` | Allows you to override the exported type with all tables | `DB` | From fbcfba8e6f1a9d52aa259542a449129e4d21705b Mon Sep 17 00:00:00 2001 From: Adam Varga Date: Mon, 20 Oct 2025 15:05:35 +0200 Subject: [PATCH 6/8] refactor: rename additionalImports to filePrefix --- README.md | 29 ++++++++++++++--------------- src/generator.ts | 2 +- src/helpers/generateFile.test.ts | 12 ++++++------ src/helpers/generateFile.ts | 6 +++--- src/helpers/generateFiles.ts | 8 ++++---- src/utils/validateConfig.ts | 4 ++-- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a112f32..77cdd89 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,8 @@ without losing the safety of the TypeScript type system? fileName = "types.ts" // Optionally generate runtime enums to a separate file enumFileName = "enums.ts" - // Optionally include a custom import section (single or multi-line) - additionalImports = "import Decimal from 'decimal.js';" + // Optionally add content at the start of generated files (imports, pragmas, comments, etc.) + filePrefix = "import type { Decimal } from 'decimal.js';" // For multi-line, use Prisma's triple-quoted string syntax (see below) } ``` @@ -48,9 +48,9 @@ without losing the safety of the TypeScript type system? 3. Run `prisma migrate dev` or `prisma generate` and use your freshly generated types when instantiating Kysely! -### Advanced Import Configuration +### File Prefix Configuration -The `additionalImports` option supports full import sections, allowing you to import multiple libraries with different syntaxes: +The `filePrefix` option allows you to add custom content at the start of generated files. This is particularly useful for importing custom types and libraries: ```prisma generator kysely { @@ -58,9 +58,9 @@ generator kysely { output = "../src/db" fileName = "types.ts" - // Import multiple libraries with different syntaxes - additionalImports = """ -import Decimal from 'decimal.js'; + // Add custom imports for libraries you need in generated types + filePrefix = """ +import type { Decimal } from 'decimal.js'; import { Big } from 'big.js'; import * as moment from 'moment'; import { v4 as uuid } from 'uuid'; @@ -72,14 +72,13 @@ import type { SomeType } from './custom-types'; This will generate a file that starts with: ```typescript -import { Big } from "big.js"; -import Decimal from "decimal.js"; -import type { ColumnType } from "kysely"; -import * as moment from "moment"; -import { v4 as uuid } from "uuid"; - -import type { SomeType } from "./custom-types"; +import type { 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'; +import type { ColumnType } from "kysely"; // ... rest of generated types ``` @@ -119,7 +118,7 @@ hope it's just as useful for you! 😎 | `enumFileName` | The filename for the generated enums. Omitting this will generate enums and files in the same file. | | | `camelCase` | Enable support for Kysely's camelCase plugin | `false` | | `exportWrappedTypes` | Kysely wrapped types such as `Selectable` are also exported as described in the [Kysely documentation](https://kysely.dev/docs/getting-started#types). The exported types follow the naming conventions of the document. | `false` | -| `additionalImports` | A full import section to prepend to the generated file. Supports any TS import syntax (default, named, namespace, renamed, and `import type`). Single-line strings or multi-line via Prisma triple-quoted strings (`""" ... """`). The content is inserted verbatim; no sorting or deduplication is performed. | | +| `filePrefix` | Content to prepend to the start of generated file(s). Useful for custom imports, pragma directives (e.g., `// @ts-nocheck`), comments, or any other content. Supports single-line strings or multi-line via Prisma triple-quoted strings (`""" ... """`). The content is inserted verbatim at the top of the file(s). | | | `readOnlyIds` | Use Kysely's `GeneratedAlways` for `@id` fields with default values, preventing insert and update. | `false` | | `[typename]TypeOverride` | Allows you to override the resulting TypeScript type for any Prisma type. Useful when targeting a different environment than Node (e.g. WinterCG compatible runtimes that use UInt8Arrays instead of Buffers for binary types etc.) Check out the [config validator](https://github.com/valtyr/prisma-kysely/blob/main/src/utils/validateConfig.ts) for a complete list of options. | | | `dbTypeName` | Allows you to override the exported type with all tables | `DB` | diff --git a/src/generator.ts b/src/generator.ts index 9e21db1..cb03597 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -123,7 +123,7 @@ generatorHandler({ defaultSchema: config.defaultSchema, importExtension: config.importExtension, exportWrappedTypes: config.exportWrappedTypes, - additionalImports: config.additionalImports, + filePrefix: config.filePrefix, }); // And write it to a file! diff --git a/src/helpers/generateFile.test.ts b/src/helpers/generateFile.test.ts index 373a96e..cb93bad 100644 --- a/src/helpers/generateFile.test.ts +++ b/src/helpers/generateFile.test.ts @@ -37,22 +37,22 @@ test("generates a file which imports Kysely wrapper types.", () => { ); }); -test("generates a file with single additional import when additionalImports is specified.", () => { +test("generates a file with custom prefix when filePrefix is specified.", () => { const result = generateFile([], { withEnumImport: false, withLeader: true, exportWrappedTypes: false, - additionalImports: "import Decimal from 'decimal.js';", + filePrefix: "import Decimal from 'decimal.js';", }); expect(result).toContain("import Decimal from 'decimal.js';"); }); -test("generates a file with multiple additional imports when additionalImports is specified.", () => { +test("generates a file with multiple imports in filePrefix.", () => { const result = generateFile([], { withEnumImport: false, withLeader: true, exportWrappedTypes: false, - additionalImports: `import Decimal from 'decimal.js'; + filePrefix: `import Decimal from 'decimal.js'; import { Big } from 'big.js'; import * as moment from 'moment';`, }); @@ -61,12 +61,12 @@ import * as moment from 'moment';`, expect(result).toContain("import * as moment from 'moment';"); }); -test("generates a file with named additional import when additionalImports is specified.", () => { +test("generates a file with filePrefix containing renamed imports.", () => { const result = generateFile([], { withEnumImport: false, withLeader: true, exportWrappedTypes: false, - additionalImports: "import { v4 as uuid } from 'uuid';", + filePrefix: "import { v4 as uuid } from 'uuid';", }); expect(result).toContain("import { v4 as uuid } from 'uuid';"); }); diff --git a/src/helpers/generateFile.ts b/src/helpers/generateFile.ts index 72dfce4..e331d5c 100644 --- a/src/helpers/generateFile.ts +++ b/src/helpers/generateFile.ts @@ -6,12 +6,12 @@ type Options = { withEnumImport: false | { importPath: string; names: string[] }; withLeader: boolean; exportWrappedTypes: boolean; - additionalImports?: string; + filePrefix?: string; }; export const generateFile = ( statements: readonly ts.Statement[], - { withEnumImport, withLeader, exportWrappedTypes, additionalImports }: Options + { withEnumImport, withLeader, exportWrappedTypes, filePrefix }: Options ) => { const file = ts.factory.createSourceFile( statements, @@ -21,7 +21,7 @@ export const generateFile = ( const result = printer.printFile(file); - const leader = `${additionalImports ? `${additionalImports}\n` : ""}import type { ColumnType${ + const leader = `${filePrefix ? `${filePrefix}\n` : ""}import type { ColumnType${ result.includes("GeneratedAlways") ? ", GeneratedAlways" : "" }${ exportWrappedTypes ? ", Insertable, Selectable, Updateable" : "" diff --git a/src/helpers/generateFiles.ts b/src/helpers/generateFiles.ts index a7fad82..4dc3775 100644 --- a/src/helpers/generateFiles.ts +++ b/src/helpers/generateFiles.ts @@ -24,7 +24,7 @@ export function generateFiles(opts: { defaultSchema: string; importExtension: string; exportWrappedTypes: boolean; - additionalImports?: string; + filePrefix?: string; }) { const models = opts.models.map( ({ definition, ...rest }: ModelType): MultiDefsModelType => ({ @@ -54,7 +54,7 @@ export function generateFiles(opts: { withEnumImport: false, withLeader: true, exportWrappedTypes: opts.exportWrappedTypes, - additionalImports: opts.additionalImports, + filePrefix: opts.filePrefix, }), }; @@ -72,7 +72,7 @@ export function generateFiles(opts: { }, withLeader: true, exportWrappedTypes: opts.exportWrappedTypes, - additionalImports: opts.additionalImports, + filePrefix: opts.filePrefix, } ), }; @@ -87,7 +87,7 @@ export function generateFiles(opts: { withEnumImport: false, withLeader: false, exportWrappedTypes: opts.exportWrappedTypes, - additionalImports: opts.additionalImports, + filePrefix: opts.filePrefix, } ), }; diff --git a/src/utils/validateConfig.ts b/src/utils/validateConfig.ts index af89d65..9462fe9 100644 --- a/src/utils/validateConfig.ts +++ b/src/utils/validateConfig.ts @@ -59,8 +59,8 @@ export const configValidator = z // Export Kysely wrapped types such as `Selectable` exportWrappedTypes: booleanStringLiteral.default(false), - // Import any additional libraries. Set to the full import section you want (e.g., "import Decimal from 'decimal.js';", "import { Big } from 'big.js';", multiple imports separated by newlines, etc.) - additionalImports: z.string().optional(), + // Content to prepend to the start of the generated file(s). Useful for custom imports, pragmas, or comments. + filePrefix: z.string().optional(), }) .strict() .transform((config) => { From c281a97dd06fe3e727ed1d0167c4c9800bf83ff7 Mon Sep 17 00:00:00 2001 From: Adam Varga Date: Tue, 13 Jan 2026 12:53:13 +0100 Subject: [PATCH 7/8] chore: prettier formatting in README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 77cdd89..8ba1ec8 100644 --- a/README.md +++ b/README.md @@ -72,11 +72,11 @@ import type { SomeType } from './custom-types'; This will generate a file that starts with: ```typescript -import type { 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'; +import type { 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"; import type { ColumnType } from "kysely"; // ... rest of generated types From 8a1cc091e147b53868db66e649ebd8600deb5528 Mon Sep 17 00:00:00 2001 From: Adam Varga Date: Tue, 13 Jan 2026 13:09:49 +0100 Subject: [PATCH 8/8] chore: add changeset for filePrefix feature --- .changeset/file-prefix-feature.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/file-prefix-feature.md diff --git a/.changeset/file-prefix-feature.md b/.changeset/file-prefix-feature.md new file mode 100644 index 0000000..0ec5eaf --- /dev/null +++ b/.changeset/file-prefix-feature.md @@ -0,0 +1,5 @@ +--- +"prisma-kysely": minor +--- + +Add `filePrefix` configuration option to allow users to prepend custom content (imports, pragmas, comments) to generated files.