-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert delete generateAlgoliaRecords
- Loading branch information
1 parent
1620205
commit e659df9
Showing
15 changed files
with
809 additions
and
382,179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
236,416 changes: 0 additions & 236,416 deletions
236,416
packages/ui/fern-docs-search-server/src/algolia/__test__/__snapshots__/cohere.test.ts.snap
This file was deleted.
Oops, something went wrong.
145,202 changes: 0 additions & 145,202 deletions
145,202
packages/ui/fern-docs-search-server/src/algolia/__test__/__snapshots__/hume.test.ts.snap
This file was deleted.
Oops, something went wrong.
371 changes: 186 additions & 185 deletions
371
packages/ui/fern-docs-search-server/src/algolia/records/archive/generateAlgoliaRecords.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,185 +1,186 @@ | ||
// // import { Algolia, ApiDefinition, FernNavigation } from "@fern-api/fdr-sdk"; | ||
// import * as ApiDefinition from "@fern-api/fdr-sdk/api-definition"; | ||
// import * as FernNavigation from "@fern-api/fdr-sdk/navigation"; | ||
// import { isNonNullish } from "@fern-api/ui-core-utils"; | ||
// import { AlgoliaRecord } from "../types"; | ||
// import { generateMarkdownRecords } from "./generate-markdown-records"; | ||
// import { generateEndpointFieldRecords, generateEndpointBaseRecord } from "./generateEndpointBaseRecords2"; | ||
// import { generateWebSocketFieldRecords, generateWebSocketRecord } from "./generateWebSocketRecords"; | ||
// import { generateWebhookFieldRecords, generateWebhookRecord } from "./generateWebhookRecords"; | ||
|
||
// interface GenerateAlgoliaRecordsOptions { | ||
// // indexSegmentId: string; | ||
// nodes: FernNavigation.RootNode; | ||
// pages: Record<FernNavigation.PageId, string>; | ||
// apis: Record<ApiDefinition.ApiDefinitionId, ApiDefinition.ApiDefinition>; | ||
// isFieldRecordsEnabled: boolean; | ||
// } | ||
|
||
// export function generateAlgoliaRecords({ | ||
// // indexSegmentId, | ||
// nodes, | ||
// pages, | ||
// apis, | ||
// isFieldRecordsEnabled, | ||
// }: GenerateAlgoliaRecordsOptions): AlgoliaRecord[] { | ||
// const collector = FernNavigation.NodeCollector.collect(nodes); | ||
|
||
// const indexablePageNodes = collector.indexablePageSlugs | ||
// .map((slug) => collector.slugMap.get(slug)) | ||
// .filter(isNonNullish); | ||
|
||
// if (collector.indexablePageSlugs.length !== indexablePageNodes.length) { | ||
// // eslint-disable-next-line no-console | ||
// console.warn( | ||
// `Some indexable page nodes were not found: ${collector.indexablePageSlugs.filter( | ||
// (slug) => !collector.slugMap.has(slug), | ||
// )}`, | ||
// ); | ||
// } | ||
|
||
// const markdownNodes = indexablePageNodes.filter(FernNavigation.hasMarkdown); | ||
// const apiLeafNodes = indexablePageNodes.filter(FernNavigation.isApiLeaf); | ||
|
||
// const records: AlgoliaRecord[] = []; | ||
|
||
// /** | ||
// * Markdown nodes contain pages, sections with overview content, and changelog nodes | ||
// * TODO: we probably want to show changelog nodes as a separate entity. | ||
// */ | ||
// markdownNodes.forEach((node) => { | ||
// const pageId = FernNavigation.getPageId(node); | ||
// if (!pageId) { | ||
// // eslint-disable-next-line no-console | ||
// console.error(`Page node ${node.slug} has no page id`); | ||
// return; | ||
// } | ||
// const markdown = pages[pageId]; | ||
// if (!markdown) { | ||
// // eslint-disable-next-line no-console | ||
// console.error(`Page node ${node.slug} has page id ${pageId} but no markdown`); | ||
// return; | ||
// } | ||
|
||
// const parents = collector.getParents(node.id) ?? []; | ||
// const breadcrumb = FernNavigation.utils.createBreadcrumb(parents); | ||
// const versionNode = parents.find((n): n is FernNavigation.VersionNode => n.type === "version"); | ||
// const version: Algolia.AlgoliaRecordVersionV3 | undefined = versionNode | ||
// ? { id: versionNode.versionId, slug: FernNavigation.V1.Slug(versionNode.pointsTo ?? versionNode.slug) } | ||
// : undefined; | ||
|
||
// records.push( | ||
// ...generateMarkdownRecords({ | ||
// indexSegmentId, | ||
// breadcrumb, | ||
// node, | ||
// version, | ||
// markdown, | ||
// }), | ||
// ); | ||
// }); | ||
|
||
// apiLeafNodes.forEach((node) => { | ||
// const apiDefinition = apis[node.apiDefinitionId]; | ||
|
||
// if (!apiDefinition) { | ||
// // eslint-disable-next-line no-console | ||
// console.error( | ||
// `API leaf node ${node.slug} has api definition id ${node.apiDefinitionId} but no api definition`, | ||
// ); | ||
// return; | ||
// } | ||
|
||
// const parents = collector.getParents(node.id) ?? []; | ||
// const breadcrumb = FernNavigation.utils.createBreadcrumb(parents); | ||
// const versionNode = parents.find((n): n is FernNavigation.VersionNode => n.type === "version"); | ||
// const version: Algolia.AlgoliaRecordVersionV3 | undefined = versionNode | ||
// ? { id: versionNode.versionId, slug: FernNavigation.V1.Slug(versionNode.pointsTo ?? versionNode.slug) } | ||
// : undefined; | ||
|
||
// if (node.type === "endpoint") { | ||
// const endpoint = apiDefinition.endpoints[node.endpointId]; | ||
// if (!endpoint) { | ||
// // eslint-disable-next-line no-console | ||
// console.error(`API leaf node ${node.slug} has endpoint id ${node.endpointId} but no endpoint`); | ||
// return; | ||
// } | ||
|
||
// const endpointRecord = generateEndpointBaseRecord({ | ||
// indexSegmentId, | ||
// node, | ||
// breadcrumb, | ||
// endpoint, | ||
// version, | ||
// }); | ||
|
||
// records.push(endpointRecord); | ||
|
||
// if (isFieldRecordsEnabled) { | ||
// records.push( | ||
// ...generateEndpointFieldRecords({ | ||
// endpointRecord, | ||
// endpoint, | ||
// types: apiDefinition.types, | ||
// }), | ||
// ); | ||
// } | ||
// } else if (node.type === "webSocket") { | ||
// const channel = apiDefinition.websockets[node.webSocketId]; | ||
// if (!channel) { | ||
// // eslint-disable-next-line no-console | ||
// console.error(`API leaf node ${node.slug} has web socket id ${node.webSocketId} but no web socket`); | ||
// return; | ||
// } | ||
|
||
// const channelRecord = generateWebSocketRecord({ | ||
// indexSegmentId, | ||
// node, | ||
// breadcrumb, | ||
// channel, | ||
// version, | ||
// }); | ||
|
||
// records.push(channelRecord); | ||
|
||
// if (isFieldRecordsEnabled) { | ||
// records.push( | ||
// ...generateWebSocketFieldRecords({ | ||
// channelRecord, | ||
// channel, | ||
// types: apiDefinition.types, | ||
// }), | ||
// ); | ||
// } | ||
// } else if (node.type === "webhook") { | ||
// const webhook = apiDefinition.webhooks[node.webhookId]; | ||
// if (!webhook) { | ||
// // eslint-disable-next-line no-console | ||
// console.error(`API leaf node ${node.slug} has web hook id ${node.webhookId} but no web hook`); | ||
// return; | ||
// } | ||
|
||
// const webhookRecord = generateWebhookRecord({ | ||
// indexSegmentId, | ||
// node, | ||
// breadcrumb, | ||
// webhook, | ||
// version, | ||
// }); | ||
|
||
// records.push(webhookRecord); | ||
|
||
// if (isFieldRecordsEnabled) { | ||
// records.push( | ||
// ...generateWebhookFieldRecords({ | ||
// webhookRecord, | ||
// webhook, | ||
// types: apiDefinition.types, | ||
// }), | ||
// ); | ||
// } | ||
// } | ||
// }); | ||
|
||
// return records; | ||
// } | ||
import { Algolia, ApiDefinition, FernNavigation } from "@fern-api/fdr-sdk"; | ||
import { isNonNullish } from "@fern-api/ui-core-utils"; | ||
import { generateEndpointFieldRecords, generateEndpointRecord } from "./generateEndpointRecords"; | ||
import { generateMarkdownRecords } from "./generateMarkdownRecords"; | ||
import { generateWebSocketFieldRecords, generateWebSocketRecord } from "./generateWebSocketRecords"; | ||
import { generateWebhookFieldRecords, generateWebhookRecord } from "./generateWebhookRecords"; | ||
import { convertEndpointV4ToV3 } from "./v1-record-converter/convertRecords"; | ||
|
||
interface GenerateAlgoliaRecordsOptions { | ||
indexSegmentId: Algolia.IndexSegmentId; | ||
nodes: FernNavigation.RootNode; | ||
pages: Record<FernNavigation.PageId, string>; | ||
apis: Record<ApiDefinition.ApiDefinitionId, ApiDefinition.ApiDefinition>; | ||
isFieldRecordsEnabled: boolean; | ||
} | ||
|
||
export function generateAlgoliaRecords({ | ||
indexSegmentId, | ||
nodes, | ||
pages, | ||
apis, | ||
isFieldRecordsEnabled, | ||
}: GenerateAlgoliaRecordsOptions): Algolia.AlgoliaRecord[] { | ||
const collector = FernNavigation.NodeCollector.collect(nodes); | ||
|
||
const indexablePageNodes = collector.indexablePageSlugs | ||
.map((slug) => collector.slugMap.get(slug)) | ||
.filter(isNonNullish); | ||
|
||
if (collector.indexablePageSlugs.length !== indexablePageNodes.length) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`Some indexable page nodes were not found: ${collector.indexablePageSlugs.filter( | ||
(slug) => !collector.slugMap.has(slug), | ||
)}`, | ||
); | ||
} | ||
|
||
const markdownNodes = indexablePageNodes.filter(FernNavigation.hasMarkdown); | ||
const apiLeafNodes = indexablePageNodes.filter(FernNavigation.isApiLeaf); | ||
|
||
const records: Algolia.AlgoliaRecord[] = []; | ||
|
||
/** | ||
* Markdown nodes contain pages, sections with overview content, and changelog nodes | ||
* TODO: we probably want to show changelog nodes as a separate entity. | ||
*/ | ||
markdownNodes.forEach((node) => { | ||
const pageId = FernNavigation.getPageId(node); | ||
if (!pageId) { | ||
// eslint-disable-next-line no-console | ||
console.error(`Page node ${node.slug} has no page id`); | ||
return; | ||
} | ||
const markdown = pages[pageId]; | ||
if (!markdown) { | ||
// eslint-disable-next-line no-console | ||
console.error(`Page node ${node.slug} has page id ${pageId} but no markdown`); | ||
return; | ||
} | ||
|
||
const parents = collector.getParents(node.id) ?? []; | ||
const breadcrumb = FernNavigation.utils.createBreadcrumb(parents); | ||
const versionNode = parents.find((n): n is FernNavigation.VersionNode => n.type === "version"); | ||
const version: Algolia.AlgoliaRecordVersionV3 | undefined = versionNode | ||
? { id: versionNode.versionId, slug: FernNavigation.V1.Slug(versionNode.pointsTo ?? versionNode.slug) } | ||
: undefined; | ||
|
||
records.push( | ||
...generateMarkdownRecords({ | ||
indexSegmentId, | ||
breadcrumb, | ||
node, | ||
version, | ||
markdown, | ||
}), | ||
); | ||
}); | ||
|
||
apiLeafNodes.forEach((node) => { | ||
const apiDefinition = apis[node.apiDefinitionId]; | ||
|
||
if (!apiDefinition) { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
`API leaf node ${node.slug} has api definition id ${node.apiDefinitionId} but no api definition`, | ||
); | ||
return; | ||
} | ||
|
||
const parents = collector.getParents(node.id) ?? []; | ||
const breadcrumb = FernNavigation.utils.createBreadcrumb(parents); | ||
const versionNode = parents.find((n): n is FernNavigation.VersionNode => n.type === "version"); | ||
const version: Algolia.AlgoliaRecordVersionV3 | undefined = versionNode | ||
? { id: versionNode.versionId, slug: FernNavigation.V1.Slug(versionNode.pointsTo ?? versionNode.slug) } | ||
: undefined; | ||
|
||
if (node.type === "endpoint") { | ||
const endpoint = apiDefinition.endpoints[node.endpointId]; | ||
if (!endpoint) { | ||
// eslint-disable-next-line no-console | ||
console.error(`API leaf node ${node.slug} has endpoint id ${node.endpointId} but no endpoint`); | ||
return; | ||
} | ||
|
||
const endpointRecord = generateEndpointRecord({ | ||
indexSegmentId, | ||
node, | ||
breadcrumb, | ||
endpoint, | ||
version, | ||
}); | ||
|
||
// TODO: remove this once we've migrated to v4 | ||
const endpointRecordV3 = convertEndpointV4ToV3(endpointRecord, endpoint, apiDefinition.types); | ||
|
||
records.push(endpointRecordV3); | ||
|
||
if (isFieldRecordsEnabled) { | ||
records.push( | ||
...generateEndpointFieldRecords({ | ||
endpointRecord, | ||
endpoint, | ||
types: apiDefinition.types, | ||
}), | ||
); | ||
} | ||
} else if (node.type === "webSocket") { | ||
const channel = apiDefinition.websockets[node.webSocketId]; | ||
if (!channel) { | ||
// eslint-disable-next-line no-console | ||
console.error(`API leaf node ${node.slug} has web socket id ${node.webSocketId} but no web socket`); | ||
return; | ||
} | ||
|
||
const channelRecord = generateWebSocketRecord({ | ||
indexSegmentId, | ||
node, | ||
breadcrumb, | ||
channel, | ||
version, | ||
}); | ||
|
||
records.push(channelRecord); | ||
|
||
if (isFieldRecordsEnabled) { | ||
records.push( | ||
...generateWebSocketFieldRecords({ | ||
channelRecord, | ||
channel, | ||
types: apiDefinition.types, | ||
}), | ||
); | ||
} | ||
} else if (node.type === "webhook") { | ||
const webhook = apiDefinition.webhooks[node.webhookId]; | ||
if (!webhook) { | ||
// eslint-disable-next-line no-console | ||
console.error(`API leaf node ${node.slug} has web hook id ${node.webhookId} but no web hook`); | ||
return; | ||
} | ||
|
||
const webhookRecord = generateWebhookRecord({ | ||
indexSegmentId, | ||
node, | ||
breadcrumb, | ||
webhook, | ||
version, | ||
}); | ||
|
||
records.push(webhookRecord); | ||
|
||
if (isFieldRecordsEnabled) { | ||
records.push( | ||
...generateWebhookFieldRecords({ | ||
webhookRecord, | ||
webhook, | ||
types: apiDefinition.types, | ||
}), | ||
); | ||
} | ||
} | ||
}); | ||
|
||
return records; | ||
} |
Oops, something went wrong.