@xyd-js/sources 0.0.0-build
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/ISSUES.md +10 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/TODO.md +9 -0
- package/__fixtures__/-1.typescript/package.json +5 -0
- package/__fixtures__/-1.typescript/src/index.ts +0 -0
- package/__fixtures__/-1.typescript/src/settings.ts +592 -0
- package/__fixtures__/-1.typescript/tsconfig.json +8 -0
- package/__fixtures__/-2.react.basic/1.flat-interface.output.json +114 -0
- package/__fixtures__/-2.react.basic/2.file-connect-interface.output.json +60 -0
- package/__fixtures__/-2.react.basic/2a.file-connect-interface-advanced.output.json +92 -0
- package/__fixtures__/-2.react.basic/3.props-as-variants.output.json +166 -0
- package/__fixtures__/-2.react.basic/4.outside-interface.output.json +60 -0
- package/__fixtures__/-2.react.basic/5.inline-props.output.json +60 -0
- package/__fixtures__/-2.react.basic/5.outside-inline-props.output.json +60 -0
- package/__fixtures__/-2.react.basic/5a.inline-props+outside.output.json +60 -0
- package/__fixtures__/-2.react.basic/5b.inline-props+interfaces.output.json +92 -0
- package/__fixtures__/-2.react.basic/package.json +4 -0
- package/__fixtures__/-2.react.basic/src/1.flat-interface.tsx +41 -0
- package/__fixtures__/-2.react.basic/src/2.file-connect-interface.tsx +28 -0
- package/__fixtures__/-2.react.basic/src/2a.file-connect-interace+advanced.tsx +54 -0
- package/__fixtures__/-2.react.basic/src/3.props-as-variants.tsx +67 -0
- package/__fixtures__/-2.react.basic/src/4.outside-interface.tsx +13 -0
- package/__fixtures__/-2.react.basic/src/4.outside-interface2.ts +15 -0
- package/__fixtures__/-2.react.basic/src/5.inline-props.tsx +19 -0
- package/__fixtures__/-2.react.basic/src/5a.inline-props+outside.tsx +19 -0
- package/__fixtures__/-2.react.basic/src/5b.inline-props+interfaces.tsx +62 -0
- package/__fixtures__/-2.react.basic/src/index.ts +0 -0
- package/__fixtures__/-2.react.basic/tsconfig.json +8 -0
- package/__tests__/sourcesToUniform.test.ts +167 -0
- package/__tests__/testResolvePropertySymbol.ts +838 -0
- package/__tests__/types.ts +12 -0
- package/__tests__/utils.ts +108 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +237 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +6 -0
- package/dist/react.d.ts +6 -0
- package/dist/react.js +212 -0
- package/dist/react.js.map +1 -0
- package/dist/ts.cjs +1794 -0
- package/dist/ts.cjs.map +1 -0
- package/dist/ts.d.cts +14 -0
- package/dist/ts.d.ts +14 -0
- package/dist/ts.js +1760 -0
- package/dist/ts.js.map +1 -0
- package/package.json +41 -0
- package/packages/react/index.ts +1 -0
- package/packages/react/uniformToReactUniform.ts +275 -0
- package/packages/ts/SignatureText.ts +233 -0
- package/packages/ts/TypeDocTransformer.ts +1519 -0
- package/packages/ts/__fixtures__/packages/package-a/package.json +4 -0
- package/packages/ts/__fixtures__/packages/package-a/src/index.ts +56 -0
- package/packages/ts/__fixtures__/packages/package-a/tsconfig.json +23 -0
- package/packages/ts/__fixtures__/packages/package-b/package.json +7 -0
- package/packages/ts/__fixtures__/packages/package-b/src/billing.ts +193 -0
- package/packages/ts/__fixtures__/packages/package-b/src/index.ts +8 -0
- package/packages/ts/__fixtures__/packages/package-b/tsconfig.json +20 -0
- package/packages/ts/__fixtures__/packages2/package-a/package.json +4 -0
- package/packages/ts/__fixtures__/packages2/package-a/src/index.ts +496 -0
- package/packages/ts/__fixtures__/packages2/package-a/tsconfig.json +6 -0
- package/packages/ts/__fixtures__/packages3/package-a/package.json +4 -0
- package/packages/ts/__fixtures__/packages3/package-a/src/index.ts +488 -0
- package/packages/ts/__fixtures__/packages3/package-a/tsconfig.json +6 -0
- package/packages/ts/__fixtures__/packages3/project.json +171 -0
- package/packages/ts/__fixtures__/react/react-a/package.json +5 -0
- package/packages/ts/__fixtures__/react/react-a/src/TestAbc.tsx +90 -0
- package/packages/ts/__fixtures__/react/react-a/src/TestBasic.tsx +27 -0
- package/packages/ts/__fixtures__/react/react-a/src/TestNamedParameters.tsx +27 -0
- package/packages/ts/__fixtures__/react/react-a/src/TestNamedParameters2.tsx +26 -0
- package/packages/ts/__fixtures__/react/react-a/src/TestUnion.tsx +32 -0
- package/packages/ts/__fixtures__/react/react-a/src/index.ts +1 -0
- package/packages/ts/__fixtures__/react/react-a/tsconfig.json +8 -0
- package/packages/ts/__fixtures__/references-output-project.json +344 -0
- package/packages/ts/__fixtures__/references-output-react.json +68 -0
- package/packages/ts/__fixtures__/references-output.json +129 -0
- package/packages/ts/__tests__/sourcesToUniform.test.ts +106 -0
- package/packages/ts/context.ts +0 -0
- package/packages/ts/converterts/ts-class.ts +0 -0
- package/packages/ts/converterts/ts-enum.ts +0 -0
- package/packages/ts/converterts/ts-function.ts +0 -0
- package/packages/ts/converterts/ts-interface.ts +0 -0
- package/packages/ts/converterts/ts-type.ts +0 -0
- package/packages/ts/index.ts +129 -0
- package/packages/ts/ts-core.ts +0 -0
- package/packages/ts/uniformToMiniUniform.ts +486 -0
- package/src/index.ts +0 -0
- package/test-cmd/index.ts +62 -0
- package/tsconfig.json +38 -0
- package/tsup.config.ts +39 -0
- package/vitest.config.ts +34 -0
|
@@ -0,0 +1,1519 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
JSONOutput,
|
|
6
|
+
ContainerReflection,
|
|
7
|
+
DeclarationReflection,
|
|
8
|
+
SomeType,
|
|
9
|
+
ReflectionSymbolId,
|
|
10
|
+
Comment,
|
|
11
|
+
} from 'typedoc';
|
|
12
|
+
import {ReflectionKind} from "typedoc";
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
Reference,
|
|
16
|
+
Definition,
|
|
17
|
+
TypeDocReferenceContext,
|
|
18
|
+
DefinitionProperty,
|
|
19
|
+
DefinitionTypeDocMeta,
|
|
20
|
+
SymbolDef, DefinitionPropertyMeta,
|
|
21
|
+
TypeDocReferenceContextMeta
|
|
22
|
+
} from "@xyd-js/uniform";
|
|
23
|
+
import {DEFINED_DEFINITION_PROPERTY_TYPE} from "@xyd-js/uniform";
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
MultiSignatureLoader,
|
|
27
|
+
signatureTextByLine,
|
|
28
|
+
signatureSourceCodeByLine
|
|
29
|
+
} from "./SignatureText";
|
|
30
|
+
|
|
31
|
+
class TypeDocSignatureTextLoader extends MultiSignatureLoader {
|
|
32
|
+
constructor(
|
|
33
|
+
private project: JSONOutput.ProjectReflection,
|
|
34
|
+
private packagePathMap: { [id: number]: string }
|
|
35
|
+
) {
|
|
36
|
+
super();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public signatureText(
|
|
40
|
+
id: number,
|
|
41
|
+
line: number,
|
|
42
|
+
options?: any // TODO: fix options
|
|
43
|
+
) {
|
|
44
|
+
const loader = this.getSignatuerLoader(id)
|
|
45
|
+
if (!loader) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const signTxt = signatureTextByLine(loader, line, options)
|
|
50
|
+
if (!signTxt) {
|
|
51
|
+
console.warn('(TypeDocSignatureTextLoader.signatureText): Signature text is empty', id)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return signTxt
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public signatureSourceCode(
|
|
59
|
+
id: number,
|
|
60
|
+
line: number
|
|
61
|
+
) {
|
|
62
|
+
const loader = this.getSignatuerLoader(id)
|
|
63
|
+
if (!loader) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const sourceCode = signatureSourceCodeByLine(loader, line)
|
|
68
|
+
if (!sourceCode) {
|
|
69
|
+
console.warn('(TypeDocSignatureTextLoader.signatureSourceCode): Source code is empty', id)
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return sourceCode
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private getSignatuerLoader(id: number) {
|
|
77
|
+
const symbolMap = this.project.symbolIdMap[id] as ReflectionSymbolId
|
|
78
|
+
if (!symbolMap) {
|
|
79
|
+
console.warn('(TypeDocSignatureTextLoader.getSignatuerLoader): Symbol not found', id)
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const fullPath = this.packagePathMap[id]
|
|
84
|
+
if (!fullPath) {
|
|
85
|
+
console.warn('(TypeDocSignatureTextLoader.getSignatuerLoader): Package path not found for symbol', symbolMap.packageName)
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const loader = this.load(fullPath)
|
|
90
|
+
if (!loader) {
|
|
91
|
+
console.warn('(TypeDocSignatureTextLoader.getSignatuerLoader): Loader not found', fullPath)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return loader
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class Transformer {
|
|
100
|
+
public packagePathMap: { [id: number]: string } = {};
|
|
101
|
+
public signatureTextLoader!: TypeDocSignatureTextLoader;
|
|
102
|
+
|
|
103
|
+
constructor(
|
|
104
|
+
private rootPath: string,
|
|
105
|
+
protected project: JSONOutput.ProjectReflection,
|
|
106
|
+
protected references: Reference[] = []
|
|
107
|
+
) {
|
|
108
|
+
const packagePathMap = this.createPackagePathMap()
|
|
109
|
+
if (packagePathMap) {
|
|
110
|
+
this.packagePathMap = packagePathMap
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private createPackagePathMap() {
|
|
115
|
+
const packagePathMap: { [id: number]: string } = {};
|
|
116
|
+
const packageJsonPaths = this.findPackageJsonPaths(this.rootPath);
|
|
117
|
+
|
|
118
|
+
if (!packageJsonPaths.length) {
|
|
119
|
+
console.warn('(Transformer.createPackagePathMap): No package.json found in rootPath', this.rootPath)
|
|
120
|
+
return {packageMap: null, moduleRootMap: null}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const packageJsonPath of packageJsonPaths) {
|
|
124
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
125
|
+
const packageName = packageJson.name;
|
|
126
|
+
const moduleRoot = path.dirname(packageJsonPath);
|
|
127
|
+
|
|
128
|
+
if (!packageName) {
|
|
129
|
+
console.warn('(Transformer.createPackagePathMap): Package name not found in package.json', packageJsonPath)
|
|
130
|
+
continue
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (const id in this.project.symbolIdMap) {
|
|
134
|
+
const symbolMap = this.project.symbolIdMap[id] as ReflectionSymbolId;
|
|
135
|
+
|
|
136
|
+
if (symbolMap.packageName === packageName) {
|
|
137
|
+
const fullPath = path.join(moduleRoot, symbolMap.packagePath);
|
|
138
|
+
packagePathMap[Number.parseInt(id)] = fullPath;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return packagePathMap
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private findPackageJsonPaths(dir: string): string[] {
|
|
147
|
+
let results: string[] = [];
|
|
148
|
+
const list = fs.readdirSync(dir);
|
|
149
|
+
|
|
150
|
+
for (const file of list) {
|
|
151
|
+
const filePath = path.join(dir, file);
|
|
152
|
+
const stat = fs.statSync(filePath);
|
|
153
|
+
if (stat && stat.isDirectory()) {
|
|
154
|
+
// Skip node_modules directory
|
|
155
|
+
if (file === 'node_modules') {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
results = results.concat(this.findPackageJsonPaths(filePath));
|
|
159
|
+
} else if (file === 'package.json') {
|
|
160
|
+
results.push(filePath);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return results;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function typedocToUniform(
|
|
168
|
+
rootPath: string,
|
|
169
|
+
project: JSONOutput.ProjectReflection
|
|
170
|
+
): Reference[] {
|
|
171
|
+
const references: Reference[] = []
|
|
172
|
+
const transformer = new Transformer(
|
|
173
|
+
rootPath,
|
|
174
|
+
project,
|
|
175
|
+
references
|
|
176
|
+
)
|
|
177
|
+
const signatureTextLoader = new TypeDocSignatureTextLoader(
|
|
178
|
+
project,
|
|
179
|
+
transformer.packagePathMap,
|
|
180
|
+
)
|
|
181
|
+
transformer.signatureTextLoader = signatureTextLoader
|
|
182
|
+
|
|
183
|
+
// TODO: in the future abstraction?
|
|
184
|
+
if (project.kind !== ReflectionKind.Project) {
|
|
185
|
+
throw new Error('Project reflection expected');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
for (const child of project.children || []) {
|
|
189
|
+
if (!("kind" in child)) {
|
|
190
|
+
throw new Error('(typedocToUniform): Child reflection expected in project childrens');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (typeof child.kind != "number") {
|
|
194
|
+
throw new Error('(typedocToUniform): Child reflection kind expected to be a number');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (!(child.kind satisfies ReflectionKind)) {
|
|
198
|
+
throw new Error('(typedocToUniform): Child reflection kind expected to be a valid ReflectionKind');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const kind = child.kind as ReflectionKind
|
|
202
|
+
|
|
203
|
+
switch (kind) {
|
|
204
|
+
case ReflectionKind.Module: {
|
|
205
|
+
const container = child as ContainerReflection
|
|
206
|
+
|
|
207
|
+
for (const group of container.children || []) {
|
|
208
|
+
const ref = typedocGroupToUniform.call(
|
|
209
|
+
transformer,
|
|
210
|
+
group
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
if (!ref) {
|
|
214
|
+
continue
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
ref.context = {
|
|
218
|
+
...ref.context,
|
|
219
|
+
packageName: container.name,
|
|
220
|
+
} as TypeDocReferenceContext;
|
|
221
|
+
|
|
222
|
+
references.push(ref)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
break
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
case ReflectionKind.Function:
|
|
229
|
+
case ReflectionKind.Class:
|
|
230
|
+
case ReflectionKind.Interface: {
|
|
231
|
+
if (!('kind' in child) || child.kind !== ReflectionKind.Function &&
|
|
232
|
+
child.kind !== ReflectionKind.Class &&
|
|
233
|
+
child.kind !== ReflectionKind.Interface) {
|
|
234
|
+
throw new Error('(typedocToUniform): Function/Class/Interface reflection expected to be a DeclarationReflection');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const ref = typedocGroupToUniform.call(
|
|
238
|
+
transformer,
|
|
239
|
+
child as DeclarationReflection
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
if (!ref) {
|
|
243
|
+
break
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
ref.context = {
|
|
247
|
+
...ref.context,
|
|
248
|
+
packageName: project.name,
|
|
249
|
+
} as TypeDocReferenceContext;
|
|
250
|
+
references.push(ref)
|
|
251
|
+
|
|
252
|
+
break
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
case ReflectionKind.TypeAlias: {
|
|
256
|
+
if (!('kind' in child) || child.kind !== ReflectionKind.TypeAlias) {
|
|
257
|
+
throw new Error('(typedocToUniform): Type alias reflection expected to be a DeclarationReflection');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const ref = jsTypeAliasToUniformRef.call(
|
|
261
|
+
transformer,
|
|
262
|
+
child as DeclarationReflection
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
if (!ref) {
|
|
266
|
+
break
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
ref.context = {
|
|
270
|
+
...ref.context,
|
|
271
|
+
packageName: project.name,
|
|
272
|
+
} as TypeDocReferenceContext;
|
|
273
|
+
references.push(ref)
|
|
274
|
+
|
|
275
|
+
break
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
case ReflectionKind.Enum: {
|
|
279
|
+
if (!('kind' in child) || child.kind !== ReflectionKind.Enum) {
|
|
280
|
+
throw new Error('(typedocToUniform): Enum reflection expected to be a DeclarationReflection');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const ref = jsEnumToUniformRef.call(
|
|
284
|
+
transformer,
|
|
285
|
+
child as DeclarationReflection
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
if (!ref) {
|
|
289
|
+
break
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
ref.context = {
|
|
293
|
+
...ref.context,
|
|
294
|
+
packageName: project.name,
|
|
295
|
+
} as TypeDocReferenceContext;
|
|
296
|
+
|
|
297
|
+
references.push(ref)
|
|
298
|
+
|
|
299
|
+
break
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
default: {
|
|
303
|
+
console.warn("(typedocToUniform): Another children project kind not supported", child.kind)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Sort references by file path and line number to preserve the original order in the source files
|
|
309
|
+
references.sort((a, b) => {
|
|
310
|
+
// First sort by file pathc
|
|
311
|
+
const contextA = a.context as unknown as TypeDocReferenceContext | undefined;
|
|
312
|
+
const contextB = b.context as unknown as TypeDocReferenceContext | undefined;
|
|
313
|
+
|
|
314
|
+
const filePathA = contextA?.fileFullPath || '';
|
|
315
|
+
const filePathB = contextB?.fileFullPath || '';
|
|
316
|
+
|
|
317
|
+
if (filePathA !== filePathB) {
|
|
318
|
+
return filePathA.localeCompare(filePathB);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Then sort by line number
|
|
322
|
+
const lineA = contextA?.line || 0;
|
|
323
|
+
const lineB = contextB?.line || 0;
|
|
324
|
+
|
|
325
|
+
return lineA - lineB;
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
return references
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function typedocGroupToUniform(
|
|
332
|
+
this: Transformer,
|
|
333
|
+
group: DeclarationReflection
|
|
334
|
+
) {
|
|
335
|
+
let ref: Reference | undefined
|
|
336
|
+
|
|
337
|
+
switch (group.kind) {
|
|
338
|
+
case ReflectionKind.Class: {
|
|
339
|
+
ref = jsClassToUniformRef.call(this, group)
|
|
340
|
+
|
|
341
|
+
break
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
case ReflectionKind.Function: {
|
|
345
|
+
ref = jsFunctionToUniformRef.call(this, group)
|
|
346
|
+
|
|
347
|
+
break
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
case ReflectionKind.Interface: {
|
|
351
|
+
ref = jsInterfaceToUniformRef.call(this, group)
|
|
352
|
+
|
|
353
|
+
break
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
case ReflectionKind.Enum: {
|
|
357
|
+
ref = jsEnumToUniformRef.call(this, group)
|
|
358
|
+
|
|
359
|
+
break
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
case ReflectionKind.TypeAlias: {
|
|
363
|
+
ref = jsTypeAliasToUniformRef.call(this, group)
|
|
364
|
+
|
|
365
|
+
break
|
|
366
|
+
}
|
|
367
|
+
default: {
|
|
368
|
+
console.warn('(typedocGroupToUniform): Unhandled reflection kind', group.kind)
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return ref
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function jsClassToUniformRef(
|
|
376
|
+
this: Transformer,
|
|
377
|
+
dec: DeclarationReflection
|
|
378
|
+
) {
|
|
379
|
+
const definitions: Definition[] = []
|
|
380
|
+
|
|
381
|
+
const ref: Reference = {
|
|
382
|
+
title: `Class ${dec.name}`,
|
|
383
|
+
canonical: "",
|
|
384
|
+
description: '',
|
|
385
|
+
context: undefined,
|
|
386
|
+
examples: {
|
|
387
|
+
groups: []
|
|
388
|
+
},
|
|
389
|
+
definitions
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const declarationCtx = declarationUniformContext.call(this, dec)
|
|
393
|
+
if (declarationCtx) {
|
|
394
|
+
ref.context = {
|
|
395
|
+
...ref.context,
|
|
396
|
+
...declarationCtx
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
ref.canonical = uniformCanonical(dec, declarationCtx)
|
|
400
|
+
|
|
401
|
+
if (dec.comment) {
|
|
402
|
+
const description = commentToUniformDescription(dec.comment)
|
|
403
|
+
const group = uniformGroup(declarationCtx)
|
|
404
|
+
|
|
405
|
+
if (ref.context) {
|
|
406
|
+
ref.context.group = [
|
|
407
|
+
...group,
|
|
408
|
+
"Classes"
|
|
409
|
+
]
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
ref.description = description
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// handle constructor
|
|
416
|
+
{
|
|
417
|
+
const constructor = dec.children?.find(child => child.name === 'constructor')
|
|
418
|
+
if (constructor?.signatures?.[0]) {
|
|
419
|
+
const constructorDef: Definition = {
|
|
420
|
+
title: 'Constructor',
|
|
421
|
+
properties: []
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const constructorSign = constructor.signatures[0]
|
|
425
|
+
for (const param of constructorSign.parameters || []) {
|
|
426
|
+
if (!param.type) {
|
|
427
|
+
console.warn('(jsClassToUniformRef): Constructor parameter type not found', param.name)
|
|
428
|
+
continue
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
let description = ""
|
|
432
|
+
if (param.comment) {
|
|
433
|
+
description = commentToUniformDescription(param.comment)
|
|
434
|
+
}
|
|
435
|
+
let uniformType = someTypeToUniform.call(this, param.type)
|
|
436
|
+
let someTypeProps = {}
|
|
437
|
+
if (typeof uniformType === "object") {
|
|
438
|
+
delete uniformType.ofType
|
|
439
|
+
someTypeProps = uniformType
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
constructorDef.properties.push({
|
|
443
|
+
name: param.name,
|
|
444
|
+
type: typeof uniformType === "string" ? uniformType : "",
|
|
445
|
+
description,
|
|
446
|
+
...someTypeProps
|
|
447
|
+
})
|
|
448
|
+
}
|
|
449
|
+
definitions.push(constructorDef)
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// handle methods
|
|
454
|
+
{
|
|
455
|
+
const methods = dec.children?.filter(child =>
|
|
456
|
+
child.kind === ReflectionKind.Method && child.name !== 'constructor'
|
|
457
|
+
) || []
|
|
458
|
+
|
|
459
|
+
if (methods.length > 0) {
|
|
460
|
+
const methodsDef: Definition = {
|
|
461
|
+
title: 'Methods',
|
|
462
|
+
properties: []
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
for (const method of methods) {
|
|
466
|
+
if (!method.signatures?.[0]) continue
|
|
467
|
+
|
|
468
|
+
const methodSign = method.signatures[0]
|
|
469
|
+
let methodDesc = ""
|
|
470
|
+
if (methodSign.comment) {
|
|
471
|
+
methodDesc = commentToUniformDescription(methodSign.comment)
|
|
472
|
+
}
|
|
473
|
+
let type = ""
|
|
474
|
+
let someTypeProps = {}
|
|
475
|
+
if (methodSign.type) {
|
|
476
|
+
if (typeof methodSign.type === "object") {
|
|
477
|
+
someTypeProps = methodSign.type
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
type = typeof methodSign.type === "string" ? methodSign.type : ""
|
|
481
|
+
} else {
|
|
482
|
+
type = "void"
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const property: DefinitionProperty = {
|
|
486
|
+
name: method.name,
|
|
487
|
+
type,
|
|
488
|
+
description: methodDesc,
|
|
489
|
+
...someTypeProps
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (method.comment) {
|
|
493
|
+
const examples = commentToUniformExamples(method.comment)
|
|
494
|
+
if (examples.length > 0) {
|
|
495
|
+
property.examples = examples
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
methodsDef.properties.push(property)
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
definitions.push(methodsDef)
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return ref
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function jsFunctionToUniformRef(
|
|
510
|
+
this: Transformer,
|
|
511
|
+
dec: DeclarationReflection
|
|
512
|
+
) {
|
|
513
|
+
const definitions: Definition[] = []
|
|
514
|
+
const ref: Reference = {
|
|
515
|
+
title: `Function ${dec.name}`,
|
|
516
|
+
canonical: "",
|
|
517
|
+
description: '',
|
|
518
|
+
context: undefined,
|
|
519
|
+
examples: {
|
|
520
|
+
groups: [],
|
|
521
|
+
},
|
|
522
|
+
definitions,
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const declarationCtx = declarationUniformContext.call(this, dec)
|
|
526
|
+
if (declarationCtx) {
|
|
527
|
+
ref.context = {
|
|
528
|
+
...ref.context,
|
|
529
|
+
...declarationCtx
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
ref.canonical = uniformCanonical(dec, declarationCtx)
|
|
533
|
+
|
|
534
|
+
const signatures = dec.signatures || []
|
|
535
|
+
if (signatures.length > 1) {
|
|
536
|
+
console.error('(jsFunctionToUniformRef): Multiple signatures not supported for function declaration', dec.name)
|
|
537
|
+
return
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
for (const sign of dec.signatures || []) {
|
|
541
|
+
{
|
|
542
|
+
if (sign.comment) {
|
|
543
|
+
const description = commentToUniformDescription(sign.comment)
|
|
544
|
+
const group = uniformGroup(declarationCtx)
|
|
545
|
+
|
|
546
|
+
if (ref.context) {
|
|
547
|
+
ref.context.group = [
|
|
548
|
+
...group,
|
|
549
|
+
"Functions"
|
|
550
|
+
]
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
ref.description = description
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// handle returns
|
|
558
|
+
{
|
|
559
|
+
const meta: DefinitionTypeDocMeta[] = [
|
|
560
|
+
{
|
|
561
|
+
name: "type",
|
|
562
|
+
value: "returns"
|
|
563
|
+
}
|
|
564
|
+
]
|
|
565
|
+
|
|
566
|
+
const returnsUniformDef: Definition = {
|
|
567
|
+
title: 'Returns',
|
|
568
|
+
properties: [],
|
|
569
|
+
meta
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (sign.type) {
|
|
573
|
+
let desc = ""
|
|
574
|
+
|
|
575
|
+
if (sign.comment) {
|
|
576
|
+
desc = returnCommentToUniform(sign.comment) || ""
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const uniformType = someTypeToUniform.call(this, sign.type)
|
|
580
|
+
let someTypeProps = {}
|
|
581
|
+
if (typeof uniformType === "object") {
|
|
582
|
+
delete uniformType.ofType
|
|
583
|
+
someTypeProps = uniformType
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
returnsUniformDef.properties.push({
|
|
587
|
+
name: "",
|
|
588
|
+
type: typeof uniformType === "string" ? uniformType : "",
|
|
589
|
+
description: desc,
|
|
590
|
+
...someTypeProps
|
|
591
|
+
})
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
ref.definitions.push(returnsUniformDef)
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// handle parameters
|
|
598
|
+
{
|
|
599
|
+
const meta: DefinitionTypeDocMeta[] = [
|
|
600
|
+
{
|
|
601
|
+
name: "type",
|
|
602
|
+
value: "parameters"
|
|
603
|
+
}
|
|
604
|
+
]
|
|
605
|
+
|
|
606
|
+
const parametersUniformDef: Definition = {
|
|
607
|
+
title: 'Parameters',
|
|
608
|
+
properties: [],
|
|
609
|
+
meta
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
for (const param of sign.parameters || []) {
|
|
613
|
+
if (!param.type) {
|
|
614
|
+
console.warn('(jsFunctionToUniformRef): Parameter type not found', param.name)
|
|
615
|
+
continue
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
let description = ""
|
|
619
|
+
if (param.comment) {
|
|
620
|
+
description = commentToUniformDescription(param.comment)
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const uniformType = someTypeToUniform.call(this, param.type)
|
|
624
|
+
let someTypeProps = {}
|
|
625
|
+
if (typeof uniformType === "object") {
|
|
626
|
+
delete uniformType.ofType
|
|
627
|
+
someTypeProps = uniformType
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const prop: DefinitionProperty = {
|
|
631
|
+
name: param.name,
|
|
632
|
+
type: typeof uniformType === "string" ? uniformType : "",
|
|
633
|
+
description,
|
|
634
|
+
...someTypeProps
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
switch (prop.name) {
|
|
638
|
+
case "__namedParameters": {
|
|
639
|
+
prop.name = ""
|
|
640
|
+
prop.type = DEFINED_DEFINITION_PROPERTY_TYPE.UNION
|
|
641
|
+
// prop.type = "param"
|
|
642
|
+
break
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (param.comment) {
|
|
647
|
+
const examples = commentToUniformExamples(param.comment)
|
|
648
|
+
if (examples.length > 0) {
|
|
649
|
+
prop.examples = examples
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
parametersUniformDef.properties.push(prop)
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
ref.definitions.push(parametersUniformDef)
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
return ref
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function jsInterfaceToUniformRef(
|
|
664
|
+
this: Transformer,
|
|
665
|
+
dec: DeclarationReflection
|
|
666
|
+
) {
|
|
667
|
+
const definitions: Definition[] = []
|
|
668
|
+
|
|
669
|
+
const ref: Reference = {
|
|
670
|
+
title: `Interface ${dec.name}`,
|
|
671
|
+
canonical: "",
|
|
672
|
+
description: '',
|
|
673
|
+
context: undefined,
|
|
674
|
+
examples: {
|
|
675
|
+
groups: []
|
|
676
|
+
},
|
|
677
|
+
definitions
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const declarationCtx = declarationUniformContext.call(this, dec)
|
|
681
|
+
if (declarationCtx) {
|
|
682
|
+
ref.context = {
|
|
683
|
+
...ref.context,
|
|
684
|
+
...declarationCtx
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
ref.canonical = uniformCanonical(dec, declarationCtx)
|
|
688
|
+
|
|
689
|
+
if (dec.comment) {
|
|
690
|
+
const description = commentToUniformDescription(dec.comment)
|
|
691
|
+
const group = uniformGroup(declarationCtx)
|
|
692
|
+
|
|
693
|
+
if (ref.context) {
|
|
694
|
+
ref.context.group = [
|
|
695
|
+
...group,
|
|
696
|
+
"Interfaces"
|
|
697
|
+
]
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
ref.description = description
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// handle properties
|
|
704
|
+
{
|
|
705
|
+
const properties = dec.children?.filter(child =>
|
|
706
|
+
child.kind === ReflectionKind.Property
|
|
707
|
+
) || []
|
|
708
|
+
|
|
709
|
+
if (properties.length > 0) {
|
|
710
|
+
const propertiesDef: Definition = {
|
|
711
|
+
title: 'Properties',
|
|
712
|
+
properties: []
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
for (const prop of properties) {
|
|
716
|
+
if (!prop.type) {
|
|
717
|
+
console.warn('(jsInterfaceToUniformRef): Property type not found', prop.name)
|
|
718
|
+
continue
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
let description = ""
|
|
722
|
+
if (prop.comment) {
|
|
723
|
+
description = commentToUniformDescription(prop.comment)
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const uniformType = someTypeToUniform.call(this, prop.type)
|
|
727
|
+
let someTypeProps = {}
|
|
728
|
+
let meta: DefinitionPropertyMeta[] = []
|
|
729
|
+
if (typeof uniformType === "object") {
|
|
730
|
+
delete uniformType.ofType
|
|
731
|
+
someTypeProps = uniformType
|
|
732
|
+
meta = uniformType.meta || []
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// TODO: unify interfaceToUniformRef with uniformProperties
|
|
736
|
+
if (!prop.flags?.isOptional) {
|
|
737
|
+
meta.push({
|
|
738
|
+
name: "required",
|
|
739
|
+
value: "true"
|
|
740
|
+
})
|
|
741
|
+
}
|
|
742
|
+
if (Array.isArray(prop.comment?.modifierTags) && prop.comment?.modifierTags?.includes("@internal")) {
|
|
743
|
+
meta.push({
|
|
744
|
+
name: "internal",
|
|
745
|
+
value: "true"
|
|
746
|
+
})
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
const property: DefinitionProperty = {
|
|
750
|
+
name: prop.name,
|
|
751
|
+
type: typeof uniformType === "string" ? uniformType : "",
|
|
752
|
+
description,
|
|
753
|
+
...someTypeProps,
|
|
754
|
+
meta
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
if (prop.comment) {
|
|
758
|
+
const examples = commentToUniformExamples(prop.comment)
|
|
759
|
+
if (examples.length > 0) {
|
|
760
|
+
property.examples = examples
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
propertiesDef.properties.push(property)
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
definitions.push(propertiesDef)
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// handle methods
|
|
772
|
+
{
|
|
773
|
+
const methods = dec.children?.filter(child =>
|
|
774
|
+
child.kind === ReflectionKind.Method
|
|
775
|
+
) || []
|
|
776
|
+
|
|
777
|
+
if (methods.length > 0) {
|
|
778
|
+
const methodsDef: Definition = {
|
|
779
|
+
title: 'Methods',
|
|
780
|
+
properties: []
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
for (const method of methods) {
|
|
784
|
+
if (!method.signatures?.[0]) continue
|
|
785
|
+
|
|
786
|
+
const methodSign = method.signatures[0]
|
|
787
|
+
let methodDesc = ""
|
|
788
|
+
if (methodSign.comment) {
|
|
789
|
+
methodDesc = commentToUniformDescription(methodSign.comment)
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
let type = ""
|
|
793
|
+
let someTypeProps = {}
|
|
794
|
+
if (methodSign.type) {
|
|
795
|
+
if (typeof methodSign.type === "object") {
|
|
796
|
+
someTypeProps = methodSign.type
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
type = typeof methodSign.type === "string" ? methodSign.type : ""
|
|
800
|
+
} else {
|
|
801
|
+
type = "void"
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
const property: DefinitionProperty = {
|
|
805
|
+
name: method.name,
|
|
806
|
+
type,
|
|
807
|
+
description: methodDesc,
|
|
808
|
+
...someTypeProps
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
if (method.comment) {
|
|
812
|
+
const examples = commentToUniformExamples(method.comment)
|
|
813
|
+
if (examples.length > 0) {
|
|
814
|
+
property.examples = examples
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
methodsDef.properties.push(property)
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
definitions.push(methodsDef)
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return ref
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function jsTypeAliasToUniformRef(
|
|
829
|
+
this: Transformer,
|
|
830
|
+
dec: DeclarationReflection
|
|
831
|
+
) {
|
|
832
|
+
const definitions: Definition[] = []
|
|
833
|
+
|
|
834
|
+
const ref: Reference = {
|
|
835
|
+
title: `Type ${dec.name}`,
|
|
836
|
+
canonical: "",
|
|
837
|
+
description: '',
|
|
838
|
+
context: undefined,
|
|
839
|
+
examples: {
|
|
840
|
+
groups: []
|
|
841
|
+
},
|
|
842
|
+
definitions,
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
const declarationCtx = declarationUniformContext.call(this, dec)
|
|
846
|
+
if (declarationCtx) {
|
|
847
|
+
ref.context = {
|
|
848
|
+
...ref.context,
|
|
849
|
+
...declarationCtx
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
ref.canonical = uniformCanonical(dec, declarationCtx)
|
|
853
|
+
|
|
854
|
+
if (dec.comment) {
|
|
855
|
+
const description = commentToUniformDescription(dec.comment)
|
|
856
|
+
const group = uniformGroup(declarationCtx)
|
|
857
|
+
|
|
858
|
+
if (ref.context) {
|
|
859
|
+
ref.context.group = [
|
|
860
|
+
...group,
|
|
861
|
+
"Types"
|
|
862
|
+
]
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
ref.description = description
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
if (dec.type && dec.children?.length) {
|
|
869
|
+
console.warn("(jsTypeAliasToUniformRef): Type alias with children is not fully supported, only type definition will be handled", dec.name)
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// handle type definition
|
|
873
|
+
{
|
|
874
|
+
const typeDef: Definition = {
|
|
875
|
+
title: 'Type Definition',
|
|
876
|
+
properties: []
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
let comment = ""
|
|
880
|
+
|
|
881
|
+
if (dec.comment) {
|
|
882
|
+
comment = commentToUniformDescription(dec.comment)
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
if (dec.type) {
|
|
887
|
+
const uniformType = someTypeToUniform.call(this, dec.type)
|
|
888
|
+
let someTypeProps = {}
|
|
889
|
+
if (typeof uniformType === "object") {
|
|
890
|
+
delete uniformType.ofType
|
|
891
|
+
someTypeProps = uniformType
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
const propDefinition: DefinitionProperty = {
|
|
895
|
+
name: "",
|
|
896
|
+
type: typeof uniformType === "string" ? uniformType : "",
|
|
897
|
+
description: comment,
|
|
898
|
+
...someTypeProps
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
typeDef.rootProperty = propDefinition
|
|
902
|
+
} else if (dec?.children?.length) {
|
|
903
|
+
const properties = uniformProperties.call(this, dec)
|
|
904
|
+
|
|
905
|
+
typeDef.properties = properties
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
definitions.push(typeDef)
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
return ref
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function jsEnumToUniformRef(
|
|
915
|
+
this: Transformer,
|
|
916
|
+
dec: DeclarationReflection
|
|
917
|
+
) {
|
|
918
|
+
const definitions: Definition[] = []
|
|
919
|
+
|
|
920
|
+
const ref: Reference = {
|
|
921
|
+
title: `Enum ${dec.name}`,
|
|
922
|
+
canonical: "",
|
|
923
|
+
description: '',
|
|
924
|
+
context: undefined,
|
|
925
|
+
examples: {
|
|
926
|
+
groups: []
|
|
927
|
+
},
|
|
928
|
+
definitions
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
const declarationCtx = declarationUniformContext.call(this, dec)
|
|
932
|
+
if (declarationCtx) {
|
|
933
|
+
ref.context = {
|
|
934
|
+
...ref.context,
|
|
935
|
+
...declarationCtx
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
ref.canonical = uniformCanonical(dec, declarationCtx)
|
|
939
|
+
|
|
940
|
+
if (dec.comment) {
|
|
941
|
+
const description = commentToUniformDescription(dec.comment)
|
|
942
|
+
const group = uniformGroup(declarationCtx)
|
|
943
|
+
|
|
944
|
+
if (ref.context) {
|
|
945
|
+
ref.context.group = [
|
|
946
|
+
...group,
|
|
947
|
+
"Enums"
|
|
948
|
+
]
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
ref.description = description
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// handle enum members
|
|
955
|
+
{
|
|
956
|
+
const members = dec.children?.filter(child =>
|
|
957
|
+
child.kind === ReflectionKind.EnumMember
|
|
958
|
+
) || []
|
|
959
|
+
|
|
960
|
+
if (members.length > 0) {
|
|
961
|
+
const membersDef: Definition = {
|
|
962
|
+
title: 'Members',
|
|
963
|
+
properties: []
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// Sort members by their line number to preserve the original order in the source code
|
|
967
|
+
const sortedMembers = [...members].sort((a, b) => {
|
|
968
|
+
if (!a.sources?.[0]?.line || !b.sources?.[0]?.line) {
|
|
969
|
+
return 0;
|
|
970
|
+
}
|
|
971
|
+
return a.sources[0].line - b.sources[0].line;
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
for (const member of sortedMembers) {
|
|
975
|
+
let description = ""
|
|
976
|
+
if (member.comment) {
|
|
977
|
+
description = commentToUniformDescription(member.comment)
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// Extract the enum member value
|
|
981
|
+
let value = "";
|
|
982
|
+
let type = "number";
|
|
983
|
+
|
|
984
|
+
// Check if the member has a type property with a literal value
|
|
985
|
+
if (member.type && typeof member.type === 'object' && member.type.type === 'literal' && member.type.value !== null) {
|
|
986
|
+
// If the value is a string, it's a string enum
|
|
987
|
+
if (typeof member.type.value === 'string') {
|
|
988
|
+
value = member.type.value;
|
|
989
|
+
type = "string";
|
|
990
|
+
} else {
|
|
991
|
+
// Otherwise it's a number enum
|
|
992
|
+
value = member.type.value.toString();
|
|
993
|
+
type = "number";
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
// Fallback to defaultValue if type is not available
|
|
997
|
+
else if (member.defaultValue !== undefined) {
|
|
998
|
+
value = member.defaultValue.toString();
|
|
999
|
+
// Check if the value is a string (enclosed in quotes)
|
|
1000
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
1001
|
+
type = "string";
|
|
1002
|
+
// Remove the quotes for display
|
|
1003
|
+
value = value.substring(1, value.length - 1);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
const formattedName = `${member.name} (${value})`;
|
|
1008
|
+
|
|
1009
|
+
membersDef.properties.push({
|
|
1010
|
+
name: formattedName,
|
|
1011
|
+
type: type,
|
|
1012
|
+
description
|
|
1013
|
+
})
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
definitions.push(membersDef)
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
return ref
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function declarationUniformContext(
|
|
1024
|
+
this: Transformer,
|
|
1025
|
+
dec: DeclarationReflection,
|
|
1026
|
+
): TypeDocReferenceContext | undefined {
|
|
1027
|
+
if (!dec.sources || !dec.sources.length) {
|
|
1028
|
+
return
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
if (dec.sources.length > 1) {
|
|
1032
|
+
console.warn('(declarationUniformContext): Multiple sources not supported for function declaration', dec.name)
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
const source = dec.sources[0]
|
|
1036
|
+
|
|
1037
|
+
const signTxt = this.signatureTextLoader.signatureText(
|
|
1038
|
+
dec.id,
|
|
1039
|
+
source?.line
|
|
1040
|
+
) || ""
|
|
1041
|
+
|
|
1042
|
+
const sourceCode = this.signatureTextLoader.signatureSourceCode(
|
|
1043
|
+
dec.id,
|
|
1044
|
+
source?.line
|
|
1045
|
+
) || ""
|
|
1046
|
+
|
|
1047
|
+
// Get the symbol map to find the package path
|
|
1048
|
+
const symbolMap = this.project.symbolIdMap[dec.id] as ReflectionSymbolId
|
|
1049
|
+
|
|
1050
|
+
// Use the packagePath directly as it's already relative to the module root
|
|
1051
|
+
const fileFullPath = symbolMap.packagePath
|
|
1052
|
+
|
|
1053
|
+
const meta: TypeDocReferenceContextMeta[] = []
|
|
1054
|
+
|
|
1055
|
+
if (Array.isArray(dec.comment?.modifierTags) && dec.comment?.modifierTags?.includes("@internal")) {
|
|
1056
|
+
meta.push({
|
|
1057
|
+
name: "internal",
|
|
1058
|
+
value: "true"
|
|
1059
|
+
})
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
const ctx: TypeDocReferenceContext = {
|
|
1063
|
+
symbolId: dec.id?.toString(),
|
|
1064
|
+
symbolName: dec.name,
|
|
1065
|
+
symbolKind: dec.kind,
|
|
1066
|
+
packageName: symbolMap?.packageName,
|
|
1067
|
+
fileName: source.fileName,
|
|
1068
|
+
fileFullPath,
|
|
1069
|
+
line: source.line,
|
|
1070
|
+
col: source.character,
|
|
1071
|
+
signatureText: {
|
|
1072
|
+
code: signTxt,
|
|
1073
|
+
lang: "ts",
|
|
1074
|
+
},
|
|
1075
|
+
sourcecode: {
|
|
1076
|
+
code: sourceCode,
|
|
1077
|
+
lang: "ts"
|
|
1078
|
+
},
|
|
1079
|
+
meta,
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
const category = uniformCategory(dec)
|
|
1083
|
+
if (category) {
|
|
1084
|
+
ctx.category = category
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
return ctx
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
type SomeTypeUniform = string | {
|
|
1091
|
+
type?: string;
|
|
1092
|
+
ofType?: string;
|
|
1093
|
+
symbolDef?: SymbolDef;
|
|
1094
|
+
ofProperty?: DefinitionProperty;
|
|
1095
|
+
properties?: DefinitionProperty[];
|
|
1096
|
+
meta?: DefinitionPropertyMeta[];
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
function someTypeToUniform(
|
|
1100
|
+
this: Transformer,
|
|
1101
|
+
someType: SomeType
|
|
1102
|
+
): SomeTypeUniform | string {
|
|
1103
|
+
const meta: DefinitionPropertyMeta[] = []
|
|
1104
|
+
|
|
1105
|
+
if ("target" in someType) {
|
|
1106
|
+
// TODO: better data structure - is there any map for this?
|
|
1107
|
+
for (const child of this?.project?.children || []) {
|
|
1108
|
+
if (String(child.id) === String(someType.target)) {
|
|
1109
|
+
if (Array.isArray(child.comment?.modifierTags) && child.comment?.modifierTags?.includes("@internal")) {
|
|
1110
|
+
meta.push({
|
|
1111
|
+
name: "internal",
|
|
1112
|
+
value: "true"
|
|
1113
|
+
})
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
switch (someType.type) {
|
|
1120
|
+
case "reference": { // e.g ReferenceType
|
|
1121
|
+
let refType = `${someType.qualifiedName || someType.name}`
|
|
1122
|
+
|
|
1123
|
+
if ("target" in someType && typeof someType.target === "number") {
|
|
1124
|
+
return {
|
|
1125
|
+
type: refType,
|
|
1126
|
+
symbolDef: {
|
|
1127
|
+
id: someType.target?.toString()
|
|
1128
|
+
},
|
|
1129
|
+
meta
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
// Handle generic types like Record with typeArguments
|
|
1134
|
+
if ("typeArguments" in someType && someType.typeArguments) {
|
|
1135
|
+
const typeArgs = someType.typeArguments.map(arg => {
|
|
1136
|
+
const argType = someTypeToUniform.call(this, arg)
|
|
1137
|
+
return typeof argType === "string" ? argType : argType.type || ""
|
|
1138
|
+
})
|
|
1139
|
+
refType = `${refType}<${typeArgs.join(", ")}>`
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
return refType
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
case "union": { // e.g type | type2
|
|
1146
|
+
const resp = unionLikeSomeType.call(this, someType.types)
|
|
1147
|
+
|
|
1148
|
+
if (typeof resp === "string") {
|
|
1149
|
+
return resp
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
return {
|
|
1153
|
+
...resp,
|
|
1154
|
+
meta: [
|
|
1155
|
+
...(resp.meta || []),
|
|
1156
|
+
...meta
|
|
1157
|
+
]
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
case "literal": { // primitive types or string literals
|
|
1162
|
+
if (typeof someType.value === "string") { // e.g `"opener"`
|
|
1163
|
+
return `"${someType.value}"`
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
return (someType.value || "").toString() // e.g `123` or `true`
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
case "reflection": { // inline like {something: true}
|
|
1170
|
+
const properties = uniformProperties.call(this, someType.declaration)
|
|
1171
|
+
|
|
1172
|
+
let type = ""
|
|
1173
|
+
|
|
1174
|
+
if (someType.declaration.indexSignatures?.length || someType.declaration.children?.length) {
|
|
1175
|
+
type = this.signatureTextLoader.signatureText(
|
|
1176
|
+
someType.declaration.id,
|
|
1177
|
+
someType.declaration.sources?.[0]?.line || 0,
|
|
1178
|
+
{
|
|
1179
|
+
typeOnly: true,
|
|
1180
|
+
}
|
|
1181
|
+
) || ""
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
if (someType.declaration.indexSignatures?.length) {
|
|
1185
|
+
if (properties.length > 1) {
|
|
1186
|
+
console.warn('(someTypeToUniform): Reflection type with multiple properties, using first one as ofProperty', someType.declaration.name)
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
return {
|
|
1190
|
+
type: DEFINED_DEFINITION_PROPERTY_TYPE.UNION,
|
|
1191
|
+
properties: [],
|
|
1192
|
+
meta,
|
|
1193
|
+
ofProperty: {
|
|
1194
|
+
name: "",
|
|
1195
|
+
type,
|
|
1196
|
+
description: "",
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
return {
|
|
1202
|
+
type,
|
|
1203
|
+
properties,
|
|
1204
|
+
meta
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
case "array": { // e.g type[]
|
|
1209
|
+
const arrayItemType = someTypeToUniform.call(this, someType.elementType)
|
|
1210
|
+
|
|
1211
|
+
if (typeof arrayItemType === "string") {
|
|
1212
|
+
return {
|
|
1213
|
+
type: arrayItemType + "[]",
|
|
1214
|
+
meta,
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
return {
|
|
1219
|
+
ofType: (arrayItemType.type || "") + "[]",
|
|
1220
|
+
type: DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY,
|
|
1221
|
+
ofProperty: {
|
|
1222
|
+
name: "",
|
|
1223
|
+
description: "",
|
|
1224
|
+
type: (arrayItemType.type || ""),
|
|
1225
|
+
properties: [],
|
|
1226
|
+
symbolDef: arrayItemType.symbolDef
|
|
1227
|
+
},
|
|
1228
|
+
meta,
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
case "tuple": { // e.g [type, type2]
|
|
1233
|
+
const elements = someType.elements || []
|
|
1234
|
+
const elementTypes = elements.map(element => someTypeToUniform.call(this, element))
|
|
1235
|
+
|
|
1236
|
+
const tupleType = `[${elementTypes.map(t => typeof t === "string" ? t : t.type || "").join(", ")}]`
|
|
1237
|
+
|
|
1238
|
+
// 1. collect all symbol definitions from tuple elements
|
|
1239
|
+
const symbolIds: string[] = []
|
|
1240
|
+
for (const t of elementTypes) {
|
|
1241
|
+
if (typeof t === "object" && t.symbolDef?.id) {
|
|
1242
|
+
if (Array.isArray(t.symbolDef.id)) {
|
|
1243
|
+
symbolIds.push(...t.symbolDef.id)
|
|
1244
|
+
} else {
|
|
1245
|
+
symbolIds.push(t.symbolDef.id)
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
return {
|
|
1251
|
+
type: tupleType,
|
|
1252
|
+
symbolDef: symbolIds.length > 0 ? {id: symbolIds} : undefined,
|
|
1253
|
+
meta
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
case "intersection": { // e.g type & type2
|
|
1258
|
+
const resp = unionLikeSomeType.call(this, someType.types)
|
|
1259
|
+
|
|
1260
|
+
if (typeof resp === "string") {
|
|
1261
|
+
return resp
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
return {
|
|
1265
|
+
...resp,
|
|
1266
|
+
meta: [
|
|
1267
|
+
...(resp.meta || []),
|
|
1268
|
+
...meta
|
|
1269
|
+
]
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
case "rest": {
|
|
1274
|
+
const resp = someTypeToUniform.call(this, someType.elementType)
|
|
1275
|
+
|
|
1276
|
+
if (typeof resp === "string") {
|
|
1277
|
+
return `${resp}[]`
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
return {
|
|
1281
|
+
...resp,
|
|
1282
|
+
type: `${resp.type || ""}[]`,
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
default: {
|
|
1287
|
+
if (!("name" in someType)) {
|
|
1288
|
+
console.warn('SomeType does not have name property', someType.type)
|
|
1289
|
+
return ""
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
return someType.name
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
return ""
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
function unionLikeSomeType(this: Transformer, someTypes: SomeType[]): SomeTypeUniform | string {
|
|
1300
|
+
let types: string[] = []
|
|
1301
|
+
const symbolIds: string[] = []
|
|
1302
|
+
|
|
1303
|
+
for (const t of someTypes) {
|
|
1304
|
+
const tUniform = someTypeToUniform.call(this, t)
|
|
1305
|
+
|
|
1306
|
+
if (typeof tUniform === "object") {
|
|
1307
|
+
// TODO: IN THE FUTURE CREATE AUDIENCES TO UNLOCK INTERNAL TYPES
|
|
1308
|
+
if (tUniform.meta?.some(m => m.name === "internal" && m.value === "true")) {
|
|
1309
|
+
continue
|
|
1310
|
+
}
|
|
1311
|
+
// If it's a tuple type, don't split it
|
|
1312
|
+
if (tUniform.type?.startsWith('[') && tUniform.type?.endsWith(']')) {
|
|
1313
|
+
types.push(tUniform.type)
|
|
1314
|
+
} else {
|
|
1315
|
+
types.push(tUniform.ofType || tUniform.type || "")
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
if (tUniform?.symbolDef?.id) {
|
|
1319
|
+
if (Array.isArray(tUniform?.symbolDef?.id)) {
|
|
1320
|
+
symbolIds.push(...tUniform.symbolDef?.id)
|
|
1321
|
+
} else {
|
|
1322
|
+
symbolIds.push(tUniform.symbolDef.id)
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
delete tUniform.ofType
|
|
1327
|
+
} else {
|
|
1328
|
+
types.push(tUniform)
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
return {
|
|
1333
|
+
type: types.filter(Boolean).join(" | "),
|
|
1334
|
+
symbolDef: {
|
|
1335
|
+
id: symbolIds,
|
|
1336
|
+
},
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
function commentToUniformDescription(comment: Comment): string {
|
|
1341
|
+
let desc = ""
|
|
1342
|
+
|
|
1343
|
+
for (const summary of comment?.summary || []) {
|
|
1344
|
+
desc += `${summary.text}\n`
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
return desc
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
function commentToUniformExamples(comment: Comment): string[] {
|
|
1351
|
+
if (!comment.blockTags || !comment.blockTags.length) {
|
|
1352
|
+
return []
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
const examples: string[] = []
|
|
1356
|
+
|
|
1357
|
+
for (const tag of comment.blockTags) {
|
|
1358
|
+
if (tag.tag === "@example") {
|
|
1359
|
+
for (const content of tag.content || []) {
|
|
1360
|
+
if (content.kind === "code") {
|
|
1361
|
+
// Remove the ```ts and ``` markers from the code block
|
|
1362
|
+
const code = content.text.replace(/```ts\n|\n```/g, '')
|
|
1363
|
+
examples.push(code)
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
return examples
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
function uniformCategory(dec?: DeclarationReflection): string {
|
|
1373
|
+
if (!dec) {
|
|
1374
|
+
return ""
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
let category = ""
|
|
1378
|
+
for (const signature of dec.signatures || []) {
|
|
1379
|
+
if (signature.comment) {
|
|
1380
|
+
const comment = signature.comment
|
|
1381
|
+
if (comment.blockTags) {
|
|
1382
|
+
for (const tag of comment.blockTags) {
|
|
1383
|
+
if (tag.tag === "@category") {
|
|
1384
|
+
for (const content of tag.content || []) {
|
|
1385
|
+
category += content.text
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
return category
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
function returnCommentToUniform(comment: Comment): string {
|
|
1397
|
+
if (!comment.blockTags || !comment.blockTags.length) {
|
|
1398
|
+
return ""
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
let desc = ""
|
|
1402
|
+
for (const tag of comment.blockTags) {
|
|
1403
|
+
if (tag.tag === "@returns") {
|
|
1404
|
+
for (const content of tag.content || []) {
|
|
1405
|
+
desc += `${content.text}\n`
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
return desc
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
function uniformProperties(
|
|
1414
|
+
this: Transformer,
|
|
1415
|
+
dec: DeclarationReflection
|
|
1416
|
+
): DefinitionProperty[] {
|
|
1417
|
+
const properties: DefinitionProperty[] = []
|
|
1418
|
+
|
|
1419
|
+
for (const prop of dec.children || []) {
|
|
1420
|
+
if (!prop.type) {
|
|
1421
|
+
console.warn('(uniformProperties): Property type not found', prop.name)
|
|
1422
|
+
continue
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
let description = ""
|
|
1426
|
+
if (prop.comment) {
|
|
1427
|
+
description = commentToUniformDescription(prop.comment)
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
const uniformType = someTypeToUniform.call(this, prop.type)
|
|
1431
|
+
let meta: DefinitionPropertyMeta[] = []
|
|
1432
|
+
|
|
1433
|
+
let someTypeProps = {}
|
|
1434
|
+
if (typeof uniformType === "object") {
|
|
1435
|
+
delete uniformType.ofType
|
|
1436
|
+
someTypeProps = uniformType
|
|
1437
|
+
|
|
1438
|
+
meta = uniformType.meta || []
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
if (!prop.flags?.isOptional) {
|
|
1442
|
+
meta.push({
|
|
1443
|
+
name: "required",
|
|
1444
|
+
value: "true"
|
|
1445
|
+
})
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
if (Array.isArray(prop.comment?.modifierTags) && prop.comment?.modifierTags?.includes("@internal")) {
|
|
1449
|
+
meta.push({
|
|
1450
|
+
name: "internal",
|
|
1451
|
+
value: "true"
|
|
1452
|
+
})
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
const property: DefinitionProperty = {
|
|
1456
|
+
name: prop.name,
|
|
1457
|
+
type: typeof uniformType === "string" ? uniformType : "",
|
|
1458
|
+
description,
|
|
1459
|
+
...someTypeProps,
|
|
1460
|
+
meta
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
if (prop.comment) {
|
|
1464
|
+
const examples = commentToUniformExamples(prop.comment)
|
|
1465
|
+
if (examples.length > 0) {
|
|
1466
|
+
property.examples = examples
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
properties.push(property)
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
return properties
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
function uniformGroup(ctx?: TypeDocReferenceContext): string[] {
|
|
1477
|
+
if (!ctx) {
|
|
1478
|
+
return []
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
const group = ctx.packageName.split("/")
|
|
1482
|
+
|
|
1483
|
+
return group
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
function uniformCanonical(dec: DeclarationReflection, ctx?: TypeDocReferenceContext): string {
|
|
1487
|
+
const parts: string[] = []
|
|
1488
|
+
if (ctx?.packageName) {
|
|
1489
|
+
parts.push(ctx.packageName)
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
switch (dec.kind) {
|
|
1493
|
+
case ReflectionKind.Class: {
|
|
1494
|
+
parts.push("classes", dec.name)
|
|
1495
|
+
break
|
|
1496
|
+
}
|
|
1497
|
+
case ReflectionKind.Interface: {
|
|
1498
|
+
parts.push("interfaces", dec.name)
|
|
1499
|
+
break
|
|
1500
|
+
}
|
|
1501
|
+
case ReflectionKind.Function: {
|
|
1502
|
+
parts.push("functions", dec.name)
|
|
1503
|
+
break
|
|
1504
|
+
}
|
|
1505
|
+
case ReflectionKind.TypeAlias: {
|
|
1506
|
+
parts.push("types", dec.name)
|
|
1507
|
+
break
|
|
1508
|
+
}
|
|
1509
|
+
case ReflectionKind.Enum: {
|
|
1510
|
+
parts.push("enums", dec.name)
|
|
1511
|
+
break
|
|
1512
|
+
}
|
|
1513
|
+
default: {
|
|
1514
|
+
return ""
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
return parts.join("/")
|
|
1519
|
+
}
|