@openpkg-ts/sdk 0.43.0 → 0.45.0
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 +41 -1
- package/dist/index.js +166 -18
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1653,6 +1653,41 @@ import ts15 from "typescript";
|
|
|
1653
1653
|
* Used for types that have specific serialization formats.
|
|
1654
1654
|
*/
|
|
1655
1655
|
declare const BUILTIN_TYPE_SCHEMAS: Record<string, SpecSchema2>;
|
|
1656
|
+
/**
|
|
1657
|
+
* Remove `import("<abs path>").` qualifiers from checker-rendered type text.
|
|
1658
|
+
* Machine-specific paths must never appear in a published spec.
|
|
1659
|
+
*/
|
|
1660
|
+
declare function scrubImportQualifiers(text: string): string;
|
|
1661
|
+
/**
|
|
1662
|
+
* Render the developer-facing type text at its owning declaration.
|
|
1663
|
+
* NoTruncation keeps long unions intact; import() qualifiers are scrubbed.
|
|
1664
|
+
*/
|
|
1665
|
+
declare function renderTypeText(type: ts15.Type, checker: ts15.TypeChecker, enclosing?: ts15.Node, extraFlags?: ts15.TypeFormatFlags): string;
|
|
1666
|
+
/**
|
|
1667
|
+
* Strip `undefined` from a union type when optionality is already expressed
|
|
1668
|
+
* elsewhere (`required: false`, `flags.optional`). Used for both schema shape
|
|
1669
|
+
* and x-ts-type text so neither re-encodes optionality as `| undefined`.
|
|
1670
|
+
*/
|
|
1671
|
+
declare function stripUndefinedFromType(type: ts15.Type, checker: ts15.TypeChecker): ts15.Type;
|
|
1672
|
+
/** Declaration-modifier readonly check — matches the member-layer flags.readonly source. */
|
|
1673
|
+
declare function isReadonlyPropertySymbol(prop: ts15.Symbol): boolean;
|
|
1674
|
+
/**
|
|
1675
|
+
* Decorate a property schema with TS-fidelity metadata:
|
|
1676
|
+
* - `x-ts-type`: checker-rendered text at the owning declaration. Emitted
|
|
1677
|
+
* unless trivially derivable — a bare primitive keyword, or a $ref whose
|
|
1678
|
+
* target name equals the text. Optional props render without `| undefined`.
|
|
1679
|
+
* - `readOnly`: JSON Schema readonly marker from the declaration modifier.
|
|
1680
|
+
* - `x-ts-method`: declaration form marker for method-syntax members
|
|
1681
|
+
* (SymbolFlags.Method survives on true methods, is stripped by mapping).
|
|
1682
|
+
*/
|
|
1683
|
+
declare function decoratePropertySchema(schema: SpecSchema2, prop: ts15.Symbol, propType: ts15.Type, checker: ts15.TypeChecker): SpecSchema2;
|
|
1684
|
+
/**
|
|
1685
|
+
* Alias-level x-ts-type is emitted when the alias RHS is a renderable
|
|
1686
|
+
* expression (array, instantiation, union, intersection, function, keyof, …).
|
|
1687
|
+
* Type-literal and mapped bodies are skipped — their structure is already
|
|
1688
|
+
* carried by schema.properties and the text would be the whole literal body.
|
|
1689
|
+
*/
|
|
1690
|
+
declare function shouldEmitAliasTypeText(typeNode: ts15.TypeNode): boolean;
|
|
1656
1691
|
declare const PRIMITIVES: Set<string>;
|
|
1657
1692
|
declare const ARRAY_PROTOTYPE_METHODS: Set<string>;
|
|
1658
1693
|
declare const STRING_PROTOTYPE_METHODS: Set<string>;
|
|
@@ -1662,6 +1697,11 @@ declare const NUMBER_PROTOTYPE_METHODS: Set<string>;
|
|
|
1662
1697
|
*/
|
|
1663
1698
|
declare function isPrimitiveName(name: string): boolean;
|
|
1664
1699
|
/**
|
|
1700
|
+
* Check if a symbol is from TypeScript's built-in lib (lib.es*.d.ts).
|
|
1701
|
+
* Used to detect Array, Object, and other built-in types.
|
|
1702
|
+
*/
|
|
1703
|
+
declare function isBuiltinSymbol(symbol: ts15.Symbol | undefined): boolean;
|
|
1704
|
+
/**
|
|
1665
1705
|
* Get the origin package name for a type if it comes from node_modules.
|
|
1666
1706
|
* Returns undefined for types defined in the current project.
|
|
1667
1707
|
*
|
|
@@ -1795,4 +1835,4 @@ declare function normalizeMembers(members: SpecMember3[], options?: NormalizeOpt
|
|
|
1795
1835
|
import ts16 from "typescript";
|
|
1796
1836
|
declare function isExported(node: ts16.Node): boolean;
|
|
1797
1837
|
declare function getNodeName(node: ts16.Node): string | undefined;
|
|
1798
|
-
export { zodAdapter, withDescription2 as withDescription, withDeprecated, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, sortByName, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveTypeRef, resolveExportTarget, resolveCompiledPath, registerReferencedTypes, registerAdapter, recommendSemverBump, query, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, mergeConfig, loadSpec, loadConfig, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isProperty, isPrimitiveName, isMethod, isExported, isBuiltinGeneric, isAnonymous, hasDeprecatedTag, groupByVisibility, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExportKind, getExport2 as getExport, getDeprecationMessage, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findMissingParamDocs, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, buildSignatureString, buildSchema, buildObjectSchema, buildFunctionSchema, arktypeAdapter, analyzeSpec, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecDiff, SpecDiagnostics, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaExtractionResult, SchemaAdapter, STRING_PROTOTYPE_METHODS, QueryBuilder, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, PRIMITIVES, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, NUMBER_PROTOTYPE_METHODS, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, FilterResult, FilterCriteria, ExtractionWarningCode, ExtractionWarning, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExternalsConfig, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, DiagnosticItem, Diagnostic, CategorizedBreaking, CacheManagerOptions, CacheManager, CONFIG_FILENAME, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
|
1838
|
+
export { zodAdapter, withDescription2 as withDescription, withDeprecated, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, stripUndefinedFromType, sortByName, shouldEmitAliasTypeText, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, scrubImportQualifiers, schemasAreEqual, schemaIsAny, resolveTypeRef, resolveExportTarget, resolveCompiledPath, renderTypeText, registerReferencedTypes, registerAdapter, recommendSemverBump, query, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, mergeConfig, loadSpec, loadConfig, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isReadonlyPropertySymbol, isPureRefSchema, isProperty, isPrimitiveName, isMethod, isExported, isBuiltinSymbol, isBuiltinGeneric, isAnonymous, hasDeprecatedTag, groupByVisibility, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExportKind, getExport2 as getExport, getDeprecationMessage, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findMissingParamDocs, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, decoratePropertySchema, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, buildSignatureString, buildSchema, buildObjectSchema, buildFunctionSchema, arktypeAdapter, analyzeSpec, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecDiff, SpecDiagnostics, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaExtractionResult, SchemaAdapter, STRING_PROTOTYPE_METHODS, QueryBuilder, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, PRIMITIVES, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, NUMBER_PROTOTYPE_METHODS, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, FilterResult, FilterCriteria, ExtractionWarningCode, ExtractionWarning, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExternalsConfig, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, DiagnosticItem, Diagnostic, CategorizedBreaking, CacheManagerOptions, CacheManager, CONFIG_FILENAME, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
package/dist/index.js
CHANGED
|
@@ -1875,6 +1875,51 @@ var BUILTIN_TYPE_SCHEMAS = {
|
|
|
1875
1875
|
function setSchemaExtension(schema, key, value) {
|
|
1876
1876
|
schema[key] = value;
|
|
1877
1877
|
}
|
|
1878
|
+
function scrubImportQualifiers(text) {
|
|
1879
|
+
return text.replace(/import\((?:"[^"]*"|'[^']*')\)\./g, "");
|
|
1880
|
+
}
|
|
1881
|
+
function renderTypeText(type, checker, enclosing, extraFlags = 0) {
|
|
1882
|
+
return scrubImportQualifiers(checker.typeToString(type, enclosing, ts3.TypeFormatFlags.NoTruncation | extraFlags));
|
|
1883
|
+
}
|
|
1884
|
+
function stripUndefinedFromType(type, checker) {
|
|
1885
|
+
if (!type.isUnion())
|
|
1886
|
+
return type;
|
|
1887
|
+
const nonUndefinedTypes = type.types.filter((t) => !(t.flags & ts3.TypeFlags.Undefined));
|
|
1888
|
+
if (nonUndefinedTypes.length === 0)
|
|
1889
|
+
return type;
|
|
1890
|
+
if (nonUndefinedTypes.length === 1)
|
|
1891
|
+
return nonUndefinedTypes[0];
|
|
1892
|
+
return checker.getUnionType(nonUndefinedTypes);
|
|
1893
|
+
}
|
|
1894
|
+
function isReadonlyPropertySymbol(prop) {
|
|
1895
|
+
const decls = prop.getDeclarations() ?? [];
|
|
1896
|
+
return decls.some((d) => (ts3.getCombinedModifierFlags(d) & ts3.ModifierFlags.Readonly) !== 0);
|
|
1897
|
+
}
|
|
1898
|
+
function decoratePropertySchema(schema, prop, propType, checker) {
|
|
1899
|
+
if (typeof schema !== "object" || schema === null || Array.isArray(schema))
|
|
1900
|
+
return schema;
|
|
1901
|
+
const decl = prop.valueDeclaration ?? prop.getDeclarations()?.[0];
|
|
1902
|
+
const optional = !!(prop.flags & ts3.SymbolFlags.Optional);
|
|
1903
|
+
const textType = optional ? stripUndefinedFromType(propType, checker) : propType;
|
|
1904
|
+
const text = renderTypeText(textType, checker, decl);
|
|
1905
|
+
const obj = schema;
|
|
1906
|
+
const refTarget = typeof obj.$ref === "string" ? obj.$ref : Array.isArray(obj.allOf) && obj.allOf.length === 1 && isPureRefSchema(obj.allOf[0]) ? obj.allOf[0].$ref : undefined;
|
|
1907
|
+
const derivable = PRIMITIVES.has(text) || refTarget === `#/types/${text}`;
|
|
1908
|
+
let result = obj;
|
|
1909
|
+
if (!derivable && !("x-ts-type" in obj)) {
|
|
1910
|
+
result = { ...result, "x-ts-type": text };
|
|
1911
|
+
}
|
|
1912
|
+
if (isReadonlyPropertySymbol(prop) && !("readOnly" in obj)) {
|
|
1913
|
+
result = { ...result, readOnly: true };
|
|
1914
|
+
}
|
|
1915
|
+
if (prop.flags & ts3.SymbolFlags.Method && !("x-ts-method" in obj)) {
|
|
1916
|
+
result = { ...result, "x-ts-method": true };
|
|
1917
|
+
}
|
|
1918
|
+
return result;
|
|
1919
|
+
}
|
|
1920
|
+
function shouldEmitAliasTypeText(typeNode) {
|
|
1921
|
+
return !ts3.isTypeLiteralNode(typeNode) && !ts3.isMappedTypeNode(typeNode);
|
|
1922
|
+
}
|
|
1878
1923
|
var PRIMITIVES = new Set([
|
|
1879
1924
|
"string",
|
|
1880
1925
|
"number",
|
|
@@ -2482,6 +2527,7 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
|
|
|
2482
2527
|
if (deprecated) {
|
|
2483
2528
|
propSchema = withDeprecated(propSchema, reason);
|
|
2484
2529
|
}
|
|
2530
|
+
propSchema = decoratePropertySchema(propSchema, prop, propType, checker);
|
|
2485
2531
|
props[propName] = propSchema;
|
|
2486
2532
|
if (!(prop.flags & ts3.SymbolFlags.Optional)) {
|
|
2487
2533
|
required.push(propName);
|
|
@@ -2628,16 +2674,6 @@ function findDiscriminatorProperty(unionTypes, checker) {
|
|
|
2628
2674
|
}
|
|
2629
2675
|
|
|
2630
2676
|
// src/types/parameters.ts
|
|
2631
|
-
function stripUndefinedFromType(type, checker) {
|
|
2632
|
-
if (!type.isUnion())
|
|
2633
|
-
return type;
|
|
2634
|
-
const nonUndefinedTypes = type.types.filter((t) => !(t.flags & ts4.TypeFlags.Undefined));
|
|
2635
|
-
if (nonUndefinedTypes.length === 0)
|
|
2636
|
-
return type;
|
|
2637
|
-
if (nonUndefinedTypes.length === 1)
|
|
2638
|
-
return nonUndefinedTypes[0];
|
|
2639
|
-
return checker.getUnionType(nonUndefinedTypes);
|
|
2640
|
-
}
|
|
2641
2677
|
function extractParameters(signature, ctx) {
|
|
2642
2678
|
const { typeChecker: checker } = ctx;
|
|
2643
2679
|
const result = [];
|
|
@@ -2965,6 +3001,12 @@ class TypeRegistry {
|
|
|
2965
3001
|
schema = enumSchema;
|
|
2966
3002
|
}
|
|
2967
3003
|
}
|
|
3004
|
+
if (kind === "type" && decl && ts5.isTypeAliasDeclaration(decl) && shouldEmitAliasTypeText(decl.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
|
|
3005
|
+
const text = renderTypeText(type, checker, decl, ts5.TypeFormatFlags.InTypeAlias);
|
|
3006
|
+
if (!PRIMITIVES.has(text) && text !== name) {
|
|
3007
|
+
schema["x-ts-type"] = text;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
2968
3010
|
return {
|
|
2969
3011
|
id: name,
|
|
2970
3012
|
name,
|
|
@@ -3011,6 +3053,19 @@ class TypeRegistry {
|
|
|
3011
3053
|
if (callSignatures.length > 0 && type.getProperties().length === 0) {
|
|
3012
3054
|
return buildFunctionSchema(callSignatures, checker, ctx);
|
|
3013
3055
|
}
|
|
3056
|
+
if (checker.isTupleType(type)) {
|
|
3057
|
+
const elementTypes = checker.getTypeArguments(type) ?? [];
|
|
3058
|
+
return {
|
|
3059
|
+
type: "array",
|
|
3060
|
+
prefixedItems: elementTypes.map((t) => buildSchema(t, checker, ctx)),
|
|
3061
|
+
minItems: elementTypes.length,
|
|
3062
|
+
maxItems: elementTypes.length
|
|
3063
|
+
};
|
|
3064
|
+
}
|
|
3065
|
+
if (checker.isArrayType(type)) {
|
|
3066
|
+
const elementType = checker.getTypeArguments(type)?.[0];
|
|
3067
|
+
return elementType ? { type: "array", items: buildSchema(elementType, checker, ctx) } : { type: "array" };
|
|
3068
|
+
}
|
|
3014
3069
|
return this.buildObjectSchemaFromProperties(type, checker, ctx);
|
|
3015
3070
|
}
|
|
3016
3071
|
buildEnumSchema(symbol, checker) {
|
|
@@ -3083,6 +3138,7 @@ class TypeRegistry {
|
|
|
3083
3138
|
if (deprecated) {
|
|
3084
3139
|
propSchema = withDeprecated(propSchema, reason);
|
|
3085
3140
|
}
|
|
3141
|
+
propSchema = decoratePropertySchema(propSchema, prop, propType, checker);
|
|
3086
3142
|
props[propName] = propSchema;
|
|
3087
3143
|
if (!(prop.flags & ts5.SymbolFlags.Optional)) {
|
|
3088
3144
|
required.push(propName);
|
|
@@ -3321,6 +3377,9 @@ function serializeClass(node, ctx) {
|
|
|
3321
3377
|
}
|
|
3322
3378
|
}
|
|
3323
3379
|
members.push(...methodsByName.values());
|
|
3380
|
+
if (signatures.length === 0) {
|
|
3381
|
+
signatures.push(...serializeInheritedConstructors(node, ctx));
|
|
3382
|
+
}
|
|
3324
3383
|
const ownMemberNames = new Set;
|
|
3325
3384
|
for (const member of node.members) {
|
|
3326
3385
|
const memberName = getMemberName(member);
|
|
@@ -3401,7 +3460,7 @@ function serializeProperty(node, ctx) {
|
|
|
3401
3460
|
}
|
|
3402
3461
|
const type = checker.getTypeAtLocation(node);
|
|
3403
3462
|
registerReferencedTypes(type, ctx);
|
|
3404
|
-
|
|
3463
|
+
let schema = buildSchema(type, checker, ctx);
|
|
3405
3464
|
const flags = {};
|
|
3406
3465
|
if (isStatic(node))
|
|
3407
3466
|
flags.static = true;
|
|
@@ -3410,6 +3469,9 @@ function serializeProperty(node, ctx) {
|
|
|
3410
3469
|
if (node.questionToken)
|
|
3411
3470
|
flags.optional = true;
|
|
3412
3471
|
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
3472
|
+
if (symbol) {
|
|
3473
|
+
schema = decoratePropertySchema(schema, symbol, type, checker);
|
|
3474
|
+
}
|
|
3413
3475
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3414
3476
|
return {
|
|
3415
3477
|
name,
|
|
@@ -3440,6 +3502,7 @@ function serializeMethod(node, ctx) {
|
|
|
3440
3502
|
flags.static = true;
|
|
3441
3503
|
if (node.asteriskToken)
|
|
3442
3504
|
flags.generator = true;
|
|
3505
|
+
flags.methodSyntax = true;
|
|
3443
3506
|
const modifiers = ts7.getModifiers(node);
|
|
3444
3507
|
if (modifiers?.some((m) => m.kind === ts7.SyntaxKind.AsyncKeyword)) {
|
|
3445
3508
|
flags.async = true;
|
|
@@ -3462,16 +3525,44 @@ function serializeMethod(node, ctx) {
|
|
|
3462
3525
|
}
|
|
3463
3526
|
function serializeConstructor(node, ctx) {
|
|
3464
3527
|
const { typeChecker: checker } = ctx;
|
|
3465
|
-
const { description } = getJSDocComment(node);
|
|
3466
3528
|
const sig = checker.getSignatureFromDeclaration(node);
|
|
3467
3529
|
if (!sig)
|
|
3468
3530
|
return null;
|
|
3531
|
+
return serializeConstructorSignature(node, sig, ctx);
|
|
3532
|
+
}
|
|
3533
|
+
function serializeConstructorSignature(node, sig, ctx) {
|
|
3534
|
+
const { description, tags, examples } = getJSDocComment(node);
|
|
3469
3535
|
const params = extractParameters(sig, ctx);
|
|
3470
3536
|
return {
|
|
3471
3537
|
description,
|
|
3472
|
-
parameters: params.length > 0 ? params : undefined
|
|
3538
|
+
parameters: params.length > 0 ? params : undefined,
|
|
3539
|
+
...tags.length > 0 ? { tags } : {},
|
|
3540
|
+
...examples.length > 0 ? { examples } : {}
|
|
3473
3541
|
};
|
|
3474
3542
|
}
|
|
3543
|
+
function serializeInheritedConstructors(node, ctx) {
|
|
3544
|
+
const { typeChecker: checker } = ctx;
|
|
3545
|
+
const hasExtends = node.heritageClauses?.some((c) => c.token === ts7.SyntaxKind.ExtendsKeyword);
|
|
3546
|
+
if (!hasExtends)
|
|
3547
|
+
return [];
|
|
3548
|
+
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
3549
|
+
if (!symbol)
|
|
3550
|
+
return [];
|
|
3551
|
+
const staticType = checker.getTypeOfSymbolAtLocation(symbol, node);
|
|
3552
|
+
const ctorSigs = staticType.getConstructSignatures().filter((sig) => {
|
|
3553
|
+
const decl = sig.getDeclaration();
|
|
3554
|
+
return decl !== undefined && ts7.isConstructorDeclaration(decl);
|
|
3555
|
+
});
|
|
3556
|
+
return ctorSigs.map((sig, index) => {
|
|
3557
|
+
const decl = sig.getDeclaration();
|
|
3558
|
+
const owner = ts7.isClassLike(decl.parent) ? decl.parent.name?.text : undefined;
|
|
3559
|
+
return {
|
|
3560
|
+
...serializeConstructorSignature(decl, sig, ctx),
|
|
3561
|
+
...owner ? { inheritedFrom: owner } : {},
|
|
3562
|
+
...ctorSigs.length > 1 ? { overloadIndex: index } : {}
|
|
3563
|
+
};
|
|
3564
|
+
});
|
|
3565
|
+
}
|
|
3475
3566
|
function serializeAccessor(node, ctx) {
|
|
3476
3567
|
const { typeChecker: checker } = ctx;
|
|
3477
3568
|
const name = getMemberName(node);
|
|
@@ -3760,7 +3851,7 @@ function serializePropertySignature(node, ctx) {
|
|
|
3760
3851
|
const name = node.name.getText();
|
|
3761
3852
|
const { description, tags } = getJSDocComment(node);
|
|
3762
3853
|
const type = checker.getTypeAtLocation(node);
|
|
3763
|
-
|
|
3854
|
+
let schema = buildSchema(type, checker, ctx);
|
|
3764
3855
|
registerReferencedTypes(type, ctx);
|
|
3765
3856
|
const flags = {};
|
|
3766
3857
|
if (node.questionToken)
|
|
@@ -3769,6 +3860,9 @@ function serializePropertySignature(node, ctx) {
|
|
|
3769
3860
|
flags.readonly = true;
|
|
3770
3861
|
}
|
|
3771
3862
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
3863
|
+
if (symbol) {
|
|
3864
|
+
schema = decoratePropertySchema(schema, symbol, type, checker);
|
|
3865
|
+
}
|
|
3772
3866
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3773
3867
|
return {
|
|
3774
3868
|
name,
|
|
@@ -3790,6 +3884,7 @@ function serializeMethodSignature(node, ctx) {
|
|
|
3790
3884
|
const flags = {};
|
|
3791
3885
|
if (node.questionToken)
|
|
3792
3886
|
flags.optional = true;
|
|
3887
|
+
flags.methodSyntax = true;
|
|
3793
3888
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
3794
3889
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3795
3890
|
return {
|
|
@@ -3899,6 +3994,15 @@ function serializeTypeAlias(node, ctx) {
|
|
|
3899
3994
|
members = serializeResolvedMembers(type, node, ctx);
|
|
3900
3995
|
} else {
|
|
3901
3996
|
schema = buildSchema(type, ctx.typeChecker, ctx);
|
|
3997
|
+
if (isObjectShapedAlias(type, ctx)) {
|
|
3998
|
+
members = serializeResolvedMembers(type, node, ctx);
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
if (shouldEmitAliasTypeText(node.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
|
|
4002
|
+
const text = renderTypeText(type, ctx.typeChecker, node, ts10.TypeFormatFlags.InTypeAlias);
|
|
4003
|
+
if (!PRIMITIVES.has(text) && text !== name) {
|
|
4004
|
+
schema["x-ts-type"] = text;
|
|
4005
|
+
}
|
|
3902
4006
|
}
|
|
3903
4007
|
return {
|
|
3904
4008
|
id: name,
|
|
@@ -3914,6 +4018,20 @@ function serializeTypeAlias(node, ctx) {
|
|
|
3914
4018
|
...examples.length > 0 ? { examples } : {}
|
|
3915
4019
|
};
|
|
3916
4020
|
}
|
|
4021
|
+
function isObjectShapedAlias(type, ctx) {
|
|
4022
|
+
const { typeChecker: checker } = ctx;
|
|
4023
|
+
if (!(type.flags & ts10.TypeFlags.Object))
|
|
4024
|
+
return false;
|
|
4025
|
+
if (checker.isArrayType(type) || checker.isTupleType(type))
|
|
4026
|
+
return false;
|
|
4027
|
+
const objectFlags = type.objectFlags;
|
|
4028
|
+
if (!(objectFlags & ts10.ObjectFlags.Mapped)) {
|
|
4029
|
+
const targetSymbol = type.target?.getSymbol?.() ?? type.getSymbol();
|
|
4030
|
+
if (isBuiltinSymbol(targetSymbol))
|
|
4031
|
+
return false;
|
|
4032
|
+
}
|
|
4033
|
+
return type.getProperties().length > 0 && type.getCallSignatures().length === 0;
|
|
4034
|
+
}
|
|
3917
4035
|
function isInlineFunctionAlias(typeNode) {
|
|
3918
4036
|
return ts10.isFunctionTypeNode(typeNode) || ts10.isTypeLiteralNode(typeNode) && typeNode.members.some(ts10.isCallSignatureDeclaration);
|
|
3919
4037
|
}
|
|
@@ -3987,13 +4105,25 @@ function serializeResolvedMembers(type, node, ctx) {
|
|
|
3987
4105
|
if (!deprecated && armAlias) {
|
|
3988
4106
|
({ deprecated, reason: deprecationReason } = isSymbolDeprecated(armAlias));
|
|
3989
4107
|
}
|
|
4108
|
+
const flags = {};
|
|
4109
|
+
if (prop.flags & ts10.SymbolFlags.Optional)
|
|
4110
|
+
flags.optional = true;
|
|
4111
|
+
if (isReadonlyPropertySymbol(prop))
|
|
4112
|
+
flags.readonly = true;
|
|
4113
|
+
if (prop.flags & ts10.SymbolFlags.Method)
|
|
4114
|
+
flags.methodSyntax = true;
|
|
4115
|
+
let schema;
|
|
4116
|
+
if (kind === "property") {
|
|
4117
|
+
schema = decoratePropertySchema(buildSchema(propType, checker, ctx), prop, propType, checker);
|
|
4118
|
+
}
|
|
3990
4119
|
members.push({
|
|
3991
4120
|
name: prop.getName(),
|
|
3992
4121
|
kind,
|
|
3993
4122
|
description,
|
|
3994
4123
|
tags: tags.length > 0 ? tags : undefined,
|
|
3995
|
-
schema
|
|
4124
|
+
schema,
|
|
3996
4125
|
signatures: kind === "method" ? buildSignatures(callSigs, checker, ctx) : undefined,
|
|
4126
|
+
flags: Object.keys(flags).length > 0 ? flags : undefined,
|
|
3997
4127
|
...deprecated ? { deprecated: true, deprecationReason } : {}
|
|
3998
4128
|
});
|
|
3999
4129
|
}
|
|
@@ -4220,13 +4350,18 @@ function normalizeSchema(schema, options = {}) {
|
|
|
4220
4350
|
}
|
|
4221
4351
|
function normalizeSchemaInternal(schema, options) {
|
|
4222
4352
|
const result = normalizeSchemaDispatch(schema, options);
|
|
4223
|
-
if (schema && typeof schema === "object") {
|
|
4353
|
+
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
4224
4354
|
const s = schema;
|
|
4225
4355
|
if (s.deprecated === true && result.deprecated === undefined) {
|
|
4226
4356
|
result.deprecated = true;
|
|
4227
4357
|
}
|
|
4228
|
-
if (
|
|
4229
|
-
result
|
|
4358
|
+
if (s.readOnly === true && result.readOnly === undefined) {
|
|
4359
|
+
result.readOnly = true;
|
|
4360
|
+
}
|
|
4361
|
+
for (const key of Object.keys(s)) {
|
|
4362
|
+
if (key.startsWith("x-") && s[key] !== undefined && result[key] === undefined) {
|
|
4363
|
+
result[key] = s[key];
|
|
4364
|
+
}
|
|
4230
4365
|
}
|
|
4231
4366
|
}
|
|
4232
4367
|
return result;
|
|
@@ -4606,6 +4741,9 @@ function memberDocExtras(member) {
|
|
|
4606
4741
|
if (member.description) {
|
|
4607
4742
|
extras.description = member.description;
|
|
4608
4743
|
}
|
|
4744
|
+
if (member.flags?.readonly === true) {
|
|
4745
|
+
extras.readOnly = true;
|
|
4746
|
+
}
|
|
4609
4747
|
if (member.deprecated) {
|
|
4610
4748
|
extras.deprecated = true;
|
|
4611
4749
|
const reason = member.deprecationReason ?? member.tags?.find((t) => t.name === "deprecated")?.text;
|
|
@@ -4653,6 +4791,9 @@ function normalizeMethodMember(member, options) {
|
|
|
4653
4791
|
const result = {
|
|
4654
4792
|
"x-ts-function": true
|
|
4655
4793
|
};
|
|
4794
|
+
if (member.flags?.methodSyntax === true) {
|
|
4795
|
+
result["x-ts-method"] = true;
|
|
4796
|
+
}
|
|
4656
4797
|
if (member.signatures && member.signatures.length > 0) {
|
|
4657
4798
|
result["x-ts-signatures"] = member.signatures.map((sig) => normalizeSignature(sig, options));
|
|
4658
4799
|
}
|
|
@@ -6964,18 +7105,22 @@ export {
|
|
|
6964
7105
|
toFumadocsMetaJSON,
|
|
6965
7106
|
toDocusaurusSidebarJS,
|
|
6966
7107
|
toAlgoliaRecords,
|
|
7108
|
+
stripUndefinedFromType,
|
|
6967
7109
|
sortByName,
|
|
7110
|
+
shouldEmitAliasTypeText,
|
|
6968
7111
|
serializeVariable,
|
|
6969
7112
|
serializeTypeAlias,
|
|
6970
7113
|
serializeInterface,
|
|
6971
7114
|
serializeFunctionExport,
|
|
6972
7115
|
serializeEnum,
|
|
6973
7116
|
serializeClass,
|
|
7117
|
+
scrubImportQualifiers,
|
|
6974
7118
|
schemasAreEqual,
|
|
6975
7119
|
schemaIsAny,
|
|
6976
7120
|
resolveTypeRef,
|
|
6977
7121
|
resolveExportTarget2 as resolveExportTarget,
|
|
6978
7122
|
resolveCompiledPath,
|
|
7123
|
+
renderTypeText,
|
|
6979
7124
|
registerReferencedTypes,
|
|
6980
7125
|
registerAdapter,
|
|
6981
7126
|
recommendSemverBump,
|
|
@@ -6993,11 +7138,13 @@ export {
|
|
|
6993
7138
|
isSymbolDeprecated,
|
|
6994
7139
|
isStandardJSONSchema,
|
|
6995
7140
|
isSchemaType,
|
|
7141
|
+
isReadonlyPropertySymbol,
|
|
6996
7142
|
isPureRefSchema,
|
|
6997
7143
|
isProperty,
|
|
6998
7144
|
isPrimitiveName,
|
|
6999
7145
|
isMethod,
|
|
7000
7146
|
isExported,
|
|
7147
|
+
isBuiltinSymbol,
|
|
7001
7148
|
isBuiltinGeneric,
|
|
7002
7149
|
isAnonymous,
|
|
7003
7150
|
hasDeprecatedTag,
|
|
@@ -7040,6 +7187,7 @@ export {
|
|
|
7040
7187
|
diffSpec,
|
|
7041
7188
|
detectTsRuntime,
|
|
7042
7189
|
deduplicateSchemas,
|
|
7190
|
+
decoratePropertySchema,
|
|
7043
7191
|
createProgram,
|
|
7044
7192
|
createDocs,
|
|
7045
7193
|
categorizeBreakingChanges,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test": "bun test"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@openpkg-ts/spec": "^0.
|
|
46
|
+
"@openpkg-ts/spec": "^0.45.0",
|
|
47
47
|
"picomatch": "4.0.3",
|
|
48
48
|
"typescript": "^5.0.0"
|
|
49
49
|
},
|