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 types for query, remove type assertions and switch to inference where possible #26

Merged
merged 1 commit into from
Feb 3, 2024

Conversation

calirvine
Copy link
Contributor

@calirvine calirvine commented Feb 2, 2024

Connects #13

Sorry about the formatting changes 🤔 I think they're just prettier defaults. I'll try to revert them all to the previous style (unless you want to add a prettier config, then I can just apply that to the branch).

Notes on changes

  • I introduced an invariant fn for asserting on types returned from the cloudflare API
    • Made invariant checks a bit optimistic, as I thought looping over the whole dataset might get expensive 🤷‍♂️
    • Invariants throw, but accessing malformed data will probably also throw later, so I figure that's ok.
  • Based types on documentation, haven't tested them.

Hopefully changes aren't controversial, but let me know.

@calirvine
Copy link
Contributor Author

@benvinegar These types should work, but the prettier changes make this un-reviewable 😅 will revert them tonight before marking this ready for review. These types can probably be more ergonomic than this, but it's better than any.

@@ -133,14 +133,14 @@ describe("Dashboard route", () => {
countByDevice: [['Desktop', 3]],
viewsGroupedByInterval: [
['2024-01-11 00:00:00', 4],
['2024-01-26 00:00:00', 0],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flakey test, reported in #27

@calirvine calirvine marked this pull request as ready for review February 3, 2024 02:05
Copy link

codecov bot commented Feb 3, 2024

Codecov Report

Attention: 48 lines in your changes are missing coverage. Please review.

Comparison is base (aaca36b) 71.68% compared to head (888df60) 71.21%.

Files Patch % Lines
app/analytics/query.ts 68.91% 39 Missing and 7 partials ⚠️
app/lib/utils.ts 90.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #26      +/-   ##
==========================================
- Coverage   71.68%   71.21%   -0.47%     
==========================================
  Files          18       18              
  Lines        1695     1831     +136     
  Branches      110      124      +14     
==========================================
+ Hits         1215     1304      +89     
- Misses        474      514      +40     
- Partials        6       13       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@benvinegar benvinegar merged commit 104f9db into benvinegar:main Feb 3, 2024
3 checks passed
@benvinegar
Copy link
Owner

I spent a solid 30 minutes going over this, mostly because my TypeScript experience is pretty basic, and I had to read up on a bunch of concepts (like user-defined type guards).

I think this hardens the API-calling surface a ton, so +1 from me.

(Also should probably just put some Prettier rules in here already and add it to the pre-commit stuff.)

@benvinegar
Copy link
Owner

Also – thanks! You've made the first external contribution, which I'm super glad for, because this project isn't going anywhere with just me 😬

@calirvine
Copy link
Contributor Author

Invariants are nice, they're basically the same as as X but they add a runtime check. The one I included (and which I usually use) is a paired back version of tiny-invariant.

@anurag-roy anurag-roy mentioned this pull request Feb 4, 2024
benvinegar added a commit that referenced this pull request Feb 4, 2024
@benvinegar
Copy link
Owner

FYI I had to revert this PR in 6c7108 because #30. I didn't do any deep debugging but I agree with the reporters that the invariant code seems likely, and we should probably have more tests to cover these range of cases.

Let me know if that's something you wanna poke at – I'm happy to, but I also want to make room for folks.

@calirvine
Copy link
Contributor Author

First contributor, first to break everything. Casual 😅 . Agreed it's the invariants, though they should be throwing very clear errors. I wonder where those are getting swallowed 🤔 .

I see which invariant is broken, it's getVisitorCountByColumn.

I was working last night on improving that method to infer the return type based on the name of the column passed in, I'll update that branch to be a bit less aggressive in enforcing type correctness.

@calirvine calirvine mentioned this pull request Feb 5, 2024
benvinegar pushed a commit that referenced this pull request Dec 20, 2024
benvinegar added a commit that referenced this pull request Dec 20, 2024
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