Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add dependency manager #947

Conversation

jonaslagoni
Copy link
Member

@jonaslagoni jonaslagoni commented Oct 12, 2022

Description
Up until now, dependencies have been part of the renderer instance as it was only the presets and renderers that needed to add dependencies, however, there is a need to let the type constrainer add dependencies. This creates a bit of a dilemma, as the renderer expects a constrained model, and to create a constrained model it needs a renderer...

So therefore I suggest we split out the dependency functionality into its own instance where each language can create its own custom logic for handling dependencies. For example, TypeScript needs specific functions to more efficiently make imports based on the options from the user.

I would love to have alternatives, and if you have something please let me know, cause it does create somewhat of a complexity 🙃 But maybe this is for version 2? 🤷

Alternatives I considered:

  • We could use something like a singleton pattern instead of passing the instance across the entire flow, but it's not possible because each rendering needs its own set of dependencies.
  • Redoing the renderer + constrained model dependency so they would no longer be dependent on each other and we could then pass the renderer to the container. This just seems more complex to do than this...
  • ??

Changes introduced:

  • Introduce the concept of dependency managers which you have access to in constraints and presets.

Related issue(s)
Fixes #851

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me these solution can be, but the AbstractDependencyManager itself should have a method that renders all dependencies as output like renderDependencies(). In addition, a better solution would be if we could pass the dependency manager class as generator option (definition of it) and create it during rendering - currently someone can pass this via an argument to the method, and it should be passed to the constructor option.

@jonaslagoni
Copy link
Member Author

For me these solution can be, but the AbstractDependencyManager itself should have a method that renders all dependencies as output like renderDependencies()

I think that makes sense, let me try to look into that!

In addition, a better solution would be if we could pass the dependency manager class as generator option (definition of it) and create it during rendering - currently someone can pass this via an argument to the method, and it should be passed to the constructor option.

I don't quite understand this suggestion, can you clarify it?

@magicmatatjahu
Copy link
Member

magicmatatjahu commented Oct 19, 2022

@jonaslagoni

I don't quite understand this suggestion, can you clarify it?

For example. you have signature:

public abstract render(model: MetaModel, inputModel: InputMetaModel, dependencyManager?: AbstractDependencyManager): Promise<RenderOutput>;

I think that's would be better if people would pass AbstractDependencyManager definition to the Generator class, not to the function signature, so CommonGeneratorOptions should have this new field:

{
  dependencyManager?: typeof AbstractDependencyManager // definition of class not instance!
}

and then if someone will run render function, we will create AbstractDependencyManager instance based on options.dependencyManager like:

render(...) {
  const dependencyManager = new options.dependencyManager(...)
}

Is it clarify? :D

@jonaslagoni
Copy link
Member Author

Is it clarify? :D

Yes! Actually, that's brilliant!

Let me try out that approach 😄

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments :)

src/generators/typescript/TypeScriptDependencyManager.ts Outdated Show resolved Hide resolved
src/generators/typescript/TypeScriptGenerator.ts Outdated Show resolved Hide resolved
src/generators/AbstractGenerator.ts Outdated Show resolved Hide resolved
Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing, we discussed about it as I remember 😅

src/generators/AbstractDependencyManager.ts Show resolved Hide resolved
# Conflicts:
#	examples/README.md
#	src/generators/typescript/TypeScriptGenerator.ts
#	src/generators/typescript/TypeScriptRenderer.ts
#	src/helpers/ConstrainHelpers.ts
#	src/helpers/TypeHelpers.ts
Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. A couple of things I don't like is that you add too many things through class arguments and not through some single object, such as here https://github.com/asyncapi/modelina/pull/947/files#diff-a6a5c62c72e934883df999f53c7335c2b386754b04ca5222520015351537d546R20 but it's ok 👌🏼

src/generators/typescript/TypeScriptGenerator.ts Outdated Show resolved Hide resolved
@jonaslagoni jonaslagoni changed the base branch from next to dependency_-manager December 2, 2022 12:06
@jonaslagoni jonaslagoni marked this pull request as ready for review December 2, 2022 12:06
Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
@jonaslagoni
Copy link
Member Author

@magicmatatjahu lets merge it into a separate branch to allow each generator and maintainer to review the changes more easily.

@sonarcloud
Copy link

sonarcloud bot commented Dec 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonaslagoni Yeah, good idea. If new feature has a bugs that I don't see, it will be easier to fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants