digidem / comapeo-schema

Data schemas for mapeo data types
MIT License
2 stars 0 forks source link

fix: observation metadata types #248

Closed gmaclennan closed 2 months ago

gmaclennan commented 2 months ago

boy protobuf and typescript are tricky beasts...

So there were a few edge-cases around the way we type, encode and decode observation position metadata.

We were using fromPartial for encoding metadata, which assigns defaults for missing props, which meant that decoding would pass type checks, but defaults would be assigned to the missing props, in this case longitude and latitude, which is a "null island" bug.

This PR makes a few changes:

This PR also removes usage of fromPartial, and stops generating it since it's no longer needed. Using this is "dangerous" because it assigns default values deeply to a message, which can lead to unexpected results - data that is type safe, but might have required fields set to default values.

Impact on frontend:

This is breaking, because it changes types to make some fields required. However fields that are newly set to required are also required / always set on the Expo Location LocationObject and LocationProviderStatus. Therefore in frontend code this should not break things, because these values are being set from these objects from Expo.

These changes are not really specific to Expo - it would not make sense to add this metadata without these required fields being available, even if we move away from Expo for reading location.

Why is this important?

In the future, this (position) metadata is potentially important for "proofs" of observations. Without these changes it is possible that default values could be unexpectedly set, e.g. values could be false when they were actually unknown (undefined).