@tsed/prisma 8.39.0 → 8.40.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.
@@ -9,20 +9,41 @@ function parseStringBoolean(stringBoolean) {
9
9
  function toUnixPath(maybeWindowsPath) {
10
10
  return maybeWindowsPath.split("\\").join("/");
11
11
  }
12
+ /**
13
+ * Name (without extension) of the barrel file each supported Prisma client generator emits at the root of its output directory.
14
+ */
15
+ const CLIENT_ENTRY_BY_PROVIDER = {
16
+ "prisma-client": "client",
17
+ "prisma-client-js": "index"
18
+ };
19
+ export function resolveClientGenerator(otherGenerators) {
20
+ const clientGenerator = otherGenerators.find((it) => internals.parseEnvValue(it.provider) in CLIENT_ENTRY_BY_PROVIDER);
21
+ if (!clientGenerator) {
22
+ throw new Error(`@tsed/prisma requires a Prisma client generator ("prisma-client" or "prisma-client-js") declared in your schema.prisma. Add one of the following blocks:\n\n` +
23
+ `generator client {\n provider = "prisma-client"\n output = "../generated/prisma"\n}\n`);
24
+ }
25
+ const provider = internals.parseEnvValue(clientGenerator.provider);
26
+ const output = clientGenerator.output ? internals.parseEnvValue(clientGenerator.output) : undefined;
27
+ if (!output) {
28
+ throw new Error(`The "${provider}" generator must declare an explicit "output" path so @tsed/prisma can resolve the generated Prisma client import. ` +
29
+ `Add an "output" property to your "${provider}" generator block in schema.prisma.`);
30
+ }
31
+ return { output, entry: CLIENT_ENTRY_BY_PROVIDER[provider] };
32
+ }
12
33
  export function generate({ defaultOutput, packageDir }) {
13
34
  return async (options) => {
35
+ const { output: prismaClientPath, entry: prismaClientEntry } = resolveClientGenerator(options.otherGenerators);
14
36
  const outputDir = internals.parseEnvValue(options.generator.output);
15
37
  await fs.mkdir(outputDir, { recursive: true });
16
38
  await removeDir(outputDir, true);
17
39
  const generatorConfig = options.generator.config;
18
- const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
19
- const prismaClientPath = internals.parseEnvValue(prismaClientProvider.output);
20
40
  await generateCode(options.dmmf, {
21
41
  emitTranspiledCode: parseStringBoolean(generatorConfig.emitTranspiledCode),
22
42
  outputDirPath: outputDir,
23
43
  prismaClientPath: prismaClientPath.includes("node_modules")
24
44
  ? "@prisma/client"
25
- : toUnixPath(path.relative(outputDir, prismaClientPath))
45
+ : toUnixPath(path.relative(outputDir, prismaClientPath)),
46
+ prismaClientEntry
26
47
  });
27
48
  if (outputDir === defaultOutput) {
28
49
  await fs.copy(join(packageDir, "scripts", "backup-index.esm.js"), join(packageDir, "lib", "esm", "index.js"));
@@ -26,10 +26,11 @@ export async function generateCode(dmmf, options) {
26
26
  })
27
27
  }
28
28
  });
29
+ const prismaClientEntry = options.prismaClientEntry ?? "index";
29
30
  const hasEnum = generateEnums(dmmf, project, baseDirPath);
30
- generateModels(dmmf, project, baseDirPath, options.prismaClientPath);
31
+ generateModels(dmmf, project, baseDirPath, options.prismaClientPath, prismaClientEntry);
31
32
  generateInterfaces(project, baseDirPath);
32
- generateClientIndex(project, baseDirPath, options);
33
+ generateClientIndex(project, baseDirPath, { ...options, prismaClientEntry });
33
34
  generatePrismaService(project, baseDirPath);
34
35
  generateRepositories(dmmf, project, baseDirPath);
35
36
  generateIndex(project, baseDirPath, hasEnum);
