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

feat: validate latitude and longitude #16

Merged
merged 2 commits into from
Dec 9, 2024
Merged

Conversation

EvanHahn
Copy link
Contributor

It is now impossible to encode/decode a position with an invalid latitude or longitude.

There are two motivations for this change:

  1. General correctness.

  2. @mapeo/mock-data is currently generating invalid latitudes and longitudes because of the schema in this repo. That causes some workarounds if you need valid coordinates, and I plan to add more tests that will require similar workarounds. I felt that fixing the problem here, at the source, was best.

It is now impossible to encode/decode a position with an invalid
latitude or longitude.

There are two motivations for this change:

1. General correctness.

2. `@mapeo/mock-data` is currently generating invalid latitudes and
   longitudes because of the schema in this repo. That causes [some
   workarounds if you need valid coordinates][0], and I plan to add more
   tests that will require similar workarounds. I felt that fixing the
   problem here, at the source, was best.

[0]: https://github.com/digidem/comapeo-cloud/blob/d6ab53197ac3970ee8f287ddb30663a04c6449d1/test/add-alerts-endpoint.js#L240-L243
@EvanHahn EvanHahn requested a review from gmaclennan November 26, 2024 19:29
Copy link

github-actions bot commented Nov 26, 2024

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedNov 27, 2024, 3:46 PM

Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

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

JSON schema change looks good, however it doesn't quite feel right to validate as part of the encode step. I don't think we validate anything other than the types in the encode step for other things, and instead we rely on the ajv validate function when writing data. Not sure why we would do this differently here?

@EvanHahn
Copy link
Contributor Author

Removed the encode validation in 71e08c2.

@EvanHahn EvanHahn requested a review from gmaclennan November 27, 2024 15:46
@EvanHahn EvanHahn merged commit eda2f94 into main Dec 9, 2024
3 checks passed
@EvanHahn EvanHahn deleted the more-precise-lat-lon-types branch December 9, 2024 14:36
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.

2 participants