MCPcopy Create free account
hub / github.com/TanStack/query / addReferenceDetails

Function addReferenceDetails

scripts/generate-docs.ts:712–914  ·  view source on GitHub ↗
(outputDir: string)

Source from the content-addressed store, hash-verified

710// properties come from the generated page of the type, following plain aliases and, for a union,
711// the interface all of its members extend. Types that override or omit properties get no table.
712async function addReferenceDetails(outputDir: string) {
713 const files = await readdir(resolve(outputDir, 'functions')).catch(
714 () => [] as Array<string>,
715 )
716 for (const file of files.filter((name) => name.endsWith('.md'))) {
717 const pagePath = `functions/${file.slice(0, -3)}`
718 const pageFile = resolve(outputDir, `${pagePath}.md`)
719 const page = await readFile(pageFile, 'utf8')
720 const [head, ...signatures] = page.split('\n## Call Signature\n')
721 const isOverloaded = signatures.length > 1
722 const lastSignature = signatures.at(-1) ?? page
723
724 // Property tables of the arguments whose type has a `## Properties` table, and of the result.
725 const tables: Array<{
726 id: string
727 title: string
728 table: string
729 parameter?: string
730 }> = []
731 const parametersHeading = lastSignature.match(/\n#{2,3} Parameters\n/)
732 const returnsHeading = lastSignature.match(/\n#{2,3} Returns\n/)
733 const parameters = parametersHeading
734 ? lastSignature.slice(
735 parametersHeading.index! + parametersHeading[0].length - 1,
736 returnsHeading?.index,
737 )
738 : ''
739 // Overloads describe the same arguments with different types, so a table missing from the
740 // last (most general) signature is taken from the latest earlier one that has it.
741 const signatureTypeLines = (signatures.length ? signatures : [page])
742 .map(signatureTypes)
743 .reverse()
744 for (const name of signatureTypeLines[0]!.parameters.keys()) {
745 const table = await findPropertiesTable(
746 outputDir,
747 signatureTypeLines.flatMap((types) => types.parameters.get(name) ?? []),
748 )
749 if (!table) {
750 continue
751 }
752 const argument = name.replace(/\\/g, '').replace(/\?$/, '')
753 const key = argument === '__namedParameters' ? 'props' : argument
754 tables.push({
755 id: `${key}-properties`,
756 title: `\`${key}\` properties`,
757 table,
758 parameter: name,
759 })
760 }
761 const resultTable = await findPropertiesTable(
762 outputDir,
763 signatureTypeLines.flatMap((types) => types.returns ?? []),
764 )
765 if (resultTable) {
766 tables.push({
767 id: 'result-properties',
768 title: 'Result properties',
769 table: resultTable,

Callers 1

Calls 10

resolveFunction · 0.85
readFileFunction · 0.85
findPropertiesTableFunction · 0.85
sectionFunction · 0.85
declaredSignatureTypesFunction · 0.85
declaredTypeLabelFunction · 0.85
typeNameInCodeFunction · 0.85
promoteFunction · 0.85
getMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected