-
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
Hidden properties #1914
Comments
@wohldani In theory, since LB4 is using mostly the same juggler under the hood as LB3, hidden and protected properties should be supported out of the box. Have you tried to define them in @model({
settings: {hidden: ['password']}
})
class User extends Entity {
// ...
@property({
type: 'string',
required: true
})
password: string;
} |
I can understand @wohldani's confusion. I encountered the same initially. As part of our Migration from LoopBack 3.x epic, we should have a "How to do in LB4, what you used to do in LB3" guide. |
@bajtos thank you for your answer. I have tried to define the hidden properties in Account model:
|
There is an issue in LB4 to honor |
Based on the discussion in #1947, this issue is not as easy to fix as it seems. Cross-posting a part of #1947 (comment):
Personally, I am thinking about a different approach that may be easier to implement: modify LB4's I agree that we should reevaluate property modifiers in LB4 for long term. We already have some ideas encoded in LB4 repository types, see https://github.com/strongloop/loopback-next/blob/0e1b06f546aea97855556f985b39e50cd3e7956e/packages/repository/src/model.ts#L26-L45 I am not sure if these interfaces are a good solution for what we need though. I think we should follow scenario-based approach here and start by defining somewhat realistic use cases for these properties. @wohldani what are your use cases for hidden properties, besides the Based on my experience, it's better to store user credentials like password and 2FA tokens in a related model (e.g. Credentials) and use hasOne relation to access them. Cross-posting from #1996:
LB4 does not support hasOne relation yet, but we are actively working on this feature - see #1422, #1956 and the related pull requests. |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I override the
|
@karianpour can you show all code? Or prev steps reproduced official method? |
Let's say that we have a
Actually, for the case of |
To sum it up: hidden properties are not supported in LB4? |
I aggree with;
|
Yes, that's the case right now. Any volunteers to contribute the proposal I have described earlier?
We are happy to help you along the way. See https://loopback.io/doc/en/contrib/code-contrib-lb4.html to get started. |
The hiddenProperties setting would not be the same as this #2782 ? |
Hidden and read-only properties are different concepts. It makes sense to use a similar configuration mechanism for both of them, but there is no need to implement them at the same time. |
toJSON(): Object {
const def = (<typeof Model>this.constructor).definition;
if (def == null || def.settings.strict === false) {
return this.toObject({ignoreUnknownProperties: false});
}
const copyPropertyAsJson = (key: string) => {
json[key] = asJSON((this as AnyObject)[key]);
};
const json: AnyObject = {};
for (const p in def.properties) {
const hiddenProperties = ['remindAtGeo'];
console.log('p <-Param->:', p);
console.log('this <-Param->:', this);
console.log('----> INDEX OF <----', hiddenProperties.indexOf(p));
if (p in this && hiddenProperties.indexOf(p) === -1) {
copyPropertyAsJson(p);
}
}
for (const r in def.relations) {
const relName = def.relations[r].name;
if (relName in this) {
copyPropertyAsJson(relName);
}
}
console.log(json);
return json;
}
Can I prove this somehow? In the explorer would appear? I do not quite understand the flow |
@bajtos I would like to contribute to this feature. Can you assign this to me? |
@bhupesh-sf There is already a pull request in progress contributed by @frbuceta, see #3265. Can you work with @frbuceta to see how you can help? |
@frbuceta let me know how can I help you on this. The current solution is a short-term solution but I believe we should enhance it to full blown solution? |
@bhupesh-sf I'm beginning to understand how this is going. But yes, we can work on a better solution |
@bajtos Although its not related to the current issue but do you think to have internal properties for the model. Use case could be some kind of calculated properties which can be only internally created/updated and I don't want them to be the part of request but of the response?? Syntax could be something like
|
I don't know what exactly is happening but it works for me
|
The problem is with de setting "strict: false", if eliminate that, works well, Is it normal or is an error? |
I investigate it |
@joel-izaguirre In the next version of LoopBack (in a few days) it will work |
Still not working, or I miss something? |
@dhmlau like this:
|
Reopening this issue to be able to track this issue. @mycolaos, I just tried it with the latest LB4 modules and seems to be working for me. My
Then I tested it with API explorer,
Is it what you're seeing too? |
@dhmlau I believe I found the problem. I have an abstract class Then, how I can make it work with |
This is worked for me., try this |
Description / Steps to reproduce / Feature proposal
Does Loopback 4 supports hidden properties like LB3 did?
Current Behavior
I could not find any docs or resources about this.
Expected Behavior
https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#hidden-properties
The text was updated successfully, but these errors were encountered: