@openpkg-ts/sdk 0.32.0 → 0.32.1
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 +1 -1
- package/dist/index.js +18 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1330,7 +1330,7 @@ import ts7 from "typescript";
|
|
|
1330
1330
|
declare function serializeEnum(node: ts7.EnumDeclaration, ctx: SerializerContext): SpecExport8 | null;
|
|
1331
1331
|
import { SpecExport as SpecExport9 } from "@openpkg-ts/spec";
|
|
1332
1332
|
import ts8 from "typescript";
|
|
1333
|
-
declare function serializeFunctionExport(node: ts8.FunctionDeclaration | ts8.ArrowFunction, ctx: SerializerContext): SpecExport9 | null;
|
|
1333
|
+
declare function serializeFunctionExport(node: ts8.FunctionDeclaration | ts8.ArrowFunction, ctx: SerializerContext, nameOverride?: string): SpecExport9 | null;
|
|
1334
1334
|
import { SpecExport as SpecExport10 } from "@openpkg-ts/spec";
|
|
1335
1335
|
import ts9 from "typescript";
|
|
1336
1336
|
declare function serializeInterface(node: ts9.InterfaceDeclaration, ctx: SerializerContext): SpecExport10 | null;
|
package/dist/index.js
CHANGED
|
@@ -2703,10 +2703,12 @@ function buildFunctionSchema(callSignatures, checker, ctx) {
|
|
|
2703
2703
|
const signatures = callSignatures.map((sig) => {
|
|
2704
2704
|
const params = sig.getParameters().map((param) => {
|
|
2705
2705
|
const paramType = checker.getTypeOfSymbolAtLocation(param, param.valueDeclaration);
|
|
2706
|
+
const decl = param.valueDeclaration;
|
|
2707
|
+
const isOptional = !!decl?.questionToken || !!decl?.initializer;
|
|
2706
2708
|
return {
|
|
2707
2709
|
name: param.getName(),
|
|
2708
2710
|
schema: buildSchema(paramType, checker, ctx),
|
|
2709
|
-
required: !
|
|
2711
|
+
required: !isOptional
|
|
2710
2712
|
};
|
|
2711
2713
|
});
|
|
2712
2714
|
const returnType = checker.getReturnTypeOfSignature(sig);
|
|
@@ -2887,7 +2889,7 @@ function extractParameters(signature, ctx) {
|
|
|
2887
2889
|
const expandedParams = expandBindingPattern(decl, type, jsdocTags, ctx);
|
|
2888
2890
|
result.push(...expandedParams);
|
|
2889
2891
|
} else {
|
|
2890
|
-
const isOptional = !!
|
|
2892
|
+
const isOptional = !!decl?.questionToken || !!decl?.initializer;
|
|
2891
2893
|
const effectiveType = isOptional ? stripUndefinedFromType(type, checker) : type;
|
|
2892
2894
|
registerReferencedTypes(effectiveType, ctx);
|
|
2893
2895
|
const paramName = param.getName();
|
|
@@ -3751,9 +3753,9 @@ function buildReturnSchema(sig, ctx) {
|
|
|
3751
3753
|
}
|
|
3752
3754
|
return { schema };
|
|
3753
3755
|
}
|
|
3754
|
-
function serializeFunctionExport(node, ctx) {
|
|
3756
|
+
function serializeFunctionExport(node, ctx, nameOverride) {
|
|
3755
3757
|
const symbol = ctx.typeChecker.getSymbolAtLocation(node.name ?? node);
|
|
3756
|
-
const name = symbol?.getName() ?? node.name?.getText();
|
|
3758
|
+
const name = nameOverride ?? symbol?.getName() ?? node.name?.getText();
|
|
3757
3759
|
if (!name)
|
|
3758
3760
|
return null;
|
|
3759
3761
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
@@ -4758,7 +4760,12 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
|
|
|
4758
4760
|
} else if (ts11.isVariableDeclaration(declaration)) {
|
|
4759
4761
|
const varStatement = declaration.parent?.parent;
|
|
4760
4762
|
if (varStatement && ts11.isVariableStatement(varStatement)) {
|
|
4761
|
-
|
|
4763
|
+
if (declaration.initializer && ts11.isArrowFunction(declaration.initializer)) {
|
|
4764
|
+
const varName = ts11.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
|
|
4765
|
+
result = serializeFunctionExport(declaration.initializer, ctx, varName);
|
|
4766
|
+
} else {
|
|
4767
|
+
result = serializeVariable(declaration, varStatement, ctx);
|
|
4768
|
+
}
|
|
4762
4769
|
}
|
|
4763
4770
|
}
|
|
4764
4771
|
if (result) {
|
|
@@ -5948,7 +5955,12 @@ function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportN
|
|
|
5948
5955
|
} else if (ts14.isVariableDeclaration(declaration)) {
|
|
5949
5956
|
const varStatement = declaration.parent?.parent;
|
|
5950
5957
|
if (varStatement && ts14.isVariableStatement(varStatement)) {
|
|
5951
|
-
|
|
5958
|
+
if (declaration.initializer && ts14.isArrowFunction(declaration.initializer)) {
|
|
5959
|
+
const varName = ts14.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
|
|
5960
|
+
result = serializeFunctionExport(declaration.initializer, ctx, varName);
|
|
5961
|
+
} else {
|
|
5962
|
+
result = serializeVariable(declaration, varStatement, ctx);
|
|
5963
|
+
}
|
|
5952
5964
|
}
|
|
5953
5965
|
} else if (ts14.isNamespaceExport(declaration) || ts14.isModuleDeclaration(declaration)) {
|
|
5954
5966
|
try {
|