Mermaid - Styling class diagram in markdown - uml

Hello I would styling a class diagram defined with mermaid. I need to integrate this diagram in a markdown document (no css customization).
%%{init: {'theme': 'dark'}}%%
classDiagram
class Company {
id: string
cognito_sub: string
first_name: string
last_name: string
phone: Phone
email: string
tax_code: string
birth_date: number
birth_place: string
img_url: string
origin: string
status: CustomerStatus
note: Note[]
created_at: number
updated_at: number
}
I would change background and border color. I can't use css because I need to integrate this diagram on a Notion document.

You can customise diagram with themeVariables inside init block, for example:
%%{init: {'theme': 'base', 'themeVariables': { 'primaryBorderColor': 'green', 'background': 'yellow'}}}%%
More information about accessible variables: https://mermaid-js.github.io/mermaid/#/./theming?id=theme-variables-reference-table

Related

save style for each field in database

I use mongodb and I have a model like this:
{
title: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
date: {
type: Date,
required: true,
},
}
I want to save styles (such as font, size, color, etc.) for each field
What is the best way to store them in a database?
Do I have to create a new field for each of them to store their style as a string (HTML code)?
You can create the list of css class like what bootstrap does. And then, you will create a new filed for each of them where you will just store the classes name.
all css will be stored in the css files
classes names associated to each elements will be stored in the database.
In that way, your app will be stay clean and you can reuse a lot of css class.

OpenAPI: Mandatory properties of an Optional Property

Pretty much what the title says. I have an optional object in the request body. However, if that object is given, it should mandatorily contain a few child properties.
My OpenAPI component config looks like this:
UserDetails:
type: object
properties:
surname:
type: string
givenName:
type: string
dob:
type: string
format: date
gender:
type: string
enum:
- male
- female
- others
partner:
type: object
properties:
name:
type: string
phone:
type: string
maxLength: 10
minLength: 10
pattern: ^[1-9]+[0-9]{9}$
required: [name, phone]
required:
- surname
- givenName
- dob
I am using express-openapi-validator to validate this. Now, I don't understand if this is the problem of the express-openapi-validator package or not, but the required fields (name, phone) of the optional field (partner) is never validated. I can just provide partner: {} and it slips in right through, or even, partner: { name: 'some name', phone: '123' }. Phone number should be validated for the length and the regex.
Am I missing anything in the definition?
There does not seem to be a solution to this, but I am closing this just for peace to my mind.
like what #Helen has replied, this seems to be an issue with the library itself.
In the process of developing my application, I discovered more problems, which make the the library express-openapi-validator and another library swagger-express-middleware I used, even lesser reliable for validating requests.
The other problem that I discovered was that a value is validated with a provided enum only if it is provided as an array:
eg. The following is validated correctly:
UserLiabilities:
type: object
properties:
liabilities:
type: object
properties:
creditCards:
type: array
items:
allOf:
- $ref: '#/components/schemas/Provider'
- type: object
properties:
limit:
type: number
minimum: 0
Here Provider is:
Provider:
type: object
properties:
provider:
type: string
enum: ['ABC', 'DEF', 'GHI', 'Others']
However, if I need provider as a plain string in an object (not in an array like above), it is not validated. And, it allows any arbitrary string:
homeLoan:
allOf:
- $ref: '#/components/schemas/Provider'
- type: object
properties:
amount:
type: number
minimum: 0
This behavior is consistent with atleast two libraries that I have tried and mentioned above. I am not sure I am doing something wrong here, but I have lost enough time trying to debug this and had to finally resolve this in my server itself.

GraphQL: How nested to make schema?

