UNPKG

3.59 kBTypeScriptView Raw
1export interface Documentation {
2 childContext?: Record<string, PropDescriptor>;
3 composes?: string[];
4 context?: Record<string, PropDescriptor>;
5 description?: string;
6 displayName?: string;
7 methods?: MethodDescriptor[];
8 props?: Record<string, PropDescriptor>;
9}
10export interface MethodParameter {
11 name: string;
12 description?: string;
13 optional: boolean;
14 type?: TypeDescriptor<FunctionSignatureType> | null;
15}
16export interface MethodReturn {
17 description?: string;
18 type: TypeDescriptor<FunctionSignatureType> | undefined;
19}
20export type MethodModifier = 'async' | 'generator' | 'get' | 'set' | 'static';
21export interface MethodDescriptor {
22 name: string;
23 description?: string | null;
24 docblock: string | null;
25 modifiers: MethodModifier[];
26 params: MethodParameter[];
27 returns: MethodReturn | null;
28}
29export interface PropTypeDescriptor {
30 name: 'any' | 'array' | 'arrayOf' | 'bool' | 'custom' | 'element' | 'elementType' | 'enum' | 'exact' | 'func' | 'instanceOf' | 'node' | 'number' | 'object' | 'objectOf' | 'shape' | 'string' | 'symbol' | 'union';
31 value?: unknown;
32 raw?: string;
33 computed?: boolean;
34 description?: string;
35 required?: boolean;
36}
37export interface DefaultValueDescriptor {
38 value: unknown;
39 computed: boolean;
40}
41export interface BaseType {
42 required?: boolean;
43 nullable?: boolean;
44 alias?: string;
45}
46export interface SimpleType extends BaseType {
47 name: string;
48 raw?: string;
49}
50export interface LiteralType extends BaseType {
51 name: 'literal';
52 value: string;
53}
54export interface ElementsType<T = FunctionSignatureType> extends BaseType {
55 name: string;
56 raw: string;
57 elements: Array<TypeDescriptor<T>>;
58}
59export interface FunctionArgumentType<T> {
60 name: string;
61 type?: TypeDescriptor<T>;
62 rest?: boolean;
63}
64export interface FunctionSignatureType extends BaseType {
65 name: 'signature';
66 type: 'function';
67 raw: string;
68 signature: {
69 arguments: Array<FunctionArgumentType<FunctionSignatureType>>;
70 return?: TypeDescriptor<FunctionSignatureType>;
71 };
72}
73export interface TSFunctionSignatureType extends FunctionSignatureType {
74 signature: {
75 arguments: Array<FunctionArgumentType<TSFunctionSignatureType>>;
76 return?: TypeDescriptor<TSFunctionSignatureType>;
77 this?: TypeDescriptor<TSFunctionSignatureType>;
78 };
79}
80export interface ObjectSignatureType<T = FunctionSignatureType> extends BaseType {
81 name: 'signature';
82 type: 'object';
83 raw: string;
84 signature: {
85 properties: Array<{
86 key: TypeDescriptor<T> | string;
87 value: TypeDescriptor<T>;
88 description?: string;
89 }>;
90 constructor?: TypeDescriptor<T>;
91 };
92}
93export type TypeDescriptor<T = FunctionSignatureType> = ElementsType<T> | LiteralType | ObjectSignatureType<T> | SimpleType | T;
94export interface PropDescriptor {
95 type?: PropTypeDescriptor;
96 flowType?: TypeDescriptor<FunctionSignatureType>;
97 tsType?: TypeDescriptor<TSFunctionSignatureType>;
98 required?: boolean;
99 defaultValue?: DefaultValueDescriptor;
100 description?: string;
101}
102export default class DocumentationBuilder {
103 #private;
104 constructor();
105 addComposes(moduleName: string): void;
106 set(key: string, value: unknown): void;
107 get<T>(key: string): T | null;
108 getPropDescriptor(propName: string): PropDescriptor;
109 getContextDescriptor(propName: string): PropDescriptor;
110 getChildContextDescriptor(propName: string): PropDescriptor;
111 build(): Documentation;
112}