@kavo/prisma 0.22.3 → 0.23.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 +1 -1
- package/dist/generator.d.ts +13 -1
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +79 -2
- package/dist/generator.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ references: [id])`) — the [documented best
|
|
|
59
59
|
practice](https://www.prisma.io/docs/orm/prisma-schema/data-model/relations)
|
|
60
60
|
for any 1:1/1:n relation. An **implicit many-to-many** relation (no
|
|
61
61
|
scalar field on either side, Prisma manages the join table itself) has no
|
|
62
|
-
foreign key for a
|
|
62
|
+
foreign key for a schema to expose, so it cannot be associated through the
|
|
63
63
|
normal write path — a custom operation handler reaching for the raw
|
|
64
64
|
Prisma Client is the escape hatch, same as any write shape Kavo doesn't
|
|
65
65
|
model directly.
|
package/dist/generator.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PrismaMetadata } from "./datamodel.js";
|
|
2
|
+
/**
|
|
3
|
+
* The generated module's content: `prismaMetadata` as before, plus one
|
|
4
|
+
* marker class per DMMF model (typed field-for-field, so `filter`/`sort`/
|
|
5
|
+
* `include` config keeps compile-time checking) and a ready-made `entities`
|
|
6
|
+
* array built from them — so an app wires
|
|
7
|
+
* `createPrismaKavo(prisma, { metadata, entities })` straight from
|
|
8
|
+
* `prisma generate` output instead of hand-declaring a marker class per
|
|
9
|
+
* model (issue #459). `createInfrastructure`'s `entities` option is
|
|
10
|
+
* unchanged — a caller who wants their own marker classes (for
|
|
11
|
+
* `instanceof`/DI use elsewhere) can still pass their own array.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generatedModule(metadata: PrismaMetadata): string;
|
|
2
14
|
//# sourceMappingURL=generator.d.ts.map
|
package/dist/generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA+ClE;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAoChE"}
|
package/dist/generator.js
CHANGED
|
@@ -3,8 +3,81 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
const require = createRequire(import.meta.url);
|
|
5
5
|
const { generatorHandler } = require("@prisma/generator-helper");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/** The TS type of one field's value, ignoring list/nullable — see {@link tsFieldType}. */
|
|
7
|
+
function scalarTsType(field) {
|
|
8
|
+
if (field.kind === "object") {
|
|
9
|
+
// A relation: the field's own type name is the target model, which the
|
|
10
|
+
// generated module declares a class for under the same name.
|
|
11
|
+
return field.type;
|
|
12
|
+
}
|
|
13
|
+
if (field.kind === "enum") {
|
|
14
|
+
// The generated module declares a union type under the enum's own name.
|
|
15
|
+
return field.type;
|
|
16
|
+
}
|
|
17
|
+
switch (field.type) {
|
|
18
|
+
case "Int":
|
|
19
|
+
case "Float":
|
|
20
|
+
case "BigInt":
|
|
21
|
+
case "Decimal":
|
|
22
|
+
return "number";
|
|
23
|
+
case "Boolean":
|
|
24
|
+
return "boolean";
|
|
25
|
+
case "DateTime":
|
|
26
|
+
return "Date";
|
|
27
|
+
case "Json":
|
|
28
|
+
return "unknown";
|
|
29
|
+
default:
|
|
30
|
+
return "string";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A field's full TS type, matching the shape the hand-written marker
|
|
35
|
+
* classes used to declare by hand: `T[]` for a list (never nullable — an
|
|
36
|
+
* empty list, not null, is Prisma's absence value for a to-many relation),
|
|
37
|
+
* `T | null` for an optional scalar or to-one relation, plain `T` otherwise.
|
|
38
|
+
*/
|
|
39
|
+
function tsFieldType(field) {
|
|
40
|
+
const base = scalarTsType(field);
|
|
41
|
+
if (field.isList) {
|
|
42
|
+
return `${base}[]`;
|
|
43
|
+
}
|
|
44
|
+
return field.isRequired ? base : `${base} | null`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The generated module's content: `prismaMetadata` as before, plus one
|
|
48
|
+
* marker class per DMMF model (typed field-for-field, so `filter`/`sort`/
|
|
49
|
+
* `include` config keeps compile-time checking) and a ready-made `entities`
|
|
50
|
+
* array built from them — so an app wires
|
|
51
|
+
* `createPrismaKavo(prisma, { metadata, entities })` straight from
|
|
52
|
+
* `prisma generate` output instead of hand-declaring a marker class per
|
|
53
|
+
* model (issue #459). `createInfrastructure`'s `entities` option is
|
|
54
|
+
* unchanged — a caller who wants their own marker classes (for
|
|
55
|
+
* `instanceof`/DI use elsewhere) can still pass their own array.
|
|
56
|
+
*/
|
|
57
|
+
export function generatedModule(metadata) {
|
|
58
|
+
const enumDeclarations = metadata.enums
|
|
59
|
+
.map((prismaEnum) => `export type ${prismaEnum.name} = ${prismaEnum.values.length > 0
|
|
60
|
+
? prismaEnum.values.map((value) => JSON.stringify(value.name)).join(" | ")
|
|
61
|
+
: "never"};`)
|
|
62
|
+
.join("\n");
|
|
63
|
+
const classDeclarations = metadata.models
|
|
64
|
+
.map((model) => {
|
|
65
|
+
const fields = model.fields.map((field) => ` ${field.name}!: ${tsFieldType(field)};`).join("\n");
|
|
66
|
+
return (`export class ${model.name} {\n${fields}\n}\n` +
|
|
67
|
+
// A bundler's production minification (e.g. Next.js's SWC minify)
|
|
68
|
+
// renames classes — @kavo/prisma matches a marker class to its
|
|
69
|
+
// Prisma model by the class's runtime `name` (ADR-0017), so pin it
|
|
70
|
+
// to a string literal, which survives minification.
|
|
71
|
+
`Object.defineProperty(${model.name}, "name", { value: ${JSON.stringify(model.name)} });`);
|
|
72
|
+
})
|
|
73
|
+
.join("\n\n");
|
|
74
|
+
const entityNames = metadata.models.map((model) => model.name).join(", ");
|
|
75
|
+
return (`// Generated by @kavo/prisma. Do not edit.\n` +
|
|
76
|
+
`export const prismaMetadata = ${JSON.stringify(metadata, null, 2)} as const;\n\n` +
|
|
77
|
+
`export default prismaMetadata;\n\n` +
|
|
78
|
+
`${enumDeclarations}${enumDeclarations.length > 0 ? "\n\n" : ""}` +
|
|
79
|
+
`${classDeclarations}\n\n` +
|
|
80
|
+
`export const entities = [${entityNames}] as const;\n`);
|
|
8
81
|
}
|
|
9
82
|
generatorHandler({
|
|
10
83
|
onManifest() {
|
|
@@ -20,6 +93,10 @@ generatorHandler({
|
|
|
20
93
|
}
|
|
21
94
|
const outputPath = resolve(output);
|
|
22
95
|
await mkdir(resolve(outputPath, ".."), { recursive: true });
|
|
96
|
+
// `options.dmmf.datamodel` is `@prisma/dmmf`'s `Datamodel` — importing
|
|
97
|
+
// that real type (rather than casting through `unknown`) means a future
|
|
98
|
+
// DMMF shape change that actually breaks `PrismaMetadata`'s assumptions
|
|
99
|
+
// fails here at compile time instead of silently.
|
|
23
100
|
await writeFile(outputPath, generatedModule(options.dmmf.datamodel), "utf8");
|
|
24
101
|
},
|
|
25
102
|
});
|
package/dist/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CA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gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QACjE,GAAG,iBAAiB,MAAM;QAC1B,4BAA4B,WAAW,eAAe,CACvD,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC;IACf,UAAU;QACR,OAAO;YACL,aAAa,EAAE,8BAA8B;YAC7C,UAAU,EAAE,sBAAsB;SACnC,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,OAAO;QACtB,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC;QAC/C,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QACjF,CAAC;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACnC,MAAM,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,uEAAuE;QACvE,wEAAwE;QACxE,wEAAwE;QACxE,kDAAkD;QAClD,MAAM,SAAS,CAAC,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,SAA4C,CAAC,EAAE,MAAM,CAAC,CAAC;IAClH,CAAC;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kavo/prisma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Kavo Prisma adapter — implements @kavo/core's RepositoryAdapter over Prisma Client.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@prisma/generator-helper": "^7.10.0",
|
|
34
|
-
"@kavo/core": "^0.
|
|
34
|
+
"@kavo/core": "^0.23.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@prisma/client": "^7.0.0"
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@prisma/adapter-better-sqlite3": "^7.10.0",
|
|
41
41
|
"@prisma/client": "^7.10.0",
|
|
42
|
+
"@prisma/dmmf": "^7.10.0",
|
|
42
43
|
"better-sqlite3": "^13.0.3",
|
|
43
44
|
"prisma": "^7.10.0"
|
|
44
45
|
},
|