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: Message type guard helpers #1572

Merged
merged 7 commits into from
Aug 27, 2024
Merged

feat: Message type guard helpers #1572

merged 7 commits into from
Aug 27, 2024

Conversation

msfstef
Copy link
Contributor

@msfstef msfstef commented Aug 27, 2024

Addresses #1453

Adds the type guards to check whether a message is a ControlMessage or a ChangeMessage, documented, tested, and exported.

I've also honed in on the message type definitions a bit more as I had experienced an uncaught bug due to the generality of the Headers type.

Copy link

netlify bot commented Aug 27, 2024

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit 8b3e898
🔍 Latest deploy log https://app.netlify.com/sites/electric-next/deploys/66cdd0c07d8eec000842e9fa
😎 Deploy Preview https://deploy-preview-1572--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

great! These will be very helpful.

Could you check the examples for where these would be helpful as well? Anywhere using ShapeStream. E.g. the Redis example needs it

if (!(`key` in message)) return

Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

Great!
Is there a reason we have packages/typescript-client/test/helpers.test.ts and packages/typescript-client/test/helpers.test-d.ts ? These are executing different tests, can we merge them into one file?

@msfstef
Copy link
Contributor Author

msfstef commented Aug 27, 2024

@KyleAMathews will update codebase in this same PR to use these helpers

@kevin-dp the test-d.ts files are "type tests" (see vitest docs) which essentially are making sure the type system is behaving as intended. In order for the test to test types rather than test code (and separately have tsc for the typecheck of the test files), I like having the separate "type tests" that ensure our type system makes sense explicitly.

@msfstef msfstef merged commit a6c7bed into main Aug 27, 2024
21 checks passed
@msfstef msfstef deleted the msfstef/message-type-helpers branch August 27, 2024 14:58
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.

Message type doesn't allow discriminating between a ControlMessage and ChangeMessage at the type level.
3 participants