@openpkg-ts/sdk 0.44.0 → 0.46.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 +144 -17
- 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,10 +3001,21 @@ 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
|
+
}
|
|
3010
|
+
let typeParameters;
|
|
3011
|
+
if (decl && (ts5.isTypeAliasDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isClassDeclaration(decl))) {
|
|
3012
|
+
typeParameters = extractTypeParameters(decl, checker);
|
|
3013
|
+
}
|
|
2968
3014
|
return {
|
|
2969
3015
|
id: name,
|
|
2970
3016
|
name,
|
|
2971
3017
|
kind,
|
|
3018
|
+
...typeParameters && typeParameters.length > 0 ? { typeParameters } : {},
|
|
2972
3019
|
schema,
|
|
2973
3020
|
...external ? { external: true } : {}
|
|
2974
3021
|
};
|
|
@@ -3011,6 +3058,19 @@ class TypeRegistry {
|
|
|
3011
3058
|
if (callSignatures.length > 0 && type.getProperties().length === 0) {
|
|
3012
3059
|
return buildFunctionSchema(callSignatures, checker, ctx);
|
|
3013
3060
|
}
|
|
3061
|
+
if (checker.isTupleType(type)) {
|
|
3062
|
+
const elementTypes = checker.getTypeArguments(type) ?? [];
|
|
3063
|
+
return {
|
|
3064
|
+
type: "array",
|
|
3065
|
+
prefixedItems: elementTypes.map((t) => buildSchema(t, checker, ctx)),
|
|
3066
|
+
minItems: elementTypes.length,
|
|
3067
|
+
maxItems: elementTypes.length
|
|
3068
|
+
};
|
|
3069
|
+
}
|
|
3070
|
+
if (checker.isArrayType(type)) {
|
|
3071
|
+
const elementType = checker.getTypeArguments(type)?.[0];
|
|
3072
|
+
return elementType ? { type: "array", items: buildSchema(elementType, checker, ctx) } : { type: "array" };
|
|
3073
|
+
}
|
|
3014
3074
|
return this.buildObjectSchemaFromProperties(type, checker, ctx);
|
|
3015
3075
|
}
|
|
3016
3076
|
buildEnumSchema(symbol, checker) {
|
|
@@ -3083,6 +3143,7 @@ class TypeRegistry {
|
|
|
3083
3143
|
if (deprecated) {
|
|
3084
3144
|
propSchema = withDeprecated(propSchema, reason);
|
|
3085
3145
|
}
|
|
3146
|
+
propSchema = decoratePropertySchema(propSchema, prop, propType, checker);
|
|
3086
3147
|
props[propName] = propSchema;
|
|
3087
3148
|
if (!(prop.flags & ts5.SymbolFlags.Optional)) {
|
|
3088
3149
|
required.push(propName);
|
|
@@ -3241,7 +3302,7 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
|
|
|
3241
3302
|
description,
|
|
3242
3303
|
tags: tags.length > 0 ? tags : undefined,
|
|
3243
3304
|
visibility,
|
|
3244
|
-
schema: kind !== "method" ? buildSchema(type, checker, ctx) :
|
|
3305
|
+
schema: kind !== "method" ? buildSchema(type, checker, ctx) : decoratePropertySchema({ "x-ts-function": true }, symbol, type, checker),
|
|
3245
3306
|
signatures,
|
|
3246
3307
|
flags: Object.keys(flags).length > 0 ? flags : undefined
|
|
3247
3308
|
};
|
|
@@ -3404,7 +3465,7 @@ function serializeProperty(node, ctx) {
|
|
|
3404
3465
|
}
|
|
3405
3466
|
const type = checker.getTypeAtLocation(node);
|
|
3406
3467
|
registerReferencedTypes(type, ctx);
|
|
3407
|
-
|
|
3468
|
+
let schema = buildSchema(type, checker, ctx);
|
|
3408
3469
|
const flags = {};
|
|
3409
3470
|
if (isStatic(node))
|
|
3410
3471
|
flags.static = true;
|
|
@@ -3413,6 +3474,9 @@ function serializeProperty(node, ctx) {
|
|
|
3413
3474
|
if (node.questionToken)
|
|
3414
3475
|
flags.optional = true;
|
|
3415
3476
|
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
3477
|
+
if (symbol) {
|
|
3478
|
+
schema = decoratePropertySchema(schema, symbol, type, checker);
|
|
3479
|
+
}
|
|
3416
3480
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3417
3481
|
return {
|
|
3418
3482
|
name,
|
|
@@ -3443,6 +3507,7 @@ function serializeMethod(node, ctx) {
|
|
|
3443
3507
|
flags.static = true;
|
|
3444
3508
|
if (node.asteriskToken)
|
|
3445
3509
|
flags.generator = true;
|
|
3510
|
+
flags.methodSyntax = true;
|
|
3446
3511
|
const modifiers = ts7.getModifiers(node);
|
|
3447
3512
|
if (modifiers?.some((m) => m.kind === ts7.SyntaxKind.AsyncKeyword)) {
|
|
3448
3513
|
flags.async = true;
|
|
@@ -3452,12 +3517,14 @@ function serializeMethod(node, ctx) {
|
|
|
3452
3517
|
}
|
|
3453
3518
|
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
3454
3519
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3520
|
+
const schema = symbol ? decoratePropertySchema({ "x-ts-function": true }, symbol, type, checker) : undefined;
|
|
3455
3521
|
return {
|
|
3456
3522
|
name,
|
|
3457
3523
|
kind: "method",
|
|
3458
3524
|
description,
|
|
3459
3525
|
tags: tags.length > 0 ? tags : undefined,
|
|
3460
3526
|
visibility,
|
|
3527
|
+
schema,
|
|
3461
3528
|
signatures: signatures.length > 0 ? signatures : undefined,
|
|
3462
3529
|
flags: Object.keys(flags).length > 0 ? flags : undefined,
|
|
3463
3530
|
...deprecated ? { deprecated: true, deprecationReason } : {}
|
|
@@ -3791,7 +3858,7 @@ function serializePropertySignature(node, ctx) {
|
|
|
3791
3858
|
const name = node.name.getText();
|
|
3792
3859
|
const { description, tags } = getJSDocComment(node);
|
|
3793
3860
|
const type = checker.getTypeAtLocation(node);
|
|
3794
|
-
|
|
3861
|
+
let schema = buildSchema(type, checker, ctx);
|
|
3795
3862
|
registerReferencedTypes(type, ctx);
|
|
3796
3863
|
const flags = {};
|
|
3797
3864
|
if (node.questionToken)
|
|
@@ -3800,6 +3867,9 @@ function serializePropertySignature(node, ctx) {
|
|
|
3800
3867
|
flags.readonly = true;
|
|
3801
3868
|
}
|
|
3802
3869
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
3870
|
+
if (symbol) {
|
|
3871
|
+
schema = decoratePropertySchema(schema, symbol, type, checker);
|
|
3872
|
+
}
|
|
3803
3873
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3804
3874
|
return {
|
|
3805
3875
|
name,
|
|
@@ -3821,13 +3891,16 @@ function serializeMethodSignature(node, ctx) {
|
|
|
3821
3891
|
const flags = {};
|
|
3822
3892
|
if (node.questionToken)
|
|
3823
3893
|
flags.optional = true;
|
|
3894
|
+
flags.methodSyntax = true;
|
|
3824
3895
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
3825
3896
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3897
|
+
const schema = symbol ? decoratePropertySchema({ "x-ts-function": true }, symbol, type, checker) : undefined;
|
|
3826
3898
|
return {
|
|
3827
3899
|
name,
|
|
3828
3900
|
kind: "method",
|
|
3829
3901
|
description,
|
|
3830
3902
|
tags: tags.length > 0 ? tags : undefined,
|
|
3903
|
+
schema,
|
|
3831
3904
|
signatures: signatures.length > 0 ? signatures : undefined,
|
|
3832
3905
|
flags: Object.keys(flags).length > 0 ? flags : undefined,
|
|
3833
3906
|
...deprecated ? { deprecated: true, deprecationReason } : {}
|
|
@@ -3930,6 +4003,15 @@ function serializeTypeAlias(node, ctx) {
|
|
|
3930
4003
|
members = serializeResolvedMembers(type, node, ctx);
|
|
3931
4004
|
} else {
|
|
3932
4005
|
schema = buildSchema(type, ctx.typeChecker, ctx);
|
|
4006
|
+
if (isObjectShapedAlias(type, ctx)) {
|
|
4007
|
+
members = serializeResolvedMembers(type, node, ctx);
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
4010
|
+
if (shouldEmitAliasTypeText(node.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
|
|
4011
|
+
const text = renderTypeText(type, ctx.typeChecker, node, ts10.TypeFormatFlags.InTypeAlias);
|
|
4012
|
+
if (!PRIMITIVES.has(text) && text !== name) {
|
|
4013
|
+
schema["x-ts-type"] = text;
|
|
4014
|
+
}
|
|
3933
4015
|
}
|
|
3934
4016
|
return {
|
|
3935
4017
|
id: name,
|
|
@@ -3945,6 +4027,20 @@ function serializeTypeAlias(node, ctx) {
|
|
|
3945
4027
|
...examples.length > 0 ? { examples } : {}
|
|
3946
4028
|
};
|
|
3947
4029
|
}
|
|
4030
|
+
function isObjectShapedAlias(type, ctx) {
|
|
4031
|
+
const { typeChecker: checker } = ctx;
|
|
4032
|
+
if (!(type.flags & ts10.TypeFlags.Object))
|
|
4033
|
+
return false;
|
|
4034
|
+
if (checker.isArrayType(type) || checker.isTupleType(type))
|
|
4035
|
+
return false;
|
|
4036
|
+
const objectFlags = type.objectFlags;
|
|
4037
|
+
if (!(objectFlags & ts10.ObjectFlags.Mapped)) {
|
|
4038
|
+
const targetSymbol = type.target?.getSymbol?.() ?? type.getSymbol();
|
|
4039
|
+
if (isBuiltinSymbol(targetSymbol))
|
|
4040
|
+
return false;
|
|
4041
|
+
}
|
|
4042
|
+
return type.getProperties().length > 0 && type.getCallSignatures().length === 0;
|
|
4043
|
+
}
|
|
3948
4044
|
function isInlineFunctionAlias(typeNode) {
|
|
3949
4045
|
return ts10.isFunctionTypeNode(typeNode) || ts10.isTypeLiteralNode(typeNode) && typeNode.members.some(ts10.isCallSignatureDeclaration);
|
|
3950
4046
|
}
|
|
@@ -4018,13 +4114,22 @@ function serializeResolvedMembers(type, node, ctx) {
|
|
|
4018
4114
|
if (!deprecated && armAlias) {
|
|
4019
4115
|
({ deprecated, reason: deprecationReason } = isSymbolDeprecated(armAlias));
|
|
4020
4116
|
}
|
|
4117
|
+
const flags = {};
|
|
4118
|
+
if (prop.flags & ts10.SymbolFlags.Optional)
|
|
4119
|
+
flags.optional = true;
|
|
4120
|
+
if (isReadonlyPropertySymbol(prop))
|
|
4121
|
+
flags.readonly = true;
|
|
4122
|
+
if (prop.flags & ts10.SymbolFlags.Method)
|
|
4123
|
+
flags.methodSyntax = true;
|
|
4124
|
+
const schema = kind === "property" ? decoratePropertySchema(buildSchema(propType, checker, ctx), prop, propType, checker) : decoratePropertySchema({ "x-ts-function": true }, prop, propType, checker);
|
|
4021
4125
|
members.push({
|
|
4022
4126
|
name: prop.getName(),
|
|
4023
4127
|
kind,
|
|
4024
4128
|
description,
|
|
4025
4129
|
tags: tags.length > 0 ? tags : undefined,
|
|
4026
|
-
schema
|
|
4130
|
+
schema,
|
|
4027
4131
|
signatures: kind === "method" ? buildSignatures(callSigs, checker, ctx) : undefined,
|
|
4132
|
+
flags: Object.keys(flags).length > 0 ? flags : undefined,
|
|
4028
4133
|
...deprecated ? { deprecated: true, deprecationReason } : {}
|
|
4029
4134
|
});
|
|
4030
4135
|
}
|
|
@@ -4251,13 +4356,18 @@ function normalizeSchema(schema, options = {}) {
|
|
|
4251
4356
|
}
|
|
4252
4357
|
function normalizeSchemaInternal(schema, options) {
|
|
4253
4358
|
const result = normalizeSchemaDispatch(schema, options);
|
|
4254
|
-
if (schema && typeof schema === "object") {
|
|
4359
|
+
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
4255
4360
|
const s = schema;
|
|
4256
4361
|
if (s.deprecated === true && result.deprecated === undefined) {
|
|
4257
4362
|
result.deprecated = true;
|
|
4258
4363
|
}
|
|
4259
|
-
if (
|
|
4260
|
-
result
|
|
4364
|
+
if (s.readOnly === true && result.readOnly === undefined) {
|
|
4365
|
+
result.readOnly = true;
|
|
4366
|
+
}
|
|
4367
|
+
for (const key of Object.keys(s)) {
|
|
4368
|
+
if (key.startsWith("x-") && s[key] !== undefined && result[key] === undefined) {
|
|
4369
|
+
result[key] = s[key];
|
|
4370
|
+
}
|
|
4261
4371
|
}
|
|
4262
4372
|
}
|
|
4263
4373
|
return result;
|
|
@@ -4637,6 +4747,9 @@ function memberDocExtras(member) {
|
|
|
4637
4747
|
if (member.description) {
|
|
4638
4748
|
extras.description = member.description;
|
|
4639
4749
|
}
|
|
4750
|
+
if (member.flags?.readonly === true) {
|
|
4751
|
+
extras.readOnly = true;
|
|
4752
|
+
}
|
|
4640
4753
|
if (member.deprecated) {
|
|
4641
4754
|
extras.deprecated = true;
|
|
4642
4755
|
const reason = member.deprecationReason ?? member.tags?.find((t) => t.name === "deprecated")?.text;
|
|
@@ -4684,6 +4797,13 @@ function normalizeMethodMember(member, options) {
|
|
|
4684
4797
|
const result = {
|
|
4685
4798
|
"x-ts-function": true
|
|
4686
4799
|
};
|
|
4800
|
+
if (member.flags?.methodSyntax === true) {
|
|
4801
|
+
result["x-ts-method"] = true;
|
|
4802
|
+
}
|
|
4803
|
+
const memberTypeText = member.schema && typeof member.schema === "object" ? member.schema["x-ts-type"] : undefined;
|
|
4804
|
+
if (typeof memberTypeText === "string") {
|
|
4805
|
+
result["x-ts-type"] = memberTypeText;
|
|
4806
|
+
}
|
|
4687
4807
|
if (member.signatures && member.signatures.length > 0) {
|
|
4688
4808
|
result["x-ts-signatures"] = member.signatures.map((sig) => normalizeSignature(sig, options));
|
|
4689
4809
|
}
|
|
@@ -6995,18 +7115,22 @@ export {
|
|
|
6995
7115
|
toFumadocsMetaJSON,
|
|
6996
7116
|
toDocusaurusSidebarJS,
|
|
6997
7117
|
toAlgoliaRecords,
|
|
7118
|
+
stripUndefinedFromType,
|
|
6998
7119
|
sortByName,
|
|
7120
|
+
shouldEmitAliasTypeText,
|
|
6999
7121
|
serializeVariable,
|
|
7000
7122
|
serializeTypeAlias,
|
|
7001
7123
|
serializeInterface,
|
|
7002
7124
|
serializeFunctionExport,
|
|
7003
7125
|
serializeEnum,
|
|
7004
7126
|
serializeClass,
|
|
7127
|
+
scrubImportQualifiers,
|
|
7005
7128
|
schemasAreEqual,
|
|
7006
7129
|
schemaIsAny,
|
|
7007
7130
|
resolveTypeRef,
|
|
7008
7131
|
resolveExportTarget2 as resolveExportTarget,
|
|
7009
7132
|
resolveCompiledPath,
|
|
7133
|
+
renderTypeText,
|
|
7010
7134
|
registerReferencedTypes,
|
|
7011
7135
|
registerAdapter,
|
|
7012
7136
|
recommendSemverBump,
|
|
@@ -7024,11 +7148,13 @@ export {
|
|
|
7024
7148
|
isSymbolDeprecated,
|
|
7025
7149
|
isStandardJSONSchema,
|
|
7026
7150
|
isSchemaType,
|
|
7151
|
+
isReadonlyPropertySymbol,
|
|
7027
7152
|
isPureRefSchema,
|
|
7028
7153
|
isProperty,
|
|
7029
7154
|
isPrimitiveName,
|
|
7030
7155
|
isMethod,
|
|
7031
7156
|
isExported,
|
|
7157
|
+
isBuiltinSymbol,
|
|
7032
7158
|
isBuiltinGeneric,
|
|
7033
7159
|
isAnonymous,
|
|
7034
7160
|
hasDeprecatedTag,
|
|
@@ -7071,6 +7197,7 @@ export {
|
|
|
7071
7197
|
diffSpec,
|
|
7072
7198
|
detectTsRuntime,
|
|
7073
7199
|
deduplicateSchemas,
|
|
7200
|
+
decoratePropertySchema,
|
|
7074
7201
|
createProgram,
|
|
7075
7202
|
createDocs,
|
|
7076
7203
|
categorizeBreakingChanges,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.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.46.0",
|
|
47
47
|
"picomatch": "4.0.3",
|
|
48
48
|
"typescript": "^5.0.0"
|
|
49
49
|
},
|