Skip to content

Commit e6d6960

Browse files
Refactor RSS collection types and remove unnecessary validation checks
Co-authored-by: sam.willis <[email protected]>
1 parent e56c792 commit e6d6960

File tree

3 files changed

+60
-25
lines changed

3 files changed

+60
-25
lines changed

packages/rss-db-collection/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@
5959
"sideEffects": false,
6060
"type": "module",
6161
"types": "dist/esm/index.d.ts"
62-
}
62+
}

packages/rss-db-collection/src/rss.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {
44
FeedFetchError,
55
FeedParsingError,
66
FeedTimeoutError,
7-
FeedURLRequiredError,
8-
GetKeyRequiredError,
97
InvalidPollingIntervalError,
108
UnsupportedFeedFormatError,
119
} from "./errors"
@@ -82,7 +80,7 @@ export interface HTTPOptions {
8280
* Base configuration interface for feed collection options
8381
*/
8482
interface BaseFeedCollectionConfig<
85-
TExplicit = unknown,
83+
TExplicit extends object = Record<string, unknown>,
8684
TSchema extends StandardSchemaV1 = never,
8785
TFallback extends object = Record<string, unknown>,
8886
TKey extends string | number = string | number,
@@ -169,7 +167,7 @@ interface BaseFeedCollectionConfig<
169167
* Configuration interface for RSS collection options
170168
*/
171169
export interface RSSCollectionConfig<
172-
TExplicit = unknown,
170+
TExplicit extends object = RSSItem,
173171
TSchema extends StandardSchemaV1 = never,
174172
TFallback extends object = RSSItem,
175173
TKey extends string | number = string | number,
@@ -184,7 +182,7 @@ export interface RSSCollectionConfig<
184182
* Configuration interface for Atom collection options
185183
*/
186184
export interface AtomCollectionConfig<
187-
TExplicit = unknown,
185+
TExplicit extends object = AtomItem,
188186
TSchema extends StandardSchemaV1 = never,
189187
TFallback extends object = AtomItem,
190188
TKey extends string | number = string | number,
@@ -197,18 +195,21 @@ export interface AtomCollectionConfig<
197195

198196
// Type resolution helper (copied from TanStack DB patterns)
199197
type InferSchemaOutput<T> = T extends StandardSchemaV1
200-
? StandardSchemaV1.InferOutput<T>
198+
? StandardSchemaV1.InferOutput<T> extends object
199+
? StandardSchemaV1.InferOutput<T>
200+
: Record<string, unknown>
201201
: Record<string, unknown>
202202

203203
type ResolveType<
204-
TExplicit = unknown,
204+
TExplicit extends object = Record<string, unknown>,
205205
TSchema extends StandardSchemaV1 = never,
206206
TFallback extends object = Record<string, unknown>,
207-
> = unknown extends TExplicit
208-
? [TSchema] extends [never]
209-
? TFallback
210-
: InferSchemaOutput<TSchema>
211-
: TExplicit
207+
> =
208+
Record<string, unknown> extends TExplicit
209+
? [TSchema] extends [never]
210+
? TFallback
211+
: InferSchemaOutput<TSchema>
212+
: TExplicit
212213

213214
/**
214215
* Feed collection utilities
@@ -469,7 +470,7 @@ function getItemId(item: FeedItem, feedType: `rss` | `atom`): string {
469470
* Internal implementation shared between RSS and Atom collections
470471
*/
471472
function createFeedCollectionOptions<
472-
TExplicit = unknown,
473+
TExplicit extends object = Record<string, unknown>,
473474
TSchema extends StandardSchemaV1 = never,
474475
TFallback extends object = Record<string, unknown>,
475476
TKey extends string | number = string | number,
@@ -499,14 +500,6 @@ function createFeedCollectionOptions<
499500
} = config
500501

501502
// Validation
502-
if (!feedUrl) {
503-
throw new FeedURLRequiredError()
504-
}
505-
506-
if (!getKey) {
507-
throw new GetKeyRequiredError()
508-
}
509-
510503
if (pollingInterval <= 0) {
511504
throw new InvalidPollingIntervalError(pollingInterval)
512505
}
@@ -571,6 +564,7 @@ function createFeedCollectionOptions<
571564

572565
const xmlContent = await fetchFeed(feedUrl, httpOptions)
573566

567+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
574568
if (!XMLValidator.validate(xmlContent)) {
575569
throw new FeedParsingError(feedUrl, new Error(`Invalid XML content`))
576570
}
@@ -580,7 +574,10 @@ function createFeedCollectionOptions<
580574
`Parsed ${parsedFeed.items.length} items from ${parsedFeed.type} feed`
581575
)
582576

583-
if (expectedFeedType && expectedFeedType !== parsedFeed.type) {
577+
if (
578+
expectedFeedType !== undefined &&
579+
expectedFeedType !== parsedFeed.type
580+
) {
584581
throw new UnsupportedFeedFormatError(feedUrl)
585582
}
586583

@@ -763,7 +760,7 @@ function createFeedCollectionOptions<
763760
* Creates RSS collection options for use with a standard Collection
764761
*/
765762
export function rssCollectionOptions<
766-
TExplicit = unknown,
763+
TExplicit extends object = RSSItem,
767764
TSchema extends StandardSchemaV1 = never,
768765
TFallback extends object = RSSItem,
769766
TKey extends string | number = string | number,
@@ -781,7 +778,7 @@ export function rssCollectionOptions<
781778
* Creates Atom collection options for use with a standard Collection
782779
*/
783780
export function atomCollectionOptions<
784-
TExplicit = unknown,
781+
TExplicit extends object = AtomItem,
785782
TSchema extends StandardSchemaV1 = never,
786783
TFallback extends object = AtomItem,
787784
TKey extends string | number = string | number,

pnpm-lock.yaml

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)