Skip to content

Commit

Permalink
feat: upgrade to prisma 5
Browse files Browse the repository at this point in the history
  • Loading branch information
luisrudge committed Jul 21, 2023
1 parent b029a5d commit 2f879a2
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 301 deletions.
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"start": "ts-node index.ts"
},
"dependencies": {
"@prisma/client": "4.12.0",
"@prisma/client": "^5.0.0",
"ts-node": "^10.9.1"
},
"devDependencies": {
"@types/node": "18.15.11",
"prisma": "4.12.0",
"prisma": "^5.0.0",
"typescript": "5.0.2"
}
}
36 changes: 18 additions & 18 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@prisma/client@4.12.0":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-4.12.0.tgz#119b692888b1fe0fd3305c7d0e0ac48520aa6839"
integrity sha512-j9/ighfWwux97J2dS15nqhl60tYoH8V0IuSsgZDb6bCFcQD3fXbXmxjYC8GHhIgOk3lB7Pq+8CwElz2MiDpsSg==
"@prisma/client@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.0.0.tgz#9f0cd4164f4ffddb28bb1811c27eb7fa1e01a087"
integrity sha512-XlO5ELNAQ7rV4cXIDJUNBEgdLwX3pjtt9Q/RHqDpGf43szpNJx2hJnggfFs7TKNx0cOFsl6KJCSfqr5duEU/bQ==
dependencies:
"@prisma/engines-version" "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7"
"@prisma/engines-version" "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584"

"@prisma/engines-version@4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7":
version "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7.tgz#51a1cc5c886564b542acde64a873645d0dee2566"
integrity sha512-JIHNj5jlXb9mcaJwakM0vpgRYJIAurxTUqM0iX0tfEQA5XLZ9ONkIckkhuAKdAzocZ+80GYg7QSsfpjg7OxbOA==
"@prisma/engines-version@4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584":
version "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584.tgz#b36eda5620872d3fac810c302a7e46cf41daa033"
integrity sha512-HHiUF6NixsldsP3JROq07TYBLEjXFKr6PdH8H4gK/XAoTmIplOJBCgrIUMrsRAnEuGyRoRLXKXWUb943+PFoKQ==

"@prisma/engines@4.12.0":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-4.12.0.tgz#68d99078b70b2d9c339d0e8cbf2e99f00b72aa8c"
integrity sha512-0alKtnxhNB5hYU+ymESBlGI4b9XrGGSdv7Ud+8TE/fBNOEhIud0XQsAR+TrvUZgS4na5czubiMsODw0TUrgkIA==
"@prisma/engines@5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.0.0.tgz#5249650eabe77c458c90f2be97d8210353c2e22e"
integrity sha512-kyT/8fd0OpWmhAU5YnY7eP31brW1q1YrTGoblWrhQJDiN/1K+Z8S1kylcmtjqx5wsUGcP1HBWutayA/jtyt+sg==

"@tsconfig/node10@^1.0.7":
version "1.0.9"
Expand Down Expand Up @@ -99,12 +99,12 @@ make-error@^1.1.1:
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

prisma@4.12.0:
version "4.12.0"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-4.12.0.tgz#1080eda951928cb3b0274ad29da9ae4f93143d68"
integrity sha512-xqVper4mbwl32BWzLpdznHAYvYDWQQWK2tBfXjdUD397XaveRyAP7SkBZ6kFlIg8kKayF4hvuaVtYwXd9BodAg==
prisma@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.0.0.tgz#f6571c46dc2478172cb7bc1bb62d74026a2c2630"
integrity sha512-KYWk83Fhi1FH59jSpavAYTt2eoMVW9YKgu8ci0kuUnt6Dup5Qy47pcB4/TLmiPAbhGrxxSz7gsSnJcCmkyPANA==
dependencies:
"@prisma/engines" "4.12.0"
"@prisma/engines" "5.0.0"

ts-node@^10.9.1:
version "10.9.1"
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
},
"dependencies": {
"@faker-js/faker": "^7.6.0",
"@prisma/client": "4.12.0",
"@prisma/generator-helper": "4.12.0",
"@prisma/internals": "^4.12.0"
"@prisma/client": "^5.0.0",
"@prisma/generator-helper": "^5.0.0",
"@prisma/internals": "^5.0.0",
"tiny-invariant": "^1.3.1"
},
"devDependencies": {
"@release-it/conventional-changelog": "^5.1.1",
Expand All @@ -30,7 +31,7 @@
"generate-changelog": "^1.8.0",
"prettier": "^2.8.7",
"pretty-quick": "^3.1.3",
"prisma": "^4.12.0",
"prisma": "^5.0.0",
"release-it": "^15.9.3",
"typescript": "^5.0.2",
"vitest": "^0.29.8"
Expand Down
23 changes: 20 additions & 3 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { generatorHandler, GeneratorOptions } from '@prisma/generator-helper';
import { GENERATOR_NAME } from './constants';
import { createMethods } from './helpers/createMethods';
import { writeFileSafely } from './utils/writeFileSafely';
import invariant from 'tiny-invariant';

const { version } = require('../package.json');
generatorHandler({
Expand All @@ -14,11 +15,27 @@ generatorHandler({
};
},
async onGenerate(options: GeneratorOptions) {
invariant(
typeof options.generator.config.extraExport === 'string' ||
options.generator.config.extraExport === undefined,
'extraExport must be a string or empty',
);
invariant(
typeof options.generator.config.extraExport === 'string' ||
options.generator.config.extraExport === undefined,
'extraExport must be a string or empty',
);
invariant(
typeof options.generator.config.emptyValueAs === 'string' ||
options.generator.config.emptyValueAs === undefined,
'emptyValueAs must be a string or empty',
);

const fakeMethods = await createMethods(
options.dmmf.datamodel,
options.generator.config.extraImport,
options.generator.config.extraExport,
options.generator.config.emptyValueAs,
options.generator.config.extraImport as string | undefined,
options.generator.config.extraExport as string | undefined,
options.generator.config.emptyValueAs as string | undefined,
);

await writeFileSafely(options.generator.output?.value!, fakeMethods);
Expand Down
Loading

0 comments on commit 2f879a2

Please sign in to comment.