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