This past year I converted an application to use Graphql. Its been great so far, during the conversion I essentially ported all my services that backed my REST endpoints to back grapqhl queries and mutations. The app is working well but would like to continue to evolve my object graph.
Lets consider I have the following relationships.
User -> Team -> Boards -> Lists -> Cards -> Comments
I currently have two different nested schema: User -> team:
type User {
id: ID!
email: String!
role: String!
name: String!
resetPasswordToken: String
team: Team!
lastActiveAt: Date
}
type Team {
id: ID!
inviteToken: String!
owner: String!
name: String!
archived: Boolean!
members: [String]
}
Then I have Boards -> Lists -> Cards -> Comments
type Board {
id: ID!
name: String!
teamId: String!
lists: [List]
createdAt: Date
updatedAt: Date
}
type List {
id: ID!
name: String!
order: Int!
description: String
backgroundColor: String
cardColor: String
archived: Boolean
boardId: String!
ownerId: String!
teamId: String!
cards: [Card]
}
type Card {
id: ID!
text: String!
order: Int
groupCards: [Card]
type: String
backgroundColor: String
votes: [String]
boardId: String
listId: String
ownerId: String
teamId: String!
comments: [Comment]
createdAt: Date
updatedAt: Date
}
type Comment {
id: ID!
text: String!
archived: Boolean
boardId: String!
ownerId: String
teamId: String!
cardId: String!
createdAt: Date
updatedAt: Date
}
Which works great. But I'm curious how nested I can truly make my schema. If I added the rest to make the graph complete:
type Team {
id: ID!
inviteToken: String!
owner: String!
name: String!
archived: Boolean!
members: [String]
**boards: [Board]**
}
This would achieve a much much deeper graph. However I worried how much complicated mutations would be. Specifically for the board schema downwards I need to publish subscription updates for all actions. Which if I add a comment, publish the entire board update is incredibly inefficient. While built a subscription logic for each create/update of every nested schema seems like a ton of code to achieve something simple.
Any thoughts on what the right depth is in object graphs? With keeping in mind the every object beside a user needs to be broadcast to multiple users.
Thanks
GraphQL's purpose is to avoid a couple of queries, so I'm sure that making the nested structure is the right way. With security in mind, add some GraphQL depth limit libraries.
GraphQL style guides suggest you have all complex structures in separate Object Types ( as you have, Comment, Team, Board... ).
Then making a complex query/mutation is up to you.
I'd like you to expand this sentence
Which if I add a comment, publish the entire board update is
incredibly inefficient
I'm not sure about this as you have your id of the Card. So adding new comment will trigger mutation which will create new Comment record and update Card with the new comment.
So your structure of data on the backend will define the way you fetch it but not so much the way you mutate it.
Take a look at the GitHub GraphQL API for example:
each of the mutations is a small function for updating/creating piece of the complex tree even if they have nested structure of types on the backend.
In addition for general knowledge of what are approaches for designing the mutations, I'd suggest this article.
You can use nesting in GraphQL like
type NestedObject {
title: String
content: String
}
type MainObject {
id: ID!
myObject: [NestedObject]
}
In the above code, the type definition of NestObject gets injected into the myObject array. To understand better you can see it as:
type MainObject {
id: ID!
myobject: [
{
title: String
content: String
}
]
}
I Hope this solves your problem!

Library to mock nodejs object base on flow typing

I'm looking for a JS library to mock object base of my type declaration.
For example this is my user type:
export type UserType = {
id: string,
userId: string,
platform: ?string,
gender: ?string,
timezone: ?number,
picture_url: ?string,
first_name: string,
last_name: string,
locale: ?string,
created_on: ?Date
};
I want to be able to do that: let userMock = mock(UserType)
do you know something that allow to do that?
For typescript, you can use Factory to generate factories for test data for Typescript based on the interface provided.
For a normal js, you can utilize Faker which provides a good tool to generate random test data.

Mongoose best practices for document creation with unknown number of items in a field

I've looked around left and right, I wrote some demo code, wrote some tests to implement a school management system.
What I want to know from people more used to mongoose development is how would be the best practice to create this schema in a way that made it possible to add as many address, and contact fees as I want from this single document.
I made my own solution, but I don't know if it is the most elegant and feasible way, I want an opinion from seasoned people.
Should I create separate models for address, email and phone numbers?
I created this schema. It still has some pseudo-code, but for giving the general idea is fine.
var student = {
name: String,
surname: String,
currentClass: {
type: mongoose.Schema.Types.ObjectId,
ref: "Classes"
},
birthday: {
year: Number,
month: Number,
day: Number
},
address: [{
name: String,
zip: Number,
address: String,
city: String,
state: String,
complement: String
}]
accountable: {
name: String,
surname: String,
email: [{
type: String,
required: true,
lowercase: true
}],
phone: [String, String]
}
My sollution was, by using html, creating a new "email" or "address" fields as the user requested by clickinking in the propper button. This generated a new input field with a name that followed a pattern like:
email1, email2, email3, email4
And so, when the user sent the data, if we were creating a new student I would first create the array with the data and send it to mongoose.
In case of updating, I would get the already created emails and add it to the new array with the newEmails.concat(old_emails)
To design the database, there are many situations for it:
1 to 1, 1 to many, many to many.
One to one: you should to put the strong object inside the other, for example:a person can have only one passport, then we should put passport object inside the person object.
One to Many, 3 cases for one to many.
One to Few:few is less than 100 objects,Then you should add the few as list in the one object, for example:
A person can have multiple addresses as in your example above.
One to Many:many is Thousands, then you should put the primary keys of the many in a list inside the the one object.
One to Too many: then do not do the previous solution, but instead add the primary of the one in every objects of the many.
And finally, Many to Many: you should put them as list in both sides.
Check the below references:
https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-1
https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-2
https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-3
Morover, for this part phone: [String, String], you should make it phone: [String]

Resources