prisma-kysely 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/generator.js +15 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -39,12 +39,49 @@ without losing the safety of the TypeScript type system?
|
|
|
39
39
|
fileName = "types.ts"
|
|
40
40
|
// Optionally generate runtime enums to a separate file
|
|
41
41
|
enumFileName = "enums.ts"
|
|
42
|
+
// Optionally add content at the start of generated files (imports, pragmas, comments, etc.)
|
|
43
|
+
banner = "import type { Decimal } from 'decimal.js';"
|
|
44
|
+
// For multi-line, use Prisma's triple-quoted string syntax (see below)
|
|
42
45
|
}
|
|
43
46
|
```
|
|
44
47
|
|
|
45
48
|
3. Run `prisma migrate dev` or `prisma generate` and use your freshly generated
|
|
46
49
|
types when instantiating Kysely!
|
|
47
50
|
|
|
51
|
+
### Banner Configuration
|
|
52
|
+
|
|
53
|
+
The `banner` option allows you to add custom content at the start of generated files. This is particularly useful for importing custom types and libraries:
|
|
54
|
+
|
|
55
|
+
```prisma
|
|
56
|
+
generator kysely {
|
|
57
|
+
provider = "prisma-kysely"
|
|
58
|
+
output = "../src/db"
|
|
59
|
+
fileName = "types.ts"
|
|
60
|
+
|
|
61
|
+
// Add custom imports for libraries you need in generated types
|
|
62
|
+
banner = """
|
|
63
|
+
import type { Decimal } from 'decimal.js';
|
|
64
|
+
import { Big } from 'big.js';
|
|
65
|
+
import * as moment from 'moment';
|
|
66
|
+
import { v4 as uuid } from 'uuid';
|
|
67
|
+
import type { SomeType } from './custom-types';
|
|
68
|
+
"""
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
This will generate a file that starts with:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import type { Decimal } from "decimal.js";
|
|
76
|
+
import { Big } from "big.js";
|
|
77
|
+
import * as moment from "moment";
|
|
78
|
+
import { v4 as uuid } from "uuid";
|
|
79
|
+
import type { SomeType } from "./custom-types";
|
|
80
|
+
|
|
81
|
+
import type { ColumnType } from "kysely";
|
|
82
|
+
// ... rest of generated types
|
|
83
|
+
```
|
|
84
|
+
|
|
48
85
|
### Motivation
|
|
49
86
|
|
|
50
87
|
Prisma's migration and schema definition workflow is undeniably great, and the
|
|
@@ -81,6 +118,7 @@ hope it's just as useful for you! 😎
|
|
|
81
118
|
| `enumFileName` | The filename for the generated enums. Omitting this will generate enums and files in the same file. | |
|
|
82
119
|
| `camelCase` | Enable support for Kysely's camelCase plugin | `false` |
|
|
83
120
|
| `exportWrappedTypes` | Kysely wrapped types such as `Selectable<Model>` 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` |
|
|
121
|
+
| `banner` | 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). | |
|
|
84
122
|
| `readOnlyIds` | Use Kysely's `GeneratedAlways` for `@id` fields with default values, preventing insert and update. | `false` |
|
|
85
123
|
| `[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. | |
|
|
86
124
|
| `dbTypeName` | Allows you to override the exported type with all tables | `DB` |
|
package/dist/generator.js
CHANGED
|
@@ -23,7 +23,7 @@ import path3 from "node:path";
|
|
|
23
23
|
// package.json
|
|
24
24
|
var package_default = {
|
|
25
25
|
name: "prisma-kysely",
|
|
26
|
-
version: "3.
|
|
26
|
+
version: "3.1.0",
|
|
27
27
|
description: "Generate Kysely database types from a Prisma schema",
|
|
28
28
|
repository: {
|
|
29
29
|
url: "git+https://github.com/valtyr/prisma-kysely.git"
|
|
@@ -87,7 +87,7 @@ var package_default = {
|
|
|
87
87
|
devDependencies: {
|
|
88
88
|
"@changesets/cli": "^2.29.8",
|
|
89
89
|
"@types/bun": "^1.3.5",
|
|
90
|
-
"@types/node": "
|
|
90
|
+
"@types/node": "25.1.0",
|
|
91
91
|
"@types/pg": "^8.16.0",
|
|
92
92
|
"@types/prettier": "3.0.0",
|
|
93
93
|
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
@@ -260,10 +260,11 @@ import ts7 from "typescript";
|
|
|
260
260
|
// src/helpers/generateFile.ts
|
|
261
261
|
import ts6 from "typescript";
|
|
262
262
|
var printer = ts6.createPrinter({ newLine: ts6.NewLineKind.LineFeed });
|
|
263
|
-
var generateFile = (statements, { withEnumImport, withLeader, exportWrappedTypes }) => {
|
|
263
|
+
var generateFile = (statements, { withEnumImport, withLeader, exportWrappedTypes, banner }) => {
|
|
264
264
|
const file = ts6.factory.createSourceFile(statements, ts6.factory.createToken(ts6.SyntaxKind.EndOfFileToken), ts6.NodeFlags.None);
|
|
265
265
|
const result = printer.printFile(file);
|
|
266
|
-
const leader =
|
|
266
|
+
const leader = `${banner ? `${banner}
|
|
267
|
+
` : ""}import type { ColumnType${result.includes("GeneratedAlways") ? ", GeneratedAlways" : ""}${exportWrappedTypes ? ", Insertable, Selectable, Updateable" : ""} } from "kysely";
|
|
267
268
|
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
|
|
268
269
|
? ColumnType<S, I | undefined, U>
|
|
269
270
|
: ColumnType<T, T | undefined, T>;
|
|
@@ -304,7 +305,8 @@ function generateFiles(opts) {
|
|
|
304
305
|
content: generateFile([...statements, opts.databaseType], {
|
|
305
306
|
withEnumImport: false,
|
|
306
307
|
withLeader: true,
|
|
307
|
-
exportWrappedTypes: opts.exportWrappedTypes
|
|
308
|
+
exportWrappedTypes: opts.exportWrappedTypes,
|
|
309
|
+
banner: opts.banner
|
|
308
310
|
})
|
|
309
311
|
};
|
|
310
312
|
return [typesFileWithEnums];
|
|
@@ -317,7 +319,8 @@ function generateFiles(opts) {
|
|
|
317
319
|
names: opts.enumNames
|
|
318
320
|
},
|
|
319
321
|
withLeader: true,
|
|
320
|
-
exportWrappedTypes: opts.exportWrappedTypes
|
|
322
|
+
exportWrappedTypes: opts.exportWrappedTypes,
|
|
323
|
+
banner: opts.banner
|
|
321
324
|
})
|
|
322
325
|
};
|
|
323
326
|
if (opts.enums.length === 0)
|
|
@@ -327,7 +330,8 @@ function generateFiles(opts) {
|
|
|
327
330
|
content: generateFile(opts.enums.flatMap((e) => [e.objectDeclaration, e.typeDeclaration]), {
|
|
328
331
|
withEnumImport: false,
|
|
329
332
|
withLeader: false,
|
|
330
|
-
exportWrappedTypes: opts.exportWrappedTypes
|
|
333
|
+
exportWrappedTypes: opts.exportWrappedTypes,
|
|
334
|
+
banner: opts.banner
|
|
331
335
|
})
|
|
332
336
|
};
|
|
333
337
|
return [typesFileWithoutEnums, enumFile];
|
|
@@ -749,7 +753,8 @@ var configValidator = z.object({
|
|
|
749
753
|
groupBySchema: booleanStringLiteral.default(false),
|
|
750
754
|
defaultSchema: z.string().default("public"),
|
|
751
755
|
filterBySchema: z.array(z.string()).optional(),
|
|
752
|
-
exportWrappedTypes: booleanStringLiteral.default(false)
|
|
756
|
+
exportWrappedTypes: booleanStringLiteral.default(false),
|
|
757
|
+
banner: z.string().optional()
|
|
753
758
|
}).strict().transform((config) => {
|
|
754
759
|
if (!config.enumFileName) {
|
|
755
760
|
config.enumFileName = config.fileName;
|
|
@@ -862,7 +867,8 @@ generatorHandler({
|
|
|
862
867
|
groupBySchema: config.groupBySchema,
|
|
863
868
|
defaultSchema: config.defaultSchema,
|
|
864
869
|
importExtension: config.importExtension,
|
|
865
|
-
exportWrappedTypes: config.exportWrappedTypes
|
|
870
|
+
exportWrappedTypes: config.exportWrappedTypes,
|
|
871
|
+
banner: config.banner
|
|
866
872
|
});
|
|
867
873
|
await Promise.allSettled(files.map(({ filepath, content }) => {
|
|
868
874
|
const writeLocation = path3.join(options.generator.output?.value || "", filepath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-kysely",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Generate Kysely database types from a Prisma schema",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "git+https://github.com/valtyr/prisma-kysely.git"
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@changesets/cli": "^2.29.8",
|
|
66
66
|
"@types/bun": "^1.3.5",
|
|
67
|
-
"@types/node": "
|
|
67
|
+
"@types/node": "25.1.0",
|
|
68
68
|
"@types/pg": "^8.16.0",
|
|
69
69
|
"@types/prettier": "3.0.0",
|
|
70
70
|
"@typescript-eslint/eslint-plugin": "^8.52.0",
|