@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.
Files changed (97) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/ISSUES.md +10 -0
  3. package/LICENSE +21 -0
  4. package/README.md +3 -0
  5. package/TODO.md +9 -0
  6. package/__fixtures__/-1.typescript/package.json +5 -0
  7. package/__fixtures__/-1.typescript/src/index.ts +0 -0
  8. package/__fixtures__/-1.typescript/src/settings.ts +592 -0
  9. package/__fixtures__/-1.typescript/tsconfig.json +8 -0
  10. package/__fixtures__/-2.react.basic/1.flat-interface.output.json +114 -0
  11. package/__fixtures__/-2.react.basic/2.file-connect-interface.output.json +60 -0
  12. package/__fixtures__/-2.react.basic/2a.file-connect-interface-advanced.output.json +92 -0
  13. package/__fixtures__/-2.react.basic/3.props-as-variants.output.json +166 -0
  14. package/__fixtures__/-2.react.basic/4.outside-interface.output.json +60 -0
  15. package/__fixtures__/-2.react.basic/5.inline-props.output.json +60 -0
  16. package/__fixtures__/-2.react.basic/5.outside-inline-props.output.json +60 -0
  17. package/__fixtures__/-2.react.basic/5a.inline-props+outside.output.json +60 -0
  18. package/__fixtures__/-2.react.basic/5b.inline-props+interfaces.output.json +92 -0
  19. package/__fixtures__/-2.react.basic/package.json +4 -0
  20. package/__fixtures__/-2.react.basic/src/1.flat-interface.tsx +41 -0
  21. package/__fixtures__/-2.react.basic/src/2.file-connect-interface.tsx +28 -0
  22. package/__fixtures__/-2.react.basic/src/2a.file-connect-interace+advanced.tsx +54 -0
  23. package/__fixtures__/-2.react.basic/src/3.props-as-variants.tsx +67 -0
  24. package/__fixtures__/-2.react.basic/src/4.outside-interface.tsx +13 -0
  25. package/__fixtures__/-2.react.basic/src/4.outside-interface2.ts +15 -0
  26. package/__fixtures__/-2.react.basic/src/5.inline-props.tsx +19 -0
  27. package/__fixtures__/-2.react.basic/src/5a.inline-props+outside.tsx +19 -0
  28. package/__fixtures__/-2.react.basic/src/5b.inline-props+interfaces.tsx +62 -0
  29. package/__fixtures__/-2.react.basic/src/index.ts +0 -0
  30. package/__fixtures__/-2.react.basic/tsconfig.json +8 -0
  31. package/__tests__/sourcesToUniform.test.ts +167 -0
  32. package/__tests__/testResolvePropertySymbol.ts +838 -0
  33. package/__tests__/types.ts +12 -0
  34. package/__tests__/utils.ts +108 -0
  35. package/dist/index.cjs +2 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +2 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/react.cjs +237 -0
  42. package/dist/react.cjs.map +1 -0
  43. package/dist/react.d.cts +6 -0
  44. package/dist/react.d.ts +6 -0
  45. package/dist/react.js +212 -0
  46. package/dist/react.js.map +1 -0
  47. package/dist/ts.cjs +1794 -0
  48. package/dist/ts.cjs.map +1 -0
  49. package/dist/ts.d.cts +14 -0
  50. package/dist/ts.d.ts +14 -0
  51. package/dist/ts.js +1760 -0
  52. package/dist/ts.js.map +1 -0
  53. package/package.json +41 -0
  54. package/packages/react/index.ts +1 -0
  55. package/packages/react/uniformToReactUniform.ts +275 -0
  56. package/packages/ts/SignatureText.ts +233 -0
  57. package/packages/ts/TypeDocTransformer.ts +1519 -0
  58. package/packages/ts/__fixtures__/packages/package-a/package.json +4 -0
  59. package/packages/ts/__fixtures__/packages/package-a/src/index.ts +56 -0
  60. package/packages/ts/__fixtures__/packages/package-a/tsconfig.json +23 -0
  61. package/packages/ts/__fixtures__/packages/package-b/package.json +7 -0
  62. package/packages/ts/__fixtures__/packages/package-b/src/billing.ts +193 -0
  63. package/packages/ts/__fixtures__/packages/package-b/src/index.ts +8 -0
  64. package/packages/ts/__fixtures__/packages/package-b/tsconfig.json +20 -0
  65. package/packages/ts/__fixtures__/packages2/package-a/package.json +4 -0
  66. package/packages/ts/__fixtures__/packages2/package-a/src/index.ts +496 -0
  67. package/packages/ts/__fixtures__/packages2/package-a/tsconfig.json +6 -0
  68. package/packages/ts/__fixtures__/packages3/package-a/package.json +4 -0
  69. package/packages/ts/__fixtures__/packages3/package-a/src/index.ts +488 -0
  70. package/packages/ts/__fixtures__/packages3/package-a/tsconfig.json +6 -0
  71. package/packages/ts/__fixtures__/packages3/project.json +171 -0
  72. package/packages/ts/__fixtures__/react/react-a/package.json +5 -0
  73. package/packages/ts/__fixtures__/react/react-a/src/TestAbc.tsx +90 -0
  74. package/packages/ts/__fixtures__/react/react-a/src/TestBasic.tsx +27 -0
  75. package/packages/ts/__fixtures__/react/react-a/src/TestNamedParameters.tsx +27 -0
  76. package/packages/ts/__fixtures__/react/react-a/src/TestNamedParameters2.tsx +26 -0
  77. package/packages/ts/__fixtures__/react/react-a/src/TestUnion.tsx +32 -0
  78. package/packages/ts/__fixtures__/react/react-a/src/index.ts +1 -0
  79. package/packages/ts/__fixtures__/react/react-a/tsconfig.json +8 -0
  80. package/packages/ts/__fixtures__/references-output-project.json +344 -0
  81. package/packages/ts/__fixtures__/references-output-react.json +68 -0
  82. package/packages/ts/__fixtures__/references-output.json +129 -0
  83. package/packages/ts/__tests__/sourcesToUniform.test.ts +106 -0
  84. package/packages/ts/context.ts +0 -0
  85. package/packages/ts/converterts/ts-class.ts +0 -0
  86. package/packages/ts/converterts/ts-enum.ts +0 -0
  87. package/packages/ts/converterts/ts-function.ts +0 -0
  88. package/packages/ts/converterts/ts-interface.ts +0 -0
  89. package/packages/ts/converterts/ts-type.ts +0 -0
  90. package/packages/ts/index.ts +129 -0
  91. package/packages/ts/ts-core.ts +0 -0
  92. package/packages/ts/uniformToMiniUniform.ts +486 -0
  93. package/src/index.ts +0 -0
  94. package/test-cmd/index.ts +62 -0
  95. package/tsconfig.json +38 -0
  96. package/tsup.config.ts +39 -0
  97. package/vitest.config.ts +34 -0
