4
4
FeedFetchError ,
5
5
FeedParsingError ,
6
6
FeedTimeoutError ,
7
+ FeedURLRequiredError ,
7
8
InvalidPollingIntervalError ,
8
9
UnsupportedFeedFormatError ,
9
10
} from "./errors"
@@ -430,10 +431,7 @@ function createFeedCollectionOptions<
430
431
TKey extends string | number = string | number ,
431
432
> (
432
433
config : BaseFeedCollectionConfig < TExplicit , TSchema , TFallback , TKey > & {
433
- transform ?: (
434
- item : FeedItem ,
435
- feedType : `rss` | `atom`
436
- ) => ResolveType < TExplicit , TSchema , TFallback >
434
+ transform ?: ( item : FeedItem ) => ResolveType < TExplicit , TSchema , TFallback >
437
435
expectedFeedType ?: `rss` | `atom`
438
436
}
439
437
) {
@@ -454,13 +452,15 @@ function createFeedCollectionOptions<
454
452
} = config
455
453
456
454
// Validation
455
+ if ( ! feedUrl ) {
456
+ throw new FeedURLRequiredError ( )
457
+ }
457
458
if ( pollingInterval <= 0 ) {
458
459
throw new InvalidPollingIntervalError ( pollingInterval )
459
460
}
460
461
461
462
// State management
462
463
let seenItems = new Map < string , { id : string ; lastSeen : number } > ( )
463
- let pollingTimeoutId : NodeJS . Timeout | null = null
464
464
let syncParams :
465
465
| Parameters <
466
466
SyncConfig < ResolveType < TExplicit , TSchema , TFallback > , TKey > [ `sync`]
@@ -546,7 +546,7 @@ function createFeedCollectionOptions<
546
546
let transformedItem : ResolveType < TExplicit , TSchema , TFallback >
547
547
548
548
if ( transform ) {
549
- transformedItem = transform ( rawItem , parsedFeed . type )
549
+ transformedItem = transform ( rawItem )
550
550
} else {
551
551
// Use default transformation
552
552
const defaultTransformed =
@@ -597,16 +597,6 @@ function createFeedCollectionOptions<
597
597
}
598
598
}
599
599
600
- /**
601
- * Stop polling
602
- */
603
- const stopPolling = ( ) => {
604
- if ( pollingTimeoutId ) {
605
- clearTimeout ( pollingTimeoutId )
606
- pollingTimeoutId = null
607
- }
608
- }
609
-
610
600
/**
611
601
* Sync configuration
612
602
*/
@@ -628,7 +618,7 @@ function createFeedCollectionOptions<
628
618
629
619
// Schedule next poll if polling is enabled
630
620
if ( startPolling ) {
631
- pollingTimeoutId = setTimeout ( poll , pollingInterval )
621
+ setTimeout ( poll , pollingInterval )
632
622
}
633
623
}
634
624
@@ -639,7 +629,7 @@ function createFeedCollectionOptions<
639
629
640
630
// Start polling if configured to do so
641
631
if ( startPolling ) {
642
- pollingTimeoutId = setTimeout ( poll , pollingInterval )
632
+ setTimeout ( poll , pollingInterval )
643
633
}
644
634
} )
645
635
. catch ( ( error ) => {
@@ -648,15 +638,12 @@ function createFeedCollectionOptions<
648
638
649
639
// Still start polling for retry attempts
650
640
if ( startPolling ) {
651
- pollingTimeoutId = setTimeout ( poll , pollingInterval )
641
+ setTimeout ( poll , pollingInterval )
652
642
}
653
643
} )
654
644
655
- // Return cleanup function
656
- return ( ) => {
657
- stopPolling ( )
658
- syncParams = null
659
- }
645
+ // Note: sync functions should return void
646
+ // Cleanup will be handled when the collection is destroyed
660
647
} ,
661
648
}
662
649
@@ -678,6 +665,7 @@ function createFeedCollectionOptions<
678
665
...restConfig ,
679
666
getKey,
680
667
sync,
668
+ startSync : true ,
681
669
onInsert,
682
670
onUpdate,
683
671
onDelete,
0 commit comments