Documentation.d.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. export 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. }
  10. export interface MethodParameter {
  11. name: string;
  12. description?: string;
  13. optional: boolean;
  14. type?: TypeDescriptor<FunctionSignatureType> | null;
  15. }
  16. export interface MethodReturn {
  17. description?: string;
  18. type: TypeDescriptor<FunctionSignatureType> | undefined;
  19. }
  20. export type MethodModifier = 'async' | 'generator' | 'get' | 'set' | 'static';
  21. export interface MethodDescriptor {
  22. name: string;
  23. description?: string | null;
  24. docblock: string | null;
  25. modifiers: MethodModifier[];
  26. params: MethodParameter[];
  27. returns: MethodReturn | null;
  28. }
  29. export 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. }
  37. export interface DefaultValueDescriptor {
  38. value: unknown;
  39. computed: boolean;
  40. }
  41. export interface BaseType {
  42. required?: boolean;
  43. nullable?: boolean;
  44. alias?: string;
  45. }
  46. export interface SimpleType extends BaseType {
  47. name: string;
  48. raw?: string;
  49. }
  50. export interface LiteralType extends BaseType {
  51. name: 'literal';
  52. value: string;
  53. }
  54. export interface ElementsType<T = FunctionSignatureType> extends BaseType {
  55. name: string;
  56. raw: string;
  57. elements: Array<TypeDescriptor<T>>;
  58. }
  59. export interface FunctionArgumentType<T> {
  60. name: string;
  61. type?: TypeDescriptor<T>;
  62. rest?: boolean;
  63. }
  64. export 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. }
  73. export interface TSFunctionSignatureType extends FunctionSignatureType {
  74. signature: {
  75. arguments: Array<FunctionArgumentType<TSFunctionSignatureType>>;
  76. return?: TypeDescriptor<TSFunctionSignatureType>;
  77. this?: TypeDescriptor<TSFunctionSignatureType>;
  78. };
  79. }
  80. export 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. }
  93. export type TypeDescriptor<T = FunctionSignatureType> = ElementsType<T> | LiteralType | ObjectSignatureType<T> | SimpleType | T;
  94. export interface PropDescriptor {
  95. type?: PropTypeDescriptor;
  96. flowType?: TypeDescriptor<FunctionSignatureType>;
  97. tsType?: TypeDescriptor<TSFunctionSignatureType>;
  98. required?: boolean;
  99. defaultValue?: DefaultValueDescriptor;
  100. description?: string;
  101. }
  102. export 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. }