Skip to content

Commit

Permalink
feat: Upgrade Mermaid dependency to v10.0.2 (#175)
Browse files Browse the repository at this point in the history
* feat: Upgrade Mermaid dependency to v9

* fix tests and remove search from from/to many to many count array

* remove husky and lint staging tools

* Testing alpha/beta package releases
  • Loading branch information
keonik committed Mar 20, 2023
1 parent 948bb51 commit efe5959
Show file tree
Hide file tree
Showing 7 changed files with 787 additions and 1,416 deletions.
2 changes: 1 addition & 1 deletion ERD.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions __tests__/issues/138.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ test('id not override before key name', async () => {
expect(svgContent).toContain('UserSetting');

// User has id
expect(svgContent).toContain('id="entity-User-attr-1-name"');
expect(svgContent).toContain('>id</text>');
expect(svgContent).toMatch(
/id="text-entity-User([^\><]*)-attr-1-name"([^<\>]*)\>id<\/text\>/
);

// UserSetting has id and userId
expect(svgContent).toContain('id="entity-UserSetting-attr-1-name"');
expect(svgContent).toContain('id="entity-UserSetting-attr-2-name"');
expect(svgContent).toContain('>user_id</text>');
// // UserSetting has a relation to User
expect(svgContent).toContain('>user</text>');
expect(svgContent).toMatch(
/id="text-entity-UserSetting([^\><]*)-attr-\d-name"([^<\>]*)\>id<\/text\>/
);
expect(svgContent).toMatch(
/id="text-entity-UserSetting([^\><]*)-attr-\d-name"([^<\>]*)\>user_id<\/text\>/
);
// UserSetting has a relation to User
expect(svgContent).toMatch(/<text([^><]*)\>user<\/text\>/);
// expect(svgContent).toContain('>user</text>');
});
2,129 changes: 745 additions & 1,384 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,33 @@
}
],
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/core": "^7.21.3",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@babel/preset-typescript": "^7.21.0",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^9.0.2",
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/jest": "^29.2.5",
"@types/jest": "^29.5.0",
"all-contributors-cli": "^6.24.0",
"babel-jest": "^29.4.1",
"babel-jest": "^29.5.0",
"concurrently": "^7.6.0",
"jest": "^29.3.1",
"prettier": "2.8.2",
"prisma": "^4.8.1",
"jest": "^29.5.0",
"prettier": "2.8.4",
"prisma": "^4.11.0",
"semantic-release": "^20.1.3",
"standard-version": "^9.5.0",
"tslib": "^2.4.1",
"typescript": "^4.9.5"
"tslib": "^2.5.0",
"typescript": "^5.0.2"
},
"dependencies": {
"@mermaid-js/mermaid-cli": "^8.14.0",
"@prisma/client": "^4.0.0",
"@prisma/generator-helper": "^4.0.0",
"@mermaid-js/mermaid-cli": "^10.0.2",
"@prisma/client": "^4.11.0",
"@prisma/generator-helper": "^4.11.0",
"dotenv": "^16.0.3"
},
"peerDependencies": {
"@mermaid-js/mermaid-cli": "^8.14.0",
"@mermaid-js/mermaid-cli": "^10.0.2",
"@prisma/client": "^4.0.0",
"@prisma/generator-helper": "^4.0.0"
},
Expand Down
7 changes: 4 additions & 3 deletions prisma/issues/138.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
generator erd {
provider = "node ./dist/index.js"
output = "../../__tests__/138.svg"
provider = "node ./dist/index.js"
output = "../../__tests__/138.svg"
includeRelationFromFields = "true"
}

datasource db {
Expand All @@ -20,4 +21,4 @@ model UserSetting {
userId Int @map("user_id")
user User @relation(fields: [userId], references: [id])
}
}
7 changes: 4 additions & 3 deletions prisma/many-to-many.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ datasource db {
}

generator erd {
provider = "node ./dist/index.js"
output = "../__tests__/ManyToMany.svg"
theme = "forest"
provider = "node ./dist/index.js"
output = "../__tests__/ManyToMany.svg"
theme = "forest"
includeRelationFromFields = "true"
}

model Booking {
Expand Down
13 changes: 8 additions & 5 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ ${
const relationshipName = `${isEnum ? 'enum:' : ''}${field.name}`;
const thisSide = model.dbName || model.name;
const otherSide = field.type;

// normal relations
if (
(field.relationFromFields &&
Expand Down Expand Up @@ -237,10 +236,10 @@ ${
modellikes.find(
(m) => m.name === field.type || m.dbName === field.type
) &&
field.relationFromFields?.length === 0 &&
field.relationToFields?.length
field.relationFromFields?.length === 0
// && field.relationToFields?.length
) {
relationships += ` ${thisSide} o{--}o ${otherSide} : ""\n`;
relationships += ` ${thisSide} o{--}o ${otherSide} : "${field.name}"\n`;
}
// composite types
else if (field.kind == 'object') {
Expand Down Expand Up @@ -433,10 +432,14 @@ export default async (options: GeneratorOptions) => {
const tempMermaidFile = path.resolve(path.join(tmpDir, 'prisma.mmd'));
fs.writeFileSync(tempMermaidFile, mermaid);

// default config parameters https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts
const tempConfigFile = path.resolve(path.join(tmpDir, 'config.json'));
fs.writeFileSync(
tempConfigFile,
JSON.stringify({ deterministicIds: true, maxTextSize: 90000 })
JSON.stringify({
deterministicIds: true,
maxTextSize: 90000,
})
);

let mermaidCliNodePath = path.resolve(
Expand Down

0 comments on commit efe5959

Please sign in to comment.