appConfig - are the file paths really necessary? #1819
Replies: 6 comments
-
Hi, @oliversturm ! As I understand it, this issue actually raises two questions: how to import resources into a configuration file and how resources are divided into their component parts. The first part is discussed in detail in the earlier issue #1361 . In a nutshell, it's impossible to perform direct resources import in app.config, because the reSolve framework performs massive codegeneration, and use customer application files to generate JS-code from pieces. Therefore reSolve framework claims path to files and not materialized objects from these files, because it will read source code of those files, combine it with resolve-runtime pieces, generate on-the-fly JS bundle and only then execute it. The second part of issue is subject to discuss. Some parts of configuration file can de reduced to composite import, like you suppose above. For instance, aggregates and read-models can be joined in united file, but view-models must be placed in separate files. To preserve a universal style, it was decided to define all configuration sections as a set of constituent resources. There will probably be many questions why an aggregate can be imported as a single file, and the view model must be included as several compound files. |
Beta Was this translation helpful? Give feedback.
-
Can you elaborate about the view model requirements here? A view model really only needs one file anyway - I believe the (de)serialize_state files are optional, right? In any case, why couldn't I have something like this in export default {
Init: () => [],
Serialize: state => JSON.stringify(state || []),
Deserialize: state => JSON.parse(state),
[EVENT1]: ...
... Further, are you saying that it is possible right now to combine commands and projections for an aggregate in one file? And projections and resolvers for a read model as well? If so, can you give an example? |
Beta Was this translation helpful? Give feedback.
-
Main difference between read-models, aggregates, api-handlers, etc in one hand, and view-models in another hand is isomorphism. View-models are used mutually on client and server side, so isomorphic code should be imported different way than server-only code. View-model is consists of multiple parts, and some of them are server-only for technical and security resons https://github.com/reimagined/resolve/blob/master/packages/core/resolve-scripts/configs/schema.resolve.config.json#L118-L150. For instance, view-model serializer can use Bcrypt/JWT npm packages, which are written in C++ and therefore cannot be imported in client side. Since ECMAScript language has no "unimport" semantics, where is no way no make composite file describing one view-model, because it will directly import all dependent parts recursively, and bundling will fail on server-only libraries. Consider following simplified one-line view-model serializer If example above with hypothetic |
Beta Was this translation helpful? Give feedback.
-
Okay, these are very good points - thanks for explaining. I understand that for this reason we will need to keep the split between view model files - but I would still add that these are "special' scenarios and many devs will probably not encounter them. Or perhaps I'm not understanding why this would be a common thing... Meanwhile, I still don't think that we couldn't support a one-file scenario for aggregates and read models, if that's possible. I don't think this will result in great confusion, even more so since the core of the view model setup is also a one-file thing. |
Beta Was this translation helpful? Give feedback.
-
Yes, I think you are right, and we can provide support one-file implementation for domain configuration entities, including view-models, and leave current multiple-file configuration as advanced mode for including server-only libraries in view-model parts, like encryption and serialization. The only serious drawback in this scheme is that if the developer uses the single-file configuration for the view model, and then includes the server library there and forgets to change the configuration to the multi-file one, then the application building will fall with an unobvious error that we cannot intercept at this moment (although maybe this one https://webpack.js.org/loaders/node-loader/ can help and it is subject to research) |
Beta Was this translation helpful? Give feedback.
-
That is certainly unfortunate. But the goal of the discussion in this thread is, from my point of view, to simplify the setup requirements for first-time users and 80% cases - if a dev starts doing something advanced with custom serialization of view models, they are probably outside the scope of this simplification. Of course it would be great if we could show a really useful message if they get it wrong.
I believe this is already possible - at least I had it set up like that in a test, and it was my impression that the standard template code (i.e. |
Beta Was this translation helpful? Give feedback.
-
The structure of the config blocks for aggregates, read models and other parts requires me to pass the relative path for each source code file:
This seems unusual, and extra work for maintenance. Of course there are many ways of building up this structure. I think there are two aspects that are strange for reSolve:
To provide an example of a contrasting implementation, here is some code from a demo that uses my own CQRS/ES framework. This is an aggregate implementation - never mind the details, but you can see that all aspects are handled in the same place. Of course I would still be free to separate command and projection related code - this way it's left to the dev which way they prefer.
And then I have this to accumulate all aggregates:
I think this is a pretty compact and standard structure without enforced maintenance overhead. Couldn't the reSolve config work this way?
Beta Was this translation helpful? Give feedback.
All reactions