fumadocs-typescript
Version:
Typescript Integration for Fumadocs
141 lines (140 loc) • 4.12 kB
TypeScript
import { ExportedDeclarations, Node, Project, Symbol, Type, TypeChecker } from "ts-morph";
import { Nodes } from "hast";
import { BundledTheme, CodeOptionsThemes, CodeToHastOptionsCommon } from "shiki";
//#region src/lib/type-table.d.ts
interface BaseTypeTableProps {
/**
* The path to source TypeScript file.
*/
path?: string;
/**
* Exported type name to generate from.
*/
name?: string;
/**
* Set the type to generate from.
*
* When used with `name`, it generates the type with `name` as export name.
*
* ```ts
* export const myName = MyType;
* ```
*
* When `type` contains multiple lines, `export const` is not added.
* You need to export it manually, and specify the type name with `name`.
*
* ```tsx
* <AutoTypeTable
* path="./file.ts"
* type={`import { ReactNode } from "react"
* export const MyName = ReactNode`}
* name="MyName"
* />
* ```
*/
type?: string;
}
interface GenerateTypeTableOptions extends GenerateOptions {
/**
* base path to resolve `path` prop
*/
basePath?: string;
}
//#endregion
//#region src/cache/index.d.ts
interface Cache {
read: (hash: string) => unknown | undefined | Promise<unknown | undefined>;
write: (hash: string, value: unknown) => void | Promise<void>;
}
declare function generateHash(str: string): string;
//#endregion
//#region src/lib/get-simple-form.d.ts
interface TypeSimplifierContext {
type: Type;
checker: TypeChecker;
location?: Node;
}
interface TypeSimplifierOptions {
/**
* whether the simplified names should be preferred over the type names.
*
* Default: always prefer simplified ones.
*/
shouldSimplify?: (ctx: TypeSimplifierContext) => boolean;
override?: (ctx: TypeSimplifierContext) => string | undefined;
noUndefined?: boolean;
}
//#endregion
//#region src/lib/base.d.ts
interface GeneratedDoc {
/**
* unique ID generated from file name & export declaration.
*/
id: string;
name: string;
description?: string;
entries: DocEntry[];
}
interface DocEntry {
name: string;
description: string;
type: string;
typeHref?: string;
simplifiedType: string;
tags: RawTag[];
required: boolean;
deprecated: boolean;
}
interface RawTag {
name: string;
text: string;
}
interface EntryContext extends GenerateOptions {
program: Project;
type: Type;
declaration: ExportedDeclarations;
}
type Transformer = (this: EntryContext, entry: DocEntry, propertyType: Type, propertySymbol: Symbol) => void;
interface GenerateOptions {
/**
* Allow fields with `@internal` tag
*
* @defaultValue false
*/
allowInternal?: boolean;
/**
* Modify output property entry
*/
transform?: Transformer;
typeSimplifier?: TypeSimplifierOptions;
}
type Generator = ReturnType<typeof createGenerator>;
interface GeneratorOptions extends TypescriptConfig {
/**
* cache results, note that some options are not marked as dependency.
*
* @defaultValue false
*/
cache?: Cache | false;
project?: Project;
}
interface TypescriptConfig {
tsconfigPath?: string;
}
declare function createProject(options?: TypescriptConfig): Promise<Project>;
declare function createGenerator(options?: GeneratorOptions): {
generateDocumentation(file: {
path: string;
content?: string;
}, name: string | undefined, options?: GenerateOptions): Promise<GeneratedDoc[]>;
generateTypeTable(props: BaseTypeTableProps, options?: GenerateTypeTableOptions): Promise<GeneratedDoc[]>;
};
//#endregion
//#region src/markdown.d.ts
interface MarkdownRenderer {
renderTypeToHast: (type: string) => Nodes | Promise<Nodes>;
renderMarkdownToHast: (md: string) => Nodes | Promise<Nodes>;
}
type ShikiOptions = Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BundledTheme>;
//#endregion
export { GeneratedDoc as a, RawTag as c, createProject as d, Cache as f, GenerateTypeTableOptions as h, GenerateOptions as i, TypescriptConfig as l, BaseTypeTableProps as m, ShikiOptions as n, Generator as o, generateHash as p, DocEntry as r, GeneratorOptions as s, MarkdownRenderer as t, createGenerator as u };