@openpkg-ts/sdk 0.44.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 +133 -16
- 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);
|
|
@@ -3404,7 +3460,7 @@ function serializeProperty(node, ctx) {
|
|
|
3404
3460
|
}
|
|
3405
3461
|
const type = checker.getTypeAtLocation(node);
|
|
3406
3462
|
registerReferencedTypes(type, ctx);
|
|
3407
|
-
|
|
3463
|
+
let schema = buildSchema(type, checker, ctx);
|
|
3408
3464
|
const flags = {};
|
|
3409
3465
|
if (isStatic(node))
|
|
3410
3466
|
flags.static = true;
|
|
@@ -3413,6 +3469,9 @@ function serializeProperty(node, ctx) {
|
|
|
3413
3469
|
if (node.questionToken)
|
|
3414
3470
|
flags.optional = true;
|
|
3415
3471
|
const symbol = checker.getSymbolAtLocation(node.name ?? node);
|
|
3472
|
+
if (symbol) {
|
|
3473
|
+
schema = decoratePropertySchema(schema, symbol, type, checker);
|
|
3474
|
+
}
|
|
3416
3475
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3417
3476
|
return {
|
|
3418
3477
|
name,
|
|
@@ -3443,6 +3502,7 @@ function serializeMethod(node, ctx) {
|
|
|
3443
3502
|
flags.static = true;
|
|
3444
3503
|
if (node.asteriskToken)
|
|
3445
3504
|
flags.generator = true;
|
|
3505
|
+
flags.methodSyntax = true;
|
|
3446
3506
|
const modifiers = ts7.getModifiers(node);
|
|
3447
3507
|
if (modifiers?.some((m) => m.kind === ts7.SyntaxKind.AsyncKeyword)) {
|
|
3448
3508
|
flags.async = true;
|
|
@@ -3791,7 +3851,7 @@ function serializePropertySignature(node, ctx) {
|
|
|
3791
3851
|
const name = node.name.getText();
|
|
3792
3852
|
const { description, tags } = getJSDocComment(node);
|
|
3793
3853
|
const type = checker.getTypeAtLocation(node);
|
|
3794
|
-
|
|
3854
|
+
let schema = buildSchema(type, checker, ctx);
|
|
3795
3855
|
registerReferencedTypes(type, ctx);
|
|
3796
3856
|
const flags = {};
|
|
3797
3857
|
if (node.questionToken)
|
|
@@ -3800,6 +3860,9 @@ function serializePropertySignature(node, ctx) {
|
|
|
3800
3860
|
flags.readonly = true;
|
|
3801
3861
|
}
|
|
3802
3862
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
3863
|
+
if (symbol) {
|
|
3864
|
+
schema = decoratePropertySchema(schema, symbol, type, checker);
|
|
3865
|
+
}
|
|
3803
3866
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3804
3867
|
return {
|
|
3805
3868
|
name,
|
|
@@ -3821,6 +3884,7 @@ function serializeMethodSignature(node, ctx) {
|
|
|
3821
3884
|
const flags = {};
|
|
3822
3885
|
if (node.questionToken)
|
|
3823
3886
|
flags.optional = true;
|
|
3887
|
+
flags.methodSyntax = true;
|
|
3824
3888
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
3825
3889
|
const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
|
|
3826
3890
|
return {
|
|
@@ -3930,6 +3994,15 @@ function serializeTypeAlias(node, ctx) {
|
|
|
3930
3994
|
members = serializeResolvedMembers(type, node, ctx);
|
|
3931
3995
|
} else {
|
|
3932
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
|
+
}
|
|
3933
4006
|
}
|
|
3934
4007
|
return {
|
|
3935
4008
|
id: name,
|
|
@@ -3945,6 +4018,20 @@ function serializeTypeAlias(node, ctx) {
|
|
|
3945
4018
|
...examples.length > 0 ? { examples } : {}
|
|
3946
4019
|
};
|
|
3947
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
|
+
}
|
|
3948
4035
|
function isInlineFunctionAlias(typeNode) {
|
|
3949
4036
|
return ts10.isFunctionTypeNode(typeNode) || ts10.isTypeLiteralNode(typeNode) && typeNode.members.some(ts10.isCallSignatureDeclaration);
|
|
3950
4037
|
}
|
|
@@ -4018,13 +4105,25 @@ function serializeResolvedMembers(type, node, ctx) {
|
|
|
4018
4105
|
if (!deprecated && armAlias) {
|
|
4019
4106
|
({ deprecated, reason: deprecationReason } = isSymbolDeprecated(armAlias));
|
|
4020
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
|
+
}
|
|
4021
4119
|
members.push({
|
|
4022
4120
|
name: prop.getName(),
|
|
4023
4121
|
kind,
|
|
4024
4122
|
description,
|
|
4025
4123
|
tags: tags.length > 0 ? tags : undefined,
|
|
4026
|
-
schema
|
|
4124
|
+
schema,
|
|
4027
4125
|
signatures: kind === "method" ? buildSignatures(callSigs, checker, ctx) : undefined,
|
|
4126
|
+
flags: Object.keys(flags).length > 0 ? flags : undefined,
|
|
4028
4127
|
...deprecated ? { deprecated: true, deprecationReason } : {}
|
|
4029
4128
|
});
|
|
4030
4129
|
}
|
|
@@ -4251,13 +4350,18 @@ function normalizeSchema(schema, options = {}) {
|
|
|
4251
4350
|
}
|
|
4252
4351
|
function normalizeSchemaInternal(schema, options) {
|
|
4253
4352
|
const result = normalizeSchemaDispatch(schema, options);
|
|
4254
|
-
if (schema && typeof schema === "object") {
|
|
4353
|
+
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
4255
4354
|
const s = schema;
|
|
4256
4355
|
if (s.deprecated === true && result.deprecated === undefined) {
|
|
4257
4356
|
result.deprecated = true;
|
|
4258
4357
|
}
|
|
4259
|
-
if (
|
|
4260
|
-
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
|
+
}
|
|
4261
4365
|
}
|
|
4262
4366
|
}
|
|
4263
4367
|
return result;
|
|
@@ -4637,6 +4741,9 @@ function memberDocExtras(member) {
|
|
|
4637
4741
|
if (member.description) {
|
|
4638
4742
|
extras.description = member.description;
|
|
4639
4743
|
}
|
|
4744
|
+
if (member.flags?.readonly === true) {
|
|
4745
|
+
extras.readOnly = true;
|
|
4746
|
+
}
|
|
4640
4747
|
if (member.deprecated) {
|
|
4641
4748
|
extras.deprecated = true;
|
|
4642
4749
|
const reason = member.deprecationReason ?? member.tags?.find((t) => t.name === "deprecated")?.text;
|
|
@@ -4684,6 +4791,9 @@ function normalizeMethodMember(member, options) {
|
|
|
4684
4791
|
const result = {
|
|
4685
4792
|
"x-ts-function": true
|
|
4686
4793
|
};
|
|
4794
|
+
if (member.flags?.methodSyntax === true) {
|
|
4795
|
+
result["x-ts-method"] = true;
|
|
4796
|
+
}
|
|
4687
4797
|
if (member.signatures && member.signatures.length > 0) {
|
|
4688
4798
|
result["x-ts-signatures"] = member.signatures.map((sig) => normalizeSignature(sig, options));
|
|
4689
4799
|
}
|
|
@@ -6995,18 +7105,22 @@ export {
|
|
|
6995
7105
|
toFumadocsMetaJSON,
|
|
6996
7106
|
toDocusaurusSidebarJS,
|
|
6997
7107
|
toAlgoliaRecords,
|
|
7108
|
+
stripUndefinedFromType,
|
|
6998
7109
|
sortByName,
|
|
7110
|
+
shouldEmitAliasTypeText,
|
|
6999
7111
|
serializeVariable,
|
|
7000
7112
|
serializeTypeAlias,
|
|
7001
7113
|
serializeInterface,
|
|
7002
7114
|
serializeFunctionExport,
|
|
7003
7115
|
serializeEnum,
|
|
7004
7116
|
serializeClass,
|
|
7117
|
+
scrubImportQualifiers,
|
|
7005
7118
|
schemasAreEqual,
|
|
7006
7119
|
schemaIsAny,
|
|
7007
7120
|
resolveTypeRef,
|
|
7008
7121
|
resolveExportTarget2 as resolveExportTarget,
|
|
7009
7122
|
resolveCompiledPath,
|
|
7123
|
+
renderTypeText,
|
|
7010
7124
|
registerReferencedTypes,
|
|
7011
7125
|
registerAdapter,
|
|
7012
7126
|
recommendSemverBump,
|
|
@@ -7024,11 +7138,13 @@ export {
|
|
|
7024
7138
|
isSymbolDeprecated,
|
|
7025
7139
|
isStandardJSONSchema,
|
|
7026
7140
|
isSchemaType,
|
|
7141
|
+
isReadonlyPropertySymbol,
|
|
7027
7142
|
isPureRefSchema,
|
|
7028
7143
|
isProperty,
|
|
7029
7144
|
isPrimitiveName,
|
|
7030
7145
|
isMethod,
|
|
7031
7146
|
isExported,
|
|
7147
|
+
isBuiltinSymbol,
|
|
7032
7148
|
isBuiltinGeneric,
|
|
7033
7149
|
isAnonymous,
|
|
7034
7150
|
hasDeprecatedTag,
|
|
@@ -7071,6 +7187,7 @@ export {
|
|
|
7071
7187
|
diffSpec,
|
|
7072
7188
|
detectTsRuntime,
|
|
7073
7189
|
deduplicateSchemas,
|
|
7190
|
+
decoratePropertySchema,
|
|
7074
7191
|
createProgram,
|
|
7075
7192
|
createDocs,
|
|
7076
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
|
},
|