use ValidatedEvent type instead of defineEvent#181
Conversation
📝 WalkthroughWalkthroughThe patch introduces a new exported Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code graph analysis (1)example/convex/userConfirmation.ts (1)
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
README.md (1)
490-490: Minor typo: "event" should be "name".The note mentions
{ event, validator }but the actual type fields are{ name, validator }.🔎 Suggested fix
-Note: this is just a convenience to create a typed { event, validator } pair. +Note: this is just a convenience to create a typed { name, validator } pair.
🧹 Nitpick comments (1)
example/convex/userConfirmation.ts (1)
52-56: Consider consistent spread order with README example.The README shows
{ ...approvalEvent, workflowId, value }while this code uses{ workflowId, value, ...approvalEvent }. While functionally equivalent (no property conflicts), matching the README pattern improves consistency.🔎 Optional: Align with README pattern
await workflow.sendEvent(ctx, { + ...approvalEvent, workflowId: args.workflowId, value: { approved: true, choice: args.choice }, - ...approvalEvent, });
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md(1 hunks)example/convex/userConfirmation.ts(2 hunks)src/client/index.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
example/convex/userConfirmation.ts (1)
src/client/index.ts (1)
ValidatedEvent(354-364)
🔇 Additional comments (5)
src/client/index.ts (2)
347-352: LGTM! ThedefineEventfunction is preserved for backward compatibility.The generic parameter change from
Validator<unknown, "required", string>toValidator<unknown, "required", any>broadens compatibility with various validator configurations.
354-364: Clean type definition that enables the object literal pattern.The
ValidatedEventtype with sensible defaults allows users to define events as plain objects withsatisfies ValidatedEvent, making them easier to spread insendEventcalls compared to the function-baseddefineEventapproach.README.md (1)
470-485: Clear documentation of the new pattern.The example effectively demonstrates the recommended approach using
satisfies ValidatedEventwithas constfor proper type narrowing on the event name.example/convex/userConfirmation.ts (2)
10-16: Good migration to theValidatedEventpattern.The
as constassertion onnameis essential for preserving the literal type"approval", enabling proper type inference when the event is used inawaitEventandsendEvent.
20-39: Well-structured workflow example.The workflow demonstrates the complete approval flow pattern with proper type annotations and error handling for both approved and rejected cases.
6c8d67c to
b3de97a
Compare
Support both, but point people more towards using a type, which is less surprising to spread, etc.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Summary by CodeRabbit
Documentation
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.