@@ -12,7 +12,8 @@ export function transformScalarToType(field, ctx) {
12
12
  TSType = ScalarTsTypes[field.type];
13
13
  // Import Prisma namespace when Decimal is used
14
14
  if (field.type === PrismaScalars.Decimal) {
15
- field.model.addImportDeclaration(resolveExtension(ctx.prismaClientPath === "@prisma/client" ? ctx.prismaClientPath : `../${ctx.prismaClientPath}/index`), "Prisma");
15
+ const prismaClientEntry = ctx.prismaClientEntry ?? "index";
16
+ field.model.addImportDeclaration(resolveExtension(ctx.prismaClientPath === "@prisma/client" ? ctx.prismaClientPath : `../${ctx.prismaClientPath}/${prismaClientEntry}`), "Prisma");
16
17
  }
17
18
  break;
18
19
  case "enumTypes":
@@ -3,7 +3,8 @@ import { resolveExtension } from "./resolveExtension.js";
3
3
  export function generateClientIndex(project, baseDirPath, options) {
4
4
  const directory = project.createDirectory(path.resolve(baseDirPath, "client"));
5
5
  const indexFile = directory.createSourceFile("index.ts", undefined, { overwrite: true });
6
- const moduleSpecifier = resolveExtension(options.prismaClientPath === "@prisma/client" ? options.prismaClientPath : `../${options.prismaClientPath}/index`);
6
+ const prismaClientEntry = options.prismaClientEntry ?? "index";
7
+ const moduleSpecifier = resolveExtension(options.prismaClientPath === "@prisma/client" ? options.prismaClientPath : `../${options.prismaClientPath}/${prismaClientEntry}`);
7
8
  indexFile.addExportDeclarations([
8
9
  {
9
10
  moduleSpecifier
@@ -4,7 +4,7 @@ import { generateDocuments } from "./generateDocuments.js";
4
4
  import { generateOutputsBarrelFile } from "./generateOutputsBarrelFile.js";
5
5
  import path from "node:path";
6
6
  import { transformModelToClass } from "../transform/transformModelToClass.js";
7
- export function generateModels(dmmf, project, baseDirPath, prismaClientPath = "@prisma/client") {
7
+ export function generateModels(dmmf, project, baseDirPath, prismaClientPath = "@prisma/client", prismaClientEntry = "index") {
8
8
  const modelsMap = toMap(getValue(dmmf, "datamodel.models", []), "name");
9
9
  const typesMap = toMap(getValue(dmmf, "datamodel.types", []), "name");
10
10
  const models = DmmfModel.getModels(dmmf, modelsMap, typesMap);
@@ -15,7 +15,8 @@ export function generateModels(dmmf, project, baseDirPath, prismaClientPath = "@
15
15
  return transformModelToClass(model, {
16
16
  dmmf,
17
17
  modelsMap,
18
- prismaClientPath
18
+ prismaClientPath,
19
+ prismaClientEntry
19
20
  });
20
21
  });
21
22
  generateOutputsBarrelFile(modelsIndex, exportedModels);
@@ -8,8 +8,7 @@ export const packageDir = join(rootDir, "..", "..");
8
8
  helpers.generatorHandler({
9
9
  onManifest: () => ({
10
10
  defaultOutput,
11
- prettyName: "Ts.ED integration",
12
- requiresGenerators: ["prisma-client-js"]
11
+ prettyName: "Ts.ED integration"
13
12
  }),
14
13
  onGenerate: generate({ defaultOutput, packageDir })
15
14
  });
@@ -3,4 +3,9 @@ export interface GenerateOptions {
3
3
  defaultOutput: string;
4
4
  packageDir: string;
5
5
  }
6
+ export interface ClientGenerator {
7
+ output: string;
8
+ entry: string;
9
+ }
10
+ export declare function resolveClientGenerator(otherGenerators: GeneratorOptions["otherGenerators"]): ClientGenerator;
6
11
  export declare function generate({ defaultOutput, packageDir }: GenerateOptions): (options: GeneratorOptions) => Promise<string>;
@@ -3,4 +3,9 @@ export interface TransformContext {
3
3
  dmmf: DMMF.Document;
4
4
  modelsMap: Map<string, DMMF.Model>;
5
5
  prismaClientPath: string;
6
+ /**
7
+ * Name (without extension) of the barrel file exported by the Prisma client generator.
8
+ * "index" for prisma-client-js, "client" for the newer prisma-client generator.
9
+ */
10
+ prismaClientEntry: string;
6
11
  }
@@ -3,5 +3,10 @@ export interface GenerateCodeOptions {
3
3
  emitTranspiledCode: boolean;
4
4
  outputDirPath: string;
5
5
  prismaClientPath: string;
6
+ /**
7
+ * Name (without extension) of the barrel file exported by the Prisma client generator.
8
+ * "index" for prisma-client-js, "client" for the newer prisma-client generator.
9
+ */
10
+ prismaClientEntry?: string;
6
11
  }
7
12
  export declare function generateCode(dmmf: DMMF.Document, options: GenerateCodeOptions): Promise<void>;
@@ -1,3 +1,3 @@
1
1
  import { DMMF } from "@prisma/generator-helper";
2
2
  import { Project } from "ts-morph";
3
- export declare function generateModels(dmmf: DMMF.Document, project: Project, baseDirPath: string, prismaClientPath?: string): void;
3
+ export declare function generateModels(dmmf: DMMF.Document, project: Project, baseDirPath: string, prismaClientPath?: string, prismaClientEntry?: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/prisma",
3
- "version": "8.39.0",
3
+ "version": "8.40.0",
4
4
  "description": "Generate Ts.ED JsonSchema based on Prisma models",
5
5
  "keywords": [
6
6
  "JsonSchema",
@@ -39,6 +39,7 @@
39
39
  "generate:postgres:esm": "yarn build && cd test/postgres-esm && DATABASE_URL=postgres://localhost:8000/db prisma generate",
40
40
  "generate:mongo:esm": "yarn build && cd test/mongo-esm && DATABASE_URL=postgres://localhost:8000/db prisma generate",
41
41
  "generate:circular:esm": "yarn build && cd test/circular-ref && DATABASE_URL=postgres://localhost:8000/db prisma generate",
42
+ "generate:prisma-client": "yarn build && cd test/prisma-client && DATABASE_URL=postgres://localhost:8000/db prisma generate",
42
43
  "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
43
44
  },
44
45
  "dependencies": {
@@ -52,13 +53,13 @@
52
53
  },
53
54
  "devDependencies": {
54
55
  "@prisma/client": "^7.3.0",
55
- "@tsed/barrels": "8.39.0",
56
- "@tsed/core": "8.39.0",
57
- "@tsed/di": "8.39.0",
58
- "@tsed/json-mapper": "8.39.0",
56
+ "@tsed/barrels": "8.40.0",
57
+ "@tsed/core": "8.40.0",
58
+ "@tsed/di": "8.40.0",
59
+ "@tsed/json-mapper": "8.40.0",
59
60
  "@tsed/monorepo-utils": "3.3.3",
60
- "@tsed/schema": "8.39.0",
61
- "@tsed/typescript": "8.39.0",
61
+ "@tsed/schema": "8.40.0",
62
+ "@tsed/typescript": "8.40.0",
62
63
  "@types/change-case": "^2.3.1",
63
64
  "@types/pluralize": "0.0.33",
64
65
  "prisma": "^7.3.0",
package/readme.md CHANGED
@@ -50,6 +50,27 @@ generator tsed {
50
50
  The generated Ts.ED models import the `Prisma` namespace from this configured client output, including for `Decimal`
51
51
  fields.
52
52
 
53
+ ### Prisma's new `prisma-client` generator
54
+
55
+ Prisma recommends migrating from `prisma-client-js` to the newer `prisma-client` generator, which requires an
56
+ explicit `output` and generates the client outside `node_modules`. `@tsed/prisma` supports both generators during
57
+ this transition — just declare the generator you use, with an explicit `output`:
58
+
59
+ ```prisma
60
+ generator client {
61
+ provider = "prisma-client"
62
+ output = "../generated/prisma"
63
+ }
64
+
65
+ generator tsed {
66
+ provider = "tsed-prisma"
67
+ output = "../generated/tsed"
68
+ }
69
+ ```
70
+
71
+ If your `schema.prisma` declares neither `prisma-client` nor `prisma-client-js`, or the declared generator has no
72
+ `output`, `@tsed/prisma` fails early with an explicit error telling you how to fix your configuration.
73
+
53
74
  ## Contributors
54
75
 
55
76
  <a href="https://github.com/tsedio/tsed/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>