mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: use eslint-config-neon for packages. (#8579)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable n/shebang */
|
||||
import process from 'node:process';
|
||||
import { createCommand } from 'commander';
|
||||
import { build } from './index.js';
|
||||
import packageFile from '../package.json';
|
||||
import { build } from './index.js';
|
||||
|
||||
export interface CLIOptions {
|
||||
input: string[];
|
||||
custom: string;
|
||||
root: string;
|
||||
input: string[];
|
||||
output: string;
|
||||
root: string;
|
||||
typescript: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { dirname, join, relative } from 'node:path';
|
||||
import type { DeclarationReflection } from 'typedoc';
|
||||
import packageFile from '../package.json';
|
||||
import type { ChildTypes, Class, Config, CustomDocs, RootTypes } from './interfaces/index.js';
|
||||
import { DocumentedClass } from './types/class.js';
|
||||
import { DocumentedConstructor } from './types/constructor.js';
|
||||
@@ -9,7 +10,6 @@ import { DocumentedInterface } from './types/interface.js';
|
||||
import { DocumentedMember } from './types/member.js';
|
||||
import { DocumentedMethod } from './types/method.js';
|
||||
import { DocumentedTypeDef } from './types/typedef.js';
|
||||
import packageFile from '../package.json';
|
||||
|
||||
export class Documentation {
|
||||
public readonly classes = new Map<string, DocumentedClass>();
|
||||
@@ -23,7 +23,7 @@ export class Documentation {
|
||||
public readonly externals = new Map<string, DocumentedExternal>();
|
||||
|
||||
public constructor(
|
||||
data: RootTypes[] | DeclarationReflection[],
|
||||
data: DeclarationReflection[] | RootTypes[],
|
||||
private readonly config: Config,
|
||||
private readonly custom?: Record<string, CustomDocs>,
|
||||
) {
|
||||
@@ -37,6 +37,7 @@ export class Documentation {
|
||||
if (item.children) {
|
||||
this.parse(item.children, item);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -52,6 +53,7 @@ export class Documentation {
|
||||
if (item.children) {
|
||||
this.parse(item.children, item);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -60,37 +62,43 @@ export class Documentation {
|
||||
}
|
||||
} else {
|
||||
let items = data as RootTypes[];
|
||||
items = items.filter((i) => !i.ignore);
|
||||
items = items.filter((item) => !item.ignore);
|
||||
|
||||
for (const item of items) {
|
||||
switch (item.kind) {
|
||||
case 'class': {
|
||||
this.classes.set(item.name, new DocumentedClass(item, config));
|
||||
items = items.filter((i) => i.longname !== item.longname || i.kind !== item.kind);
|
||||
items = items.filter((otherItem) => otherItem.longname !== item.longname || otherItem.kind !== item.kind);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'function': {
|
||||
if (item.scope === 'global' || !item.memberof) {
|
||||
this.functions.set(item.name, new DocumentedMethod(item, config));
|
||||
items = items.filter((i) => i.longname !== item.longname);
|
||||
items = items.filter((otherItem) => otherItem.longname !== item.longname);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'interface': {
|
||||
this.interfaces.set(item.name, new DocumentedInterface(item as unknown as Class, config));
|
||||
items = items.filter((i) => i.longname !== item.longname);
|
||||
items = items.filter((otherItem) => otherItem.longname !== item.longname);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'typedef': {
|
||||
this.typedefs.set(item.name, new DocumentedTypeDef(item, config));
|
||||
items = items.filter((i) => i.longname !== item.longname);
|
||||
items = items.filter((otherItem) => otherItem.longname !== item.longname);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'external': {
|
||||
this.externals.set(item.name, new DocumentedExternal(item, config));
|
||||
items = items.filter((i) => i.longname !== item.longname);
|
||||
items = items.filter((otherItem) => otherItem.longname !== item.longname);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -100,39 +108,43 @@ export class Documentation {
|
||||
}
|
||||
}
|
||||
|
||||
public parse(items: ChildTypes[] | DeclarationReflection[], p?: DeclarationReflection) {
|
||||
public parse(items: ChildTypes[] | DeclarationReflection[], prop?: DeclarationReflection) {
|
||||
if (this.config.typescript) {
|
||||
const it = items as DeclarationReflection[];
|
||||
|
||||
for (const member of it) {
|
||||
let item: DocumentedMethod | DocumentedConstructor | DocumentedMember | DocumentedEvent | null = null;
|
||||
let item: DocumentedConstructor | DocumentedEvent | DocumentedMember | DocumentedMethod | null = null;
|
||||
|
||||
switch (member.kindString) {
|
||||
case 'Constructor': {
|
||||
item = new DocumentedConstructor(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'Method': {
|
||||
const event = p?.groups?.find((group) => group.title === 'Events');
|
||||
const event = prop?.groups?.find((group) => group.title === 'Events');
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
if ((event?.children as unknown as number[])?.includes(member.id)) {
|
||||
item = new DocumentedEvent(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
item = new DocumentedMethod(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'Property': {
|
||||
item = new DocumentedMember(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
console.warn(`- Unknown documentation kind "${member.kindString}" - \n${JSON.stringify(member)}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
const parent = this.classes.get(p!.name) ?? this.interfaces.get(p!.name);
|
||||
const parent = this.classes.get(prop!.name) ?? this.interfaces.get(prop!.name);
|
||||
if (parent) {
|
||||
if (item) {
|
||||
parent.add(item);
|
||||
@@ -141,6 +153,7 @@ export class Documentation {
|
||||
`- Documentation item could not be constructed for "${member.name}" - \n${JSON.stringify(member)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -155,9 +168,10 @@ export class Documentation {
|
||||
path: dirname(member.sources?.[0]?.fileName ?? ''),
|
||||
};
|
||||
|
||||
if (p!.name) {
|
||||
info.push(`member of "${p!.name}"`);
|
||||
if (prop!.name) {
|
||||
info.push(`member of "${prop!.name}"`);
|
||||
}
|
||||
|
||||
if (meta) {
|
||||
info.push(
|
||||
`${relative(this.config.root, join(meta.path, meta.file ?? ''))}${meta.line ? `:${meta.line}` : ''}`,
|
||||
@@ -173,27 +187,31 @@ export class Documentation {
|
||||
const it = items as ChildTypes[];
|
||||
|
||||
for (const member of it) {
|
||||
let item: DocumentedMethod | DocumentedConstructor | DocumentedMember | DocumentedEvent | null = null;
|
||||
let item: DocumentedConstructor | DocumentedEvent | DocumentedMember | DocumentedMethod | null = null;
|
||||
|
||||
switch (member.kind) {
|
||||
case 'constructor': {
|
||||
item = new DocumentedConstructor(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'function': {
|
||||
item = new DocumentedMethod(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'member': {
|
||||
item = new DocumentedMember(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'event': {
|
||||
item = new DocumentedEvent(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: This is a valid case
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
console.warn(`- Unknown documentation kind "${member.kind}" - \n${JSON.stringify(member)}\n`);
|
||||
}
|
||||
@@ -208,12 +226,13 @@ export class Documentation {
|
||||
`- Documentation item could not be constructed for "${member.name}" - \n${JSON.stringify(member)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const info = [];
|
||||
const name = (member.name || item?.data.name) ?? 'UNKNOWN';
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Typescript can't infer this
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition
|
||||
const memberof = member.memberof ?? item?.data?.memberof;
|
||||
const meta =
|
||||
@@ -224,6 +243,7 @@ export class Documentation {
|
||||
if (memberof) {
|
||||
info.push(`member of "${memberof as string}"`);
|
||||
}
|
||||
|
||||
if (meta) {
|
||||
info.push(`${relative(this.config.root, join(meta.path, meta.file))}${meta.line ? `:${meta.line}` : ''}`);
|
||||
}
|
||||
@@ -243,16 +263,14 @@ export class Documentation {
|
||||
format: Documentation.FORMAT_VERSION,
|
||||
date: Date.now(),
|
||||
},
|
||||
classes: [...this.classes.values()].map((c) => c.serialize()),
|
||||
functions: [...this.functions.values()].map((f) => f.serialize()),
|
||||
interfaces: [...this.interfaces.values()].map((i) => i.serialize()),
|
||||
typedefs: [...this.typedefs.values()].map((t) => t.serialize()),
|
||||
externals: [...this.externals.values()].map((e) => e.serialize()),
|
||||
classes: [...this.classes.values()].map((_class) => _class.serialize()),
|
||||
functions: [...this.functions.values()].map((_function) => _function.serialize()),
|
||||
interfaces: [...this.interfaces.values()].map((_interface) => _interface.serialize()),
|
||||
typedefs: [...this.typedefs.values()].map((_typedef) => _typedef.serialize()),
|
||||
externals: [...this.externals.values()].map((_external) => _external.serialize()),
|
||||
custom: this.custom,
|
||||
};
|
||||
}
|
||||
|
||||
public static get FORMAT_VERSION() {
|
||||
return 30;
|
||||
}
|
||||
public static readonly FORMAT_VERSION = 30;
|
||||
}
|
||||
|
||||
@@ -3,22 +3,22 @@ import { dirname, join, extname, basename, relative } from 'node:path';
|
||||
import jsdoc2md from 'jsdoc-to-markdown';
|
||||
import { type DeclarationReflection, Application, TSConfigReader } from 'typedoc';
|
||||
import type { CLIOptions } from './cli';
|
||||
import { Documentation } from './documentation';
|
||||
import { Documentation } from './documentation.js';
|
||||
import type { RootTypes, ChildTypes, CustomDocs } from './interfaces';
|
||||
|
||||
interface CustomFiles {
|
||||
id?: string;
|
||||
name: string;
|
||||
path?: string;
|
||||
files: {
|
||||
id?: string;
|
||||
name: string;
|
||||
path: string;
|
||||
}[];
|
||||
id?: string;
|
||||
name: string;
|
||||
path?: string;
|
||||
}
|
||||
|
||||
export function build({ input, custom: customDocs, root, output, typescript }: CLIOptions) {
|
||||
let data: (RootTypes & ChildTypes)[] | DeclarationReflection[] = [];
|
||||
let data: (ChildTypes & RootTypes)[] | DeclarationReflection[] = [];
|
||||
if (typescript) {
|
||||
console.log('Parsing Typescript in source files...');
|
||||
const app = new Application();
|
||||
@@ -26,13 +26,14 @@ export function build({ input, custom: customDocs, root, output, typescript }: C
|
||||
app.bootstrap({ entryPoints: input });
|
||||
const project = app.convert();
|
||||
if (project) {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Types are lost with this method
|
||||
data = app.serializer.toObject(project).children!;
|
||||
console.log(`${data.length} items parsed.`);
|
||||
}
|
||||
} else {
|
||||
console.log('Parsing JSDocs in source files...');
|
||||
data = jsdoc2md.getTemplateDataSync({ files: input }) as (RootTypes & ChildTypes)[];
|
||||
// eslint-disable-next-line n/no-sync
|
||||
data = jsdoc2md.getTemplateDataSync({ files: input }) as (ChildTypes & RootTypes)[];
|
||||
console.log(`${data.length} JSDoc items parsed.`);
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ export function build({ input, custom: customDocs, root, output, typescript }: C
|
||||
if (customDocs) {
|
||||
console.log('Loading custom docs files...');
|
||||
const customDir = dirname(customDocs);
|
||||
const file = readFileSync(customDocs, 'utf-8');
|
||||
const file = readFileSync(customDocs, 'utf8');
|
||||
const data = JSON.parse(file) as CustomFiles[];
|
||||
|
||||
for (const category of data) {
|
||||
@@ -51,23 +52,23 @@ export function build({ input, custom: customDocs, root, output, typescript }: C
|
||||
files: {},
|
||||
};
|
||||
|
||||
for (const f of category.files) {
|
||||
const fileRootPath = join(dir, f.path);
|
||||
const extension = extname(f.path);
|
||||
const fileId = f.id ?? basename(f.path, extension);
|
||||
const fileData = readFileSync(fileRootPath, 'utf-8');
|
||||
for (const file of category.files) {
|
||||
const fileRootPath = join(dir, file.path);
|
||||
const extension = extname(file.path);
|
||||
const fileId = file.id ?? basename(file.path, extension);
|
||||
const fileData = readFileSync(fileRootPath, 'utf8');
|
||||
custom[categoryId]!.files[fileId] = {
|
||||
name: f.name,
|
||||
name: file.name,
|
||||
type: extension.toLowerCase().replace(/^\./, ''),
|
||||
content: fileData,
|
||||
path: relative(root, fileRootPath).replace(/\\/g, '/'),
|
||||
path: relative(root, fileRootPath).replaceAll('\\', '/'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const fileCount = Object.keys(custom)
|
||||
.map((k) => Object.keys(custom[k]!))
|
||||
.reduce((prev, c) => prev + c.length, 0);
|
||||
.map((key) => Object.keys(custom[key]!))
|
||||
.reduce((prev, content) => prev + content.length, 0);
|
||||
const categoryCount = Object.keys(custom).length;
|
||||
console.log(
|
||||
`${fileCount} custom docs file${fileCount === 1 ? '' : 's'} in ` +
|
||||
@@ -82,5 +83,6 @@ export function build({ input, custom: customDocs, root, output, typescript }: C
|
||||
console.log(`Writing to ${output}...`);
|
||||
writeFileSync(output, JSON.stringify(docs.serialize()));
|
||||
}
|
||||
|
||||
console.log('Done!');
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
export type Access = 'public' | 'private' | 'protected';
|
||||
export type Access = 'private' | 'protected' | 'public';
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import type { Constructor, Event, Member, Method } from './index.js';
|
||||
|
||||
export type ChildTypes = Constructor | Member | Method | Event;
|
||||
export type ChildTypes = Constructor | Event | Member | Method;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import type { Access, Item, Meta, Scope } from './index.js';
|
||||
|
||||
export interface Class extends Item {
|
||||
kind: 'class';
|
||||
scope: Scope;
|
||||
implements?: string[];
|
||||
augments?: string[];
|
||||
see?: string[];
|
||||
access?: Access;
|
||||
virtual?: boolean;
|
||||
augments?: string[];
|
||||
deprecated?: boolean | string;
|
||||
implements?: string[];
|
||||
kind: 'class';
|
||||
meta: Meta;
|
||||
scope: Scope;
|
||||
see?: string[];
|
||||
virtual?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export interface Config {
|
||||
input: string[];
|
||||
custom: string;
|
||||
root: string;
|
||||
input: string[];
|
||||
output: string;
|
||||
root: string;
|
||||
typescript: boolean;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Access, Item, Param } from './index.js';
|
||||
|
||||
export interface Constructor extends Item {
|
||||
access?: Access;
|
||||
kind: 'constructor';
|
||||
memberof: string;
|
||||
see?: string[];
|
||||
access?: Access;
|
||||
params?: Param[];
|
||||
see?: string[];
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
export interface CustomDocs {
|
||||
name?: string;
|
||||
files: Record<
|
||||
string,
|
||||
{
|
||||
name?: string;
|
||||
type?: string;
|
||||
content?: string;
|
||||
name?: string;
|
||||
path?: string;
|
||||
type?: string;
|
||||
}
|
||||
>;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { Item, Meta, Param, Scope } from './index.js';
|
||||
|
||||
export interface Event extends Item {
|
||||
kind: 'event';
|
||||
scope: Scope;
|
||||
memberof: string;
|
||||
see?: string[];
|
||||
deprecated?: boolean | string;
|
||||
params?: Param[];
|
||||
kind: 'event';
|
||||
memberof: string;
|
||||
meta: Meta;
|
||||
params?: Param[];
|
||||
scope: Scope;
|
||||
see?: string[];
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Type } from './index.js';
|
||||
|
||||
export interface Exception {
|
||||
type: Type;
|
||||
nullable?: boolean;
|
||||
description?: string;
|
||||
nullable?: boolean;
|
||||
type: Type;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ import type { Item, Meta } from './index.js';
|
||||
|
||||
export interface External extends Item {
|
||||
kind: 'external';
|
||||
see?: string[];
|
||||
meta: Meta;
|
||||
see?: string[];
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Class } from './index.js';
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Inheritance type error
|
||||
export interface Interface extends Class {
|
||||
kind: 'interface';
|
||||
classdesc: string;
|
||||
kind: 'interface';
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export interface Item {
|
||||
description: string;
|
||||
id: string;
|
||||
ignore?: boolean;
|
||||
kind: string;
|
||||
longname: string;
|
||||
name: string;
|
||||
kind: string;
|
||||
description: string;
|
||||
order: number;
|
||||
ignore?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import type { Access, Item, Meta, Param, Scope, Type } from './index.js';
|
||||
|
||||
export interface Member extends Item {
|
||||
kind: 'member';
|
||||
see?: string[];
|
||||
scope: Scope;
|
||||
memberof: string;
|
||||
type: Type;
|
||||
access?: Access;
|
||||
readonly?: boolean;
|
||||
nullable?: boolean;
|
||||
virtual?: boolean;
|
||||
deprecated?: boolean | string;
|
||||
default?: string;
|
||||
properties?: Param[];
|
||||
deprecated?: boolean | string;
|
||||
kind: 'member';
|
||||
memberof: string;
|
||||
meta: Meta;
|
||||
nullable?: boolean;
|
||||
properties?: Param[];
|
||||
readonly?: boolean;
|
||||
scope: Scope;
|
||||
see?: string[];
|
||||
type: Type;
|
||||
virtual?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface Meta {
|
||||
lineno: number;
|
||||
filename: string;
|
||||
lineno: number;
|
||||
path: string;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import type { Access, Exception, Item, Meta, Param, Return, Scope } from './index.js';
|
||||
|
||||
export interface Method extends Item {
|
||||
kind: 'function';
|
||||
see?: string[];
|
||||
scope: Scope;
|
||||
access?: Access;
|
||||
inherits?: string;
|
||||
inherited?: boolean;
|
||||
implements?: string[];
|
||||
examples?: string[];
|
||||
virtual?: boolean;
|
||||
deprecated?: boolean | string;
|
||||
memberof?: string;
|
||||
params?: Param[];
|
||||
async?: boolean;
|
||||
generator?: boolean;
|
||||
fires?: string[];
|
||||
returns?: Return[];
|
||||
deprecated?: boolean | string;
|
||||
examples?: string[];
|
||||
exceptions?: Exception[];
|
||||
fires?: string[];
|
||||
generator?: boolean;
|
||||
implements?: string[];
|
||||
inherited?: boolean;
|
||||
inherits?: string;
|
||||
kind: 'function';
|
||||
memberof?: string;
|
||||
meta: Meta;
|
||||
params?: Param[];
|
||||
returns?: Return[];
|
||||
scope: Scope;
|
||||
see?: string[];
|
||||
virtual?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { Type } from './index.js';
|
||||
|
||||
export interface Param {
|
||||
type: Type;
|
||||
defaultvalue?: string;
|
||||
description: string;
|
||||
name: string;
|
||||
optional?: boolean;
|
||||
defaultvalue?: string;
|
||||
variable?: string;
|
||||
nullable?: boolean;
|
||||
optional?: boolean;
|
||||
type: Type;
|
||||
variable?: string;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Type } from './index.js';
|
||||
|
||||
export interface Return {
|
||||
type: Required<Type>;
|
||||
nullable?: boolean;
|
||||
description?: string;
|
||||
nullable?: boolean;
|
||||
type: Required<Type>;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import type { Class, External, Interface, Method, Typedef } from './index.js';
|
||||
|
||||
export type RootTypes = Class | Method | Interface | Typedef | External;
|
||||
export type RootTypes = Class | External | Interface | Method | Typedef;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import type { Access, Item, Meta, Param, Return, Scope, Type } from './index.js';
|
||||
|
||||
export interface Typedef extends Item {
|
||||
kind: 'typedef';
|
||||
scope: Scope;
|
||||
see?: string[];
|
||||
access?: Access;
|
||||
deprecated?: boolean | string;
|
||||
type: Type;
|
||||
properties?: Param[];
|
||||
params?: Param[];
|
||||
returns?: Return[];
|
||||
kind: 'typedef';
|
||||
meta: Meta;
|
||||
params?: Param[];
|
||||
properties?: Param[];
|
||||
returns?: Return[];
|
||||
scope: Scope;
|
||||
see?: string[];
|
||||
type: Type;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Type } from './index.js';
|
||||
|
||||
export interface VarType extends Type {
|
||||
type?: Required<Type> | undefined;
|
||||
description?: string | undefined;
|
||||
nullable?: boolean | undefined;
|
||||
type?: Required<Type> | undefined;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { parse } from 'node:path';
|
||||
import type { DeclarationReflection } from 'typedoc';
|
||||
import type { Class, Config } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
import { DocumentedConstructor } from './constructor.js';
|
||||
import { DocumentedEvent } from './event.js';
|
||||
import { DocumentedItemMeta } from './item-meta.js';
|
||||
@@ -7,8 +9,6 @@ import { DocumentedItem } from './item.js';
|
||||
import { DocumentedMember } from './member.js';
|
||||
import { DocumentedMethod } from './method.js';
|
||||
import { DocumentedVarType } from './var-type.js';
|
||||
import type { Class, Config } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
|
||||
export class DocumentedClass extends DocumentedItem<Class | DeclarationReflection> {
|
||||
public readonly props = new Map<string, DocumentedMember>();
|
||||
@@ -27,51 +27,55 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
|
||||
super(data, config);
|
||||
|
||||
if (config.typescript) {
|
||||
const d = data as DeclarationReflection;
|
||||
const extended = d.extendedTypes?.[0];
|
||||
const newData = data as DeclarationReflection;
|
||||
const extended = newData.extendedTypes?.[0];
|
||||
if (extended) {
|
||||
this.extends = new DocumentedVarType({ names: [parseType(extended)] }, this.config);
|
||||
}
|
||||
|
||||
const implemented = d.implementedTypes?.[0];
|
||||
const implemented = newData.implementedTypes?.[0];
|
||||
if (implemented) {
|
||||
this.implements = new DocumentedVarType({ names: [parseType(implemented)] }, this.config);
|
||||
}
|
||||
} else {
|
||||
const d = data as Class;
|
||||
if (d.augments) {
|
||||
this.extends = new DocumentedVarType({ names: d.augments }, this.config);
|
||||
const newData = data as Class;
|
||||
if (newData.augments) {
|
||||
this.extends = new DocumentedVarType({ names: newData.augments }, this.config);
|
||||
}
|
||||
|
||||
if (d.implements) {
|
||||
this.implements = new DocumentedVarType({ names: d.implements }, this.config);
|
||||
if (newData.implements) {
|
||||
this.implements = new DocumentedVarType({ names: newData.implements }, this.config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public add(item: DocumentedConstructor | DocumentedMethod | DocumentedMember | DocumentedEvent) {
|
||||
public add(item: DocumentedConstructor | DocumentedEvent | DocumentedMember | DocumentedMethod) {
|
||||
if (item instanceof DocumentedConstructor) {
|
||||
if (this.construct) {
|
||||
throw new Error(`Doc ${this.data.name} already has constructor`);
|
||||
}
|
||||
|
||||
this.construct = item;
|
||||
} else if (item instanceof DocumentedMethod) {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: No type for methods
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
const prefix = item.data.scope === 'static' || item.data.flags?.isStatic ? 's-' : '';
|
||||
if (this.methods.has(prefix + item.data.name)) {
|
||||
throw new Error(`Doc ${this.data.name} already has method ${item.data.name}`);
|
||||
}
|
||||
|
||||
this.methods.set(prefix + item.data.name, item);
|
||||
} else if (item instanceof DocumentedMember) {
|
||||
if (this.props.has(item.data.name)) {
|
||||
throw new Error(`Doc ${this.data.name} already has prop ${item.data.name}`);
|
||||
}
|
||||
|
||||
this.props.set(item.data.name, item);
|
||||
} else if (item instanceof DocumentedEvent) {
|
||||
if (this.events.has(item.data.name)) {
|
||||
throw new Error(`Doc ${this.data.name} already has event ${item.data.name}`);
|
||||
}
|
||||
|
||||
this.events.set(item.data.name, item);
|
||||
}
|
||||
}
|
||||
@@ -88,17 +92,17 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
const see = signature.comment?.blockTags?.filter((block) => block.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
.filter((block) => block.tag === '@see')
|
||||
.map((block) => block.content.find((contentText) => contentText.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Type cannot be inferred
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
name: signature.name === 'default' ? parse(meta?.file ?? 'default').name : signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: signature.comment?.summary.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
extends: this.extends?.serialize(),
|
||||
@@ -106,22 +110,23 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
signature.comment?.blockTags?.some((block) => block.tag === '@private' || block.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/no-unnecessary-condition
|
||||
abstract: signature.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
|
||||
abstract: signature.comment?.blockTags?.some((block) => block.tag === '@abstract') || undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
deprecated: signature.comment?.blockTags?.some((block) => block.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
.find((block) => block.tag === '@deprecated')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
construct: this.construct?.serialize(),
|
||||
props: this.props.size ? [...this.props.values()].map((p) => p.serialize()) : undefined,
|
||||
methods: this.methods.size ? [...this.methods.values()].map((m) => m.serialize()) : undefined,
|
||||
events: this.events.size ? [...this.events.values()].map((e) => e.serialize()) : undefined,
|
||||
props: this.props.size ? [...this.props.values()].map((param) => param.serialize()) : undefined,
|
||||
methods: this.methods.size ? [...this.methods.values()].map((method) => method.serialize()) : undefined,
|
||||
events: this.events.size ? [...this.events.values()].map((event) => event.serialize()) : undefined,
|
||||
meta,
|
||||
};
|
||||
}
|
||||
@@ -137,9 +142,9 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
|
||||
abstract: data.virtual,
|
||||
deprecated: data.deprecated,
|
||||
construct: this.construct?.serialize(),
|
||||
props: this.props.size ? [...this.props.values()].map((p) => p.serialize()) : undefined,
|
||||
methods: this.methods.size ? [...this.methods.values()].map((m) => m.serialize()) : undefined,
|
||||
events: this.events.size ? [...this.events.values()].map((e) => e.serialize()) : undefined,
|
||||
props: this.props.size ? [...this.props.values()].map((param) => param.serialize()) : undefined,
|
||||
methods: this.methods.size ? [...this.methods.values()].map((method) => method.serialize()) : undefined,
|
||||
events: this.events.size ? [...this.events.values()].map((event) => event.serialize()) : undefined,
|
||||
meta: new DocumentedItemMeta(data.meta, this.config).serialize(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { DeclarationReflection, SignatureReflection } from 'typedoc';
|
||||
import type { Constructor } from '../interfaces/index.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import { DocumentedParam } from './param.js';
|
||||
import type { Constructor } from '../interfaces/index.js';
|
||||
|
||||
export class DocumentedConstructor extends DocumentedItem<Constructor | DeclarationReflection> {
|
||||
public override serializer() {
|
||||
@@ -10,26 +10,28 @@ export class DocumentedConstructor extends DocumentedItem<Constructor | Declarat
|
||||
const signature = (data.signatures ?? [])[0] ?? data;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
const see = signature.comment?.blockTags?.filter((block) => block.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
.filter((block) => block.tag === '@see')
|
||||
.map((block) => block.content.find((textContent) => textContent.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
signature.comment?.blockTags?.some((block) => block.tag === '@private' || block.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: No type for params
|
||||
params: signature.parameters
|
||||
? (signature as SignatureReflection).parameters?.map((p) => new DocumentedParam(p, this.config).serialize())
|
||||
? (signature as SignatureReflection).parameters?.map((param) =>
|
||||
new DocumentedParam(param, this.config).serialize(),
|
||||
)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
@@ -40,7 +42,9 @@ export class DocumentedConstructor extends DocumentedItem<Constructor | Declarat
|
||||
description: data.description,
|
||||
see: data.see,
|
||||
access: data.access,
|
||||
params: data.params?.length ? data.params.map((p) => new DocumentedParam(p, this.config).serialize()) : undefined,
|
||||
params: data.params?.length
|
||||
? data.params.map((param) => new DocumentedParam(param, this.config).serialize())
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { DeclarationReflection, SignatureReflection } from 'typedoc';
|
||||
import type { Event } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
import { DocumentedItemMeta } from './item-meta.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import { DocumentedParam } from './param.js';
|
||||
import { DocumentedVarType } from './var-type.js';
|
||||
import type { Event } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
|
||||
export class DocumentedEvent extends DocumentedItem<Event | DeclarationReflection> {
|
||||
export class DocumentedEvent extends DocumentedItem<DeclarationReflection | Event> {
|
||||
public override serializer() {
|
||||
if (this.config.typescript) {
|
||||
const data = this.data as DeclarationReflection;
|
||||
@@ -19,45 +19,47 @@ export class DocumentedEvent extends DocumentedItem<Event | DeclarationReflectio
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
const see = signature.comment?.blockTags?.filter((block) => block.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
.filter((block) => block.tag === '@see')
|
||||
.map((block) => block.content.find((contentText) => contentText.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const examples = signature.comment?.blockTags?.filter((t) => t.tag === '@example').length
|
||||
const examples = signature.comment?.blockTags?.filter((block) => block.tag === '@example').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@example')
|
||||
.map((t) => t.content.reduce((prev, curr) => (prev += curr.text), '').trim())
|
||||
.filter((block) => block.tag === '@example')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
.map((block) => block.content.reduce((prev, curr) => (prev += curr.text), '').trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: No type for params
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
||||
name: signature.parameters?.[0]?.type?.value,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
signature.comment?.blockTags?.some((block) => block.tag === '@private' || block.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
examples,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
deprecated: signature.comment?.blockTags?.some((block) => block.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
.find((block) => block.tag === '@deprecated')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Parameters type is not available
|
||||
params: signature.parameters
|
||||
? (signature as SignatureReflection).parameters
|
||||
?.slice(1)
|
||||
.map((p) => new DocumentedParam(p, this.config).serialize())
|
||||
.map((param) => new DocumentedParam(param, this.config).serialize())
|
||||
: undefined,
|
||||
returns: signature.type
|
||||
? [
|
||||
@@ -67,7 +69,8 @@ export class DocumentedEvent extends DocumentedItem<Event | DeclarationReflectio
|
||||
description:
|
||||
signature.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.find((block) => block.tag === '@returns')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
@@ -79,7 +82,8 @@ export class DocumentedEvent extends DocumentedItem<Event | DeclarationReflectio
|
||||
returnsDescription:
|
||||
signature.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.find((block) => block.tag === '@returns')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
@@ -93,7 +97,9 @@ export class DocumentedEvent extends DocumentedItem<Event | DeclarationReflectio
|
||||
description: data.description,
|
||||
see: data.see,
|
||||
deprecated: data.deprecated,
|
||||
params: data.params?.length ? data.params.map((p) => new DocumentedParam(p, this.config).serialize()) : undefined,
|
||||
params: data.params?.length
|
||||
? data.params.map((param) => new DocumentedParam(param, this.config).serialize())
|
||||
: undefined,
|
||||
meta: new DocumentedItemMeta(data.meta, this.config).serialize(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { External } from '../interfaces/index.js';
|
||||
import { DocumentedItemMeta } from './item-meta.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import type { External } from '../interfaces/index.js';
|
||||
|
||||
export class DocumentedExternal extends DocumentedItem<External> {
|
||||
public override serializer() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DocumentedClass } from './class.js';
|
||||
import type { Interface } from '../interfaces/index.js';
|
||||
import { DocumentedClass } from './class.js';
|
||||
|
||||
export class DocumentedInterface extends DocumentedClass {
|
||||
public override serializer() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { basename, relative } from 'node:path';
|
||||
import type { SourceReference } from 'typedoc';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import type { Meta } from '../interfaces/index.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
|
||||
export class DocumentedItemMeta extends DocumentedItem<Meta | SourceReference> {
|
||||
public override serializer() {
|
||||
@@ -20,7 +20,7 @@ export class DocumentedItemMeta extends DocumentedItem<Meta | SourceReference> {
|
||||
return {
|
||||
line: data.lineno,
|
||||
file: data.filename,
|
||||
path: relative(this.config.root, data.path).replace(/\\/g, '/'),
|
||||
path: relative(this.config.root, data.path).replaceAll('\\', '/'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import type { DeclarationReflection } from 'typedoc';
|
||||
import type { Config, Item } from '../interfaces/index.js';
|
||||
|
||||
export class DocumentedItem<T = Item | DeclarationReflection> {
|
||||
export class DocumentedItem<T = DeclarationReflection | Item> {
|
||||
public constructor(public readonly data: T, public readonly config: Config) {}
|
||||
|
||||
public serialize(): unknown {
|
||||
try {
|
||||
return this.serializer();
|
||||
} catch (err) {
|
||||
const error = err as Error;
|
||||
this.serializer();
|
||||
return;
|
||||
} catch (error_) {
|
||||
const error = error_ as Error;
|
||||
error.message = `Error while serializing ${this.detailedName()}: ${error.message}`;
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { DeclarationReflection } from 'typedoc';
|
||||
import type { Member } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
import { DocumentedItemMeta } from './item-meta.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import { DocumentedParam } from './param.js';
|
||||
import { DocumentedVarType } from './var-type.js';
|
||||
import type { Member } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
|
||||
export class DocumentedMember extends DocumentedItem<Member | DeclarationReflection> {
|
||||
export class DocumentedMember extends DocumentedItem<DeclarationReflection | Member> {
|
||||
public override serializer() {
|
||||
if (this.config.typescript) {
|
||||
const data = this.data as DeclarationReflection;
|
||||
@@ -19,31 +19,32 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
const see = signature.comment?.blockTags?.filter((block) => block.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
.filter((block) => block.tag === '@see')
|
||||
.map((block) => block.content.find((contentText) => contentText.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
const base = {
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
scope: data.flags.isStatic ? 'static' : undefined,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
signature.comment?.blockTags?.some((block) => block.tag === '@private' || block.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
readonly: data.flags.isReadonly,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
abstract: signature.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
|
||||
abstract: signature.comment?.blockTags?.some((block) => block.tag === '@abstract') || undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
deprecated: signature.comment?.blockTags?.some((block) => block.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
.find((block) => block.tag === '@deprecated')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
@@ -51,7 +52,8 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
(data.defaultValue === '...' ? undefined : data.defaultValue) ??
|
||||
(signature.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.find((block) => block.tag === '@default')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
@@ -75,30 +77,31 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = getter.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
const see = getter.comment?.blockTags?.filter((block) => block.tag === '@see').length
|
||||
? getter.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
.filter((block) => block.tag === '@see')
|
||||
.map((block) => block.content.find((contentText) => contentText.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
...base,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: getter.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
getter.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
getter.comment?.blockTags?.some((block) => block.tag === '@private' || block.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
readonly: base.readonly || !hasSetter,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
abstract: getter.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
|
||||
abstract: getter.comment?.blockTags?.some((block) => block.tag === '@abstract') || undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: getter.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
deprecated: getter.comment?.blockTags?.some((block) => block.tag === '@deprecated')
|
||||
? getter.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
.find((block) => block.tag === '@deprecated')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
@@ -106,7 +109,8 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
base.default ??
|
||||
(getter.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.find((block) => block.tag === '@default')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
@@ -132,7 +136,7 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
default: data.default,
|
||||
type: new DocumentedVarType(data.type, this.config).serialize(),
|
||||
props: data.properties?.length
|
||||
? data.properties.map((p) => new DocumentedParam(p, this.config).serialize())
|
||||
? data.properties.map((prop) => new DocumentedParam(prop, this.config).serialize())
|
||||
: undefined,
|
||||
meta: new DocumentedItemMeta(data.meta, this.config).serialize(),
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { DeclarationReflection, SignatureReflection } from 'typedoc';
|
||||
import type { Method } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
import { DocumentedItemMeta } from './item-meta.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import { DocumentedParam } from './param.js';
|
||||
import { DocumentedVarType } from './var-type.js';
|
||||
import type { Method } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
|
||||
export class DocumentedMethod extends DocumentedItem<Method | DeclarationReflection> {
|
||||
export class DocumentedMethod extends DocumentedItem<DeclarationReflection | Method> {
|
||||
public override serializer() {
|
||||
if (this.config.typescript) {
|
||||
const data = this.data as DeclarationReflection;
|
||||
@@ -19,46 +19,50 @@ export class DocumentedMethod extends DocumentedItem<Method | DeclarationReflect
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
const see = signature.comment?.blockTags?.filter((block) => block.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
.filter((block) => block.tag === '@see')
|
||||
.map((block) => block.content.find((innerContent) => innerContent.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const examples = signature.comment?.blockTags?.filter((t) => t.tag === '@example').length
|
||||
const examples = signature.comment?.blockTags?.filter((block) => block.tag === '@example').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@example')
|
||||
.map((t) => t.content.reduce((prev, curr) => (prev += curr.text), '').trim())
|
||||
.filter((block) => block.tag === '@example')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
.map((block) => block.content.reduce((prev, curr) => (prev += curr.text), '').trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
scope: data.flags.isStatic ? 'static' : undefined,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
signature.comment?.blockTags?.some((block) => block.tag === '@private' || block.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
examples,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
abstract: signature.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
|
||||
abstract: signature.comment?.blockTags?.some((block) => block.tag === '@abstract') || undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
deprecated: signature.comment?.blockTags?.some((block) => block.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
.find((block) => block.tag === '@deprecated')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
// emits: signature.comment?.blockTags?.filter((t) => t.tag === '@emits').map((t) => t.content),
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Typescript doesn't know that this is a SignatureReflection
|
||||
params: signature.parameters
|
||||
? (signature as SignatureReflection).parameters?.map((p) => new DocumentedParam(p, this.config).serialize())
|
||||
? (signature as SignatureReflection).parameters?.map((param) =>
|
||||
new DocumentedParam(param, this.config).serialize(),
|
||||
)
|
||||
: undefined,
|
||||
returns: signature.type
|
||||
? [
|
||||
@@ -68,7 +72,8 @@ export class DocumentedMethod extends DocumentedItem<Method | DeclarationReflect
|
||||
description:
|
||||
signature.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.find((block) => block.tag === '@returns')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
@@ -80,7 +85,8 @@ export class DocumentedMethod extends DocumentedItem<Method | DeclarationReflect
|
||||
returnsDescription:
|
||||
signature.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.find((block) => block.tag === '@returns')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
@@ -103,13 +109,15 @@ export class DocumentedMethod extends DocumentedItem<Method | DeclarationReflect
|
||||
deprecated: data.deprecated,
|
||||
emits: data.fires,
|
||||
throws: data.exceptions,
|
||||
params: data.params?.length ? data.params.map((p) => new DocumentedParam(p, this.config).serialize()) : undefined,
|
||||
params: data.params?.length
|
||||
? data.params.map((param) => new DocumentedParam(param, this.config).serialize())
|
||||
: undefined,
|
||||
async: data.async,
|
||||
generator: data.generator,
|
||||
returns: data.returns?.length
|
||||
? data.returns.map((p) =>
|
||||
? data.returns.map((param) =>
|
||||
new DocumentedVarType(
|
||||
{ names: p.type.names, description: p.description, nullable: p.nullable },
|
||||
{ names: param.type.names, description: param.description, nullable: param.nullable },
|
||||
this.config,
|
||||
).serialize(),
|
||||
)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { ParameterReflection } from 'typedoc';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import { DocumentedVarType } from './var-type.js';
|
||||
import type { Param } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import { DocumentedVarType } from './var-type.js';
|
||||
|
||||
export class DocumentedParam extends DocumentedItem<Param | ParameterReflection> {
|
||||
public override serializer() {
|
||||
@@ -11,14 +11,15 @@ export class DocumentedParam extends DocumentedItem<Param | ParameterReflection>
|
||||
|
||||
return {
|
||||
name: data.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: data.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
optional: data.flags.isOptional || typeof data.defaultValue != 'undefined',
|
||||
optional: data.flags.isOptional || typeof data.defaultValue !== 'undefined',
|
||||
default:
|
||||
(data.defaultValue === '...' ? undefined : data.defaultValue) ??
|
||||
(data.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.find((block) => block.tag === '@default')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import type { DeclarationReflection, LiteralType } from 'typedoc';
|
||||
import type { Typedef } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
import { isReflectionType } from '../util/types.js';
|
||||
import { DocumentedItemMeta } from './item-meta.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import { DocumentedParam } from './param.js';
|
||||
import { DocumentedVarType } from './var-type.js';
|
||||
import type { Typedef } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
import { isReflectionType } from '../util/types.js';
|
||||
|
||||
export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationReflection> {
|
||||
export class DocumentedTypeDef extends DocumentedItem<DeclarationReflection | Typedef> {
|
||||
public override serializer() {
|
||||
if (this.config.typescript) {
|
||||
const data = this.data as DeclarationReflection;
|
||||
@@ -20,27 +20,28 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
const see = signature.comment?.blockTags?.filter((block) => block.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
.filter((block) => block.tag === '@see')
|
||||
.map((block) => block.content.find((contentText) => contentText.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
const baseReturn = {
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
signature.comment?.blockTags?.some((block) => block.tag === '@private' || block.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
deprecated: signature.comment?.blockTags?.some((block) => block.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
.find((block) => block.tag === '@deprecated')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
@@ -63,7 +64,7 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
name: child.name,
|
||||
description:
|
||||
child.comment?.summary
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-param-reassign
|
||||
?.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
@@ -81,19 +82,20 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
name: child.name,
|
||||
description:
|
||||
child.comment?.summary
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-param-reassign
|
||||
?.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
child.signatures?.[0]?.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() ||
|
||||
undefined,
|
||||
optional: child.flags.isOptional || typeof child.defaultValue != 'undefined',
|
||||
optional: child.flags.isOptional || typeof child.defaultValue !== 'undefined',
|
||||
default:
|
||||
(child.defaultValue === '...' ? undefined : child.defaultValue) ??
|
||||
(child.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.find((block) => block.tag === '@default')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
@@ -111,7 +113,8 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
],
|
||||
description: child.signatures?.[0]?.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.find((block) => block.tag === '@returns')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim(),
|
||||
},
|
||||
@@ -131,14 +134,15 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
|
||||
const params = sig?.parameters?.map((param) => ({
|
||||
name: param.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: param.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
optional: param.flags.isOptional || typeof param.defaultValue != 'undefined',
|
||||
optional: param.flags.isOptional || typeof param.defaultValue !== 'undefined',
|
||||
default:
|
||||
(param.defaultValue === '...' ? undefined : param.defaultValue) ??
|
||||
(param.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.find((block) => block.tag === '@default')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
@@ -149,27 +153,28 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
}));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = sig?.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
const see = sig?.comment?.blockTags?.filter((block) => block.tag === '@see').length
|
||||
? sig.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
.filter((block) => block.tag === '@see')
|
||||
.map((block) => block.content.find((contentText) => contentText.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
...baseReturn,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
|
||||
description: sig?.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
sig?.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
sig?.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
sig?.comment?.blockTags?.some((block) => block.tag === '@private' || block.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: sig?.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
deprecated: sig?.comment?.blockTags?.some((block) => block.tag === '@deprecated')
|
||||
? sig.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
.find((block) => block.tag === '@deprecated')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
@@ -182,7 +187,8 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
description:
|
||||
sig.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.find((block) => block.tag === '@returns')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
@@ -194,7 +200,8 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
returnsDescription:
|
||||
sig?.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.find((block) => block.tag === '@returns')
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
@@ -215,11 +222,13 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
deprecated: data.deprecated,
|
||||
type: new DocumentedVarType(data.type, this.config).serialize(),
|
||||
props: data.properties?.length
|
||||
? data.properties.map((p) => new DocumentedParam(p, this.config).serialize())
|
||||
? data.properties.map((prop) => new DocumentedParam(prop, this.config).serialize())
|
||||
: undefined,
|
||||
params: data.params?.length
|
||||
? data.params.map((param) => new DocumentedParam(param, this.config).serialize())
|
||||
: undefined,
|
||||
params: data.params?.length ? data.params.map((p) => new DocumentedParam(p, this.config).serialize()) : undefined,
|
||||
returns: data.returns?.length
|
||||
? data.returns.map((p) => new DocumentedVarType(p, this.config).serialize())
|
||||
? data.returns.map((prop) => new DocumentedVarType(prop, this.config).serialize())
|
||||
: undefined,
|
||||
meta: new DocumentedItemMeta(data.meta, this.config).serialize(),
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DocumentedItem } from './item.js';
|
||||
import type { VarType } from '../interfaces/index.js';
|
||||
import { parseType } from '../util/parseType.js';
|
||||
import { splitVarName } from '../util/splitVarName.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
|
||||
export class DocumentedVarType extends DocumentedItem<VarType> {
|
||||
public override serializer() {
|
||||
|
||||
@@ -15,44 +15,48 @@ import {
|
||||
isInferredType,
|
||||
isIntrinsicType,
|
||||
isUnknownType,
|
||||
} from './types';
|
||||
} from './types.js';
|
||||
|
||||
export function parseType(t: JSONOutput.SomeType | JSONOutput.Type | string): string {
|
||||
if (typeof t === 'string') {
|
||||
return t;
|
||||
export function parseType(someType: JSONOutput.SomeType | JSONOutput.Type | string): string {
|
||||
if (typeof someType === 'string') {
|
||||
return someType;
|
||||
}
|
||||
|
||||
if (isArrayType(t)) {
|
||||
return `Array<${parseType(t.elementType)}>`;
|
||||
if (isArrayType(someType)) {
|
||||
return `Array<${parseType(someType.elementType)}>`;
|
||||
}
|
||||
|
||||
if (isConditionalType(t)) {
|
||||
const { checkType, extendsType, trueType, falseType } = t;
|
||||
if (isConditionalType(someType)) {
|
||||
const { checkType, extendsType, trueType, falseType } = someType;
|
||||
return `${parseType(checkType)} extends ${parseType(extendsType)} ? ${parseType(trueType)} : ${parseType(
|
||||
falseType,
|
||||
)}`;
|
||||
}
|
||||
|
||||
if (isIndexedAccessType(t)) {
|
||||
return `${parseType(t.objectType)}[${parseType(t.indexType)}]`;
|
||||
if (isIndexedAccessType(someType)) {
|
||||
return `${parseType(someType.objectType)}[${parseType(someType.indexType)}]`;
|
||||
}
|
||||
|
||||
if (isIntersectionType(t)) {
|
||||
return t.types.map(parseType).join(' & ');
|
||||
if (isIntersectionType(someType)) {
|
||||
return someType.types.map(parseType).join(' & ');
|
||||
}
|
||||
|
||||
if (isPredicateType(t)) {
|
||||
return (t.asserts ? 'asserts ' : '') + t.name + (t.targetType ? ` is ${parseType(t.targetType)}` : '');
|
||||
if (isPredicateType(someType)) {
|
||||
return (
|
||||
(someType.asserts ? 'asserts ' : '') +
|
||||
someType.name +
|
||||
(someType.targetType ? ` is ${parseType(someType.targetType)}` : '')
|
||||
);
|
||||
}
|
||||
|
||||
if (isReferenceType(t)) {
|
||||
return t.name + (t.typeArguments ? `<${t.typeArguments.map(parseType).join(', ')}>` : '');
|
||||
if (isReferenceType(someType)) {
|
||||
return someType.name + (someType.typeArguments ? `<${someType.typeArguments.map(parseType).join(', ')}>` : '');
|
||||
}
|
||||
|
||||
if (isReflectionType(t)) {
|
||||
if (isReflectionType(someType)) {
|
||||
const obj: Record<string, any> = {};
|
||||
|
||||
const { children, signatures } = t.declaration!;
|
||||
const { children, signatures } = someType.declaration!;
|
||||
|
||||
// This is run when we're parsing interface-like declaration
|
||||
if (children && children.length > 0) {
|
||||
@@ -62,6 +66,7 @@ export function parseType(t: JSONOutput.SomeType | JSONOutput.Type | string): st
|
||||
obj[child.name] = parseType(type);
|
||||
}
|
||||
}
|
||||
|
||||
return `{\n${Object.entries(obj)
|
||||
.map(([key, value]) => `${key}: ${value as string}`)
|
||||
.join(',\n')}\n}`;
|
||||
@@ -69,43 +74,48 @@ export function parseType(t: JSONOutput.SomeType | JSONOutput.Type | string): st
|
||||
|
||||
// This is run if we're parsing a function type
|
||||
if (signatures && signatures.length > 0) {
|
||||
const s = signatures[0];
|
||||
const params = s?.parameters?.map((p) => `${p.name}: ${p.type ? parseType(p.type) : 'unknown'}`);
|
||||
return `(${params?.join(', ') ?? '...args: unknown[]'}) => ${s?.type ? parseType(s.type) : 'unknown'}`;
|
||||
const signature = signatures[0];
|
||||
const params = signature?.parameters?.map(
|
||||
(param) => `${param.name}: ${param.type ? parseType(param.type) : 'unknown'}`,
|
||||
);
|
||||
return `(${params?.join(', ') ?? '...args: unknown[]'}) => ${
|
||||
signature?.type ? parseType(signature.type) : 'unknown'
|
||||
}`;
|
||||
}
|
||||
|
||||
return '{}';
|
||||
}
|
||||
|
||||
if (isLiteralType(t)) {
|
||||
if (typeof t.value == 'string') {
|
||||
return `'${t.value}'`;
|
||||
if (isLiteralType(someType)) {
|
||||
if (typeof someType.value === 'string') {
|
||||
return `'${someType.value}'`;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
return `${t.value}`;
|
||||
return `${someType.value}`;
|
||||
}
|
||||
|
||||
if (isTupleType(t)) {
|
||||
return `[${(t.elements ?? []).map(parseType).join(', ')}]`;
|
||||
if (isTupleType(someType)) {
|
||||
return `[${(someType.elements ?? []).map(parseType).join(', ')}]`;
|
||||
}
|
||||
|
||||
if (isTypeOperatorType(t)) {
|
||||
return `${t.operator} ${parseType(t.target)}`;
|
||||
if (isTypeOperatorType(someType)) {
|
||||
return `${someType.operator} ${parseType(someType.target)}`;
|
||||
}
|
||||
|
||||
if (isUnionType(t)) {
|
||||
return t.types
|
||||
if (isUnionType(someType)) {
|
||||
return someType.types
|
||||
.map(parseType)
|
||||
.filter((s) => Boolean(s) && s.trim().length > 0)
|
||||
.filter((currentType) => Boolean(currentType) && currentType.trim().length > 0)
|
||||
.join(' | ');
|
||||
}
|
||||
|
||||
if (isQueryType(t)) {
|
||||
return `(typeof ${parseType(t.queryType)})`;
|
||||
if (isQueryType(someType)) {
|
||||
return `(typeof ${parseType(someType.queryType)})`;
|
||||
}
|
||||
|
||||
if (isInferredType(t) || isIntrinsicType(t) || isUnknownType(t)) {
|
||||
return t.name;
|
||||
if (isInferredType(someType) || isIntrinsicType(someType) || isUnknownType(someType)) {
|
||||
return someType.name;
|
||||
}
|
||||
|
||||
return 'unknown';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const isASymbol = (char: string) => '-!$%^&*()_+|~=`{}[]:;<>?,. '.includes(char);
|
||||
|
||||
export function splitVarName(str: string) {
|
||||
const res: string[][] = [];
|
||||
let currGroup: string[] = [];
|
||||
let currStr = '';
|
||||
|
||||
const isASymbol = (char: string) => '-!$%^&*()_+|~=`{}[]:;<>?,. '.includes(char);
|
||||
|
||||
for (const char of str) {
|
||||
const currentlyInASymbolSection = isASymbol(currStr[0]!);
|
||||
const charIsASymbol = isASymbol(char);
|
||||
@@ -13,6 +13,7 @@ export function splitVarName(str: string) {
|
||||
if (char === '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
currGroup.push(currStr);
|
||||
currStr = char;
|
||||
|
||||
@@ -24,6 +25,7 @@ export function splitVarName(str: string) {
|
||||
currStr += char;
|
||||
}
|
||||
}
|
||||
|
||||
currGroup.push(currStr);
|
||||
res.push(currGroup);
|
||||
|
||||
|
||||
@@ -2,66 +2,66 @@
|
||||
import type { JSONOutput } from 'typedoc';
|
||||
|
||||
interface QueryType {
|
||||
type: 'query';
|
||||
queryType: JSONOutput.SomeType;
|
||||
type: 'query';
|
||||
}
|
||||
|
||||
export function isArrayType(value: any): value is JSONOutput.ArrayType {
|
||||
return typeof value == 'object' && value.type === 'array';
|
||||
return typeof value === 'object' && value.type === 'array';
|
||||
}
|
||||
|
||||
export function isConditionalType(value: any): value is JSONOutput.ConditionalType {
|
||||
return typeof value == 'object' && value.type === 'conditional';
|
||||
return typeof value === 'object' && value.type === 'conditional';
|
||||
}
|
||||
|
||||
export function isIndexedAccessType(value: any): value is JSONOutput.IndexedAccessType {
|
||||
return typeof value == 'object' && value.type === 'indexedAccess';
|
||||
return typeof value === 'object' && value.type === 'indexedAccess';
|
||||
}
|
||||
|
||||
export function isInferredType(value: any): value is JSONOutput.InferredType {
|
||||
return typeof value == 'object' && value.type === 'inferred';
|
||||
return typeof value === 'object' && value.type === 'inferred';
|
||||
}
|
||||
|
||||
export function isIntersectionType(value: any): value is JSONOutput.IntersectionType {
|
||||
return typeof value == 'object' && value.type === 'intersection';
|
||||
return typeof value === 'object' && value.type === 'intersection';
|
||||
}
|
||||
|
||||
export function isIntrinsicType(value: any): value is JSONOutput.IntrinsicType {
|
||||
return typeof value == 'object' && value.type === 'intrinsic';
|
||||
return typeof value === 'object' && value.type === 'intrinsic';
|
||||
}
|
||||
|
||||
export function isPredicateType(value: any): value is JSONOutput.PredicateType {
|
||||
return typeof value == 'object' && value.type === 'predicate';
|
||||
return typeof value === 'object' && value.type === 'predicate';
|
||||
}
|
||||
|
||||
export function isReferenceType(value: any): value is JSONOutput.ReferenceType {
|
||||
return typeof value == 'object' && value.type === 'reference';
|
||||
return typeof value === 'object' && value.type === 'reference';
|
||||
}
|
||||
|
||||
export function isReflectionType(value: any): value is JSONOutput.ReflectionType {
|
||||
return typeof value == 'object' && value.type === 'reflection';
|
||||
return typeof value === 'object' && value.type === 'reflection';
|
||||
}
|
||||
|
||||
export function isLiteralType(value: any): value is JSONOutput.LiteralType {
|
||||
return typeof value == 'object' && value.type === 'literal';
|
||||
return typeof value === 'object' && value.type === 'literal';
|
||||
}
|
||||
|
||||
export function isTupleType(value: any): value is JSONOutput.TupleType {
|
||||
return typeof value == 'object' && value.type === 'tuple';
|
||||
return typeof value === 'object' && value.type === 'tuple';
|
||||
}
|
||||
|
||||
export function isTypeOperatorType(value: any): value is JSONOutput.TypeOperatorType {
|
||||
return typeof value == 'object' && value.type === 'typeOperator';
|
||||
return typeof value === 'object' && value.type === 'typeOperator';
|
||||
}
|
||||
|
||||
export function isUnionType(value: any): value is JSONOutput.UnionType {
|
||||
return typeof value == 'object' && value.type === 'union';
|
||||
return typeof value === 'object' && value.type === 'union';
|
||||
}
|
||||
|
||||
export function isUnknownType(value: any): value is JSONOutput.UnknownType {
|
||||
return typeof value == 'object' && value.type === 'unknown';
|
||||
return typeof value === 'object' && value.type === 'unknown';
|
||||
}
|
||||
|
||||
export function isQueryType(value: any): value is QueryType {
|
||||
return typeof value == 'object' && value.type === 'query';
|
||||
return typeof value === 'object' && value.type === 'query';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user