algolia.ts — react Source File
Architecture documentation for algolia.ts, a typescript file in the react codebase. 2 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 9ff31f2c_c740_f564_0d2e_d722cd4acd1a["algolia.ts"] e06121eb_f5fa_fef4_9520_4641dc8cea88["algolia.ts"] 9ff31f2c_c740_f564_0d2e_d722cd4acd1a --> e06121eb_f5fa_fef4_9520_4641dc8cea88 75f8d0df_c01a_e850_0c4f_5a3f864edb7a["lite"] 9ff31f2c_c740_f564_0d2e_d722cd4acd1a --> 75f8d0df_c01a_e850_0c4f_5a3f864edb7a 18cd5de5_c350_7de1_3060_3c6253caf5c4["index.ts"] 18cd5de5_c350_7de1_3060_3c6253caf5c4 --> 9ff31f2c_c740_f564_0d2e_d722cd4acd1a style 9ff31f2c_c740_f564_0d2e_d722cd4acd1a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {DocSearchHit, InternalDocSearchHit} from '../types/algolia';
import {liteClient, type Hit, type SearchResponse} from 'algoliasearch/lite';
// https://github.com/reactjs/react.dev/blob/55986965fbf69c2584040039c9586a01bd54eba7/src/siteConfig.js#L15-L19
const ALGOLIA_CONFIG = {
appId: '1FCF9AYYAT',
apiKey: '1b7ad4e1c89e645e351e59d40544eda1',
indexName: 'beta-react',
};
export const ALGOLIA_CLIENT = liteClient(
ALGOLIA_CONFIG.appId,
ALGOLIA_CONFIG.apiKey,
);
export function printHierarchy(
hit: DocSearchHit | InternalDocSearchHit,
): string {
let val = `${hit.hierarchy.lvl0} > ${hit.hierarchy.lvl1}`;
if (hit.hierarchy.lvl2 != null) {
val = val.concat(` > ${hit.hierarchy.lvl2}`);
}
if (hit.hierarchy.lvl3 != null) {
val = val.concat(` > ${hit.hierarchy.lvl3}`);
}
if (hit.hierarchy.lvl4 != null) {
val = val.concat(` > ${hit.hierarchy.lvl4}`);
}
if (hit.hierarchy.lvl5 != null) {
val = val.concat(` > ${hit.hierarchy.lvl5}`);
}
if (hit.hierarchy.lvl6 != null) {
val = val.concat(` > ${hit.hierarchy.lvl6}`);
}
return val;
}
export async function queryAlgolia(
message: string | Array<string>,
): Promise<Array<string>> {
const {results} = await ALGOLIA_CLIENT.search<DocSearchHit>({
requests: [
{
query: Array.isArray(message) ? message.join('\n') : message,
indexName: ALGOLIA_CONFIG.indexName,
attributesToRetrieve: [
'hierarchy.lvl0',
'hierarchy.lvl1',
'hierarchy.lvl2',
'hierarchy.lvl3',
'hierarchy.lvl4',
'hierarchy.lvl5',
'hierarchy.lvl6',
'content',
'url',
],
attributesToSnippet: [
`hierarchy.lvl1:10`,
`hierarchy.lvl2:10`,
`hierarchy.lvl3:10`,
`hierarchy.lvl4:10`,
`hierarchy.lvl5:10`,
`hierarchy.lvl6:10`,
`content:10`,
],
snippetEllipsisText: '…',
hitsPerPage: 30,
attributesToHighlight: [
'hierarchy.lvl0',
'hierarchy.lvl1',
'hierarchy.lvl2',
'hierarchy.lvl3',
'hierarchy.lvl4',
'hierarchy.lvl5',
'hierarchy.lvl6',
'content',
],
},
],
});
const firstResult = results[0] as SearchResponse<DocSearchHit>;
const {hits} = firstResult;
const deduped = new Map();
for (const hit of hits) {
// drop hashes to dedupe properly
const u = new URL(hit.url);
if (deduped.has(u.pathname)) {
continue;
}
deduped.set(u.pathname, hit);
}
const pages: Array<string | null> = await Promise.all(
Array.from(deduped.values()).map(hit => {
return fetch(hit.url, {
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
},
}).then(res => {
if (res.ok === true) {
return res.text();
} else {
console.error(
`Could not fetch docs: ${res.status} ${res.statusText}`,
);
return null;
}
});
}),
);
return pages.filter(page => page !== null);
}
Domain
Subdomains
Functions
Dependencies
- algolia.ts
- lite
Imported By
Source
Frequently Asked Questions
What does algolia.ts do?
algolia.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in algolia.ts?
algolia.ts defines 2 function(s): printHierarchy, queryAlgolia.
What does algolia.ts depend on?
algolia.ts imports 2 module(s): algolia.ts, lite.
What files import algolia.ts?
algolia.ts is imported by 1 file(s): index.ts.
Where is algolia.ts in the architecture?
algolia.ts is located at compiler/packages/react-mcp-server/src/utils/algolia.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/react-mcp-server/src/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free