Skip to content

Commit

Permalink
Remove deprecated deserialization function and update underlaying sax…
Browse files Browse the repository at this point in the history
… parser (#51)
  • Loading branch information
MikaelPorttila authored Jul 6, 2023
1 parent 81b4c64 commit 2b00eb3
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 2,168 deletions.
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Credit:
export { SAXParser } from "https://deno.land/x/[email protected].10/src/sax.ts";
export { SAXParser } from "https://deno.land/x/[email protected].12/src/sax.ts";
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export {

export type { Options } from "./src/deserializer.ts";

export { deserializeFeed, parseFeed } from "./src/deserializer.ts";
export { parseFeed } from "./src/deserializer.ts";
3 changes: 2 additions & 1 deletion scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
],
"scripts": {
"start": "deno run dev.ts atom",
"test": "deno test"
"test": "deno test",
"benchmark": "deno run benchmark.ts"
}
}
72 changes: 3 additions & 69 deletions src/deserializer.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import { SAXParser } from "../deps.ts";
import type {
Atom,
DeserializationResult,
Feed,
JsonFeed,
RSS1,
RSS2,
} from "./types/mod.ts";
import type { Feed } from "./types/mod.ts";
import type { ResolverResult } from "./resolvers/types/resolver_result.ts";
import { SAXParser } from "../deps.ts";
import { FeedParseType, FeedType } from "./types/mod.ts";
import {
isAtomCDataField,
resolveAtomField,
resolveRss1Field,
resolveRss2Field,
} from "./resolvers/mod.ts";
import {
toFeed,
toJsonFeed,
toLegacyAtom,
toLegacyRss1,
toLegacyRss2,
} from "./mappers/mod.ts";
import { toFeed } from "./mappers/mod.ts";

/**
* Parse Atom or RSS into a common Feed type
Expand All @@ -40,59 +27,6 @@ export interface Options {
outputJsonFeed?: boolean;
}

/**
* @deprecated The method should not be used, please use the parseFeed method instead.
*/
export const deserializeFeed = (async (
input: string,
options?: Options,
) => {
const { data, feedType } = await parse(input);
let legacyFeed;
switch (feedType) {
case FeedType.Rss1:
legacyFeed = toLegacyRss1(data) as any;
break;
case FeedType.Rss2:
legacyFeed = toLegacyRss2(data) as any;
break;
case FeedType.Atom:
legacyFeed = toLegacyAtom(data) as any;
break;
default:
legacyFeed = data;
break;
}

const result: DeserializationResult<Atom | RSS1 | RSS2 | JsonFeed> & {
originalFeedType?: FeedType;
} = {
feed: options?.outputJsonFeed
? toJsonFeed(feedType, legacyFeed)
: legacyFeed,
feedType: options?.outputJsonFeed ? FeedType.JsonFeed : feedType,
originalFeedType: feedType,
};

return result;
}) as {
(input: string): Promise<DeserializationResult<Atom | RSS1 | RSS2>>;
(
input: string,
options: Options & { outputJsonFeed: false },
): Promise<DeserializationResult<Atom | RSS1 | RSS2>>;
(
input: string,
options: Options & { outputJsonFeed: true },
): Promise<
DeserializationResult<JsonFeed> & { originalFeedType: FeedType }
>;
(
input: string,
options?: Options,
): Promise<DeserializationResult<Atom | JsonFeed | RSS1 | RSS2>>;
};

const parse = (input: string) =>
new Promise<{ feedType: FeedType; data: any }>(
(resolve, reject) => {
Expand Down
Loading

0 comments on commit 2b00eb3

Please sign in to comment.