From 5003d1b0fd2d46dfafd73c729394f7c87cbc9bf8 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Sat, 26 Aug 2023 18:27:53 +0330 Subject: [PATCH] refactor: remove redundant code --- .../dataTypes/PostSearchResult.dataType.ts | 48 ------------------- src/services/unbody/dataTypes/dataTypes.ts | 2 - src/services/unbody/dataTypes/types.ts | 1 - 3 files changed, 51 deletions(-) delete mode 100644 src/services/unbody/dataTypes/PostSearchResult.dataType.ts diff --git a/src/services/unbody/dataTypes/PostSearchResult.dataType.ts b/src/services/unbody/dataTypes/PostSearchResult.dataType.ts deleted file mode 100644 index 554f508..0000000 --- a/src/services/unbody/dataTypes/PostSearchResult.dataType.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { LPE } from '../../../types/lpe.types' -import { UnbodyHelpers } from '../unbody.helpers' -import { UnbodyResSearchGoogleDocData } from '../unbody.types' -import { UnbodyDataTypeConfig } from './types' - -export const PostSearchResultDataType: UnbodyDataTypeConfig< - UnbodyResSearchGoogleDocData, - LPE.Search.ResultItem, - UnbodyResSearchGoogleDocData, - undefined, - { - query: string - tags: string[] - shows: LPE.Podcast.Show[] - } -> = { - key: 'PostSearchResultDocument', - objectType: 'GoogleDoc', - classes: ['article', 'episode', 'search'], - - isMatch: (helpers, data, original, root) => - data.__typename === 'GoogleDoc' && !root, - - transform: async (helpers, data, original, root, context) => { - const { query = '', tags = [] } = context ?? {} - - const score = - data.__typename === 'GoogleDoc' - ? UnbodyHelpers.resolveScore(data._additional) - : query.length > 0 || tags.length > 0 - ? data._additional.certainty - : 0 - - const transformers = helpers.dataTypes.get({ objectType: 'GoogleDoc' }) - const transformed = await helpers.dataTypes.transform( - transformers, - data, - undefined, - { ...context }, - ) - - return { - score, - data: transformed, - type: transformed.type, - } - }, -} diff --git a/src/services/unbody/dataTypes/dataTypes.ts b/src/services/unbody/dataTypes/dataTypes.ts index 2eb542f..9f1aeee 100644 --- a/src/services/unbody/dataTypes/dataTypes.ts +++ b/src/services/unbody/dataTypes/dataTypes.ts @@ -6,7 +6,6 @@ import { ImageBlockDataType } from './ImageBlock.dataType' import { PodcastEpisodeDataType } from './PodcastEpisodeDocument.dataType' import { PodcastShowDataType } from './PodcastShowDocument.dataType' import { StaticPageDataType } from './StaticPageDocument.dataType' -import { PostSearchResultDataType } from './PostSearchResult.dataType' import { TextBlockDataType } from './TextBlock.dataType' import { UnbodyDataTypes } from './UnbodyDataTypes' @@ -20,5 +19,4 @@ export const unbodyDataTypes = new UnbodyDataTypes([ PodcastShowDataType, PodcastEpisodeDataType, StaticPageDataType, - PostSearchResultDataType, ]) diff --git a/src/services/unbody/dataTypes/types.ts b/src/services/unbody/dataTypes/types.ts index 8c8cc13..bb89f96 100644 --- a/src/services/unbody/dataTypes/types.ts +++ b/src/services/unbody/dataTypes/types.ts @@ -50,7 +50,6 @@ export const UnbodyDataTypeKeys = { PodcastShowDocument: 'PodcastShowDocument', PodcastEpisodeDocument: 'PodcastEpisodeDocument', StaticPageDocument: 'StaticPageDocument', - PostSearchResultDocument: 'PostSearchResultDocument', } as const export type UnbodyDataTypeKey =