feat: rrule and ruleset validate - #8
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new validate function to provide a safe, non-throwing way to validate RRULE and RRuleSet strings. The function wraps the existing rrulestr parser and returns a discriminated union indicating success or failure with detailed error information.
Changes:
- New
validatefunction that accepts the same inputs asrrulestrbut returns a validation result instead of throwing - Three new TypeScript types exported:
ValidationResult,ValidationSuccess, andValidationError - Comprehensive test coverage for both valid and invalid inputs, including edge cases
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/validate.ts | Implements the core validation function that wraps rrulestr in try-catch and returns structured validation results |
| src/index.ts | Exports the new validate function and associated TypeScript types |
| test/validate.test.ts | Comprehensive test suite covering valid inputs, invalid inputs, and contract guarantees (never throws) |
| README.md | Documentation for the validate function including usage examples and TypeScript type definitions |
| .changeset/heavy-times-turn.md | Changeset entry describing the new minor feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| ```js | ||
| import { datetime, RRule, RRuleSet, rrulestr } from 'rrule' | ||
| import { datetime, RRule, RRuleSet, rrulestr, validate } from 'rrule' |
There was a problem hiding this comment.
Inconsistent package name in import statement. This line uses 'rrule' while the new validate examples added in lines 166 and 770 use '@offload-project/rrule'. Consider using the full package name '@offload-project/rrule' consistently throughout the documentation, or using the short form 'rrule' consistently.
| import { datetime, RRule, RRuleSet, rrulestr, validate } from 'rrule' | |
| import { datetime, RRule, RRuleSet, rrulestr, validate } from '@offload-project/rrule' |
Add
validatefunction for checking RRULE and RRuleSet strings without throwing.validate(s, options?)function that returns{ valid: true }or{ valid: false, error: { message, cause } }rrulestrValidationResult,ValidationSuccess, andValidationErrortypes