-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add support for embedded types #140
base: master
Are you sure you want to change the base?
Conversation
@NaridaL @mweststrate Should I update the README manually or did I miss any step? Locally, it looks to be working (build and tests). :) |
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.
You need to run yarn build-docs
to rebuild the README.
* @param type {ClazzOrModelSchema<T>} Some class or model schema. | ||
*/ | ||
export default function embedded<T>(type: ClazzOrModelSchema<T>) { | ||
return custom( |
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.
The other built-in types don't use custom, rather they build a PropSchema
manually. Unless there is a specific reason, we should do the same here.
* | ||
* @param type {ClazzOrModelSchema<T>} Some class or model schema. | ||
*/ | ||
export default function embedded<T>(type: ClazzOrModelSchema<T>) { |
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.
Other built-in types all accept an additionalArgs?: AdditionalPropArgs
argument. We should do the same here.
For this type to be flexible, we probably need a "prefix" option.
beforeDeserialize(callback, jsonValue, jsonParentValue) { | ||
callback(null, null) | ||
} |
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 this necessary? It doesn't seem to do anything.
@@ -715,3 +717,44 @@ test("list(custom(...)) with SKIP", (t) => { | |||
|
|||
t.end() | |||
}) | |||
|
|||
test("embedded(type)", (t) => { |
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.
The other typescript tests all use decorators. Can we move these to simple.js?
/** | ||
* This allows to embed the property values in the resulting json output | ||
* and vice-versa. | ||
* | ||
* @param type {ClazzOrModelSchema<T>} Some class or model schema. | ||
*/ |
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 add an example of the usage here. See the other built in types for how to format it so that it shows up properly in the README.
This is an interesting idea. I think I do see a lot of potential for property collisions or otherwise acting on a JSON element more than once, which gives me pause. Interestingly, in my own work, I could use the opposite: I have to deal with wiretypes full of totally unnecessary object nesting. |
These changes will allow support for embedded types or maybe more powerful custom serializers.
It allows the user to change the outputted object during the serialization/deserialization.