package/dist/ts.js ADDED
@@ -0,0 +1,1760 @@
1
+ // packages/ts/index.ts
2
+ import * as path2 from "path";
3
+ import { resolve as resolve2 } from "path";
4
+ import ts2 from "typescript";
5
+ import * as TypeDoc from "typedoc";
6
+
7
+ // packages/ts/TypeDocTransformer.ts
8
+ import * as fs2 from "fs";
9
+ import * as path from "path";
10
+ import { ReflectionKind } from "typedoc";
11
+ import { DEFINED_DEFINITION_PROPERTY_TYPE } from "@xyd-js/uniform";
12
+
13
+ // packages/ts/SignatureText.ts
14
+ import * as ts from "typescript";
15
+ import * as fs from "fs";
16
+ var printer = ts.createPrinter({ removeComments: true });
17
+ var SignatureTextLoader = class {
18
+ constructor(sourcePath) {
19
+ const source = fs.readFileSync(sourcePath, "utf-8");
20
+ this.sourceFile = ts.createSourceFile(
21
+ sourcePath,
22
+ source,
23
+ ts.ScriptTarget.Latest,
24
+ true
25
+ );
26
+ }
27
+ };
28
+ var MultiSignatureLoader = class {
29
+ constructor() {
30
+ this.loaders = /* @__PURE__ */ new Map();
31
+ }
32
+ load(path3) {
33
+ if (this.loaders.has(path3)) {
34
+ return this.loaders.get(path3);
35
+ }
36
+ const loader = new SignatureTextLoader(path3);
37
+ this.loaders.set(path3, loader);
38
+ return loader;
39
+ }
40
+ };
41
+ function signatureTextByLine(sign, targetLine, options) {
42
+ return signatureText.call(sign, targetLine, options);
43
+ }
44
+ function signatureSourceCodeByLine(sign, targetLine) {
45
+ return signatureSourceCode.call(sign, targetLine);
46
+ }
47
+ function signatureText(targetLine, options) {
48
+ const sourceFile = this.sourceFile;
49
+ const signatureNode = findSignatureNode.call(
50
+ this,
51
+ sourceFile,
52
+ [targetLine]
53
+ );
54
+ if (!signatureNode) {
55
+ console.error("(signatureText): `signatureNode` is empty, something went wrong");
56
+ return;
57
+ }
58
+ const printableSignatureNode = nodeToPrintableSignatureNode(signatureNode, options == null ? void 0 : options.typeOnly);
59
+ if (!printableSignatureNode) {
60
+ console.error("(signatureText): cannot convert `signatureNode` to `printableSignatureNode`");
61
+ return;
62
+ }
63
+ return printer.printNode(ts.EmitHint.Unspecified, printableSignatureNode, sourceFile).trim();
64
+ }
65
+ function findSignatureNode(node, targetLines) {
66
+ let isSourceFile = false;
67
+ if (node === node.getSourceFile()) {
68
+ isSourceFile = true;
69
+ }
70
+ if (!isSourceFile && isNodeAtLine(node, targetLines, this.sourceFile)) {
71
+ return node;
72
+ }
73
+ let signatureNode;
74
+ ts.forEachChild(node, (n) => {
75
+ if (signatureNode) {
76
+ return;
77
+ }
78
+ signatureNode = findSignatureNode.call(this, n, targetLines);
79
+ });
80
+ return signatureNode;
81
+ }
82
+ function signatureSourceCode(targetLine) {
83
+ const sourceFile = this.sourceFile;
84
+ const signatureNode = findSignatureNode.call(
85
+ this,
86
+ sourceFile,
87
+ [targetLine]
88
+ );
89
+ if (!signatureNode) {
90
+ console.error("(signatureSourceCode): `signatureNode` is empty, something went wrong");
91
+ return;
92
+ }
93
+ const start = signatureNode.getStart(sourceFile);
94
+ const end = signatureNode.getEnd();
95
+ return sourceFile.text.substring(start, end).trim();
96
+ }
97
+ function nodeToPrintableSignatureNode(node, typeOnly = false) {
98
+ if (typeOnly) {
99
+ if ("type" in node) {
100
+ return node.type;
101
+ }
102
+ return;
103
+ }
104
+ let resp;
105
+ if (ts.isFunctionDeclaration(node)) {
106
+ resp = ts.factory.updateFunctionDeclaration(
107
+ node,
108
+ node.modifiers,
109
+ node.asteriskToken,
110
+ node.name,
111
+ node.typeParameters,
112
+ node.parameters,
113
+ node.type,
114
+ void 0
115
+ );
116
+ } else if (ts.isClassDeclaration(node)) {
117
+ resp = ts.factory.updateClassDeclaration(
118
+ node,
119
+ node.modifiers,
120
+ node.name,
121
+ node.typeParameters,
122
+ node.heritageClauses,
123
+ []
124
+ );
125
+ } else if (ts.isInterfaceDeclaration(node)) {
126
+ resp = ts.factory.updateInterfaceDeclaration(
127
+ node,
128
+ node.modifiers,
129
+ node.name,
130
+ node.typeParameters,
131
+ node.heritageClauses,
132
+ []
133
+ );
134
+ } else if (ts.isEnumDeclaration(node)) {
135
+ resp = ts.factory.updateEnumDeclaration(
136
+ node,
137
+ node.modifiers,
138
+ node.name,
139
+ []
140
+ );
141
+ } else if (ts.isTypeAliasDeclaration(node)) {
142
+ resp = ts.factory.updateTypeAliasDeclaration(
143
+ node,
144
+ node.modifiers,
145
+ node.name,
146
+ node.typeParameters,
147
+ node.type
148
+ );
149
+ } else if (ts.isPropertySignature(node)) {
150
+ resp = ts.factory.updatePropertySignature(
151
+ node,
152
+ node.modifiers,
153
+ node.name,
154
+ node.questionToken,
155
+ node.type
156
+ );
157
+ } else {
158
+ resp = node;
159
+ }
160
+ if (!resp) {
161
+ console.error("(nodeToPrintableSignatureNode): resp is empty, something went wrong");
162
+ return;
163
+ }
164
+ return resp;
165
+ }
166
+ function isNodeAtLine(node, lines, sf) {
167
+ const { line: startLine } = sf.getLineAndCharacterOfPosition(node.getStart());
168
+ return lines.includes(startLine + 1);
169
+ }
170
+
171
+ // packages/ts/TypeDocTransformer.ts
172
+ var TypeDocSignatureTextLoader = class extends MultiSignatureLoader {
173
+ constructor(project, packagePathMap) {
174
+ super();
175
+ this.project = project;
176
+ this.packagePathMap = packagePathMap;
177
+ }
178
+ signatureText(id, line, options) {
179
+ const loader = this.getSignatuerLoader(id);
180
+ if (!loader) {
181
+ return;
182
+ }
183
+ const signTxt = signatureTextByLine(loader, line, options);
184
+ if (!signTxt) {
185
+ console.warn("(TypeDocSignatureTextLoader.signatureText): Signature text is empty", id);
186
+ return;
187
+ }
188
+ return signTxt;
189
+ }
190
+ signatureSourceCode(id, line) {
191
+ const loader = this.getSignatuerLoader(id);
192
+ if (!loader) {
193
+ return;
194
+ }
195
+ const sourceCode = signatureSourceCodeByLine(loader, line);
196
+ if (!sourceCode) {
197
+ console.warn("(TypeDocSignatureTextLoader.signatureSourceCode): Source code is empty", id);
198
+ return;
199
+ }
200
+ return sourceCode;
201
+ }
202
+ getSignatuerLoader(id) {
203
+ const symbolMap = this.project.symbolIdMap[id];
204
+ if (!symbolMap) {
205
+ console.warn("(TypeDocSignatureTextLoader.getSignatuerLoader): Symbol not found", id);
206
+ return;
207
+ }
208
+ const fullPath = this.packagePathMap[id];
209
+ if (!fullPath) {
210
+ console.warn("(TypeDocSignatureTextLoader.getSignatuerLoader): Package path not found for symbol", symbolMap.packageName);
211
+ return;
212
+ }
213
+ const loader = this.load(fullPath);
214
+ if (!loader) {
215
+ console.warn("(TypeDocSignatureTextLoader.getSignatuerLoader): Loader not found", fullPath);
216
+ return;
217
+ }
218
+ return loader;
219
+ }
220
+ };
221
+ var Transformer = class {
222
+ constructor(rootPath, project, references = []) {
223
+ this.rootPath = rootPath;
224
+ this.project = project;
225
+ this.references = references;
226
+ this.packagePathMap = {};
227
+ const packagePathMap = this.createPackagePathMap();
228
+ if (packagePathMap) {
229
+ this.packagePathMap = packagePathMap;
230
+ }
231
+ }
232
+ createPackagePathMap() {
233
+ const packagePathMap = {};
234
+ const packageJsonPaths = this.findPackageJsonPaths(this.rootPath);
235
+ if (!packageJsonPaths.length) {
236
+ console.warn("(Transformer.createPackagePathMap): No package.json found in rootPath", this.rootPath);
237
+ return { packageMap: null, moduleRootMap: null };
238
+ }
239
+ for (const packageJsonPath of packageJsonPaths) {
240
+ const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
241
+ const packageName = packageJson.name;
242
+ const moduleRoot = path.dirname(packageJsonPath);
243
+ if (!packageName) {
244
+ console.warn("(Transformer.createPackagePathMap): Package name not found in package.json", packageJsonPath);
245
+ continue;
246
+ }
247
+ for (const id in this.project.symbolIdMap) {
248
+ const symbolMap = this.project.symbolIdMap[id];
249
+ if (symbolMap.packageName === packageName) {
250
+ const fullPath = path.join(moduleRoot, symbolMap.packagePath);
251
+ packagePathMap[Number.parseInt(id)] = fullPath;
252
+ }
253
+ }
254
+ }
255
+ return packagePathMap;
256
+ }
257
+ findPackageJsonPaths(dir) {
258
+ let results = [];
259
+ const list = fs2.readdirSync(dir);
260
+ for (const file of list) {
261
+ const filePath = path.join(dir, file);
262
+ const stat = fs2.statSync(filePath);
263
+ if (stat && stat.isDirectory()) {
264
+ if (file === "node_modules") {
265
+ continue;
266
+ }
267
+ results = results.concat(this.findPackageJsonPaths(filePath));
268
+ } else if (file === "package.json") {
269
+ results.push(filePath);
270
+ }
271
+ }
272
+ return results;
273
+ }
274
+ };
275
+ function typedocToUniform(rootPath, project) {
276
+ const references = [];
277
+ const transformer = new Transformer(
278
+ rootPath,
279
+ project,
280
+ references
281
+ );
282
+ const signatureTextLoader = new TypeDocSignatureTextLoader(
283
+ project,
284
+ transformer.packagePathMap
285
+ );
286
+ transformer.signatureTextLoader = signatureTextLoader;
287
+ if (project.kind !== ReflectionKind.Project) {
288
+ throw new Error("Project reflection expected");
289
+ }
290
+ for (const child of project.children || []) {
291
+ if (!("kind" in child)) {
292
+ throw new Error("(typedocToUniform): Child reflection expected in project childrens");
293
+ }
294
+ if (typeof child.kind != "number") {
295
+ throw new Error("(typedocToUniform): Child reflection kind expected to be a number");
296
+ }
297
+ if (!child.kind) {
298
+ throw new Error("(typedocToUniform): Child reflection kind expected to be a valid ReflectionKind");
299
+ }
300
+ const kind = child.kind;
301
+ switch (kind) {
302
+ case ReflectionKind.Module: {
303
+ const container = child;
304
+ for (const group of container.children || []) {
305
+ const ref = typedocGroupToUniform.call(
306
+ transformer,
307
+ group
308
+ );
309
+ if (!ref) {
310
+ continue;
311
+ }
312
+ ref.context = {
313
+ ...ref.context,
314
+ packageName: container.name
315
+ };
316
+ references.push(ref);
317
+ }
318
+ break;
319
+ }
320
+ case ReflectionKind.Function:
321
+ case ReflectionKind.Class:
322
+ case ReflectionKind.Interface: {
323
+ if (!("kind" in child) || child.kind !== ReflectionKind.Function && child.kind !== ReflectionKind.Class && child.kind !== ReflectionKind.Interface) {
324
+ throw new Error("(typedocToUniform): Function/Class/Interface reflection expected to be a DeclarationReflection");
325
+ }
326
+ const ref = typedocGroupToUniform.call(
327
+ transformer,
328
+ child
329
+ );
330
+ if (!ref) {
331
+ break;
332
+ }
333
+ ref.context = {
334
+ ...ref.context,
335
+ packageName: project.name
336
+ };
337
+ references.push(ref);
338
+ break;
339
+ }
340
+ case ReflectionKind.TypeAlias: {
341
+ if (!("kind" in child) || child.kind !== ReflectionKind.TypeAlias) {
342
+ throw new Error("(typedocToUniform): Type alias reflection expected to be a DeclarationReflection");
343
+ }
344
+ const ref = jsTypeAliasToUniformRef.call(
345
+ transformer,
346
+ child
347
+ );
348
+ if (!ref) {
349
+ break;
350
+ }
351
+ ref.context = {
352
+ ...ref.context,
353
+ packageName: project.name
354
+ };
355
+ references.push(ref);
356
+ break;
357
+ }
358
+ case ReflectionKind.Enum: {
359
+ if (!("kind" in child) || child.kind !== ReflectionKind.Enum) {
360
+ throw new Error("(typedocToUniform): Enum reflection expected to be a DeclarationReflection");
361
+ }
362
+ const ref = jsEnumToUniformRef.call(
363
+ transformer,
364
+ child
365
+ );
366
+ if (!ref) {
367
+ break;
368
+ }
369
+ ref.context = {
370
+ ...ref.context,
371
+ packageName: project.name
372
+ };
373
+ references.push(ref);
374
+ break;
375
+ }
376
+ default: {
377
+ console.warn("(typedocToUniform): Another children project kind not supported", child.kind);
378
+ }
379
+ }
380
+ }
381
+ references.sort((a, b) => {
382
+ const contextA = a.context;
383
+ const contextB = b.context;
384
+ const filePathA = (contextA == null ? void 0 : contextA.fileFullPath) || "";
385
+ const filePathB = (contextB == null ? void 0 : contextB.fileFullPath) || "";
386
+ if (filePathA !== filePathB) {
387
+ return filePathA.localeCompare(filePathB);
388
+ }
389
+ const lineA = (contextA == null ? void 0 : contextA.line) || 0;
390
+ const lineB = (contextB == null ? void 0 : contextB.line) || 0;
391
+ return lineA - lineB;
392
+ });
393
+ return references;
394
+ }
395
+ function typedocGroupToUniform(group) {
396
+ let ref;
397
+ switch (group.kind) {
398
+ case ReflectionKind.Class: {
399
+ ref = jsClassToUniformRef.call(this, group);
400
+ break;
401
+ }
402
+ case ReflectionKind.Function: {
403
+ ref = jsFunctionToUniformRef.call(this, group);
404
+ break;
405
+ }
406
+ case ReflectionKind.Interface: {
407
+ ref = jsInterfaceToUniformRef.call(this, group);
408
+ break;
409
+ }
410
+ case ReflectionKind.Enum: {
411
+ ref = jsEnumToUniformRef.call(this, group);
412
+ break;
413
+ }
414
+ case ReflectionKind.TypeAlias: {
415
+ ref = jsTypeAliasToUniformRef.call(this, group);
416
+ break;
417
+ }
418
+ default: {
419
+ console.warn("(typedocGroupToUniform): Unhandled reflection kind", group.kind);
420
+ }
421
+ }
422
+ return ref;
423
+ }
424
+ function jsClassToUniformRef(dec) {
425
+ var _a, _b, _c, _d;
426
+ const definitions = [];
427
+ const ref = {
428
+ title: `Class ${dec.name}`,
429
+ canonical: "",
430
+ description: "",
431
+ context: void 0,
432
+ examples: {
433
+ groups: []
434
+ },
435
+ definitions
436
+ };
437
+ const declarationCtx = declarationUniformContext.call(this, dec);
438
+ if (declarationCtx) {
439
+ ref.context = {
440
+ ...ref.context,
441
+ ...declarationCtx
442
+ };
443
+ }
444
+ ref.canonical = uniformCanonical(dec, declarationCtx);
445
+ if (dec.comment) {
446
+ const description = commentToUniformDescription(dec.comment);
447
+ const group = uniformGroup(declarationCtx);
448
+ if (ref.context) {
449
+ ref.context.group = [
450
+ ...group,
451
+ "Classes"
452
+ ];
453
+ }
454
+ ref.description = description;
455
+ }
456
+ {
457
+ const constructor = (_a = dec.children) == null ? void 0 : _a.find((child) => child.name === "constructor");
458
+ if ((_b = constructor == null ? void 0 : constructor.signatures) == null ? void 0 : _b[0]) {
459
+ const constructorDef = {
460
+ title: "Constructor",
461
+ properties: []
462
+ };
463
+ const constructorSign = constructor.signatures[0];
464
+ for (const param of constructorSign.parameters || []) {
465
+ if (!param.type) {
466
+ console.warn("(jsClassToUniformRef): Constructor parameter type not found", param.name);
467
+ continue;
468
+ }
469
+ let description = "";
470
+ if (param.comment) {
471
+ description = commentToUniformDescription(param.comment);
472
+ }
473
+ let uniformType = someTypeToUniform.call(this, param.type);
474
+ let someTypeProps = {};
475
+ if (typeof uniformType === "object") {
476
+ delete uniformType.ofType;
477
+ someTypeProps = uniformType;
478
+ }
479
+ constructorDef.properties.push({
480
+ name: param.name,
481
+ type: typeof uniformType === "string" ? uniformType : "",
482
+ description,
483
+ ...someTypeProps
484
+ });
485
+ }
486
+ definitions.push(constructorDef);
487
+ }
488
+ }
489
+ {
490
+ const methods = ((_c = dec.children) == null ? void 0 : _c.filter(
491
+ (child) => child.kind === ReflectionKind.Method && child.name !== "constructor"
492
+ )) || [];
493
+ if (methods.length > 0) {
494
+ const methodsDef = {
495
+ title: "Methods",
496
+ properties: []
497
+ };
498
+ for (const method of methods) {
499
+ if (!((_d = method.signatures) == null ? void 0 : _d[0])) continue;
500
+ const methodSign = method.signatures[0];
501
+ let methodDesc = "";
502
+ if (methodSign.comment) {
503
+ methodDesc = commentToUniformDescription(methodSign.comment);
504
+ }
505
+ let type = "";
506
+ let someTypeProps = {};
507
+ if (methodSign.type) {
508
+ if (typeof methodSign.type === "object") {
509
+ someTypeProps = methodSign.type;
510
+ }
511
+ type = typeof methodSign.type === "string" ? methodSign.type : "";
512
+ } else {
513
+ type = "void";
514
+ }
515
+ const property = {
516
+ name: method.name,
517
+ type,
518
+ description: methodDesc,
519
+ ...someTypeProps
520
+ };
521
+ if (method.comment) {
522
+ const examples = commentToUniformExamples(method.comment);
523
+ if (examples.length > 0) {
524
+ property.examples = examples;
525
+ }
526
+ }
527
+ methodsDef.properties.push(property);
528
+ }
529
+ definitions.push(methodsDef);
530
+ }
531
+ }
532
+ return ref;
533
+ }
534
+ function jsFunctionToUniformRef(dec) {
535
+ const definitions = [];
536
+ const ref = {
537
+ title: `Function ${dec.name}`,
538
+ canonical: "",
539
+ description: "",
540
+ context: void 0,
541
+ examples: {
542
+ groups: []
543
+ },
544
+ definitions
545
+ };
546
+ const declarationCtx = declarationUniformContext.call(this, dec);
547
+ if (declarationCtx) {
548
+ ref.context = {
549
+ ...ref.context,
550
+ ...declarationCtx
551
+ };
552
+ }
553
+ ref.canonical = uniformCanonical(dec, declarationCtx);
554
+ const signatures = dec.signatures || [];
555
+ if (signatures.length > 1) {
556
+ console.error("(jsFunctionToUniformRef): Multiple signatures not supported for function declaration", dec.name);
557
+ return;
558
+ }
559
+ for (const sign of dec.signatures || []) {
560
+ {
561
+ if (sign.comment) {
562
+ const description = commentToUniformDescription(sign.comment);
563
+ const group = uniformGroup(declarationCtx);
564
+ if (ref.context) {
565
+ ref.context.group = [
566
+ ...group,
567
+ "Functions"
568
+ ];
569
+ }
570
+ ref.description = description;
571
+ }
572
+ }
573
+ {
574
+ const meta = [
575
+ {
576
+ name: "type",
577
+ value: "returns"
578
+ }
579
+ ];
580
+ const returnsUniformDef = {
581
+ title: "Returns",
582
+ properties: [],
583
+ meta
584
+ };
585
+ if (sign.type) {
586
+ let desc = "";
587
+ if (sign.comment) {
588
+ desc = returnCommentToUniform(sign.comment) || "";
589
+ }
590
+ const uniformType = someTypeToUniform.call(this, sign.type);
591
+ let someTypeProps = {};
592
+ if (typeof uniformType === "object") {
593
+ delete uniformType.ofType;
594
+ someTypeProps = uniformType;
595
+ }
596
+ returnsUniformDef.properties.push({
597
+ name: "",
598
+ type: typeof uniformType === "string" ? uniformType : "",
599
+ description: desc,
600
+ ...someTypeProps
601
+ });
602
+ }
603
+ ref.definitions.push(returnsUniformDef);
604
+ }
605
+ {
606
+ const meta = [
607
+ {
608
+ name: "type",
609
+ value: "parameters"
610
+ }
611
+ ];
612
+ const parametersUniformDef = {
613
+ title: "Parameters",
614
+ properties: [],
615
+ meta
616
+ };
617
+ for (const param of sign.parameters || []) {
618
+ if (!param.type) {
619
+ console.warn("(jsFunctionToUniformRef): Parameter type not found", param.name);
620
+ continue;
621
+ }
622
+ let description = "";
623
+ if (param.comment) {
624
+ description = commentToUniformDescription(param.comment);
625
+ }
626
+ const uniformType = someTypeToUniform.call(this, param.type);
627
+ let someTypeProps = {};
628
+ if (typeof uniformType === "object") {
629
+ delete uniformType.ofType;
630
+ someTypeProps = uniformType;
631
+ }
632
+ const prop = {
633
+ name: param.name,
634
+ type: typeof uniformType === "string" ? uniformType : "",
635
+ description,
636
+ ...someTypeProps
637
+ };
638
+ switch (prop.name) {
639
+ case "__namedParameters": {
640
+ prop.name = "";
641
+ prop.type = DEFINED_DEFINITION_PROPERTY_TYPE.UNION;
642
+ break;
643
+ }
644
+ }
645
+ if (param.comment) {
646
+ const examples = commentToUniformExamples(param.comment);
647
+ if (examples.length > 0) {
648
+ prop.examples = examples;
649
+ }
650
+ }
651
+ parametersUniformDef.properties.push(prop);
652
+ }
653
+ ref.definitions.push(parametersUniformDef);
654
+ }
655
+ }
656
+ return ref;
657
+ }
658
+ function jsInterfaceToUniformRef(dec) {
659
+ var _a, _b, _c, _d, _e, _f, _g;
660
+ const definitions = [];
661
+ const ref = {
662
+ title: `Interface ${dec.name}`,
663
+ canonical: "",
664
+ description: "",
665
+ context: void 0,
666
+ examples: {
667
+ groups: []
668
+ },
669
+ definitions
670
+ };
671
+ const declarationCtx = declarationUniformContext.call(this, dec);
672
+ if (declarationCtx) {
673
+ ref.context = {
674
+ ...ref.context,
675
+ ...declarationCtx
676
+ };
677
+ }
678
+ ref.canonical = uniformCanonical(dec, declarationCtx);
679
+ if (dec.comment) {
680
+ const description = commentToUniformDescription(dec.comment);
681
+ const group = uniformGroup(declarationCtx);
682
+ if (ref.context) {
683
+ ref.context.group = [
684
+ ...group,
685
+ "Interfaces"
686
+ ];
687
+ }
688
+ ref.description = description;
689
+ }
690
+ {
691
+ const properties = ((_a = dec.children) == null ? void 0 : _a.filter(
692
+ (child) => child.kind === ReflectionKind.Property
693
+ )) || [];
694
+ if (properties.length > 0) {
695
+ const propertiesDef = {
696
+ title: "Properties",
697
+ properties: []
698
+ };
699
+ for (const prop of properties) {
700
+ if (!prop.type) {
701
+ console.warn("(jsInterfaceToUniformRef): Property type not found", prop.name);
702
+ continue;
703
+ }
704
+ let description = "";
705
+ if (prop.comment) {
706
+ description = commentToUniformDescription(prop.comment);
707
+ }
708
+ const uniformType = someTypeToUniform.call(this, prop.type);
709
+ let someTypeProps = {};
710
+ let meta = [];
711
+ if (typeof uniformType === "object") {
712
+ delete uniformType.ofType;
713
+ someTypeProps = uniformType;
714
+ meta = uniformType.meta || [];
715
+ }
716
+ if (!((_b = prop.flags) == null ? void 0 : _b.isOptional)) {
717
+ meta.push({
718
+ name: "required",
719
+ value: "true"
720
+ });
721
+ }
722
+ if (Array.isArray((_c = prop.comment) == null ? void 0 : _c.modifierTags) && ((_e = (_d = prop.comment) == null ? void 0 : _d.modifierTags) == null ? void 0 : _e.includes("@internal"))) {
723
+ meta.push({
724
+ name: "internal",
725
+ value: "true"
726
+ });
727
+ }
728
+ const property = {
729
+ name: prop.name,
730
+ type: typeof uniformType === "string" ? uniformType : "",
731
+ description,
732
+ ...someTypeProps,
733
+ meta
734
+ };
735
+ if (prop.comment) {
736
+ const examples = commentToUniformExamples(prop.comment);
737
+ if (examples.length > 0) {
738
+ property.examples = examples;
739
+ }
740
+ }
741
+ propertiesDef.properties.push(property);
742
+ }
743
+ definitions.push(propertiesDef);
744
+ }
745
+ }
746
+ {
747
+ const methods = ((_f = dec.children) == null ? void 0 : _f.filter(
748
+ (child) => child.kind === ReflectionKind.Method
749
+ )) || [];
750
+ if (methods.length > 0) {
751
+ const methodsDef = {
752
+ title: "Methods",
753
+ properties: []
754
+ };
755
+ for (const method of methods) {
756
+ if (!((_g = method.signatures) == null ? void 0 : _g[0])) continue;
757
+ const methodSign = method.signatures[0];
758
+ let methodDesc = "";
759
+ if (methodSign.comment) {
760
+ methodDesc = commentToUniformDescription(methodSign.comment);
761
+ }
762
+ let type = "";
763
+ let someTypeProps = {};
764
+ if (methodSign.type) {
765
+ if (typeof methodSign.type === "object") {
766
+ someTypeProps = methodSign.type;
767
+ }
768
+ type = typeof methodSign.type === "string" ? methodSign.type : "";
769
+ } else {
770
+ type = "void";
771
+ }
772
+ const property = {
773
+ name: method.name,
774
+ type,
775
+ description: methodDesc,
776
+ ...someTypeProps
777
+ };
778
+ if (method.comment) {
779
+ const examples = commentToUniformExamples(method.comment);
780
+ if (examples.length > 0) {
781
+ property.examples = examples;
782
+ }
783
+ }
784
+ methodsDef.properties.push(property);
785
+ }
786
+ definitions.push(methodsDef);
787
+ }
788
+ }
789
+ return ref;
790
+ }
791
+ function jsTypeAliasToUniformRef(dec) {
792
+ var _a, _b;
793
+ const definitions = [];
794
+ const ref = {
795
+ title: `Type ${dec.name}`,
796
+ canonical: "",
797
+ description: "",
798
+ context: void 0,
799
+ examples: {
800
+ groups: []
801
+ },
802
+ definitions
803
+ };
804
+ const declarationCtx = declarationUniformContext.call(this, dec);
805
+ if (declarationCtx) {
806
+ ref.context = {
807
+ ...ref.context,
808
+ ...declarationCtx
809
+ };
810
+ }
811
+ ref.canonical = uniformCanonical(dec, declarationCtx);
812
+ if (dec.comment) {
813
+ const description = commentToUniformDescription(dec.comment);
814
+ const group = uniformGroup(declarationCtx);
815
+ if (ref.context) {
816
+ ref.context.group = [
817
+ ...group,
818
+ "Types"
819
+ ];
820
+ }
821
+ ref.description = description;
822
+ }
823
+ if (dec.type && ((_a = dec.children) == null ? void 0 : _a.length)) {
824
+ console.warn("(jsTypeAliasToUniformRef): Type alias with children is not fully supported, only type definition will be handled", dec.name);
825
+ }
826
+ {
827
+ const typeDef = {
828
+ title: "Type Definition",
829
+ properties: []
830
+ };
831
+ let comment = "";
832
+ if (dec.comment) {
833
+ comment = commentToUniformDescription(dec.comment);
834
+ }
835
+ if (dec.type) {
836
+ const uniformType = someTypeToUniform.call(this, dec.type);
837
+ let someTypeProps = {};
838
+ if (typeof uniformType === "object") {
839
+ delete uniformType.ofType;
840
+ someTypeProps = uniformType;
841
+ }
842
+ const propDefinition = {
843
+ name: "",
844
+ type: typeof uniformType === "string" ? uniformType : "",
845
+ description: comment,
846
+ ...someTypeProps
847
+ };
848
+ typeDef.rootProperty = propDefinition;
849
+ } else if ((_b = dec == null ? void 0 : dec.children) == null ? void 0 : _b.length) {
850
+ const properties = uniformProperties.call(this, dec);
851
+ typeDef.properties = properties;
852
+ }
853
+ definitions.push(typeDef);
854
+ }
855
+ return ref;
856
+ }
857
+ function jsEnumToUniformRef(dec) {
858
+ var _a;
859
+ const definitions = [];
860
+ const ref = {
861
+ title: `Enum ${dec.name}`,
862
+ canonical: "",
863
+ description: "",
864
+ context: void 0,
865
+ examples: {
866
+ groups: []
867
+ },
868
+ definitions
869
+ };
870
+ const declarationCtx = declarationUniformContext.call(this, dec);
871
+ if (declarationCtx) {
872
+ ref.context = {
873
+ ...ref.context,
874
+ ...declarationCtx
875
+ };
876
+ }
877
+ ref.canonical = uniformCanonical(dec, declarationCtx);
878
+ if (dec.comment) {
879
+ const description = commentToUniformDescription(dec.comment);
880
+ const group = uniformGroup(declarationCtx);
881
+ if (ref.context) {
882
+ ref.context.group = [
883
+ ...group,
884
+ "Enums"
885
+ ];
886
+ }
887
+ ref.description = description;
888
+ }
889
+ {
890
+ const members = ((_a = dec.children) == null ? void 0 : _a.filter(
891
+ (child) => child.kind === ReflectionKind.EnumMember
892
+ )) || [];
893
+ if (members.length > 0) {
894
+ const membersDef = {
895
+ title: "Members",
896
+ properties: []
897
+ };
898
+ const sortedMembers = [...members].sort((a, b) => {
899
+ var _a2, _b, _c, _d;
900
+ if (!((_b = (_a2 = a.sources) == null ? void 0 : _a2[0]) == null ? void 0 : _b.line) || !((_d = (_c = b.sources) == null ? void 0 : _c[0]) == null ? void 0 : _d.line)) {
901
+ return 0;
902
+ }
903
+ return a.sources[0].line - b.sources[0].line;
904
+ });
905
+ for (const member of sortedMembers) {
906
+ let description = "";
907
+ if (member.comment) {
908
+ description = commentToUniformDescription(member.comment);
909
+ }
910
+ let value = "";
911
+ let type = "number";
912
+ if (member.type && typeof member.type === "object" && member.type.type === "literal" && member.type.value !== null) {
913
+ if (typeof member.type.value === "string") {
914
+ value = member.type.value;
915
+ type = "string";
916
+ } else {
917
+ value = member.type.value.toString();
918
+ type = "number";
919
+ }
920
+ } else if (member.defaultValue !== void 0) {
921
+ value = member.defaultValue.toString();
922
+ if (value.startsWith('"') && value.endsWith('"')) {
923
+ type = "string";
924
+ value = value.substring(1, value.length - 1);
925
+ }
926
+ }
927
+ const formattedName = `${member.name} (${value})`;
928
+ membersDef.properties.push({
929
+ name: formattedName,
930
+ type,
931
+ description
932
+ });
933
+ }
934
+ definitions.push(membersDef);
935
+ }
936
+ }
937
+ return ref;
938
+ }
939
+ function declarationUniformContext(dec) {
940
+ var _a, _b, _c, _d;
941
+ if (!dec.sources || !dec.sources.length) {
942
+ return;
943
+ }
944
+ if (dec.sources.length > 1) {
945
+ console.warn("(declarationUniformContext): Multiple sources not supported for function declaration", dec.name);
946
+ }
947
+ const source = dec.sources[0];
948
+ const signTxt = this.signatureTextLoader.signatureText(
949
+ dec.id,
950
+ source == null ? void 0 : source.line
951
+ ) || "";
952
+ const sourceCode = this.signatureTextLoader.signatureSourceCode(
953
+ dec.id,
954
+ source == null ? void 0 : source.line
955
+ ) || "";
956
+ const symbolMap = this.project.symbolIdMap[dec.id];
957
+ const fileFullPath = symbolMap.packagePath;
958
+ const meta = [];
959
+ if (Array.isArray((_a = dec.comment) == null ? void 0 : _a.modifierTags) && ((_c = (_b = dec.comment) == null ? void 0 : _b.modifierTags) == null ? void 0 : _c.includes("@internal"))) {
960
+ meta.push({
961
+ name: "internal",
962
+ value: "true"
963
+ });
964
+ }
965
+ const ctx = {
966
+ symbolId: (_d = dec.id) == null ? void 0 : _d.toString(),
967
+ symbolName: dec.name,
968
+ symbolKind: dec.kind,
969
+ packageName: symbolMap == null ? void 0 : symbolMap.packageName,
970
+ fileName: source.fileName,
971
+ fileFullPath,
972
+ line: source.line,
973
+ col: source.character,
974
+ signatureText: {
975
+ code: signTxt,
976
+ lang: "ts"
977
+ },
978
+ sourcecode: {
979
+ code: sourceCode,
980
+ lang: "ts"
981
+ },
982
+ meta
983
+ };
984
+ const category = uniformCategory(dec);
985
+ if (category) {
986
+ ctx.category = category;
987
+ }
988
+ return ctx;
989
+ }
990
+ function someTypeToUniform(someType) {
991
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
992
+ const meta = [];
993
+ if ("target" in someType) {
994
+ for (const child of ((_a = this == null ? void 0 : this.project) == null ? void 0 : _a.children) || []) {
995
+ if (String(child.id) === String(someType.target)) {
996
+ if (Array.isArray((_b = child.comment) == null ? void 0 : _b.modifierTags) && ((_d = (_c = child.comment) == null ? void 0 : _c.modifierTags) == null ? void 0 : _d.includes("@internal"))) {
997
+ meta.push({
998
+ name: "internal",
999
+ value: "true"
1000
+ });
1001
+ }
1002
+ }
1003
+ }
1004
+ }
1005
+ switch (someType.type) {
1006
+ case "reference": {
1007
+ let refType = `${someType.qualifiedName || someType.name}`;
1008
+ if ("target" in someType && typeof someType.target === "number") {
1009
+ return {
1010
+ type: refType,
1011
+ symbolDef: {
1012
+ id: (_e = someType.target) == null ? void 0 : _e.toString()
1013
+ },
1014
+ meta
1015
+ };
1016
+ }
1017
+ if ("typeArguments" in someType && someType.typeArguments) {
1018
+ const typeArgs = someType.typeArguments.map((arg) => {
1019
+ const argType = someTypeToUniform.call(this, arg);
1020
+ return typeof argType === "string" ? argType : argType.type || "";
1021
+ });
1022
+ refType = `${refType}<${typeArgs.join(", ")}>`;
1023
+ }
1024
+ return refType;
1025
+ }
1026
+ case "union": {
1027
+ const resp = unionLikeSomeType.call(this, someType.types);
1028
+ if (typeof resp === "string") {
1029
+ return resp;
1030
+ }
1031
+ return {
1032
+ ...resp,
1033
+ meta: [
1034
+ ...resp.meta || [],
1035
+ ...meta
1036
+ ]
1037
+ };
1038
+ }
1039
+ case "literal": {
1040
+ if (typeof someType.value === "string") {
1041
+ return `"${someType.value}"`;
1042
+ }
1043
+ return (someType.value || "").toString();
1044
+ }
1045
+ case "reflection": {
1046
+ const properties = uniformProperties.call(this, someType.declaration);
1047
+ let type = "";
1048
+ if (((_f = someType.declaration.indexSignatures) == null ? void 0 : _f.length) || ((_g = someType.declaration.children) == null ? void 0 : _g.length)) {
1049
+ type = this.signatureTextLoader.signatureText(
1050
+ someType.declaration.id,
1051
+ ((_i = (_h = someType.declaration.sources) == null ? void 0 : _h[0]) == null ? void 0 : _i.line) || 0,
1052
+ {
1053
+ typeOnly: true
1054
+ }
1055
+ ) || "";
1056
+ }
1057
+ if ((_j = someType.declaration.indexSignatures) == null ? void 0 : _j.length) {
1058
+ if (properties.length > 1) {
1059
+ console.warn("(someTypeToUniform): Reflection type with multiple properties, using first one as ofProperty", someType.declaration.name);
1060
+ }
1061
+ return {
1062
+ type: DEFINED_DEFINITION_PROPERTY_TYPE.UNION,
1063
+ properties: [],
1064
+ meta,
1065
+ ofProperty: {
1066
+ name: "",
1067
+ type,
1068
+ description: ""
1069
+ }
1070
+ };
1071
+ }
1072
+ return {
1073
+ type,
1074
+ properties,
1075
+ meta
1076
+ };
1077
+ }
1078
+ case "array": {
1079
+ const arrayItemType = someTypeToUniform.call(this, someType.elementType);
1080
+ if (typeof arrayItemType === "string") {
1081
+ return {
1082
+ type: arrayItemType + "[]",
1083
+ meta
1084
+ };
1085
+ }
1086
+ return {
1087
+ ofType: (arrayItemType.type || "") + "[]",
1088
+ type: DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY,
1089
+ ofProperty: {
1090
+ name: "",
1091
+ description: "",
1092
+ type: arrayItemType.type || "",
1093
+ properties: [],
1094
+ symbolDef: arrayItemType.symbolDef
1095
+ },
1096
+ meta
1097
+ };
1098
+ }
1099
+ case "tuple": {
1100
+ const elements = someType.elements || [];
1101
+ const elementTypes = elements.map((element) => someTypeToUniform.call(this, element));
1102
+ const tupleType = `[${elementTypes.map((t) => typeof t === "string" ? t : t.type || "").join(", ")}]`;
1103
+ const symbolIds = [];
1104
+ for (const t of elementTypes) {
1105
+ if (typeof t === "object" && ((_k = t.symbolDef) == null ? void 0 : _k.id)) {
1106
+ if (Array.isArray(t.symbolDef.id)) {
1107
+ symbolIds.push(...t.symbolDef.id);
1108
+ } else {
1109
+ symbolIds.push(t.symbolDef.id);
1110
+ }
1111
+ }
1112
+ }
1113
+ return {
1114
+ type: tupleType,
1115
+ symbolDef: symbolIds.length > 0 ? { id: symbolIds } : void 0,
1116
+ meta
1117
+ };
1118
+ }
1119
+ case "intersection": {
1120
+ const resp = unionLikeSomeType.call(this, someType.types);
1121
+ if (typeof resp === "string") {
1122
+ return resp;
1123
+ }
1124
+ return {
1125
+ ...resp,
1126
+ meta: [
1127
+ ...resp.meta || [],
1128
+ ...meta
1129
+ ]
1130
+ };
1131
+ }
1132
+ case "rest": {
1133
+ const resp = someTypeToUniform.call(this, someType.elementType);
1134
+ if (typeof resp === "string") {
1135
+ return `${resp}[]`;
1136
+ }
1137
+ return {
1138
+ ...resp,
1139
+ type: `${resp.type || ""}[]`
1140
+ };
1141
+ }
1142
+ default: {
1143
+ if (!("name" in someType)) {
1144
+ console.warn("SomeType does not have name property", someType.type);
1145
+ return "";
1146
+ }
1147
+ return someType.name;
1148
+ }
1149
+ }
1150
+ return "";
1151
+ }
1152
+ function unionLikeSomeType(someTypes) {
1153
+ var _a, _b, _c, _d, _e, _f;
1154
+ let types = [];
1155
+ const symbolIds = [];
1156
+ for (const t of someTypes) {
1157
+ const tUniform = someTypeToUniform.call(this, t);
1158
+ if (typeof tUniform === "object") {
1159
+ if ((_a = tUniform.meta) == null ? void 0 : _a.some((m) => m.name === "internal" && m.value === "true")) {
1160
+ continue;
1161
+ }
1162
+ if (((_b = tUniform.type) == null ? void 0 : _b.startsWith("[")) && ((_c = tUniform.type) == null ? void 0 : _c.endsWith("]"))) {
1163
+ types.push(tUniform.type);
1164
+ } else {
1165
+ types.push(tUniform.ofType || tUniform.type || "");
1166
+ }
1167
+ if ((_d = tUniform == null ? void 0 : tUniform.symbolDef) == null ? void 0 : _d.id) {
1168
+ if (Array.isArray((_e = tUniform == null ? void 0 : tUniform.symbolDef) == null ? void 0 : _e.id)) {
1169
+ symbolIds.push(...(_f = tUniform.symbolDef) == null ? void 0 : _f.id);
1170
+ } else {
1171
+ symbolIds.push(tUniform.symbolDef.id);
1172
+ }
1173
+ }
1174
+ delete tUniform.ofType;
1175
+ } else {
1176
+ types.push(tUniform);
1177
+ }
1178
+ }
1179
+ return {
1180
+ type: types.filter(Boolean).join(" | "),
1181
+ symbolDef: {
1182
+ id: symbolIds
1183
+ }
1184
+ };
1185
+ }
1186
+ function commentToUniformDescription(comment) {
1187
+ let desc = "";
1188
+ for (const summary of (comment == null ? void 0 : comment.summary) || []) {
1189
+ desc += `${summary.text}
1190
+ `;
1191
+ }
1192
+ return desc;
1193
+ }
1194
+ function commentToUniformExamples(comment) {
1195
+ if (!comment.blockTags || !comment.blockTags.length) {
1196
+ return [];
1197
+ }
1198
+ const examples = [];
1199
+ for (const tag of comment.blockTags) {
1200
+ if (tag.tag === "@example") {
1201
+ for (const content of tag.content || []) {
1202
+ if (content.kind === "code") {
1203
+ const code = content.text.replace(/```ts\n|\n```/g, "");
1204
+ examples.push(code);
1205
+ }
1206
+ }
1207
+ }
1208
+ }
1209
+ return examples;
1210
+ }
1211
+ function uniformCategory(dec) {
1212
+ if (!dec) {
1213
+ return "";
1214
+ }
1215
+ let category = "";
1216
+ for (const signature of dec.signatures || []) {
1217
+ if (signature.comment) {
1218
+ const comment = signature.comment;
1219
+ if (comment.blockTags) {
1220
+ for (const tag of comment.blockTags) {
1221
+ if (tag.tag === "@category") {
1222
+ for (const content of tag.content || []) {
1223
+ category += content.text;
1224
+ }
1225
+ }
1226
+ }
1227
+ }
1228
+ }
1229
+ }
1230
+ return category;
1231
+ }
1232
+ function returnCommentToUniform(comment) {
1233
+ if (!comment.blockTags || !comment.blockTags.length) {
1234
+ return "";
1235
+ }
1236
+ let desc = "";
1237
+ for (const tag of comment.blockTags) {
1238
+ if (tag.tag === "@returns") {
1239
+ for (const content of tag.content || []) {
1240
+ desc += `${content.text}
1241
+ `;
1242
+ }
1243
+ }
1244
+ }
1245
+ return desc;
1246
+ }
1247
+ function uniformProperties(dec) {
1248
+ var _a, _b, _c, _d;
1249
+ const properties = [];
1250
+ for (const prop of dec.children || []) {
1251
+ if (!prop.type) {
1252
+ console.warn("(uniformProperties): Property type not found", prop.name);
1253
+ continue;
1254
+ }
1255
+ let description = "";
1256
+ if (prop.comment) {
1257
+ description = commentToUniformDescription(prop.comment);
1258
+ }
1259
+ const uniformType = someTypeToUniform.call(this, prop.type);
1260
+ let meta = [];
1261
+ let someTypeProps = {};
1262
+ if (typeof uniformType === "object") {
1263
+ delete uniformType.ofType;
1264
+ someTypeProps = uniformType;
1265
+ meta = uniformType.meta || [];
1266
+ }
1267
+ if (!((_a = prop.flags) == null ? void 0 : _a.isOptional)) {
1268
+ meta.push({
1269
+ name: "required",
1270
+ value: "true"
1271
+ });
1272
+ }
1273
+ if (Array.isArray((_b = prop.comment) == null ? void 0 : _b.modifierTags) && ((_d = (_c = prop.comment) == null ? void 0 : _c.modifierTags) == null ? void 0 : _d.includes("@internal"))) {
1274
+ meta.push({
1275
+ name: "internal",
1276
+ value: "true"
1277
+ });
1278
+ }
1279
+ const property = {
1280
+ name: prop.name,
1281
+ type: typeof uniformType === "string" ? uniformType : "",
1282
+ description,
1283
+ ...someTypeProps,
1284
+ meta
1285
+ };
1286
+ if (prop.comment) {
1287
+ const examples = commentToUniformExamples(prop.comment);
1288
+ if (examples.length > 0) {
1289
+ property.examples = examples;
1290
+ }
1291
+ }
1292
+ properties.push(property);
1293
+ }
1294
+ return properties;
1295
+ }
1296
+ function uniformGroup(ctx) {
1297
+ if (!ctx) {
1298
+ return [];
1299
+ }
1300
+ const group = ctx.packageName.split("/");
1301
+ return group;
1302
+ }
1303
+ function uniformCanonical(dec, ctx) {
1304
+ const parts = [];
1305
+ if (ctx == null ? void 0 : ctx.packageName) {
1306
+ parts.push(ctx.packageName);
1307
+ }
1308
+ switch (dec.kind) {
1309
+ case ReflectionKind.Class: {
1310
+ parts.push("classes", dec.name);
1311
+ break;
1312
+ }
1313
+ case ReflectionKind.Interface: {
1314
+ parts.push("interfaces", dec.name);
1315
+ break;
1316
+ }
1317
+ case ReflectionKind.Function: {
1318
+ parts.push("functions", dec.name);
1319
+ break;
1320
+ }
1321
+ case ReflectionKind.TypeAlias: {
1322
+ parts.push("types", dec.name);
1323
+ break;
1324
+ }
1325
+ case ReflectionKind.Enum: {
1326
+ parts.push("enums", dec.name);
1327
+ break;
1328
+ }
1329
+ default: {
1330
+ return "";
1331
+ }
1332
+ }
1333
+ return parts.join("/");
1334
+ }
1335
+
1336
+ // packages/ts/uniformToMiniUniform.ts
1337
+ import {
1338
+ DEFINED_DEFINITION_PROPERTY_TYPE as DEFINED_DEFINITION_PROPERTY_TYPE2
1339
+ } from "@xyd-js/uniform";
1340
+ var TXT = {
1341
+ Properties: "Properties"
1342
+ };
1343
+ var PRIMITIVE_TYPES = /* @__PURE__ */ new Set(["string", "number", "boolean"]);
1344
+ function uniformToMiniUniform(rootSymbolName, references) {
1345
+ var _a, _b;
1346
+ const output = [];
1347
+ const refBySymbolId = {};
1348
+ for (const reference of references) {
1349
+ const ctx = reference.context;
1350
+ if (ctx == null ? void 0 : ctx.symbolId) {
1351
+ if ((_b = (_a = reference.context) == null ? void 0 : _a.meta) == null ? void 0 : _b.some((m) => m.name === "internal" && m.value === "true")) {
1352
+ continue;
1353
+ }
1354
+ refBySymbolId[ctx.symbolId] = JSON.parse(JSON.stringify(reference));
1355
+ }
1356
+ }
1357
+ for (const reference of references) {
1358
+ const ctx = reference.context;
1359
+ if ((ctx == null ? void 0 : ctx.symbolName) !== rootSymbolName) {
1360
+ continue;
1361
+ }
1362
+ const miniRef = {
1363
+ ...reference,
1364
+ title: (ctx == null ? void 0 : ctx.symbolName) || reference.title,
1365
+ canonical: "",
1366
+ context: ctx,
1367
+ definitions: []
1368
+ };
1369
+ for (const def of reference.definitions) {
1370
+ const miniDef = {
1371
+ ...def,
1372
+ title: TXT.Properties,
1373
+ properties: [],
1374
+ symbolDef: {
1375
+ ...def.symbolDef || {},
1376
+ canonical: ""
1377
+ // TODO: support canonical in the future
1378
+ }
1379
+ };
1380
+ const defProperties = (def == null ? void 0 : def.rootProperty) ? [def.rootProperty] : def.properties || [];
1381
+ definitionMiniPropsPassThrough(
1382
+ refBySymbolId,
1383
+ defProperties,
1384
+ miniDef
1385
+ );
1386
+ miniRef.definitions.push(miniDef);
1387
+ }
1388
+ output.push(miniRef);
1389
+ }
1390
+ return output;
1391
+ }
1392
+ function definitionMiniPropsPassThrough(refBySymbolId, defProperties, miniDef, options) {
1393
+ for (let property of defProperties) {
1394
+ property = {
1395
+ ...property,
1396
+ symbolDef: {
1397
+ ...property.symbolDef || {},
1398
+ canonical: ""
1399
+ // TODO: support canonical in the future
1400
+ }
1401
+ };
1402
+ const resolvedProperty = resolveProperty(refBySymbolId, property, options);
1403
+ miniDef.properties.push({
1404
+ ...resolvedProperty,
1405
+ symbolDef: {
1406
+ ...resolvedProperty.symbolDef || {},
1407
+ canonical: ""
1408
+ // TODO: support canonical in the future
1409
+ }
1410
+ });
1411
+ }
1412
+ }
1413
+ function resolveProperty(refBySymbolId, property, options) {
1414
+ var _a, _b, _c;
1415
+ property = {
1416
+ ...property,
1417
+ symbolDef: {
1418
+ ...property.symbolDef || {},
1419
+ canonical: ""
1420
+ // TODO: support canonical in the future
1421
+ }
1422
+ };
1423
+ const depth = (options == null ? void 0 : options.depth) || 0;
1424
+ const visited = (options == null ? void 0 : options.visited) || /* @__PURE__ */ new Set();
1425
+ if (depth > 10) {
1426
+ console.warn("Maximum recursion depth reached for property:", property.name);
1427
+ return property;
1428
+ }
1429
+ if ((_a = property == null ? void 0 : property.properties) == null ? void 0 : _a.length) {
1430
+ return property;
1431
+ }
1432
+ const resolvedPropertyProps = [];
1433
+ const resolvedProperty = {
1434
+ ...property,
1435
+ properties: resolvedPropertyProps
1436
+ };
1437
+ if (property.type === DEFINED_DEFINITION_PROPERTY_TYPE2.ARRAY) {
1438
+ if (property.ofProperty) {
1439
+ const resolvedRootProperty = resolveProperty(
1440
+ refBySymbolId,
1441
+ property.ofProperty,
1442
+ options
1443
+ );
1444
+ resolvedProperty.ofProperty = resolvedRootProperty;
1445
+ return resolvedProperty;
1446
+ } else {
1447
+ console.warn(`Property ${property.name} is an array but has no ofProperty defined, using type only`);
1448
+ }
1449
+ return property;
1450
+ }
1451
+ const symbolId = (_b = property == null ? void 0 : property.symbolDef) == null ? void 0 : _b.id;
1452
+ if (symbolId) {
1453
+ if (typeof symbolId === "string") {
1454
+ if (visited.has(symbolId)) {
1455
+ return resolvedProperty;
1456
+ }
1457
+ visited.add(symbolId);
1458
+ const refSymbol = refBySymbolId[symbolId];
1459
+ const refSymbolDefinition = (_c = refSymbol == null ? void 0 : refSymbol.definitions) == null ? void 0 : _c[0];
1460
+ const refSymbolDefinitionProps = (refSymbolDefinition == null ? void 0 : refSymbolDefinition.properties) || [];
1461
+ if (!refSymbol) {
1462
+ console.warn(`Reference for symbol ${symbolId} not found, using type only`);
1463
+ return resolvedProperty;
1464
+ }
1465
+ if (refSymbolDefinitionProps.length) {
1466
+ for (const prop of refSymbolDefinitionProps) {
1467
+ const resolvedProp = resolveProperty(refBySymbolId, prop, {
1468
+ ...options,
1469
+ depth: depth + 1,
1470
+ visited: new Set(visited)
1471
+ });
1472
+ resolvedPropertyProps.push(resolvedProp);
1473
+ }
1474
+ } else if (refSymbolDefinition.rootProperty) {
1475
+ const resolvedProp = resolveProperty(refBySymbolId, refSymbolDefinition.rootProperty, {
1476
+ ...options,
1477
+ depth: depth + 1,
1478
+ visited: new Set(visited)
1479
+ });
1480
+ resolvedProperty.ofProperty = resolvedProp;
1481
+ } else {
1482
+ console.warn(`Reference for symbol ${symbolId} has no properties, using type and description only`);
1483
+ }
1484
+ if (!resolvedProperty.description) {
1485
+ resolvedProperty.description = refSymbol.description || "";
1486
+ }
1487
+ return resolvedProperty;
1488
+ }
1489
+ const isResolveUnion = isResolveUnionRef(property);
1490
+ if (isResolveUnion) {
1491
+ resolvedProperty.type = DEFINED_DEFINITION_PROPERTY_TYPE2.UNION;
1492
+ const unionProps = handleUnionTypes(
1493
+ refBySymbolId,
1494
+ property,
1495
+ options
1496
+ );
1497
+ if (unionProps.length > 1) {
1498
+ resolvedProperty.properties = unionProps;
1499
+ } else {
1500
+ resolvedProperty.ofProperty = unionProps[0];
1501
+ }
1502
+ const shortType = shortMergedType(resolvedProperty);
1503
+ if (shortType) {
1504
+ return shortType;
1505
+ }
1506
+ return resolvedProperty;
1507
+ }
1508
+ }
1509
+ return property;
1510
+ }
1511
+ function shortMergedType(property) {
1512
+ property = {
1513
+ ...property,
1514
+ symbolDef: {
1515
+ ...property.symbolDef || {},
1516
+ canonical: ""
1517
+ // TODO: support canonical in the future
1518
+ }
1519
+ };
1520
+ if (property.type !== DEFINED_DEFINITION_PROPERTY_TYPE2.UNION) {
1521
+ return null;
1522
+ }
1523
+ const properties = property.ofProperty ? [property.ofProperty] : property.properties || [];
1524
+ const processedProperties = properties.map((prop) => {
1525
+ if (prop.type === DEFINED_DEFINITION_PROPERTY_TYPE2.UNION) {
1526
+ const shortType2 = shortMergedType(prop);
1527
+ if (shortType2) {
1528
+ return shortType2;
1529
+ }
1530
+ }
1531
+ const shortType = shortMergedType({
1532
+ name: "",
1533
+ description: "",
1534
+ type: DEFINED_DEFINITION_PROPERTY_TYPE2.UNION,
1535
+ properties: prop.properties,
1536
+ ofProperty: prop.ofProperty
1537
+ });
1538
+ if (shortType) {
1539
+ return shortType;
1540
+ }
1541
+ return prop;
1542
+ });
1543
+ if (!(processedProperties == null ? void 0 : processedProperties.length)) {
1544
+ return null;
1545
+ }
1546
+ const hasOnlySimpleTypes = processedProperties.every((prop) => {
1547
+ if (isLiteralValues(prop.type)) {
1548
+ return true;
1549
+ }
1550
+ return PRIMITIVE_TYPES.has(prop.type);
1551
+ });
1552
+ if (!hasOnlySimpleTypes) {
1553
+ return null;
1554
+ }
1555
+ const types = processedProperties.map((prop) => prop.type);
1556
+ const mergedType = types.join(" | ");
1557
+ return {
1558
+ ...property,
1559
+ type: mergedType,
1560
+ properties: []
1561
+ };
1562
+ }
1563
+ function handleUnionTypes(refBySymbolId, property, options) {
1564
+ var _a, _b, _c, _d;
1565
+ property = {
1566
+ ...property,
1567
+ symbolDef: {
1568
+ ...property.symbolDef || {},
1569
+ canonical: ""
1570
+ // TODO: support canonical in the future
1571
+ }
1572
+ };
1573
+ const symbolIds = Array.isArray((_a = property.symbolDef) == null ? void 0 : _a.id) ? property.symbolDef.id : [];
1574
+ const typeString = property.type;
1575
+ const properties = [];
1576
+ const unionTypeStringsMap = (typeString || "").split("|").map((t) => t.trim()).reduce((acc, type) => ({
1577
+ ...acc,
1578
+ [type]: true
1579
+ }), {});
1580
+ if (symbolIds.length > 0) {
1581
+ for (const symbolId of symbolIds) {
1582
+ const refSymbol = refBySymbolId[symbolId];
1583
+ const refSymbolDefinition = (_b = refSymbol == null ? void 0 : refSymbol.definitions) == null ? void 0 : _b[0];
1584
+ const ctx = refSymbol == null ? void 0 : refSymbol.context;
1585
+ if (refSymbolDefinition) {
1586
+ unionTypeStringsMap[ctx.symbolName] = false;
1587
+ const propProperties = [];
1588
+ const prop = {
1589
+ name: ctx.symbolName || "",
1590
+ type: ctx.symbolName || "",
1591
+ description: refSymbol.description || "",
1592
+ properties: propProperties,
1593
+ symbolDef: {
1594
+ id: symbolId,
1595
+ canonical: ""
1596
+ // TODO: support canonical in the future
1597
+ }
1598
+ };
1599
+ if (refSymbolDefinition.properties.length) {
1600
+ for (const prop2 of refSymbolDefinition.properties) {
1601
+ const resolvedProp = resolveProperty(
1602
+ refBySymbolId,
1603
+ prop2,
1604
+ options
1605
+ );
1606
+ propProperties.push(resolvedProp);
1607
+ }
1608
+ } else if (refSymbolDefinition.rootProperty) {
1609
+ const resolvedProp = resolveProperty(
1610
+ refBySymbolId,
1611
+ refSymbolDefinition.rootProperty,
1612
+ options
1613
+ );
1614
+ const shouldMergeUnion = resolvedProp.type === DEFINED_DEFINITION_PROPERTY_TYPE2.UNION && ((_c = resolvedProp.ofProperty) == null ? void 0 : _c.type) && !((_d = resolvedProp.properties) == null ? void 0 : _d.length);
1615
+ if (shouldMergeUnion) {
1616
+ prop.ofProperty = resolvedProp.ofProperty;
1617
+ } else {
1618
+ prop.ofProperty = resolvedProp;
1619
+ }
1620
+ }
1621
+ properties.push(prop);
1622
+ if (!prop.description) {
1623
+ prop.description = refSymbol.description || "";
1624
+ }
1625
+ }
1626
+ }
1627
+ }
1628
+ for (const type of Object.keys(unionTypeStringsMap)) {
1629
+ const ok = unionTypeStringsMap[type];
1630
+ if (!ok) {
1631
+ continue;
1632
+ }
1633
+ properties.push({
1634
+ name: type,
1635
+ type,
1636
+ description: "",
1637
+ properties: []
1638
+ });
1639
+ }
1640
+ return properties;
1641
+ }
1642
+ function isResolveUnionRef(property) {
1643
+ var _a;
1644
+ const symbolId = (_a = property == null ? void 0 : property.symbolDef) == null ? void 0 : _a.id;
1645
+ const symbolIsArr = Array.isArray(symbolId) && symbolId.length;
1646
+ if (symbolIsArr) {
1647
+ return true;
1648
+ }
1649
+ const hasUnionString = property.type && property.type.includes("|");
1650
+ if (hasUnionString) {
1651
+ const literalValues = isLiteralValues(property.type);
1652
+ if (literalValues) {
1653
+ return false;
1654
+ }
1655
+ return true;
1656
+ }
1657
+ return false;
1658
+ }
1659
+ function isLiteralValues(type) {
1660
+ const types = type.split("|").map((t) => t.trim());
1661
+ return types.every(
1662
+ (t) => t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'")
1663
+ );
1664
+ }
1665
+
1666
+ // packages/ts/index.ts
1667
+ var importedFiles = /* @__PURE__ */ new Set();
1668
+ async function sourcesToUniformV2(root, entryPoints) {
1669
+ var _a;
1670
+ const commonOptions = {
1671
+ // entryPoints,
1672
+ // entryPointStrategy: TypeDoc.EntryPointStrategy.Packages,
1673
+ exclude: ["**/*.test.ts", "**/*.test.tsx"],
1674
+ // @ts-ignore // TODO: for some reason on build types mismatch
1675
+ excludePrivate: true,
1676
+ // @ts-ignore
1677
+ excludeProtected: true,
1678
+ // @ts-ignore
1679
+ excludeExternals: true,
1680
+ // @ts-ignore
1681
+ includeVersion: true,
1682
+ // @ts-ignore
1683
+ // hideGenerator: true,
1684
+ // @ts-ignore
1685
+ skipErrorChecking: true,
1686
+ // @ts-ignore
1687
+ sort: ["source-order"],
1688
+ // @ts-ignore
1689
+ sortEntryPoints: false
1690
+ };
1691
+ const options = {
1692
+ ...commonOptions
1693
+ };
1694
+ const everySingleFile = entryPoints == null ? void 0 : entryPoints.every((ep) => !!path2.extname(ep));
1695
+ if (everySingleFile) {
1696
+ entryPoints.map((ep) => {
1697
+ findImports(root, path2.resolve(root, ep));
1698
+ });
1699
+ const fileImported = Array.from(importedFiles) || [];
1700
+ options.entryPoints = [
1701
+ ...(_a = [
1702
+ ...entryPoints,
1703
+ ...fileImported
1704
+ ]) == null ? void 0 : _a.map((ep) => path2.resolve(root, ep))
1705
+ ];
1706
+ } else {
1707
+ options.entryPointStrategy = TypeDoc.EntryPointStrategy.Packages;
1708
+ options.entryPoints = entryPoints;
1709
+ options.packageOptions = {
1710
+ ...commonOptions
1711
+ };
1712
+ }
1713
+ const app = await TypeDoc.Application.bootstrapWithPlugins(options);
1714
+ const project = await app.convert();
1715
+ if (!project) {
1716
+ console.error("Failed to generate documentation.");
1717
+ return;
1718
+ }
1719
+ const jsonOutput = await app.serializer.projectToObject(project, root);
1720
+ const projectJson = jsonOutput;
1721
+ if (!projectJson.schemaVersion || !projectJson.children || !projectJson.children.length) {
1722
+ console.error("Failed to generate documentation.");
1723
+ return;
1724
+ }
1725
+ const references = typedocToUniform(root, projectJson);
1726
+ if (!references) {
1727
+ console.error("Failed to generate documentation.");
1728
+ return;
1729
+ }
1730
+ return {
1731
+ references,
1732
+ projectJson
1733
+ };
1734
+ }
1735
+ function findImports(root, file, seen = /* @__PURE__ */ new Set()) {
1736
+ if (seen.has(file)) return;
1737
+ seen.add(file);
1738
+ const source = ts2.createSourceFile(
1739
+ file,
1740
+ ts2.sys.readFile(file) || "",
1741
+ ts2.ScriptTarget.Latest,
1742
+ true
1743
+ );
1744
+ for (const stmt of source.statements) {
1745
+ if (ts2.isImportDeclaration(stmt) && stmt.moduleSpecifier) {
1746
+ const importPath = stmt.moduleSpecifier.getText().replace(/['"]/g, "");
1747
+ if (importPath.startsWith(".")) {
1748
+ const resolved = resolve2(file, "..", importPath + ".ts");
1749
+ const relativePath = path2.relative(root, resolved);
1750
+ importedFiles.add(relativePath);
1751
+ findImports(root, resolved, seen);
1752
+ }
1753
+ }
1754
+ }
1755
+ }
1756
+ export {
1757
+ sourcesToUniformV2,
1758
+ uniformToMiniUniform
1759
+ };
1760
+ //# sourceMappingURL=ts.js.map