-
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
feat(repository): helper function for getting Model metadata #813
Conversation
); | ||
}); | ||
|
||
it('retrieves metadata for classes with @model and property', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to change this to say @property
.
feda037
to
0bf517a
Compare
import {MODEL_KEY, MODEL_PROPERTIES_KEY} from '../'; | ||
import {ModelDefinition, PropertyDefinition} from '../../index'; | ||
|
||
export namespace ModelMetadata { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to create a ModelMetadataHelper
class and make getModelMetadata
a static method.
Since there is only one method, we can just simply export the getModelMetadata
function.
IIRC, the naming convention for namespace
should be lower case. ModelMetadata.getModelMetadata()
will make us assume that ModelMetadata
is a class and getModelMetadata
is a static method.
const meta = new ModelDefinition( | ||
Object.assign( | ||
{ | ||
name: '<unknown>', // Name is a required field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we at least make the default value of name
to be target.name
?
@kjdelisle Please fix the commit message:
|
5aed1d4
to
d1e6381
Compare
2c70c8b
to
c5d4114
Compare
@slnode test please |
* the output of the metadata retrieval functions. | ||
*/ | ||
static getModelMetadata(target: Function, options?: InspectionOptions) { | ||
const classDef = MetadataInspector.getClassMetadata( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to cache the result on the target? See an example at https://github.com/strongloop/loopback-next/blob/master/packages/rest/src/router/metadata.ts#L177
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some code to alter the MODEL_KEY/target metadata if there aren't any properties defined on first call.
c5d4114
to
7e19fe1
Compare
*/ | ||
static getModelMetadata(target: Function, options?: InspectionOptions) { | ||
const classDef = MetadataInspector.getClassMetadata( | ||
MODEL_KEY, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use a different key to cache the fully built model definition and leave MODEL_KEY
to reference the raw spec from @model
.
classDef, | ||
), | ||
); | ||
if (_.isEmpty(_.keys(meta.properties))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a side effect of reusing MODEL_KEY
for in-place calculation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my latest comments.
0bd351a
to
e6cb743
Compare
Please fix the commit log. |
e6cb743
to
4a293d3
Compare
@slnode test please |
@slnode test please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Description
A helper function to roll the properties metadata into one object with the model's metadata.
Related issues
connected to #786
Checklist