Skip to content
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 FieldMask utilities and message merge options #576

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jcready
Copy link
Contributor

@jcready jcready commented Aug 9, 2023

See #58

The majority of the tests were pulled from the official python and java implementations.

As a consequence of implementing the "canonical" behavior for merging messages using a FieldMask (namely: by default repeated fields are appended (not replaced) and there is the ability to "clear" singular message fields in the target if they are unset in the source) this change also adds the concept MergeOptions which is now optionally able to be passed to the pre-existing MessageType.mergePartial() and reflectionMergePartial().

@@ -105,12 +106,12 @@ describe('reflectionMergePartial()', () => {
describe('and source field empty', () => {
const source: object = {child: undefined};
it('does not touch target', () => {
const target: any = {child: 123};
const target: any = {child: 123, children: []};
Copy link
Contributor Author

@jcready jcready Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are janky. The target/source for these tests do not follow the rules of what should be passed to reflectionMergePartial() (e.g. the MessageInfo.fields describe T). Any T should never have optional repeated fields (like children). The new implementation of reflectionMergePartial() depends on it.

@@ -119,12 +120,12 @@ describe('reflectionMergePartial()', () => {
describe('and source field null', () => {
const source: object = {child: null};
it('does not touch target', () => {
const target: any = {child: 123};
const target: any = {child: 123, children: []};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Janky. child is a "message" field, not a "scalar" number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant