@openpkg-ts/sdk 0.54.7 → 0.54.8
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/dist/index.d.ts +10 -3
- package/dist/index.js +323 -188
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1781,7 +1781,7 @@ function filterSpec(spec, criteria) {
|
|
|
1781
1781
|
};
|
|
1782
1782
|
}
|
|
1783
1783
|
// src/primitives/get.ts
|
|
1784
|
-
import
|
|
1784
|
+
import ts16 from "typescript";
|
|
1785
1785
|
|
|
1786
1786
|
// src/ast/type-identity.ts
|
|
1787
1787
|
import * as path3 from "node:path";
|
|
@@ -2450,6 +2450,15 @@ function discoverAmbientTypePackages(baseDir) {
|
|
|
2450
2450
|
}
|
|
2451
2451
|
return found;
|
|
2452
2452
|
}
|
|
2453
|
+
function resolutionFor(module) {
|
|
2454
|
+
if (module === ts3.ModuleKind.NodeNext)
|
|
2455
|
+
return ts3.ModuleResolutionKind.NodeNext;
|
|
2456
|
+
if (module >= ts3.ModuleKind.Node16 && module < ts3.ModuleKind.NodeNext)
|
|
2457
|
+
return ts3.ModuleResolutionKind.Node16;
|
|
2458
|
+
if (module >= ts3.ModuleKind.ES2015)
|
|
2459
|
+
return ts3.ModuleResolutionKind.Bundler;
|
|
2460
|
+
return;
|
|
2461
|
+
}
|
|
2453
2462
|
function createProgram(options) {
|
|
2454
2463
|
const { content } = options;
|
|
2455
2464
|
const entryFile = path5.resolve(options.entryFile);
|
|
@@ -2465,7 +2474,7 @@ function createProgram(options) {
|
|
|
2465
2474
|
const parsedConfig = ts3.parseJsonConfigFileContent(configFile.config, ts3.sys, path5.dirname(configPath));
|
|
2466
2475
|
compilerOptions = { ...compilerOptions, ...parsedConfig.options };
|
|
2467
2476
|
if (parsedConfig.options.module !== undefined && parsedConfig.options.moduleResolution === undefined) {
|
|
2468
|
-
|
|
2477
|
+
compilerOptions.moduleResolution = resolutionFor(parsedConfig.options.module);
|
|
2469
2478
|
}
|
|
2470
2479
|
additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
|
|
2471
2480
|
let sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
|
|
@@ -2546,7 +2555,7 @@ function createProgram(options) {
|
|
|
2546
2555
|
}
|
|
2547
2556
|
|
|
2548
2557
|
// src/serializers/classes.ts
|
|
2549
|
-
import
|
|
2558
|
+
import ts10 from "typescript";
|
|
2550
2559
|
|
|
2551
2560
|
// src/types/parameters.ts
|
|
2552
2561
|
import ts6 from "typescript";
|
|
@@ -3721,7 +3730,8 @@ function buildFunctionSchema(callSignatures, checker, ctx) {
|
|
|
3721
3730
|
return {
|
|
3722
3731
|
name: param.getName(),
|
|
3723
3732
|
schema: buildSchema(effectiveType, checker, ctx, decl.type),
|
|
3724
|
-
required: !isOptional
|
|
3733
|
+
required: !isOptional && !decl.dotDotDotToken,
|
|
3734
|
+
...decl.dotDotDotToken ? { rest: true } : {}
|
|
3725
3735
|
};
|
|
3726
3736
|
});
|
|
3727
3737
|
const returnType = checker.getReturnTypeOfSignature(sig);
|
|
@@ -3947,6 +3957,7 @@ function extractParameters(signature, ctx) {
|
|
|
3947
3957
|
result.push(...expandedParams);
|
|
3948
3958
|
} else {
|
|
3949
3959
|
const isOptional = !!decl?.questionToken || !!decl?.initializer;
|
|
3960
|
+
const isRest = !!decl.dotDotDotToken;
|
|
3950
3961
|
const paramName = param.getName();
|
|
3951
3962
|
const description = getParamDescription(paramName, jsdocTags);
|
|
3952
3963
|
const schema = defer ? buildSchemaFromTypeNode(decl.type, checker, ctx) : buildSchema(isOptional ? stripUndefinedFromType(type, checker) : type, checker, ctx, decl.type);
|
|
@@ -3956,7 +3967,8 @@ function extractParameters(signature, ctx) {
|
|
|
3956
3967
|
const paramResult = {
|
|
3957
3968
|
name: paramName,
|
|
3958
3969
|
schema,
|
|
3959
|
-
required: !isOptional
|
|
3970
|
+
required: !isOptional && !isRest,
|
|
3971
|
+
...isRest ? { rest: true } : {}
|
|
3960
3972
|
};
|
|
3961
3973
|
if (description) {
|
|
3962
3974
|
paramResult.description = description;
|
|
@@ -4561,7 +4573,7 @@ function walkBaseTypes(type, ownMemberNames, inherited, inheritedNames, visited,
|
|
|
4561
4573
|
continue;
|
|
4562
4574
|
if (propName.startsWith("#") || propName.startsWith("__"))
|
|
4563
4575
|
continue;
|
|
4564
|
-
const member = serializeInheritedMember(prop, baseName, ctx, isStatic);
|
|
4576
|
+
const member = serializeInheritedMember(prop, declaringTypeName(prop) ?? baseName, ctx, isStatic);
|
|
4565
4577
|
if (member) {
|
|
4566
4578
|
inherited.push(member);
|
|
4567
4579
|
inheritedNames.add(propName);
|
|
@@ -4570,6 +4582,12 @@ function walkBaseTypes(type, ownMemberNames, inherited, inheritedNames, visited,
|
|
|
4570
4582
|
walkBaseTypes(baseType, ownMemberNames, inherited, inheritedNames, visited, ctx, isStatic);
|
|
4571
4583
|
}
|
|
4572
4584
|
}
|
|
4585
|
+
function declaringTypeName(prop) {
|
|
4586
|
+
const parent = prop.declarations?.[0]?.parent;
|
|
4587
|
+
if (!parent || !(ts8.isClassLike(parent) || ts8.isInterfaceDeclaration(parent)))
|
|
4588
|
+
return;
|
|
4589
|
+
return parent.name?.text;
|
|
4590
|
+
}
|
|
4573
4591
|
function getStaticMembers(classType, checker) {
|
|
4574
4592
|
const symbol = classType.getSymbol();
|
|
4575
4593
|
if (!symbol)
|
|
@@ -4583,6 +4601,15 @@ function getStaticMembers(classType, checker) {
|
|
|
4583
4601
|
return name !== "prototype" && name !== "constructor" && !name.startsWith("__");
|
|
4584
4602
|
});
|
|
4585
4603
|
}
|
|
4604
|
+
function inheritedMethodSchema(symbol, type, ctx) {
|
|
4605
|
+
if (!ctx.budgetExceeded) {
|
|
4606
|
+
return decoratePropertySchema({ "x-ts-function": true }, symbol, type, ctx.typeChecker);
|
|
4607
|
+
}
|
|
4608
|
+
return {
|
|
4609
|
+
"x-ts-function": true,
|
|
4610
|
+
...symbol.flags & ts8.SymbolFlags.Method ? { "x-ts-method": true } : {}
|
|
4611
|
+
};
|
|
4612
|
+
}
|
|
4586
4613
|
function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
|
|
4587
4614
|
const { typeChecker: checker } = ctx;
|
|
4588
4615
|
const name = symbol.getName();
|
|
@@ -4590,8 +4617,12 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
|
|
|
4590
4617
|
const decl = declarations[0];
|
|
4591
4618
|
if (!decl)
|
|
4592
4619
|
return null;
|
|
4593
|
-
const
|
|
4594
|
-
|
|
4620
|
+
const isOptional = !!(symbol.flags & ts8.SymbolFlags.Optional);
|
|
4621
|
+
const rawType = checker.getTypeOfSymbol(symbol);
|
|
4622
|
+
const type = isOptional ? stripUndefinedFromType(rawType, checker) : rawType;
|
|
4623
|
+
const registerTypes = !ctx.budgetExceeded;
|
|
4624
|
+
if (registerTypes)
|
|
4625
|
+
registerReferencedTypes(type, ctx);
|
|
4595
4626
|
let visibility;
|
|
4596
4627
|
if (decl && ts8.canHaveModifiers(decl)) {
|
|
4597
4628
|
const modifiers = ts8.getModifiers(decl);
|
|
@@ -4609,6 +4640,7 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
|
|
|
4609
4640
|
if (visibility === "private")
|
|
4610
4641
|
return null;
|
|
4611
4642
|
const { description, tags, inlineTags } = getJSDocComment(decl);
|
|
4643
|
+
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
4612
4644
|
let kind = "property";
|
|
4613
4645
|
const callSigs = type.getCallSignatures();
|
|
4614
4646
|
if (callSigs.length > 0) {
|
|
@@ -4621,6 +4653,8 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
|
|
|
4621
4653
|
const flags = {};
|
|
4622
4654
|
if (isStatic)
|
|
4623
4655
|
flags.static = true;
|
|
4656
|
+
if (isOptional)
|
|
4657
|
+
flags.optional = true;
|
|
4624
4658
|
if (decl && ts8.canHaveModifiers(decl)) {
|
|
4625
4659
|
const modifiers = ts8.getModifiers(decl);
|
|
4626
4660
|
if (modifiers?.some((m) => m.kind === ts8.SyntaxKind.ReadonlyKeyword)) {
|
|
@@ -4632,7 +4666,8 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
|
|
|
4632
4666
|
signatures = callSigs.map((sig, index) => {
|
|
4633
4667
|
const params = extractParameters(sig, ctx);
|
|
4634
4668
|
const returnType = checker.getReturnTypeOfSignature(sig);
|
|
4635
|
-
|
|
4669
|
+
if (registerTypes)
|
|
4670
|
+
registerReferencedTypes(returnType, ctx);
|
|
4636
4671
|
const sigDoc = getJSDocForSignature(sig, checker);
|
|
4637
4672
|
return {
|
|
4638
4673
|
parameters: params.length > 0 ? params : undefined,
|
|
@@ -4653,20 +4688,25 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
|
|
|
4653
4688
|
description,
|
|
4654
4689
|
tags: tags.length > 0 ? tags : undefined,
|
|
4655
4690
|
visibility,
|
|
4656
|
-
schema: kind !== "method" ? buildSchema(type, checker, ctx, declaredTypeNode(decl)) :
|
|
4691
|
+
schema: kind !== "method" ? buildSchema(type, checker, ctx, declaredTypeNode(decl)) : inheritedMethodSchema(symbol, type, ctx),
|
|
4657
4692
|
signatures,
|
|
4658
4693
|
flags: Object.keys(flags).length > 0 ? flags : undefined,
|
|
4659
|
-
...inlineTags ? { inlineTags } : {}
|
|
4694
|
+
...inlineTags ? { inlineTags } : {},
|
|
4695
|
+
...deprecated ? { deprecated: true, deprecationReason } : {}
|
|
4660
4696
|
};
|
|
4661
4697
|
}
|
|
4662
4698
|
|
|
4663
4699
|
// src/serializers/shared.ts
|
|
4700
|
+
import ts9 from "typescript";
|
|
4664
4701
|
function extractExportMetadata(node, symbol, checker, jsdocNode) {
|
|
4665
4702
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
4666
4703
|
const { description, tags, examples, inlineTags } = getJSDocComment(jsdocNode ?? node, symbol, checker);
|
|
4667
4704
|
const source = getSourceLocation(node, node.getSourceFile());
|
|
4668
4705
|
return { description, tags, examples, source, deprecated, deprecationReason, inlineTags };
|
|
4669
4706
|
}
|
|
4707
|
+
function anonymousDefaultName(node) {
|
|
4708
|
+
return ts9.getCombinedModifierFlags(node) & ts9.ModifierFlags.Default ? "default" : undefined;
|
|
4709
|
+
}
|
|
4670
4710
|
function buildSignatures(callSignatures, checker, ctx) {
|
|
4671
4711
|
return callSignatures.map((sig, index) => {
|
|
4672
4712
|
const params = extractParameters(sig, ctx);
|
|
@@ -4691,7 +4731,7 @@ function buildSignatures(callSignatures, checker, ctx) {
|
|
|
4691
4731
|
function serializeClass(node, ctx) {
|
|
4692
4732
|
const { typeChecker: checker } = ctx;
|
|
4693
4733
|
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
4694
|
-
const name = symbol?.getName() ?? node.name?.getText();
|
|
4734
|
+
const name = symbol?.getName() ?? node.name?.getText() ?? anonymousDefaultName(node);
|
|
4695
4735
|
if (!name)
|
|
4696
4736
|
return null;
|
|
4697
4737
|
const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, checker);
|
|
@@ -4703,11 +4743,11 @@ function serializeClass(node, ctx) {
|
|
|
4703
4743
|
const memberName = getMemberName(member);
|
|
4704
4744
|
if (memberName?.startsWith("#"))
|
|
4705
4745
|
continue;
|
|
4706
|
-
if (
|
|
4746
|
+
if (ts10.isPropertyDeclaration(member)) {
|
|
4707
4747
|
const propMember = serializeProperty(member, ctx);
|
|
4708
4748
|
if (propMember)
|
|
4709
4749
|
members.push(propMember);
|
|
4710
|
-
} else if (
|
|
4750
|
+
} else if (ts10.isMethodDeclaration(member)) {
|
|
4711
4751
|
const methodMember = serializeMethod(member, ctx);
|
|
4712
4752
|
if (methodMember?.name) {
|
|
4713
4753
|
if (!methodsByName.has(methodMember.name)) {
|
|
@@ -4724,11 +4764,11 @@ function serializeClass(node, ctx) {
|
|
|
4724
4764
|
}
|
|
4725
4765
|
}
|
|
4726
4766
|
}
|
|
4727
|
-
} else if (
|
|
4767
|
+
} else if (ts10.isConstructorDeclaration(member)) {
|
|
4728
4768
|
const ctorSig = serializeConstructor(member, ctx);
|
|
4729
4769
|
if (ctorSig)
|
|
4730
4770
|
signatures.push(ctorSig);
|
|
4731
|
-
} else if (
|
|
4771
|
+
} else if (ts10.isGetAccessorDeclaration(member) || ts10.isSetAccessorDeclaration(member)) {
|
|
4732
4772
|
const accessorMember = serializeAccessor(member, ctx);
|
|
4733
4773
|
if (accessorMember)
|
|
4734
4774
|
members.push(accessorMember);
|
|
@@ -4752,8 +4792,8 @@ function serializeClass(node, ctx) {
|
|
|
4752
4792
|
const extendsClause = getExtendsClause(node, checker);
|
|
4753
4793
|
const implementsClause = getImplementsClause(node, checker);
|
|
4754
4794
|
const classFlags = {};
|
|
4755
|
-
const classModifiers =
|
|
4756
|
-
if (classModifiers?.some((m) => m.kind ===
|
|
4795
|
+
const classModifiers = ts10.getModifiers(node);
|
|
4796
|
+
if (classModifiers?.some((m) => m.kind === ts10.SyntaxKind.AbstractKeyword)) {
|
|
4757
4797
|
classFlags.abstract = true;
|
|
4758
4798
|
}
|
|
4759
4799
|
return {
|
|
@@ -4775,37 +4815,37 @@ function serializeClass(node, ctx) {
|
|
|
4775
4815
|
};
|
|
4776
4816
|
}
|
|
4777
4817
|
function getMemberName(member) {
|
|
4778
|
-
if (
|
|
4818
|
+
if (ts10.isConstructorDeclaration(member))
|
|
4779
4819
|
return "constructor";
|
|
4780
4820
|
if (!member.name)
|
|
4781
4821
|
return;
|
|
4782
|
-
if (
|
|
4822
|
+
if (ts10.isIdentifier(member.name))
|
|
4783
4823
|
return member.name.text;
|
|
4784
|
-
if (
|
|
4824
|
+
if (ts10.isPrivateIdentifier(member.name))
|
|
4785
4825
|
return member.name.text;
|
|
4786
4826
|
return member.name.getText();
|
|
4787
4827
|
}
|
|
4788
4828
|
function getVisibility(member) {
|
|
4789
|
-
const modifiers =
|
|
4829
|
+
const modifiers = ts10.canHaveModifiers(member) ? ts10.getModifiers(member) : undefined;
|
|
4790
4830
|
if (!modifiers)
|
|
4791
4831
|
return;
|
|
4792
4832
|
for (const mod of modifiers) {
|
|
4793
|
-
if (mod.kind ===
|
|
4833
|
+
if (mod.kind === ts10.SyntaxKind.PrivateKeyword)
|
|
4794
4834
|
return "private";
|
|
4795
|
-
if (mod.kind ===
|
|
4835
|
+
if (mod.kind === ts10.SyntaxKind.ProtectedKeyword)
|
|
4796
4836
|
return "protected";
|
|
4797
|
-
if (mod.kind ===
|
|
4837
|
+
if (mod.kind === ts10.SyntaxKind.PublicKeyword)
|
|
4798
4838
|
return "public";
|
|
4799
4839
|
}
|
|
4800
4840
|
return;
|
|
4801
4841
|
}
|
|
4802
4842
|
function isStatic(member) {
|
|
4803
|
-
const modifiers =
|
|
4804
|
-
return modifiers?.some((m) => m.kind ===
|
|
4843
|
+
const modifiers = ts10.canHaveModifiers(member) ? ts10.getModifiers(member) : undefined;
|
|
4844
|
+
return modifiers?.some((m) => m.kind === ts10.SyntaxKind.StaticKeyword) ?? false;
|
|
4805
4845
|
}
|
|
4806
4846
|
function isReadonly(member) {
|
|
4807
|
-
const modifiers =
|
|
4808
|
-
return modifiers?.some((m) => m.kind ===
|
|
4847
|
+
const modifiers = ts10.canHaveModifiers(member) ? ts10.getModifiers(member) : undefined;
|
|
4848
|
+
return modifiers?.some((m) => m.kind === ts10.SyntaxKind.ReadonlyKeyword) ?? false;
|
|
4809
4849
|
}
|
|
4810
4850
|
function serializeProperty(node, ctx) {
|
|
4811
4851
|
const { typeChecker: checker } = ctx;
|
|
@@ -4864,11 +4904,11 @@ function serializeMethod(node, ctx) {
|
|
|
4864
4904
|
if (node.asteriskToken)
|
|
4865
4905
|
flags.generator = true;
|
|
4866
4906
|
flags.methodSyntax = true;
|
|
4867
|
-
const modifiers =
|
|
4868
|
-
if (modifiers?.some((m) => m.kind ===
|
|
4907
|
+
const modifiers = ts10.getModifiers(node);
|
|
4908
|
+
if (modifiers?.some((m) => m.kind === ts10.SyntaxKind.AsyncKeyword)) {
|
|
4869
4909
|
flags.async = true;
|
|
4870
4910
|
}
|
|
4871
|
-
if (modifiers?.some((m) => m.kind ===
|
|
4911
|
+
if (modifiers?.some((m) => m.kind === ts10.SyntaxKind.AbstractKeyword)) {
|
|
4872
4912
|
flags.abstract = true;
|
|
4873
4913
|
}
|
|
4874
4914
|
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
@@ -4907,7 +4947,7 @@ function serializeConstructorSignature(node, sig, ctx) {
|
|
|
4907
4947
|
}
|
|
4908
4948
|
function serializeInheritedConstructors(node, ctx) {
|
|
4909
4949
|
const { typeChecker: checker } = ctx;
|
|
4910
|
-
const hasExtends = node.heritageClauses?.some((c) => c.token ===
|
|
4950
|
+
const hasExtends = node.heritageClauses?.some((c) => c.token === ts10.SyntaxKind.ExtendsKeyword);
|
|
4911
4951
|
if (!hasExtends)
|
|
4912
4952
|
return [];
|
|
4913
4953
|
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
@@ -4916,11 +4956,11 @@ function serializeInheritedConstructors(node, ctx) {
|
|
|
4916
4956
|
const staticType = checker.getTypeOfSymbolAtLocation(symbol, node);
|
|
4917
4957
|
const ctorSigs = staticType.getConstructSignatures().filter((sig) => {
|
|
4918
4958
|
const decl = sig.getDeclaration();
|
|
4919
|
-
return decl !== undefined &&
|
|
4959
|
+
return decl !== undefined && ts10.isConstructorDeclaration(decl);
|
|
4920
4960
|
});
|
|
4921
4961
|
return ctorSigs.map((sig, index) => {
|
|
4922
4962
|
const decl = sig.getDeclaration();
|
|
4923
|
-
const owner =
|
|
4963
|
+
const owner = ts10.isClassLike(decl.parent) ? decl.parent.name?.text : undefined;
|
|
4924
4964
|
return {
|
|
4925
4965
|
...serializeConstructorSignature(decl, sig, ctx),
|
|
4926
4966
|
...owner ? { inheritedFrom: owner } : {},
|
|
@@ -4939,14 +4979,14 @@ function serializeAccessor(node, ctx) {
|
|
|
4939
4979
|
return null;
|
|
4940
4980
|
}
|
|
4941
4981
|
const type = checker.getTypeAtLocation(node);
|
|
4942
|
-
const schema = buildSchema(type, checker, ctx,
|
|
4982
|
+
const schema = buildSchema(type, checker, ctx, ts10.isGetAccessorDeclaration(node) ? node.type : undefined);
|
|
4943
4983
|
registerReferencedTypes(type, ctx);
|
|
4944
|
-
const kind =
|
|
4984
|
+
const kind = ts10.isGetAccessorDeclaration(node) ? "getter" : "setter";
|
|
4945
4985
|
const flags = {};
|
|
4946
4986
|
if (isStatic(node))
|
|
4947
4987
|
flags.static = true;
|
|
4948
4988
|
let signatures;
|
|
4949
|
-
if (
|
|
4989
|
+
if (ts10.isSetAccessorDeclaration(node) && node.parameters.length > 0) {
|
|
4950
4990
|
const param = node.parameters[0];
|
|
4951
4991
|
const paramName = param.name.getText();
|
|
4952
4992
|
const paramType = checker.getTypeAtLocation(param);
|
|
@@ -4979,7 +5019,7 @@ function getExtendsClause(node, checker) {
|
|
|
4979
5019
|
if (!node.heritageClauses)
|
|
4980
5020
|
return;
|
|
4981
5021
|
for (const clause of node.heritageClauses) {
|
|
4982
|
-
if (clause.token ===
|
|
5022
|
+
if (clause.token === ts10.SyntaxKind.ExtendsKeyword) {
|
|
4983
5023
|
const expr = clause.types[0];
|
|
4984
5024
|
if (expr) {
|
|
4985
5025
|
const type = checker.getTypeAtLocation(expr);
|
|
@@ -4994,7 +5034,7 @@ function getImplementsClause(node, checker) {
|
|
|
4994
5034
|
if (!node.heritageClauses)
|
|
4995
5035
|
return;
|
|
4996
5036
|
for (const clause of node.heritageClauses) {
|
|
4997
|
-
if (clause.token ===
|
|
5037
|
+
if (clause.token === ts10.SyntaxKind.ImplementsKeyword) {
|
|
4998
5038
|
return clause.types.map((expr) => {
|
|
4999
5039
|
const type = checker.getTypeAtLocation(expr);
|
|
5000
5040
|
const symbol = type.getSymbol();
|
|
@@ -5057,16 +5097,16 @@ function serializeEnum(node, ctx) {
|
|
|
5057
5097
|
}
|
|
5058
5098
|
|
|
5059
5099
|
// src/serializers/functions.ts
|
|
5060
|
-
import
|
|
5100
|
+
import ts11 from "typescript";
|
|
5061
5101
|
function buildReturnSchema(sig, ctx) {
|
|
5062
5102
|
const returnType = ctx.typeChecker.getReturnTypeOfSignature(sig);
|
|
5063
5103
|
registerReferencedTypes(returnType, ctx);
|
|
5064
5104
|
const schema = buildSchema(returnType, ctx.typeChecker, ctx, typeNodeOfSignature(sig));
|
|
5065
5105
|
const declaration = sig.getDeclaration();
|
|
5066
|
-
if (declaration &&
|
|
5106
|
+
if (declaration && ts11.isFunctionLike(declaration) && declaration.type) {
|
|
5067
5107
|
const returnTypeNode = declaration.type;
|
|
5068
|
-
if (
|
|
5069
|
-
const parameterName =
|
|
5108
|
+
if (ts11.isTypePredicateNode(returnTypeNode)) {
|
|
5109
|
+
const parameterName = ts11.isIdentifier(returnTypeNode.parameterName) ? returnTypeNode.parameterName.text : returnTypeNode.parameterName.getText();
|
|
5070
5110
|
let predicateTypeSchema = { type: "unknown" };
|
|
5071
5111
|
if (returnTypeNode.type) {
|
|
5072
5112
|
const predicateType = ctx.typeChecker.getTypeAtLocation(returnTypeNode.type);
|
|
@@ -5087,10 +5127,10 @@ function buildReturnSchema(sig, ctx) {
|
|
|
5087
5127
|
return { schema };
|
|
5088
5128
|
}
|
|
5089
5129
|
function functionSignatureDecls(node, ctx) {
|
|
5090
|
-
if (!
|
|
5130
|
+
if (!ts11.isFunctionDeclaration(node) || !node.name)
|
|
5091
5131
|
return [node];
|
|
5092
5132
|
const symbol = ctx.typeChecker.getSymbolAtLocation(node.name);
|
|
5093
|
-
const fns = (symbol?.declarations ?? []).filter(
|
|
5133
|
+
const fns = (symbol?.declarations ?? []).filter(ts11.isFunctionDeclaration);
|
|
5094
5134
|
const overloads = fns.filter((d) => !d.body);
|
|
5095
5135
|
return overloads.length > 0 ? overloads : [node];
|
|
5096
5136
|
}
|
|
@@ -5122,14 +5162,15 @@ function schemaFromTypeNode(node, ctx) {
|
|
|
5122
5162
|
return buildSchema(ctx.typeChecker.getTypeFromTypeNode(node), ctx.typeChecker, ctx, node);
|
|
5123
5163
|
}
|
|
5124
5164
|
function parametersFromAst(decl, ctx) {
|
|
5125
|
-
const jsdocTags =
|
|
5165
|
+
const jsdocTags = ts11.getJSDocTags(decl);
|
|
5126
5166
|
return decl.parameters.map((p) => {
|
|
5127
|
-
const name =
|
|
5167
|
+
const name = ts11.isIdentifier(p.name) ? p.name.text : p.name.getText();
|
|
5128
5168
|
const isOptional = !!p.questionToken || !!p.initializer;
|
|
5129
5169
|
const param = {
|
|
5130
5170
|
name,
|
|
5131
5171
|
schema: schemaFromTypeNode(p.type, ctx),
|
|
5132
|
-
required: !isOptional
|
|
5172
|
+
required: !isOptional && !p.dotDotDotToken,
|
|
5173
|
+
...p.dotDotDotToken ? { rest: true } : {}
|
|
5133
5174
|
};
|
|
5134
5175
|
const description = getParamDescription(name, jsdocTags);
|
|
5135
5176
|
if (description)
|
|
@@ -5137,11 +5178,10 @@ function parametersFromAst(decl, ctx) {
|
|
|
5137
5178
|
return param;
|
|
5138
5179
|
});
|
|
5139
5180
|
}
|
|
5140
|
-
function signaturesFromAst(
|
|
5141
|
-
const decls = functionSignatureDecls(node, ctx);
|
|
5181
|
+
function signaturesFromAst(decls, ctx) {
|
|
5142
5182
|
return decls.map((decl, index) => {
|
|
5143
5183
|
const sigDoc = getJSDocComment(decl);
|
|
5144
|
-
const sigTypeParams =
|
|
5184
|
+
const sigTypeParams = ts11.isFunctionDeclaration(decl) || ts11.isArrowFunction(decl) || ts11.isFunctionExpression(decl) || ts11.isFunctionTypeNode(decl) ? extractTypeParameters(decl, ctx.typeChecker) : undefined;
|
|
5145
5185
|
const returns = { schema: schemaFromTypeNode(decl.type, ctx) };
|
|
5146
5186
|
return {
|
|
5147
5187
|
parameters: parametersFromAst(decl, ctx),
|
|
@@ -5154,9 +5194,7 @@ function signaturesFromAst(node, ctx) {
|
|
|
5154
5194
|
};
|
|
5155
5195
|
});
|
|
5156
5196
|
}
|
|
5157
|
-
function signaturesFromChecker(
|
|
5158
|
-
const type = ctx.typeChecker.getTypeAtLocation(node);
|
|
5159
|
-
const callSignatures = type.getCallSignatures();
|
|
5197
|
+
function signaturesFromChecker(callSignatures, ctx) {
|
|
5160
5198
|
return callSignatures.map((sig, index) => {
|
|
5161
5199
|
const sigDoc = getJSDocForSignature(sig, ctx.typeChecker);
|
|
5162
5200
|
const sigTypeParams = extractTypeParametersFromSignature(sig, ctx.typeChecker);
|
|
@@ -5171,17 +5209,31 @@ function signaturesFromChecker(node, ctx) {
|
|
|
5171
5209
|
};
|
|
5172
5210
|
});
|
|
5173
5211
|
}
|
|
5174
|
-
function
|
|
5212
|
+
function unwrapParens(node) {
|
|
5213
|
+
return ts11.isParenthesizedTypeNode(node) ? unwrapParens(node.type) : node;
|
|
5214
|
+
}
|
|
5215
|
+
function signaturesFromDeclaredType(typeNode, ctx) {
|
|
5216
|
+
const inner = unwrapParens(typeNode);
|
|
5217
|
+
if (ts11.isFunctionTypeNode(inner) && signatureDeclDefers(inner, ctx)) {
|
|
5218
|
+
return signaturesFromAst([inner], ctx);
|
|
5219
|
+
}
|
|
5220
|
+
if (typeNodeDefersExpansion(inner, ctx.typeChecker, ctx.program))
|
|
5221
|
+
return;
|
|
5222
|
+
const callSignatures = ctx.typeChecker.getTypeFromTypeNode(inner).getCallSignatures();
|
|
5223
|
+
return callSignatures.length > 0 ? signaturesFromChecker(callSignatures, ctx) : undefined;
|
|
5224
|
+
}
|
|
5225
|
+
function serializeFunctionExport(node, ctx, nameOverride, declaredType) {
|
|
5175
5226
|
const symbol = ctx.typeChecker.getSymbolAtLocation(node.name ?? node);
|
|
5176
|
-
const name = nameOverride ?? symbol?.getName() ?? node.name?.getText();
|
|
5227
|
+
const name = nameOverride ?? symbol?.getName() ?? node.name?.getText() ?? anonymousDefaultName(node);
|
|
5177
5228
|
if (!name)
|
|
5178
5229
|
return null;
|
|
5179
5230
|
const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, ctx.typeChecker);
|
|
5180
|
-
const
|
|
5181
|
-
const
|
|
5231
|
+
const declaredFn = declaredType && unwrapParens(declaredType);
|
|
5232
|
+
const typeParameters = extractTypeParameters(declaredFn && ts11.isFunctionTypeNode(declaredFn) ? declaredFn : node, ctx.typeChecker);
|
|
5233
|
+
const signatures = (declaredType && signaturesFromDeclaredType(declaredType, ctx)) ?? (anySignatureDefers(node, ctx) ? signaturesFromAst(functionSignatureDecls(node, ctx), ctx) : signaturesFromChecker(ctx.typeChecker.getTypeAtLocation(node).getCallSignatures(), ctx));
|
|
5182
5234
|
const flags = {};
|
|
5183
|
-
const modifiers =
|
|
5184
|
-
if (modifiers?.some((m) => m.kind ===
|
|
5235
|
+
const modifiers = ts11.getModifiers(node);
|
|
5236
|
+
if (modifiers?.some((m) => m.kind === ts11.SyntaxKind.AsyncKeyword)) {
|
|
5185
5237
|
flags.async = true;
|
|
5186
5238
|
}
|
|
5187
5239
|
if (node.asteriskToken) {
|
|
@@ -5204,7 +5256,7 @@ function serializeFunctionExport(node, ctx, nameOverride) {
|
|
|
5204
5256
|
}
|
|
5205
5257
|
|
|
5206
5258
|
// src/serializers/interfaces.ts
|
|
5207
|
-
import
|
|
5259
|
+
import ts12 from "typescript";
|
|
5208
5260
|
function serializeInterface(node, ctx) {
|
|
5209
5261
|
const { typeChecker: checker } = ctx;
|
|
5210
5262
|
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
@@ -5213,15 +5265,35 @@ function serializeInterface(node, ctx) {
|
|
|
5213
5265
|
return null;
|
|
5214
5266
|
const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, checker);
|
|
5215
5267
|
const typeParameters = extractTypeParameters(node, checker);
|
|
5268
|
+
const { members, callSignatureMember } = serializeTypeElements(node.members, ctx);
|
|
5269
|
+
const extendsClause = getInterfaceExtends(node, checker);
|
|
5270
|
+
const exportSignatures = callSignatureMember?.signatures && callSignatureMember.signatures.length > 0 ? callSignatureMember.signatures : undefined;
|
|
5271
|
+
return {
|
|
5272
|
+
id: name,
|
|
5273
|
+
name,
|
|
5274
|
+
kind: "interface",
|
|
5275
|
+
description,
|
|
5276
|
+
tags,
|
|
5277
|
+
source,
|
|
5278
|
+
typeParameters,
|
|
5279
|
+
members: members.length > 0 ? members : undefined,
|
|
5280
|
+
signatures: exportSignatures,
|
|
5281
|
+
extends: extendsClause,
|
|
5282
|
+
...deprecated ? { deprecated: true, deprecationReason } : {},
|
|
5283
|
+
...examples.length > 0 ? { examples } : {},
|
|
5284
|
+
...inlineTags ? { inlineTags } : {}
|
|
5285
|
+
};
|
|
5286
|
+
}
|
|
5287
|
+
function serializeTypeElements(elements, ctx) {
|
|
5216
5288
|
const members = [];
|
|
5217
5289
|
const methodsByName = new Map;
|
|
5218
5290
|
let callSignatureMember = null;
|
|
5219
|
-
for (const member of
|
|
5220
|
-
if (
|
|
5291
|
+
for (const member of elements) {
|
|
5292
|
+
if (ts12.isPropertySignature(member)) {
|
|
5221
5293
|
const propMember = serializePropertySignature(member, ctx);
|
|
5222
5294
|
if (propMember)
|
|
5223
5295
|
members.push(propMember);
|
|
5224
|
-
} else if (
|
|
5296
|
+
} else if (ts12.isMethodSignature(member)) {
|
|
5225
5297
|
const methodMember = serializeMethodSignature(member, ctx);
|
|
5226
5298
|
if (methodMember?.name && methodMember.signatures) {
|
|
5227
5299
|
const existing = methodsByName.get(methodMember.name);
|
|
@@ -5242,7 +5314,7 @@ function serializeInterface(node, ctx) {
|
|
|
5242
5314
|
methodsByName.set(methodMember.name, methodMember);
|
|
5243
5315
|
}
|
|
5244
5316
|
}
|
|
5245
|
-
} else if (
|
|
5317
|
+
} else if (ts12.isCallSignatureDeclaration(member)) {
|
|
5246
5318
|
const callSig = serializeCallSignature(member, ctx);
|
|
5247
5319
|
if (callSig?.signatures) {
|
|
5248
5320
|
if (callSignatureMember?.signatures) {
|
|
@@ -5265,7 +5337,7 @@ function serializeInterface(node, ctx) {
|
|
|
5265
5337
|
callSignatureMember = callSig;
|
|
5266
5338
|
}
|
|
5267
5339
|
}
|
|
5268
|
-
} else if (
|
|
5340
|
+
} else if (ts12.isIndexSignatureDeclaration(member)) {
|
|
5269
5341
|
const indexMember = serializeIndexSignature(member, ctx);
|
|
5270
5342
|
if (indexMember)
|
|
5271
5343
|
members.push(indexMember);
|
|
@@ -5275,22 +5347,31 @@ function serializeInterface(node, ctx) {
|
|
|
5275
5347
|
members.push(callSignatureMember);
|
|
5276
5348
|
}
|
|
5277
5349
|
members.push(...methodsByName.values());
|
|
5278
|
-
|
|
5279
|
-
|
|
5350
|
+
return { members, callSignatureMember };
|
|
5351
|
+
}
|
|
5352
|
+
function serializeMergedTypeSide(symbol, ctx) {
|
|
5353
|
+
const { typeChecker: checker } = ctx;
|
|
5354
|
+
const declarations = symbol.declarations ?? [];
|
|
5355
|
+
const interfaces = declarations.filter(ts12.isInterfaceDeclaration);
|
|
5356
|
+
const alias = declarations.find(ts12.isTypeAliasDeclaration);
|
|
5357
|
+
const typeDecl = interfaces[0] ?? alias;
|
|
5358
|
+
if (!typeDecl)
|
|
5359
|
+
return;
|
|
5360
|
+
const elements = interfaces.length > 0 ? interfaces.flatMap((decl) => [...decl.members]) : alias && ts12.isTypeLiteralNode(alias.type) ? [...alias.type.members] : [];
|
|
5361
|
+
const { members } = serializeTypeElements(elements, ctx);
|
|
5362
|
+
if (interfaces.length > 0) {
|
|
5363
|
+
const ownNames = new Set(members.flatMap((m) => m.name ? [m.name] : []));
|
|
5364
|
+
members.push(...getInheritedMembers(checker.getDeclaredTypeOfSymbol(symbol), ownNames, ctx, false));
|
|
5365
|
+
}
|
|
5366
|
+
if (members.length === 0)
|
|
5367
|
+
return;
|
|
5368
|
+
const { description, tags } = getJSDocComment(typeDecl);
|
|
5280
5369
|
return {
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5370
|
+
members,
|
|
5371
|
+
extends: interfaces.map((decl) => getInterfaceExtends(decl, checker)).find(Boolean),
|
|
5372
|
+
typeParameters: extractTypeParameters(typeDecl, checker),
|
|
5284
5373
|
description,
|
|
5285
|
-
tags
|
|
5286
|
-
source,
|
|
5287
|
-
typeParameters,
|
|
5288
|
-
members: members.length > 0 ? members : undefined,
|
|
5289
|
-
signatures: exportSignatures,
|
|
5290
|
-
extends: extendsClause,
|
|
5291
|
-
...deprecated ? { deprecated: true, deprecationReason } : {},
|
|
5292
|
-
...examples.length > 0 ? { examples } : {},
|
|
5293
|
-
...inlineTags ? { inlineTags } : {}
|
|
5374
|
+
tags
|
|
5294
5375
|
};
|
|
5295
5376
|
}
|
|
5296
5377
|
function serializePropertySignature(node, ctx) {
|
|
@@ -5304,7 +5385,7 @@ function serializePropertySignature(node, ctx) {
|
|
|
5304
5385
|
const flags = {};
|
|
5305
5386
|
if (node.questionToken)
|
|
5306
5387
|
flags.optional = true;
|
|
5307
|
-
if (node.modifiers?.some((m) => m.kind ===
|
|
5388
|
+
if (node.modifiers?.some((m) => m.kind === ts12.SyntaxKind.ReadonlyKeyword)) {
|
|
5308
5389
|
flags.readonly = true;
|
|
5309
5390
|
}
|
|
5310
5391
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
@@ -5327,7 +5408,8 @@ function serializeMethodSignature(node, ctx) {
|
|
|
5327
5408
|
const { typeChecker: checker } = ctx;
|
|
5328
5409
|
const name = node.name.getText();
|
|
5329
5410
|
const { description, tags, inlineTags } = getJSDocComment(node);
|
|
5330
|
-
const
|
|
5411
|
+
const rawType = checker.getTypeAtLocation(node);
|
|
5412
|
+
const type = node.questionToken ? stripUndefinedFromType(rawType, checker) : rawType;
|
|
5331
5413
|
const callSignatures = type.getCallSignatures();
|
|
5332
5414
|
const signatures = buildSignatures(callSignatures, checker, ctx);
|
|
5333
5415
|
const flags = {};
|
|
@@ -5396,7 +5478,7 @@ function getInterfaceExtends(node, checker) {
|
|
|
5396
5478
|
if (!node.heritageClauses)
|
|
5397
5479
|
return;
|
|
5398
5480
|
for (const clause of node.heritageClauses) {
|
|
5399
|
-
if (clause.token ===
|
|
5481
|
+
if (clause.token === ts12.SyntaxKind.ExtendsKeyword && clause.types.length > 0) {
|
|
5400
5482
|
const names = clause.types.map((expr) => {
|
|
5401
5483
|
const type = checker.getTypeAtLocation(expr);
|
|
5402
5484
|
return type.getSymbol()?.getName() ?? expr.expression.getText();
|
|
@@ -5408,7 +5490,7 @@ function getInterfaceExtends(node, checker) {
|
|
|
5408
5490
|
}
|
|
5409
5491
|
|
|
5410
5492
|
// src/serializers/type-aliases.ts
|
|
5411
|
-
import
|
|
5493
|
+
import ts13 from "typescript";
|
|
5412
5494
|
function buildIntersectionSchemaFromNode(node, ctx) {
|
|
5413
5495
|
const types = node.types;
|
|
5414
5496
|
const schemas = [];
|
|
@@ -5436,7 +5518,7 @@ function serializeTypeAlias(node, ctx) {
|
|
|
5436
5518
|
registerReferencedTypes(type, ctx);
|
|
5437
5519
|
let schema;
|
|
5438
5520
|
let members;
|
|
5439
|
-
if (
|
|
5521
|
+
if (ts13.isIntersectionTypeNode(node.type)) {
|
|
5440
5522
|
schema = buildIntersectionSchemaFromNode(node.type, ctx);
|
|
5441
5523
|
if (type.getProperties().length > 0 && type.getCallSignatures().length === 0) {
|
|
5442
5524
|
members = serializeResolvedMembers(type, node, ctx);
|
|
@@ -5446,7 +5528,7 @@ function serializeTypeAlias(node, ctx) {
|
|
|
5446
5528
|
if (type.getProperties().length > 0) {
|
|
5447
5529
|
members = serializeResolvedMembers(type, node, ctx);
|
|
5448
5530
|
}
|
|
5449
|
-
} else if ((
|
|
5531
|
+
} else if ((ts13.isMappedTypeNode(node.type) || ts13.isConditionalTypeNode(node.type)) && type.getProperties().length > 0 && type.getCallSignatures().length === 0 && !(type.flags & ts13.TypeFlags.Conditional) && !(type.flags & (ts13.TypeFlags.StringLike | ts13.TypeFlags.NumberLike))) {
|
|
5450
5532
|
schema = buildObjectSchema(type.getProperties(), ctx.typeChecker, ctx, type);
|
|
5451
5533
|
members = serializeResolvedMembers(type, node, ctx);
|
|
5452
5534
|
} else {
|
|
@@ -5456,7 +5538,7 @@ function serializeTypeAlias(node, ctx) {
|
|
|
5456
5538
|
}
|
|
5457
5539
|
}
|
|
5458
5540
|
if (shouldEmitAliasTypeText(node.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
|
|
5459
|
-
const text = renderTypeText(type, ctx.typeChecker, node,
|
|
5541
|
+
const text = renderTypeText(type, ctx.typeChecker, node, ts13.TypeFormatFlags.InTypeAlias);
|
|
5460
5542
|
if (!PRIMITIVES.has(text) && text !== name) {
|
|
5461
5543
|
schema["x-ts-type"] = text;
|
|
5462
5544
|
const declared = writtenTypeText(declaredTypeNode(node));
|
|
@@ -5482,12 +5564,12 @@ function serializeTypeAlias(node, ctx) {
|
|
|
5482
5564
|
}
|
|
5483
5565
|
function isObjectShapedAlias(type, ctx) {
|
|
5484
5566
|
const { typeChecker: checker } = ctx;
|
|
5485
|
-
if (!(type.flags &
|
|
5567
|
+
if (!(type.flags & ts13.TypeFlags.Object))
|
|
5486
5568
|
return false;
|
|
5487
5569
|
if (checker.isArrayType(type) || checker.isTupleType(type))
|
|
5488
5570
|
return false;
|
|
5489
5571
|
const objectFlags = type.objectFlags;
|
|
5490
|
-
if (!(objectFlags &
|
|
5572
|
+
if (!(objectFlags & ts13.ObjectFlags.Mapped)) {
|
|
5491
5573
|
const targetSymbol = type.target?.getSymbol?.() ?? type.getSymbol();
|
|
5492
5574
|
if (isBuiltinSymbol(targetSymbol))
|
|
5493
5575
|
return false;
|
|
@@ -5495,19 +5577,19 @@ function isObjectShapedAlias(type, ctx) {
|
|
|
5495
5577
|
return type.getProperties().length > 0 && type.getCallSignatures().length === 0;
|
|
5496
5578
|
}
|
|
5497
5579
|
function isInlineFunctionAlias(typeNode) {
|
|
5498
|
-
return
|
|
5580
|
+
return ts13.isFunctionTypeNode(typeNode) || ts13.isTypeLiteralNode(typeNode) && typeNode.members.some(ts13.isCallSignatureDeclaration);
|
|
5499
5581
|
}
|
|
5500
5582
|
function buildConditionalArmDocs(typeNode, checker) {
|
|
5501
5583
|
const docs = new Map;
|
|
5502
|
-
if (!
|
|
5584
|
+
if (!ts13.isMappedTypeNode(typeNode) || !typeNode.type)
|
|
5503
5585
|
return docs;
|
|
5504
5586
|
const literalKeys = (extendsType) => {
|
|
5505
5587
|
const keys = [];
|
|
5506
5588
|
const visit = (n) => {
|
|
5507
|
-
if (
|
|
5589
|
+
if (ts13.isUnionTypeNode(n)) {
|
|
5508
5590
|
for (const member of n.types)
|
|
5509
5591
|
visit(member);
|
|
5510
|
-
} else if (
|
|
5592
|
+
} else if (ts13.isLiteralTypeNode(n) && ts13.isStringLiteral(n.literal)) {
|
|
5511
5593
|
keys.push(n.literal.text);
|
|
5512
5594
|
}
|
|
5513
5595
|
};
|
|
@@ -5515,12 +5597,12 @@ function buildConditionalArmDocs(typeNode, checker) {
|
|
|
5515
5597
|
return keys;
|
|
5516
5598
|
};
|
|
5517
5599
|
const armDoc = (armType) => {
|
|
5518
|
-
if (!
|
|
5600
|
+
if (!ts13.isTypeReferenceNode(armType))
|
|
5519
5601
|
return;
|
|
5520
5602
|
const symbol = checker.getSymbolAtLocation(armType.typeName);
|
|
5521
5603
|
if (!symbol)
|
|
5522
5604
|
return;
|
|
5523
|
-
const target = symbol.flags &
|
|
5605
|
+
const target = symbol.flags & ts13.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
5524
5606
|
const { deprecated, reason } = isSymbolDeprecated(target);
|
|
5525
5607
|
const targetDecl = target.getDeclarations()?.[0];
|
|
5526
5608
|
const description = targetDecl ? getJSDocComment(targetDecl, target, checker).description : undefined;
|
|
@@ -5529,7 +5611,7 @@ function buildConditionalArmDocs(typeNode, checker) {
|
|
|
5529
5611
|
return { deprecated, deprecationReason: reason, description };
|
|
5530
5612
|
};
|
|
5531
5613
|
let current = typeNode.type;
|
|
5532
|
-
while (current &&
|
|
5614
|
+
while (current && ts13.isConditionalTypeNode(current)) {
|
|
5533
5615
|
const doc = armDoc(current.trueType);
|
|
5534
5616
|
if (doc) {
|
|
5535
5617
|
for (const key of literalKeys(current.extendsType)) {
|
|
@@ -5548,10 +5630,10 @@ function serializeResolvedMembers(type, node, ctx) {
|
|
|
5548
5630
|
for (const prop of type.getProperties()) {
|
|
5549
5631
|
const decl = prop.getDeclarations()?.[0] ?? node;
|
|
5550
5632
|
const rawPropType = checker.getTypeOfSymbolAtLocation(prop, decl);
|
|
5551
|
-
const propType = prop.flags &
|
|
5633
|
+
const propType = prop.flags & ts13.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
|
|
5552
5634
|
registerReferencedTypes(propType, ctx);
|
|
5553
5635
|
const callSigs = propType.getCallSignatures();
|
|
5554
|
-
const isMethodDecl =
|
|
5636
|
+
const isMethodDecl = ts13.isMethodSignature(decl) || ts13.isMethodDeclaration(decl) || ts13.isFunctionDeclaration(decl);
|
|
5555
5637
|
const kind = callSigs.length > 0 && isMethodDecl ? "method" : "property";
|
|
5556
5638
|
let { description, tags } = getJSDocComment(decl, prop, checker);
|
|
5557
5639
|
let { deprecated, reason: deprecationReason } = isSymbolDeprecated(prop);
|
|
@@ -5569,11 +5651,11 @@ function serializeResolvedMembers(type, node, ctx) {
|
|
|
5569
5651
|
({ deprecated, reason: deprecationReason } = isSymbolDeprecated(armAlias));
|
|
5570
5652
|
}
|
|
5571
5653
|
const flags = {};
|
|
5572
|
-
if (prop.flags &
|
|
5654
|
+
if (prop.flags & ts13.SymbolFlags.Optional)
|
|
5573
5655
|
flags.optional = true;
|
|
5574
5656
|
if (isReadonlyPropertySymbol(prop))
|
|
5575
5657
|
flags.readonly = true;
|
|
5576
|
-
if (prop.flags &
|
|
5658
|
+
if (prop.flags & ts13.SymbolFlags.Method)
|
|
5577
5659
|
flags.methodSyntax = true;
|
|
5578
5660
|
const schema = kind === "property" ? decoratePropertySchema(buildSchema(propType, checker, ctx, declaredTypeNode(prop.valueDeclaration ?? prop.getDeclarations()?.[0])), prop, propType, checker) : decoratePropertySchema({ "x-ts-function": true }, prop, propType, checker);
|
|
5579
5661
|
const inlineTags = parseInlineTags(description);
|
|
@@ -5592,14 +5674,17 @@ function serializeResolvedMembers(type, node, ctx) {
|
|
|
5592
5674
|
return members;
|
|
5593
5675
|
}
|
|
5594
5676
|
|
|
5677
|
+
// src/serializers/variables.ts
|
|
5678
|
+
import ts15 from "typescript";
|
|
5679
|
+
|
|
5595
5680
|
// src/schema/registry.ts
|
|
5596
|
-
import
|
|
5681
|
+
import ts14 from "typescript";
|
|
5597
5682
|
function isTypeReference(type) {
|
|
5598
|
-
return !!(type.flags &
|
|
5683
|
+
return !!(type.flags & ts14.TypeFlags.Object && type.objectFlags && type.objectFlags & ts14.ObjectFlags.Reference);
|
|
5599
5684
|
}
|
|
5600
5685
|
function getNonNullableType(type) {
|
|
5601
5686
|
if (type.isUnion()) {
|
|
5602
|
-
const nonNullable = type.types.filter((t) => !(t.flags &
|
|
5687
|
+
const nonNullable = type.types.filter((t) => !(t.flags & ts14.TypeFlags.Undefined) && !(t.flags & ts14.TypeFlags.Null));
|
|
5603
5688
|
if (nonNullable.length === 1) {
|
|
5604
5689
|
return nonNullable[0];
|
|
5605
5690
|
}
|
|
@@ -5767,7 +5852,7 @@ function serializeVariable(node, statement, ctx) {
|
|
|
5767
5852
|
const schemaExtraction = extractSchemaType(type, ctx.typeChecker);
|
|
5768
5853
|
const typeToSerialize = schemaExtraction?.outputType ?? type;
|
|
5769
5854
|
registerReferencedTypes(typeToSerialize, ctx);
|
|
5770
|
-
const schema = buildSchema(typeToSerialize, ctx.typeChecker, ctx, node.type);
|
|
5855
|
+
const schema = buildSchema(typeToSerialize, ctx.typeChecker, ctx, ts15.isVariableDeclaration(node) ? node.type : undefined);
|
|
5771
5856
|
const flags = schemaExtraction ? {
|
|
5772
5857
|
schemaLibrary: schemaExtraction.adapter.id,
|
|
5773
5858
|
...schemaExtraction.inputType && schemaExtraction.inputType !== schemaExtraction.outputType ? { hasTransform: true } : {}
|
|
@@ -6355,7 +6440,7 @@ async function getExport(options) {
|
|
|
6355
6440
|
ctx.exportedIds = exportedIds;
|
|
6356
6441
|
try {
|
|
6357
6442
|
const originalDecls = targetSymbol.declarations ?? [];
|
|
6358
|
-
const isNamespaceExportDecl = originalDecls.some((d) =>
|
|
6443
|
+
const isNamespaceExportDecl = originalDecls.some((d) => ts16.isNamespaceExport(d) || ts16.isNamespaceImport(d));
|
|
6359
6444
|
if (isNamespaceExportDecl) {
|
|
6360
6445
|
const spec2 = serializeNamespaceForGet(targetSymbol, exportName, ctx);
|
|
6361
6446
|
const types2 = ctx.typeRegistry.getAll().map((t) => normalizeType(t));
|
|
@@ -6406,42 +6491,42 @@ function resolveExportTarget2(symbol, checker) {
|
|
|
6406
6491
|
let isTypeOnly = false;
|
|
6407
6492
|
const declarations = symbol.declarations ?? [];
|
|
6408
6493
|
for (const decl of declarations) {
|
|
6409
|
-
if (
|
|
6494
|
+
if (ts16.isExportSpecifier(decl)) {
|
|
6410
6495
|
if (decl.isTypeOnly)
|
|
6411
6496
|
isTypeOnly = true;
|
|
6412
6497
|
const exportDecl = decl.parent?.parent;
|
|
6413
|
-
if (exportDecl &&
|
|
6498
|
+
if (exportDecl && ts16.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
|
|
6414
6499
|
isTypeOnly = true;
|
|
6415
6500
|
}
|
|
6416
6501
|
}
|
|
6417
6502
|
}
|
|
6418
|
-
if (symbol.flags &
|
|
6503
|
+
if (symbol.flags & ts16.SymbolFlags.Alias) {
|
|
6419
6504
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
6420
6505
|
if (aliased && aliased !== symbol) {
|
|
6421
6506
|
resolvedSymbol2 = aliased;
|
|
6422
6507
|
}
|
|
6423
6508
|
}
|
|
6424
6509
|
const targetDeclarations = resolvedSymbol2.declarations ?? [];
|
|
6425
|
-
const declaration = resolvedSymbol2.valueDeclaration || targetDeclarations.find((d) => d.kind !==
|
|
6510
|
+
const declaration = resolvedSymbol2.valueDeclaration || targetDeclarations.find((d) => d.kind !== ts16.SyntaxKind.ExportSpecifier) || targetDeclarations[0];
|
|
6426
6511
|
return { declaration, resolvedSymbol: resolvedSymbol2, isTypeOnly };
|
|
6427
6512
|
}
|
|
6428
6513
|
function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportName, ctx, isTypeOnly) {
|
|
6429
6514
|
let result = null;
|
|
6430
|
-
if (
|
|
6515
|
+
if (ts16.isFunctionDeclaration(declaration)) {
|
|
6431
6516
|
result = serializeFunctionExport(declaration, ctx);
|
|
6432
|
-
} else if (
|
|
6517
|
+
} else if (ts16.isClassDeclaration(declaration)) {
|
|
6433
6518
|
result = serializeClass(declaration, ctx);
|
|
6434
|
-
} else if (
|
|
6519
|
+
} else if (ts16.isInterfaceDeclaration(declaration)) {
|
|
6435
6520
|
result = serializeInterface(declaration, ctx);
|
|
6436
|
-
} else if (
|
|
6521
|
+
} else if (ts16.isTypeAliasDeclaration(declaration)) {
|
|
6437
6522
|
result = serializeTypeAlias(declaration, ctx);
|
|
6438
|
-
} else if (
|
|
6523
|
+
} else if (ts16.isEnumDeclaration(declaration)) {
|
|
6439
6524
|
result = serializeEnum(declaration, ctx);
|
|
6440
|
-
} else if (
|
|
6525
|
+
} else if (ts16.isVariableDeclaration(declaration)) {
|
|
6441
6526
|
const varStatement = declaration.parent?.parent;
|
|
6442
|
-
if (varStatement &&
|
|
6443
|
-
if (declaration.initializer && (
|
|
6444
|
-
const varName =
|
|
6527
|
+
if (varStatement && ts16.isVariableStatement(varStatement)) {
|
|
6528
|
+
if (declaration.initializer && (ts16.isArrowFunction(declaration.initializer) || ts16.isFunctionExpression(declaration.initializer))) {
|
|
6529
|
+
const varName = ts16.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
|
|
6445
6530
|
result = serializeFunctionExport(declaration.initializer, ctx, varName);
|
|
6446
6531
|
} else {
|
|
6447
6532
|
const checker = ctx.program.getTypeChecker();
|
|
@@ -6455,7 +6540,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
|
|
|
6455
6540
|
}
|
|
6456
6541
|
}
|
|
6457
6542
|
}
|
|
6458
|
-
} else if (
|
|
6543
|
+
} else if (ts16.isNamespaceExport(declaration) || ts16.isModuleDeclaration(declaration) || ts16.isNamespaceImport(declaration) || ts16.isSourceFile(declaration)) {
|
|
6459
6544
|
result = serializeNamespaceForGet(_exportSymbol, exportName, ctx);
|
|
6460
6545
|
}
|
|
6461
6546
|
if (result) {
|
|
@@ -6471,7 +6556,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
|
|
|
6471
6556
|
function serializeNamespaceForGet(symbol, exportName, ctx) {
|
|
6472
6557
|
const checker = ctx.program.getTypeChecker();
|
|
6473
6558
|
let targetSymbol = symbol;
|
|
6474
|
-
if (symbol.flags &
|
|
6559
|
+
if (symbol.flags & ts16.SymbolFlags.Alias) {
|
|
6475
6560
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
6476
6561
|
if (aliased && aliased !== symbol) {
|
|
6477
6562
|
targetSymbol = aliased;
|
|
@@ -6501,7 +6586,7 @@ function serializeNamespaceForGet(symbol, exportName, ctx) {
|
|
|
6501
6586
|
}
|
|
6502
6587
|
function detectExternalPackage(symbol, checker) {
|
|
6503
6588
|
let targetSymbol = symbol;
|
|
6504
|
-
if (symbol.flags &
|
|
6589
|
+
if (symbol.flags & ts16.SymbolFlags.Alias) {
|
|
6505
6590
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
6506
6591
|
if (aliased && aliased !== symbol) {
|
|
6507
6592
|
targetSymbol = aliased;
|
|
@@ -6513,9 +6598,9 @@ function detectExternalPackage(symbol, checker) {
|
|
|
6513
6598
|
const pkg = sf && packageNameFromPath(sf.fileName);
|
|
6514
6599
|
if (pkg)
|
|
6515
6600
|
return pkg;
|
|
6516
|
-
if (
|
|
6601
|
+
if (ts16.isExportSpecifier(decl)) {
|
|
6517
6602
|
const exportDecl = decl.parent?.parent;
|
|
6518
|
-
if (exportDecl &&
|
|
6603
|
+
if (exportDecl && ts16.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
|
|
6519
6604
|
const moduleText = exportDecl.moduleSpecifier.text;
|
|
6520
6605
|
if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
|
|
6521
6606
|
return moduleText;
|
|
@@ -6527,7 +6612,7 @@ function detectExternalPackage(symbol, checker) {
|
|
|
6527
6612
|
}
|
|
6528
6613
|
// src/primitives/list.ts
|
|
6529
6614
|
import * as path6 from "node:path";
|
|
6530
|
-
import
|
|
6615
|
+
import ts17 from "typescript";
|
|
6531
6616
|
async function listExports(options) {
|
|
6532
6617
|
const { entryFile, baseDir, content } = options;
|
|
6533
6618
|
const errors = [];
|
|
@@ -6570,16 +6655,16 @@ async function listExports(options) {
|
|
|
6570
6655
|
}
|
|
6571
6656
|
function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
6572
6657
|
const name = symbol.getName();
|
|
6573
|
-
const isReexport = !!(symbol.flags &
|
|
6658
|
+
const isReexport = !!(symbol.flags & ts17.SymbolFlags.Alias);
|
|
6574
6659
|
let targetSymbol = symbol;
|
|
6575
|
-
if (symbol.flags &
|
|
6660
|
+
if (symbol.flags & ts17.SymbolFlags.Alias) {
|
|
6576
6661
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
6577
6662
|
if (aliased && aliased !== symbol) {
|
|
6578
6663
|
targetSymbol = aliased;
|
|
6579
6664
|
}
|
|
6580
6665
|
}
|
|
6581
6666
|
const declarations = targetSymbol.declarations ?? [];
|
|
6582
|
-
const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !==
|
|
6667
|
+
const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts17.SyntaxKind.ExportSpecifier) || declarations[0];
|
|
6583
6668
|
if (!declaration) {
|
|
6584
6669
|
return {
|
|
6585
6670
|
name,
|
|
@@ -6589,7 +6674,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
6589
6674
|
reexport: true
|
|
6590
6675
|
};
|
|
6591
6676
|
}
|
|
6592
|
-
if (
|
|
6677
|
+
if (ts17.isSourceFile(declaration)) {
|
|
6593
6678
|
return {
|
|
6594
6679
|
name,
|
|
6595
6680
|
kind: "namespace",
|
|
@@ -6631,7 +6716,7 @@ function getDescriptionPreview(symbol, checker) {
|
|
|
6631
6716
|
import * as fs7 from "node:fs";
|
|
6632
6717
|
import * as path10 from "node:path";
|
|
6633
6718
|
import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
|
|
6634
|
-
import
|
|
6719
|
+
import ts21 from "typescript";
|
|
6635
6720
|
|
|
6636
6721
|
// src/schema/standard-schema.ts
|
|
6637
6722
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
@@ -7183,7 +7268,7 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
|
|
|
7183
7268
|
import * as fs6 from "node:fs";
|
|
7184
7269
|
import * as path8 from "node:path";
|
|
7185
7270
|
import picomatch2 from "picomatch";
|
|
7186
|
-
import
|
|
7271
|
+
import ts18 from "typescript";
|
|
7187
7272
|
function matchesExternalPattern(packageName, include, exclude) {
|
|
7188
7273
|
if (!include?.length)
|
|
7189
7274
|
return false;
|
|
@@ -7199,7 +7284,7 @@ function matchesExternalPattern(packageName, include, exclude) {
|
|
|
7199
7284
|
return true;
|
|
7200
7285
|
}
|
|
7201
7286
|
function resolveExternalModule(moduleSpecifier, containingFile, compilerOptions) {
|
|
7202
|
-
const resolved =
|
|
7287
|
+
const resolved = ts18.resolveModuleName(moduleSpecifier, containingFile, compilerOptions, ts18.sys);
|
|
7203
7288
|
if (!resolved.resolvedModule) {
|
|
7204
7289
|
return null;
|
|
7205
7290
|
}
|
|
@@ -7264,7 +7349,7 @@ function extractExternalExport(exportName, resolvedModule, program, ctx, visited
|
|
|
7264
7349
|
return null;
|
|
7265
7350
|
}
|
|
7266
7351
|
let resolvedSymbol2 = targetExport;
|
|
7267
|
-
if (targetExport.flags &
|
|
7352
|
+
if (targetExport.flags & ts18.SymbolFlags.Alias) {
|
|
7268
7353
|
const aliased = checker.getAliasedSymbol(targetExport);
|
|
7269
7354
|
if (aliased && aliased !== targetExport) {
|
|
7270
7355
|
resolvedSymbol2 = aliased;
|
|
@@ -7335,7 +7420,7 @@ function mergeRuntimeSchemas(staticExports, runtimeSchemas) {
|
|
|
7335
7420
|
}
|
|
7336
7421
|
|
|
7337
7422
|
// src/builder/type-cache.ts
|
|
7338
|
-
import
|
|
7423
|
+
import ts19 from "typescript";
|
|
7339
7424
|
|
|
7340
7425
|
// src/utils/cache-manager.ts
|
|
7341
7426
|
class CacheManager {
|
|
@@ -7442,10 +7527,10 @@ function findTypeDefinition(typeName, program, sourceFile) {
|
|
|
7442
7527
|
return typeDefinitionCache.getOrCompute(typeName, () => {
|
|
7443
7528
|
const checker = program.getTypeChecker();
|
|
7444
7529
|
const findInNode = (node) => {
|
|
7445
|
-
if ((
|
|
7530
|
+
if ((ts19.isInterfaceDeclaration(node) || ts19.isTypeAliasDeclaration(node) || ts19.isClassDeclaration(node) || ts19.isEnumDeclaration(node)) && node.name?.text === typeName) {
|
|
7446
7531
|
return node.getSourceFile().fileName;
|
|
7447
7532
|
}
|
|
7448
|
-
return
|
|
7533
|
+
return ts19.forEachChild(node, findInNode);
|
|
7449
7534
|
};
|
|
7450
7535
|
const entryResult = findInNode(sourceFile);
|
|
7451
7536
|
if (entryResult)
|
|
@@ -7457,14 +7542,14 @@ function findTypeDefinition(typeName, program, sourceFile) {
|
|
|
7457
7542
|
return result;
|
|
7458
7543
|
}
|
|
7459
7544
|
}
|
|
7460
|
-
const symbol = checker.resolveName(typeName, sourceFile,
|
|
7545
|
+
const symbol = checker.resolveName(typeName, sourceFile, ts19.SymbolFlags.Type, false);
|
|
7461
7546
|
return symbol?.declarations?.[0]?.getSourceFile().fileName;
|
|
7462
7547
|
});
|
|
7463
7548
|
}
|
|
7464
7549
|
function hasInternalTag(typeName, program, sourceFile) {
|
|
7465
7550
|
return internalTagCache.getOrCompute(typeName, () => {
|
|
7466
7551
|
const checker = program.getTypeChecker();
|
|
7467
|
-
const symbol = checker.resolveName(typeName, sourceFile,
|
|
7552
|
+
const symbol = checker.resolveName(typeName, sourceFile, ts19.SymbolFlags.Type, false);
|
|
7468
7553
|
if (!symbol)
|
|
7469
7554
|
return false;
|
|
7470
7555
|
return symbol.getJsDocTags().some((tag) => tag.name === "internal");
|
|
@@ -7472,7 +7557,7 @@ function hasInternalTag(typeName, program, sourceFile) {
|
|
|
7472
7557
|
}
|
|
7473
7558
|
|
|
7474
7559
|
// src/builder/type-expansion.ts
|
|
7475
|
-
import
|
|
7560
|
+
import ts20 from "typescript";
|
|
7476
7561
|
function createExternalExpansionPredicate(opts) {
|
|
7477
7562
|
const matchesEntry = (entry, pkg) => {
|
|
7478
7563
|
if (!entry.includes("*"))
|
|
@@ -7547,7 +7632,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
|
|
|
7547
7632
|
visit(t, depth + 1);
|
|
7548
7633
|
}
|
|
7549
7634
|
}
|
|
7550
|
-
if (!allowed || isDeferredMappedOrConditional(type) || !(type.flags &
|
|
7635
|
+
if (!allowed || isDeferredMappedOrConditional(type) || !(type.flags & ts20.TypeFlags.Object || type.isClassOrInterface())) {
|
|
7551
7636
|
return;
|
|
7552
7637
|
}
|
|
7553
7638
|
if (isForeignPackage(symbol, opts.workspacePackages)) {
|
|
@@ -7573,14 +7658,14 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
|
|
|
7573
7658
|
visit(info.type, depth + 1);
|
|
7574
7659
|
}
|
|
7575
7660
|
};
|
|
7576
|
-
const TYPE_SYMBOL_FLAGS =
|
|
7661
|
+
const TYPE_SYMBOL_FLAGS = ts20.SymbolFlags.Interface | ts20.SymbolFlags.TypeAlias | ts20.SymbolFlags.Class | ts20.SymbolFlags.RegularEnum | ts20.SymbolFlags.ConstEnum;
|
|
7577
7662
|
const visitedSymbols = new Set;
|
|
7578
7663
|
const symbolKind = (symbol) => {
|
|
7579
|
-
if (symbol.flags &
|
|
7664
|
+
if (symbol.flags & ts20.SymbolFlags.Interface)
|
|
7580
7665
|
return "interface";
|
|
7581
|
-
if (symbol.flags &
|
|
7666
|
+
if (symbol.flags & ts20.SymbolFlags.Class)
|
|
7582
7667
|
return "class";
|
|
7583
|
-
if (symbol.flags & (
|
|
7668
|
+
if (symbol.flags & (ts20.SymbolFlags.RegularEnum | ts20.SymbolFlags.ConstEnum))
|
|
7584
7669
|
return "enum";
|
|
7585
7670
|
return "type";
|
|
7586
7671
|
};
|
|
@@ -7631,7 +7716,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
|
|
|
7631
7716
|
const target = symbol && resolveAlias(symbol);
|
|
7632
7717
|
if (!target || visitedSymbols.has(target))
|
|
7633
7718
|
return;
|
|
7634
|
-
if (!(target.flags & (
|
|
7719
|
+
if (!(target.flags & (ts20.SymbolFlags.ValueModule | ts20.SymbolFlags.NamespaceModule)))
|
|
7635
7720
|
return;
|
|
7636
7721
|
if (!symbolAllowed(target))
|
|
7637
7722
|
return;
|
|
@@ -7648,22 +7733,22 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
|
|
|
7648
7733
|
}
|
|
7649
7734
|
};
|
|
7650
7735
|
const walkNode = (node) => {
|
|
7651
|
-
if (
|
|
7736
|
+
if (ts20.isTypeReferenceNode(node)) {
|
|
7652
7737
|
handleRef(node.typeName);
|
|
7653
|
-
if (
|
|
7738
|
+
if (ts20.isQualifiedName(node.typeName)) {
|
|
7654
7739
|
handleNamespaceRef(node.typeName.left);
|
|
7655
7740
|
}
|
|
7656
|
-
} else if (
|
|
7741
|
+
} else if (ts20.isExpressionWithTypeArguments(node)) {
|
|
7657
7742
|
handleRef(node.expression);
|
|
7658
|
-
} else if (
|
|
7743
|
+
} else if (ts20.isTypeQueryNode(node)) {
|
|
7659
7744
|
handleRef(node.exprName);
|
|
7660
|
-
if (
|
|
7745
|
+
if (ts20.isQualifiedName(node.exprName)) {
|
|
7661
7746
|
handleRef(node.exprName.left);
|
|
7662
7747
|
handleNamespaceRef(node.exprName.left);
|
|
7663
7748
|
}
|
|
7664
|
-
} else if (
|
|
7749
|
+
} else if (ts20.isImportTypeNode(node) && node.qualifier) {
|
|
7665
7750
|
handleRef(node.qualifier);
|
|
7666
|
-
if (
|
|
7751
|
+
if (ts20.isQualifiedName(node.qualifier)) {
|
|
7667
7752
|
handleNamespaceRef(node.qualifier.left);
|
|
7668
7753
|
}
|
|
7669
7754
|
}
|
|
@@ -7679,7 +7764,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
|
|
|
7679
7764
|
};
|
|
7680
7765
|
for (const exportSymbol of exportedSymbols) {
|
|
7681
7766
|
let target = exportSymbol;
|
|
7682
|
-
if (exportSymbol.flags &
|
|
7767
|
+
if (exportSymbol.flags & ts20.SymbolFlags.Alias) {
|
|
7683
7768
|
try {
|
|
7684
7769
|
target = checker.getAliasedSymbol(exportSymbol);
|
|
7685
7770
|
} catch {
|
|
@@ -7979,6 +8064,7 @@ async function extract(options) {
|
|
|
7979
8064
|
...included ? {} : { skipReason: "filtered" }
|
|
7980
8065
|
});
|
|
7981
8066
|
}
|
|
8067
|
+
const mergedTypeSides = [];
|
|
7982
8068
|
const followExternal = options.followExternal;
|
|
7983
8069
|
const ctx = createContext(program, sourceFile, {
|
|
7984
8070
|
maxTypeDepth,
|
|
@@ -8018,9 +8104,9 @@ async function extract(options) {
|
|
|
8018
8104
|
externalPackage = pkg;
|
|
8019
8105
|
break;
|
|
8020
8106
|
}
|
|
8021
|
-
if (
|
|
8107
|
+
if (ts21.isExportSpecifier(decl)) {
|
|
8022
8108
|
const exportDecl = decl.parent?.parent;
|
|
8023
|
-
if (exportDecl &&
|
|
8109
|
+
if (exportDecl && ts21.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
|
|
8024
8110
|
const moduleText = exportDecl.moduleSpecifier.getText().slice(1, -1);
|
|
8025
8111
|
if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
|
|
8026
8112
|
externalPackage = moduleText;
|
|
@@ -8063,6 +8149,9 @@ async function extract(options) {
|
|
|
8063
8149
|
}
|
|
8064
8150
|
const exp = serializeDeclaration2(declaration, symbol, exportName, ctx, isTypeOnly);
|
|
8065
8151
|
if (exp) {
|
|
8152
|
+
if (!exp.members && isValueDeclaration(declaration) && hasTypeSide(targetSymbol)) {
|
|
8153
|
+
mergedTypeSides.push({ index: exports.length, symbol: targetSymbol });
|
|
8154
|
+
}
|
|
8066
8155
|
exports.push(exp);
|
|
8067
8156
|
tracker.status = "success";
|
|
8068
8157
|
tracker.kind = exp.kind;
|
|
@@ -8081,6 +8170,9 @@ async function extract(options) {
|
|
|
8081
8170
|
});
|
|
8082
8171
|
}
|
|
8083
8172
|
}
|
|
8173
|
+
for (const { index, symbol } of mergedTypeSides) {
|
|
8174
|
+
exports[index] = withMergedTypeSide(exports[index], symbol, ctx);
|
|
8175
|
+
}
|
|
8084
8176
|
const verification = buildVerificationSummary(exportedSymbols.length, exports.length, exportTracker);
|
|
8085
8177
|
const meta = await getPackageMeta(entryFile, baseDir);
|
|
8086
8178
|
expandReachableTypes(filteredSymbols, ctx, {
|
|
@@ -8096,7 +8188,7 @@ async function extract(options) {
|
|
|
8096
8188
|
});
|
|
8097
8189
|
}
|
|
8098
8190
|
{
|
|
8099
|
-
const symFlags =
|
|
8191
|
+
const symFlags = ts21.SymbolFlags.Type | ts21.SymbolFlags.Interface | ts21.SymbolFlags.Class;
|
|
8100
8192
|
const maxPasses = 5;
|
|
8101
8193
|
for (let pass = 0;pass < maxPasses; pass++) {
|
|
8102
8194
|
const allRefs = new Map;
|
|
@@ -8242,22 +8334,22 @@ async function extract(options) {
|
|
|
8242
8334
|
}
|
|
8243
8335
|
function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTypeOnly = false) {
|
|
8244
8336
|
let result = null;
|
|
8245
|
-
if (
|
|
8337
|
+
if (ts21.isFunctionDeclaration(declaration)) {
|
|
8246
8338
|
result = serializeFunctionExport(declaration, ctx);
|
|
8247
|
-
} else if (
|
|
8339
|
+
} else if (ts21.isClassDeclaration(declaration)) {
|
|
8248
8340
|
result = serializeClass(declaration, ctx);
|
|
8249
|
-
} else if (
|
|
8341
|
+
} else if (ts21.isInterfaceDeclaration(declaration)) {
|
|
8250
8342
|
result = serializeInterface(declaration, ctx);
|
|
8251
|
-
} else if (
|
|
8343
|
+
} else if (ts21.isTypeAliasDeclaration(declaration)) {
|
|
8252
8344
|
result = serializeTypeAlias(declaration, ctx);
|
|
8253
|
-
} else if (
|
|
8345
|
+
} else if (ts21.isEnumDeclaration(declaration)) {
|
|
8254
8346
|
result = serializeEnum(declaration, ctx);
|
|
8255
|
-
} else if (
|
|
8256
|
-
const varStatement = declaration
|
|
8257
|
-
if (varStatement
|
|
8258
|
-
if (declaration.initializer && (
|
|
8259
|
-
const varName =
|
|
8260
|
-
result = serializeFunctionExport(declaration.initializer, ctx, varName);
|
|
8347
|
+
} else if (ts21.isVariableDeclaration(declaration) || ts21.isBindingElement(declaration)) {
|
|
8348
|
+
const varStatement = variableStatementOf(declaration);
|
|
8349
|
+
if (varStatement) {
|
|
8350
|
+
if (ts21.isVariableDeclaration(declaration) && declaration.initializer && (ts21.isArrowFunction(declaration.initializer) || ts21.isFunctionExpression(declaration.initializer))) {
|
|
8351
|
+
const varName = ts21.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
|
|
8352
|
+
result = serializeFunctionExport(declaration.initializer, ctx, varName, declaration.type);
|
|
8261
8353
|
} else {
|
|
8262
8354
|
result = serializeVariable(declaration, varStatement, ctx);
|
|
8263
8355
|
if (result?.kind === "variable") {
|
|
@@ -8277,7 +8369,7 @@ function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTyp
|
|
|
8277
8369
|
}
|
|
8278
8370
|
}
|
|
8279
8371
|
}
|
|
8280
|
-
} else if (
|
|
8372
|
+
} else if (ts21.isNamespaceExport(declaration) || ts21.isModuleDeclaration(declaration) || ts21.isNamespaceImport(declaration) || ts21.isSourceFile(declaration)) {
|
|
8281
8373
|
try {
|
|
8282
8374
|
result = serializeNamespaceExport(exportSymbol, exportName, ctx);
|
|
8283
8375
|
} catch {
|
|
@@ -8293,6 +8385,9 @@ function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTyp
|
|
|
8293
8385
|
}
|
|
8294
8386
|
if (result) {
|
|
8295
8387
|
result = withExportName(result, exportName);
|
|
8388
|
+
const localName = exportName === "default" && defaultLocalName(declaration, exportSymbol);
|
|
8389
|
+
if (localName)
|
|
8390
|
+
result = { ...result, localName };
|
|
8296
8391
|
if (isTypeOnly) {
|
|
8297
8392
|
result = {
|
|
8298
8393
|
...result,
|
|
@@ -8314,7 +8409,7 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
|
|
|
8314
8409
|
const members = [];
|
|
8315
8410
|
const checker = ctx.program.getTypeChecker();
|
|
8316
8411
|
let targetSymbol = symbol;
|
|
8317
|
-
if (symbol.flags &
|
|
8412
|
+
if (symbol.flags & ts21.SymbolFlags.Alias) {
|
|
8318
8413
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
8319
8414
|
if (aliased && aliased !== symbol) {
|
|
8320
8415
|
targetSymbol = aliased;
|
|
@@ -8342,31 +8437,31 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
|
|
|
8342
8437
|
function serializeNamespaceMember(symbol, memberName, ctx) {
|
|
8343
8438
|
const checker = ctx.program.getTypeChecker();
|
|
8344
8439
|
let targetSymbol = symbol;
|
|
8345
|
-
if (symbol.flags &
|
|
8440
|
+
if (symbol.flags & ts21.SymbolFlags.Alias) {
|
|
8346
8441
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
8347
8442
|
if (aliased && aliased !== symbol) {
|
|
8348
8443
|
targetSymbol = aliased;
|
|
8349
8444
|
}
|
|
8350
8445
|
}
|
|
8351
8446
|
const declarations = targetSymbol.declarations ?? [];
|
|
8352
|
-
const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !==
|
|
8447
|
+
const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts21.SyntaxKind.ExportSpecifier) || declarations[0];
|
|
8353
8448
|
if (!declaration)
|
|
8354
8449
|
return null;
|
|
8355
8450
|
const type = checker.getTypeAtLocation(declaration);
|
|
8356
8451
|
const callSignatures = type.getCallSignatures();
|
|
8357
8452
|
const { deprecated } = isSymbolDeprecated(targetSymbol);
|
|
8358
8453
|
let kind = "variable";
|
|
8359
|
-
if (
|
|
8454
|
+
if (ts21.isFunctionDeclaration(declaration) || ts21.isFunctionExpression(declaration)) {
|
|
8360
8455
|
kind = "function";
|
|
8361
|
-
} else if (
|
|
8456
|
+
} else if (ts21.isClassDeclaration(declaration)) {
|
|
8362
8457
|
kind = "class";
|
|
8363
|
-
} else if (
|
|
8458
|
+
} else if (ts21.isInterfaceDeclaration(declaration)) {
|
|
8364
8459
|
kind = "interface";
|
|
8365
|
-
} else if (
|
|
8460
|
+
} else if (ts21.isTypeAliasDeclaration(declaration)) {
|
|
8366
8461
|
kind = "type";
|
|
8367
|
-
} else if (
|
|
8462
|
+
} else if (ts21.isEnumDeclaration(declaration)) {
|
|
8368
8463
|
kind = "enum";
|
|
8369
|
-
} else if (
|
|
8464
|
+
} else if (ts21.isVariableDeclaration(declaration)) {
|
|
8370
8465
|
if (callSignatures.length > 0) {
|
|
8371
8466
|
kind = "function";
|
|
8372
8467
|
}
|
|
@@ -8397,18 +8492,18 @@ function serializeNamespaceMember(symbol, memberName, ctx) {
|
|
|
8397
8492
|
function flattenJSDocComment(comment) {
|
|
8398
8493
|
if (comment === undefined)
|
|
8399
8494
|
return "";
|
|
8400
|
-
return typeof comment === "string" ? comment :
|
|
8495
|
+
return typeof comment === "string" ? comment : ts21.getTextOfJSDocComment(comment) ?? "";
|
|
8401
8496
|
}
|
|
8402
8497
|
function getJSDocFromExportSymbol(symbol) {
|
|
8403
8498
|
const tags = [];
|
|
8404
8499
|
const examples = [];
|
|
8405
8500
|
const decl = symbol.declarations?.[0];
|
|
8406
8501
|
if (decl) {
|
|
8407
|
-
const exportDecl =
|
|
8408
|
-
if (exportDecl &&
|
|
8409
|
-
const jsDocs =
|
|
8502
|
+
const exportDecl = ts21.isNamespaceExport(decl) ? decl.parent : decl;
|
|
8503
|
+
if (exportDecl && ts21.isExportDeclaration(exportDecl)) {
|
|
8504
|
+
const jsDocs = ts21.getJSDocCommentsAndTags(exportDecl);
|
|
8410
8505
|
for (const doc of jsDocs) {
|
|
8411
|
-
if (
|
|
8506
|
+
if (ts21.isJSDoc(doc) && doc.comment) {
|
|
8412
8507
|
const commentText = flattenJSDocComment(doc.comment);
|
|
8413
8508
|
if (commentText) {
|
|
8414
8509
|
return {
|
|
@@ -8457,14 +8552,21 @@ function extractExamples(doc) {
|
|
|
8457
8552
|
}
|
|
8458
8553
|
return examples;
|
|
8459
8554
|
}
|
|
8555
|
+
function variableStatementOf(declaration) {
|
|
8556
|
+
let node = declaration;
|
|
8557
|
+
while (ts21.isBindingElement(node) || ts21.isBindingName(node))
|
|
8558
|
+
node = node.parent;
|
|
8559
|
+
const statement = node.parent?.parent;
|
|
8560
|
+
return statement && ts21.isVariableStatement(statement) ? statement : undefined;
|
|
8561
|
+
}
|
|
8460
8562
|
function callSignaturesForVariable(declaration, ctx) {
|
|
8461
8563
|
const checker = ctx.typeChecker;
|
|
8462
|
-
if (declaration.type &&
|
|
8463
|
-
const nameNode =
|
|
8564
|
+
if (ts21.isVariableDeclaration(declaration) && declaration.type && ts21.isTypeReferenceNode(declaration.type)) {
|
|
8565
|
+
const nameNode = ts21.isQualifiedName(declaration.type.typeName) ? declaration.type.typeName.right : declaration.type.typeName;
|
|
8464
8566
|
const raw = checker.getSymbolAtLocation(nameNode);
|
|
8465
8567
|
if (raw) {
|
|
8466
8568
|
const symbol = resolveAliasSymbol(raw, checker, undefined, ctx.program);
|
|
8467
|
-
const iface = symbol.declarations?.find((d) =>
|
|
8569
|
+
const iface = symbol.declarations?.find((d) => ts21.isInterfaceDeclaration(d));
|
|
8468
8570
|
try {
|
|
8469
8571
|
const declared = checker.getDeclaredTypeOfSymbol(symbol);
|
|
8470
8572
|
const sigs = declared.getCallSignatures();
|
|
@@ -8486,6 +8588,39 @@ function callSignaturesForVariable(declaration, ctx) {
|
|
|
8486
8588
|
}
|
|
8487
8589
|
return checker.getTypeAtLocation(declaration).getCallSignatures();
|
|
8488
8590
|
}
|
|
8591
|
+
function defaultLocalName(declaration, exportSymbol) {
|
|
8592
|
+
const declared = ts21.getNameOfDeclaration(declaration);
|
|
8593
|
+
if (declared && ts21.isIdentifier(declared) && declared.text !== "default")
|
|
8594
|
+
return declared.text;
|
|
8595
|
+
for (const decl of exportSymbol.declarations ?? []) {
|
|
8596
|
+
if (ts21.isExportAssignment(decl) && ts21.isIdentifier(decl.expression)) {
|
|
8597
|
+
return decl.expression.text;
|
|
8598
|
+
}
|
|
8599
|
+
if (ts21.isExportSpecifier(decl) && decl.propertyName && ts21.isIdentifier(decl.propertyName)) {
|
|
8600
|
+
if (decl.propertyName.text !== "default")
|
|
8601
|
+
return decl.propertyName.text;
|
|
8602
|
+
}
|
|
8603
|
+
}
|
|
8604
|
+
return;
|
|
8605
|
+
}
|
|
8606
|
+
function isValueDeclaration(declaration) {
|
|
8607
|
+
return ts21.isVariableDeclaration(declaration) || ts21.isBindingElement(declaration) || ts21.isFunctionDeclaration(declaration);
|
|
8608
|
+
}
|
|
8609
|
+
function hasTypeSide(symbol) {
|
|
8610
|
+
return (symbol.flags & (ts21.SymbolFlags.Interface | ts21.SymbolFlags.TypeAlias)) !== 0;
|
|
8611
|
+
}
|
|
8612
|
+
function withMergedTypeSide(entry, symbol, ctx) {
|
|
8613
|
+
const typeSide = serializeMergedTypeSide(symbol, ctx);
|
|
8614
|
+
if (!typeSide)
|
|
8615
|
+
return entry;
|
|
8616
|
+
const { members, description, tags, ...instanceType } = typeSide;
|
|
8617
|
+
return {
|
|
8618
|
+
...entry,
|
|
8619
|
+
members,
|
|
8620
|
+
...entry.kind === "class" ? instanceType : {},
|
|
8621
|
+
...entry.description ? {} : { description, tags: [...entry.tags ?? [], ...tags ?? []] }
|
|
8622
|
+
};
|
|
8623
|
+
}
|
|
8489
8624
|
function withExportName(entry, exportName) {
|
|
8490
8625
|
if (entry.name === exportName) {
|
|
8491
8626
|
return entry;
|
|
@@ -9002,7 +9137,7 @@ function toToolSchema(exp, spec, options) {
|
|
|
9002
9137
|
const required = [];
|
|
9003
9138
|
for (const param of sig.parameters ?? []) {
|
|
9004
9139
|
let paramSchema = normalizeSchema(param.schema);
|
|
9005
|
-
if (param.rest) {
|
|
9140
|
+
if (param.rest && paramSchema.type !== "array") {
|
|
9006
9141
|
paramSchema = { type: "array", items: paramSchema };
|
|
9007
9142
|
}
|
|
9008
9143
|
if (param.description && !paramSchema.description) {
|
|
@@ -9040,12 +9175,12 @@ function toToolSchema(exp, spec, options) {
|
|
|
9040
9175
|
};
|
|
9041
9176
|
}
|
|
9042
9177
|
// src/types/utils.ts
|
|
9043
|
-
import
|
|
9178
|
+
import ts22 from "typescript";
|
|
9044
9179
|
function isExported(node) {
|
|
9045
9180
|
const modifiers = node.modifiers;
|
|
9046
9181
|
if (!modifiers)
|
|
9047
9182
|
return false;
|
|
9048
|
-
return modifiers.some((m) => m.kind ===
|
|
9183
|
+
return modifiers.some((m) => m.kind === ts22.SyntaxKind.ExportKeyword);
|
|
9049
9184
|
}
|
|
9050
9185
|
function getNodeName(node) {
|
|
9051
9186
|
if ("name" in node && node.name) {
|