From f782719b2eebc2b141e0bce66bfd21ed9d46a2c6 Mon Sep 17 00:00:00 2001 From: Marc Stammerjohann <8985933+marcjulian@users.noreply.github.com> Date: Thu, 15 Feb 2024 19:23:08 +0100 Subject: [PATCH] support prisma 5 --- __tests__/project.test.ts | 8 +-- package-lock.json | 134 +++++++++++++++++++++----------------- package.json | 8 +-- src/cli/dbml-generator.ts | 6 +- src/generator/project.ts | 42 +++++++----- 5 files changed, 113 insertions(+), 85 deletions(-) diff --git a/__tests__/project.test.ts b/__tests__/project.test.ts index 6857dfb..faa9e64 100644 --- a/__tests__/project.test.ts +++ b/__tests__/project.test.ts @@ -10,15 +10,13 @@ describe('Project', () => { test('generate no project block', async () => { const { generators } = await generateConfig(datamodelUnnamedProject); const projectOptions = await getProjectOptions(generators[0].config); - const project = generateProject(projectOptions); - - expect(project.length).toEqual(0); + expect(projectOptions).toBeUndefined(); }); test('generate a project block with note', async () => { const { generators } = await generateConfig(datamodelProjectWithNote); const projectOptions = await getProjectOptions(generators[0].config); - const project = generateProject(projectOptions); + const project = generateProject(projectOptions!); const expected = 'Project "Test Project" {\n' + @@ -33,7 +31,7 @@ describe('Project', () => { test('generate a project block with noteMd', async () => { const { generators } = await generateConfig(datamodelProjectWithNoteMd); const projectOptions = await getProjectOptions(generators[0].config); - const project = generateProject(projectOptions); + const project = generateProject(projectOptions!); const expected = 'Project "Test Project" {\n' + diff --git a/package-lock.json b/package-lock.json index 12afe67..2829533 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,27 +1,27 @@ { "name": "prisma-dbml-generator", - "version": "0.11.0", + "version": "0.11.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "prisma-dbml-generator", - "version": "0.11.0", + "version": "0.11.1", "license": "MIT", "dependencies": { - "@prisma/generator-helper": "4.16.1", - "@prisma/internals": "4.16.1" + "@prisma/generator-helper": "5.0.0", + "@prisma/internals": "5.0.0" }, "bin": { "prisma-dbml-generator": "dist/generator.js" }, "devDependencies": { - "@prisma/client": "4.16.1", + "@prisma/client": "5.0.0", "@types/jest": "^29.2.4", "@types/node": "18.11.0", "jest": "29.7.0", "prettier": "3.2.5", - "prisma": "4.16.1", + "prisma": "5.0.0", "ts-jest": "29.1.2", "ts-toolbelt": "^9.6.0", "typescript": "5.3.3" @@ -1103,16 +1103,16 @@ } }, "node_modules/@prisma/client": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.16.1.tgz", - "integrity": "sha512-CoDHu7Bt+NuDo40ijoeHP79EHtECsPBTy3yte5Yo3op8TqXt/kV0OT5OrsWewKvQGKFMHhYQ+ePed3zzjYdGAw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.0.0.tgz", + "integrity": "sha512-XlO5ELNAQ7rV4cXIDJUNBEgdLwX3pjtt9Q/RHqDpGf43szpNJx2hJnggfFs7TKNx0cOFsl6KJCSfqr5duEU/bQ==", "dev": true, "hasInstallScript": true, "dependencies": { - "@prisma/engines-version": "4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c" + "@prisma/engines-version": "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584" }, "engines": { - "node": ">=14.17" + "node": ">=16.13" }, "peerDependencies": { "prisma": "*" @@ -1124,9 +1124,9 @@ } }, "node_modules/@prisma/debug": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-4.16.1.tgz", - "integrity": "sha512-ovjUrDq9DKNT0BbLBDEcIxQTcymzLChae4jmQiqVvaD3qJW5Ma90n8Kv6O/BIscpcGiNW910DazcZjlSGk5Zog==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.0.0.tgz", + "integrity": "sha512-3q/M/KqlQ01/HJXifU/zCNOHkoTWu24kGelMF/IBrRxm7njPqTTbwfnT1dh4JK+nuWM5/Dg1Lv00u2c0l7AHxg==", "dependencies": { "@types/debug": "4.1.8", "debug": "4.3.4", @@ -1134,24 +1134,24 @@ } }, "node_modules/@prisma/engines": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.16.1.tgz", - "integrity": "sha512-gpZG0kGGxfemgvK/LghHdBIz+crHkZjzszja94xp4oytpsXrgt/Ice82MvPsWMleVIniKuARrowtsIsim0PFJQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.0.0.tgz", + "integrity": "sha512-kyT/8fd0OpWmhAU5YnY7eP31brW1q1YrTGoblWrhQJDiN/1K+Z8S1kylcmtjqx5wsUGcP1HBWutayA/jtyt+sg==", "hasInstallScript": true }, "node_modules/@prisma/engines-version": { - "version": "4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c.tgz", - "integrity": "sha512-tMWAF/qF00fbUH1HB4Yjmz6bjh7fzkb7Y3NRoUfMlHu6V+O45MGvqwYxqwBjn1BIUXkl3r04W351D4qdJjrgvA==", + "version": "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584.tgz", + "integrity": "sha512-HHiUF6NixsldsP3JROq07TYBLEjXFKr6PdH8H4gK/XAoTmIplOJBCgrIUMrsRAnEuGyRoRLXKXWUb943+PFoKQ==", "dev": true }, "node_modules/@prisma/fetch-engine": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-4.16.1.tgz", - "integrity": "sha512-sivgi9oomELapqJkup+nyMH9J3OVAyKxrw4YV8vtx5KPWVRSWIoBvRd1juKFswYiUmRhpY8446ZUvYvCBT7vyQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.0.0.tgz", + "integrity": "sha512-eSzHTE0KcMvM5+O1++eaMuVf4D1zwWHdqjWr6D70skCg37q7RYsuty4GFnlWBuqC4aXwVf06EvIxiJ0SQIIeRw==", "dependencies": { - "@prisma/debug": "4.16.1", - "@prisma/get-platform": "4.16.1", + "@prisma/debug": "5.0.0", + "@prisma/get-platform": "5.0.0", "execa": "5.1.1", "find-cache-dir": "3.3.2", "fs-extra": "11.1.1", @@ -1159,7 +1159,7 @@ "http-proxy-agent": "7.0.0", "https-proxy-agent": "7.0.0", "kleur": "4.1.5", - "node-fetch": "2.6.11", + "node-fetch": "2.6.12", "p-filter": "2.1.0", "p-map": "4.0.0", "p-retry": "4.6.2", @@ -1178,11 +1178,11 @@ } }, "node_modules/@prisma/generator-helper": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/@prisma/generator-helper/-/generator-helper-4.16.1.tgz", - "integrity": "sha512-vMfNTD7hU0sQv/G5i8PVazAfUIaYh/xsbbnVk4Af0jSW6w6gZH95V5sbK0GSZry+D+pqXN3EiTqRFzreuzzCqg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@prisma/generator-helper/-/generator-helper-5.0.0.tgz", + "integrity": "sha512-pufQ1mhoH6WzKNtzL79HZDoW4Ql3Lf8QEKVmBoW8e3Tdb50bxpYBYue5LBqp9vNW1xd1pgZO53cNiRfLX2d4Zg==", "dependencies": { - "@prisma/debug": "4.16.1", + "@prisma/debug": "5.0.0", "@types/cross-spawn": "6.0.2", "cross-spawn": "7.0.3", "kleur": "4.1.5" @@ -1197,11 +1197,11 @@ } }, "node_modules/@prisma/get-platform": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-4.16.1.tgz", - "integrity": "sha512-Sm2WtxyROEUDKsrdNcmbJqtXm5A7XtHxrUcC3Qwj+uxZWQltWzcuasyML/lrTcg4FcsJJaAZV6pASUk6eNGXCA==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.0.0.tgz", + "integrity": "sha512-JT/rz/jaMTggDkd9OIma50si9rPLzSFe7XSrV3mKXwtv9t+rdwx5ZhmKJd+Rz6S1vhn/291k21JLfaxOW6u8KQ==", "dependencies": { - "@prisma/debug": "4.16.1", + "@prisma/debug": "5.0.0", "escape-string-regexp": "4.0.0", "execa": "5.1.1", "fs-jetpack": "5.1.0", @@ -1222,18 +1222,18 @@ } }, "node_modules/@prisma/internals": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/@prisma/internals/-/internals-4.16.1.tgz", - "integrity": "sha512-Ut6O08c7RzLXRwb03OcZEMNlr2VGNJ03DI3n2PG2xxgfMum/U1AoHXQ552gobb/SajYw1Cn5ZzVrhR9sCXo89A==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@prisma/internals/-/internals-5.0.0.tgz", + "integrity": "sha512-VGWyFk6QlSBXT8z65Alq5F3o9E8IiTtaBoa3rmKkGpZjUk85kJy3jZz4xkRv53TaeghGE5rWfwkfak26KtY5yQ==", "dependencies": { "@antfu/ni": "0.21.4", "@opentelemetry/api": "1.4.1", - "@prisma/debug": "4.16.1", - "@prisma/engines": "4.16.1", - "@prisma/fetch-engine": "4.16.1", - "@prisma/generator-helper": "4.16.1", - "@prisma/get-platform": "4.16.1", - "@prisma/prisma-fmt-wasm": "4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c", + "@prisma/debug": "5.0.0", + "@prisma/engines": "5.0.0", + "@prisma/fetch-engine": "5.0.0", + "@prisma/generator-helper": "5.0.0", + "@prisma/get-platform": "5.0.0", + "@prisma/prisma-schema-wasm": "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584", "archiver": "5.3.1", "arg": "5.0.2", "checkpoint-client": "1.1.24", @@ -1252,7 +1252,7 @@ "is-wsl": "2.2.0", "kleur": "4.1.5", "new-github-issue-url": "0.2.1", - "node-fetch": "2.6.11", + "node-fetch": "2.6.12", "npm-packlist": "5.1.3", "open": "7.4.2", "p-map": "4.0.0", @@ -1279,10 +1279,10 @@ "node": ">=6" } }, - "node_modules/@prisma/prisma-fmt-wasm": { - "version": "4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c", - "resolved": "https://registry.npmjs.org/@prisma/prisma-fmt-wasm/-/prisma-fmt-wasm-4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c.tgz", - "integrity": "sha512-BwsBw9HxhRuAjS0/1ncnnTffxw9vbT5zc115tbbiE+TTdAUS3aVxN5SixxP/8h15q0W4Z16VHS8vgyor7nbQYA==" + "node_modules/@prisma/prisma-schema-wasm": { + "version": "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584", + "resolved": "https://registry.npmjs.org/@prisma/prisma-schema-wasm/-/prisma-schema-wasm-4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584.tgz", + "integrity": "sha512-JFdsnSgBPN8reDTLOI9Vh/6ccCb2aD1LbY/LWQnkcIgNo6IdpzvuM+qRVbBuA6IZP2SdqQI8Lu6RL2P8EFBQUA==" }, "node_modules/@sinclair/typebox": { "version": "0.27.8", @@ -1958,6 +1958,25 @@ "uuid": "9.0.0" } }, + "node_modules/checkpoint-client/node_modules/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/ci-info": { "version": "3.8.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", @@ -3965,9 +3984,9 @@ } }, "node_modules/node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", + "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -4386,20 +4405,19 @@ } }, "node_modules/prisma": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.16.1.tgz", - "integrity": "sha512-C2Xm7yxHxjFjjscBEW4tmoraPHH/Vyu/A0XABdbaFtoiOZARsxvOM7rwc2iZ0qVxbh0bGBGBWZUSXO/52/nHBQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.0.0.tgz", + "integrity": "sha512-KYWk83Fhi1FH59jSpavAYTt2eoMVW9YKgu8ci0kuUnt6Dup5Qy47pcB4/TLmiPAbhGrxxSz7gsSnJcCmkyPANA==", "dev": true, "hasInstallScript": true, "dependencies": { - "@prisma/engines": "4.16.1" + "@prisma/engines": "5.0.0" }, "bin": { - "prisma": "build/index.js", - "prisma2": "build/index.js" + "prisma": "build/index.js" }, "engines": { - "node": ">=14.17" + "node": ">=16.13" } }, "node_modules/process-nextick-args": { diff --git a/package.json b/package.json index f6f530a..21ef3ea 100644 --- a/package.json +++ b/package.json @@ -43,16 +43,16 @@ "url": "https://github.com/notiz-dev/prisma-dbml-generator/issues" }, "dependencies": { - "@prisma/generator-helper": "4.16.1", - "@prisma/internals": "4.16.1" + "@prisma/generator-helper": "5.0.0", + "@prisma/internals": "5.0.0" }, "devDependencies": { - "@prisma/client": "4.16.1", + "@prisma/client": "5.0.0", "@types/jest": "^29.2.4", "@types/node": "18.11.0", "jest": "29.7.0", "prettier": "3.2.5", - "prisma": "4.16.1", + "prisma": "5.0.0", "ts-jest": "29.1.2", "ts-toolbelt": "^9.6.0", "typescript": "5.3.3" diff --git a/src/cli/dbml-generator.ts b/src/cli/dbml-generator.ts index c857e27..7a9159a 100644 --- a/src/cli/dbml-generator.ts +++ b/src/cli/dbml-generator.ts @@ -12,7 +12,11 @@ export const defaultDBMLFileName = 'schema.dbml'; export async function generate(options: GeneratorOptions) { const { output, config } = options.generator; const outputDir = parseEnvValue(output!); - const dbmlFileName = config.outputName || defaultDBMLFileName; + + const dbmlFileName = + typeof config.outputName === 'string' + ? config.outputName + : defaultDBMLFileName; const allowManyToMany = config.manyToMany === 'false' ? false : true; const mapToDbSchema = config.mapToDbSchema === 'false' ? false : true; const includeRelationFields = diff --git a/src/generator/project.ts b/src/generator/project.ts index 2357dc1..85f4f80 100644 --- a/src/generator/project.ts +++ b/src/generator/project.ts @@ -37,24 +37,32 @@ export async function getProjectOptions({ projectDatabaseType, projectNote, projectNotePath, -}: GeneratorConfig['config']): Promise { - let projectNoteMd = ''; +}: GeneratorConfig['config']): Promise { + if (typeof projectName === 'string') { + let projectNoteMd = ''; - if (projectNotePath) { - const fullPath = `${process.cwd()}/${projectNotePath}`; - try { - projectNoteMd = await readFile(fullPath, 'utf-8'); - } catch (e) { - console.log( - `❌ Error: project note markdown file not found: ${fullPath}`, - ); + if (projectNotePath) { + const fullPath = `${process.cwd()}/${projectNotePath}`; + try { + projectNoteMd = await readFile(fullPath, 'utf-8'); + } catch (e) { + console.log( + `❌ Error: project note markdown file not found: ${fullPath}`, + ); + } } - } - return { - name: projectName && `"${projectName}"`, - databaseType: projectDatabaseType || '', - note: projectNoteMd || projectNote || '', // noteMd takes precedence - isMd: projectNoteMd !== '', - }; + return { + name: projectName && `"${projectName}"`, + databaseType: + typeof projectDatabaseType === 'string' ? projectDatabaseType : '', + note: projectNoteMd + ? projectNoteMd + : typeof projectNote === 'string' + ? projectNote + : '', // noteMd takes precedence + isMd: projectNoteMd !== '', + }; + } + return undefined; }