-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[CLI] add lb4 relation
command
#1359
Comments
As for the controller generator, our current approach is to have one controller for each relation. For example, when The reason for this split is to keep application code clean and avoid controllers with too many methods. Consider the case where a model has 3-5 relations. If we kept all relation endpoints in a single controller, the controller could easily end up with more than 20 methods. As a nice side effect, our code generator will be also simpler to implement because adding a relation means adding a new controller file instead of editing existing controller classes. |
Rejecting for now. While the task is well groomed, we need consensus on if we are going with AST Approach, Declarative Support, etc. Also need a spike on AST to figure out feasibility and build expertise. Also, this task should be broken down into smaller tasks. |
We can possibly leverage const prettier = require('prettier');
const util = require('util');
async function transform() {
const prog = await prettier.format(
`/** class */
class X {
a: string;
b(): string {
return '1';
}
}`,
{
parser(text, {typescript}) {
const ast = typescript(text);
console.log(util.inspect(ast, {depth: 5}));
ast.body[0].id.name = 'Y';
return ast;
},
},
);
console.log(prog);
}
transform(); You'll now get: /** class */
class Y {
a: string;
b(): string {
return "1";
}
} |
How about these ones ? https://github.com/SBoudrias/AST-query |
@marioestradarosa Thank you for chiming in. The ones you found seem to be only for JavaScript, not TypeScript. |
@raymondfeng there are ports for TS also https://github.com/phenomnomnominal/tsquery I want to learn from you :-) , why the current typescript (with a linter) would not be suitable for this purpose? or any other package like tsquery as opposed to the excellent POC you mentioned above with prettier?. |
As we discussed in the estimation meeting, this will be a post-ga story and let's create a new issue to document how to update the relation repository as a temporary solution. |
I think that we should have this done in three separate Pull Requests. I propose the initial PR as follows
Example: The generator will update the two models in Advanced functionality using AST
Note: The other two PRs proposed should be done in the |
Per the discussion in our previous estimation meeting, this task would involve changing of the ts file. Therefore, we've created the spike #1656 to see what's the best approach. With this, I'm moving this task back to |
Hi @dhmlau, I am more than confident I can implement the CLI command for relations following your guidelines. |
@dhmlau |
Sounds great, assigning the issue to you :)
Personally, I prefer to work in small increments and start with the simplest possible solution. I think that means no user-configurable FROM/ For longer term, I think it makes sense to eventually extend |
Thanks for assigning me into this task :) From the documentation and from some tests I performed in my environment I realized:
I guess my question is why hasMany is different from hasOne in the aspect of requiring the belongsTo in the target model. |
What is special about |
Closing as done via #2426 |
Description / Steps to reproduce / Feature proposal
See also #695
cc @b-admike
Acceptance Criteria (@virkt25)
lb4 relation
commandhasMany
,belongsTo
in progress).hasMany
ask the following prompts:lb4 repository
command #1588 for prompts you should ask / need to generate a repository)hasMany
decorator. Will need to import the TO model here.HasManyRepositoryFactory
and it's implementation. If it exists, use AST to add the new property and code related to power theHasMany
relation. See: https://github.com/strongloop/loopback-next/blob/master/examples/todo-list/src/repositories/todo-list.repository.ts for details.fromModel-toModel.controller.ts
that exposes GET, POST, PATCH, DEL. Template can be based on https://github.com/strongloop/loopback-next/blob/master/examples/todo-list/src/controllers/todo-list-todo.controller.ts.--config
support (JSON Definition of Model) and--yes
support (Skip relation property name, foreign key, assume they want to create/update repo, create controller).lb4 relation fromModel hasMany toModel
... with--yes
this is 🔥Note For Estimation
CHALLENGE: Updating a pre-defined Model is tricky if we are manipulating the file as text ... user could've defined multiple Classes in a single file, etc. The best approach will be to use Abstract Syntax Tree (AST).
The text was updated successfully, but these errors were encountered: