@openpkg-ts/sdk 0.39.0 → 0.41.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/README.md +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +95 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @openpkg-ts/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Extract [OpenPkg](https://openpkg.dev) documents from TypeScript source and generate documentation. The SDK of [openpkg-ts](https://github.com/ryanwaits/openpkg-ts), the TypeScript reference implementation of the OpenPkg standard.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1675,6 +1675,14 @@ declare function ensureNonEmptySchema(schema: SpecSchema2, type: ts15.Type, chec
|
|
|
1675
1675
|
*/
|
|
1676
1676
|
declare function buildSchema(type: ts15.Type, checker: ts15.TypeChecker, ctx?: SerializerContext): SpecSchema2;
|
|
1677
1677
|
/**
|
|
1678
|
+
* Build schema for function types
|
|
1679
|
+
*/
|
|
1680
|
+
declare function buildFunctionSchema(callSignatures: readonly ts15.Signature[], checker: ts15.TypeChecker, ctx: SerializerContext | undefined): SpecSchema2;
|
|
1681
|
+
/**
|
|
1682
|
+
* Build schema for object types with properties
|
|
1683
|
+
*/
|
|
1684
|
+
declare function buildObjectSchema(properties: ts15.Symbol[], checker: ts15.TypeChecker, ctx: SerializerContext | undefined, originalType?: ts15.Type): SpecSchema2;
|
|
1685
|
+
/**
|
|
1678
1686
|
* Check if a schema is a pure $ref (only has $ref property)
|
|
1679
1687
|
*/
|
|
1680
1688
|
declare function isPureRefSchema(schema: SpecSchema2): schema is {
|
|
@@ -1767,4 +1775,4 @@ declare function normalizeMembers(members: SpecMember3[], options?: NormalizeOpt
|
|
|
1767
1775
|
import ts16 from "typescript";
|
|
1768
1776
|
declare function isExported(node: ts16.Node): boolean;
|
|
1769
1777
|
declare function getNodeName(node: ts16.Node): string | undefined;
|
|
1770
|
-
export { zodAdapter, withDescription2 as withDescription, 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, 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 };
|
|
1778
|
+
export { zodAdapter, withDescription2 as withDescription, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1636,7 +1636,8 @@ var DEFAULT_COMPILER_OPTIONS = {
|
|
|
1636
1636
|
module: ts2.ModuleKind.CommonJS,
|
|
1637
1637
|
lib: ["lib.es2021.d.ts"],
|
|
1638
1638
|
declaration: true,
|
|
1639
|
-
moduleResolution: ts2.ModuleResolutionKind.NodeJs
|
|
1639
|
+
moduleResolution: ts2.ModuleResolutionKind.NodeJs,
|
|
1640
|
+
strict: true
|
|
1640
1641
|
};
|
|
1641
1642
|
function resolveWorkspaceEntry(pkgDir) {
|
|
1642
1643
|
const candidates = [
|
|
@@ -3816,8 +3817,14 @@ function serializeTypeAlias(node, ctx) {
|
|
|
3816
3817
|
const type = ctx.typeChecker.getTypeAtLocation(node);
|
|
3817
3818
|
registerReferencedTypes(type, ctx);
|
|
3818
3819
|
let schema;
|
|
3820
|
+
let members;
|
|
3819
3821
|
if (ts10.isIntersectionTypeNode(node.type)) {
|
|
3820
3822
|
schema = buildIntersectionSchemaFromNode(node.type, ctx);
|
|
3823
|
+
} else if (isInlineFunctionAlias(node.type) && type.getCallSignatures().length > 0) {
|
|
3824
|
+
schema = buildFunctionSchema(type.getCallSignatures(), ctx.typeChecker, ctx);
|
|
3825
|
+
} else if ((ts10.isMappedTypeNode(node.type) || ts10.isConditionalTypeNode(node.type)) && type.getProperties().length > 0 && type.getCallSignatures().length === 0) {
|
|
3826
|
+
schema = buildObjectSchema(type.getProperties(), ctx.typeChecker, ctx, type);
|
|
3827
|
+
members = serializeResolvedMembers(type, node, ctx);
|
|
3821
3828
|
} else {
|
|
3822
3829
|
schema = buildSchema(type, ctx.typeChecker, ctx);
|
|
3823
3830
|
}
|
|
@@ -3830,10 +3837,95 @@ function serializeTypeAlias(node, ctx) {
|
|
|
3830
3837
|
source,
|
|
3831
3838
|
typeParameters,
|
|
3832
3839
|
schema,
|
|
3840
|
+
...members && members.length > 0 ? { members } : {},
|
|
3833
3841
|
...deprecated ? { deprecated: true, deprecationReason } : {},
|
|
3834
3842
|
...examples.length > 0 ? { examples } : {}
|
|
3835
3843
|
};
|
|
3836
3844
|
}
|
|
3845
|
+
function isInlineFunctionAlias(typeNode) {
|
|
3846
|
+
return ts10.isFunctionTypeNode(typeNode) || ts10.isTypeLiteralNode(typeNode) && typeNode.members.some(ts10.isCallSignatureDeclaration);
|
|
3847
|
+
}
|
|
3848
|
+
function buildConditionalArmDocs(typeNode, checker) {
|
|
3849
|
+
const docs = new Map;
|
|
3850
|
+
if (!ts10.isMappedTypeNode(typeNode) || !typeNode.type)
|
|
3851
|
+
return docs;
|
|
3852
|
+
const literalKeys = (extendsType) => {
|
|
3853
|
+
const keys = [];
|
|
3854
|
+
const visit = (n) => {
|
|
3855
|
+
if (ts10.isUnionTypeNode(n)) {
|
|
3856
|
+
for (const member of n.types)
|
|
3857
|
+
visit(member);
|
|
3858
|
+
} else if (ts10.isLiteralTypeNode(n) && ts10.isStringLiteral(n.literal)) {
|
|
3859
|
+
keys.push(n.literal.text);
|
|
3860
|
+
}
|
|
3861
|
+
};
|
|
3862
|
+
visit(extendsType);
|
|
3863
|
+
return keys;
|
|
3864
|
+
};
|
|
3865
|
+
const armDoc = (armType) => {
|
|
3866
|
+
if (!ts10.isTypeReferenceNode(armType))
|
|
3867
|
+
return;
|
|
3868
|
+
const symbol = checker.getSymbolAtLocation(armType.typeName);
|
|
3869
|
+
if (!symbol)
|
|
3870
|
+
return;
|
|
3871
|
+
const target = symbol.flags & ts10.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
3872
|
+
const { deprecated, reason } = isSymbolDeprecated(target);
|
|
3873
|
+
const targetDecl = target.getDeclarations()?.[0];
|
|
3874
|
+
const description = targetDecl ? getJSDocComment(targetDecl, target, checker).description : undefined;
|
|
3875
|
+
if (!deprecated && !description)
|
|
3876
|
+
return;
|
|
3877
|
+
return { deprecated, deprecationReason: reason, description };
|
|
3878
|
+
};
|
|
3879
|
+
let current = typeNode.type;
|
|
3880
|
+
while (current && ts10.isConditionalTypeNode(current)) {
|
|
3881
|
+
const doc = armDoc(current.trueType);
|
|
3882
|
+
if (doc) {
|
|
3883
|
+
for (const key of literalKeys(current.extendsType)) {
|
|
3884
|
+
if (!docs.has(key))
|
|
3885
|
+
docs.set(key, doc);
|
|
3886
|
+
}
|
|
3887
|
+
}
|
|
3888
|
+
current = current.falseType;
|
|
3889
|
+
}
|
|
3890
|
+
return docs;
|
|
3891
|
+
}
|
|
3892
|
+
function serializeResolvedMembers(type, node, ctx) {
|
|
3893
|
+
const { typeChecker: checker } = ctx;
|
|
3894
|
+
const members = [];
|
|
3895
|
+
const armDocs = buildConditionalArmDocs(node.type, checker);
|
|
3896
|
+
for (const prop of type.getProperties()) {
|
|
3897
|
+
const decl = prop.getDeclarations()?.[0] ?? node;
|
|
3898
|
+
const propType = checker.getTypeOfSymbolAtLocation(prop, decl);
|
|
3899
|
+
registerReferencedTypes(propType, ctx);
|
|
3900
|
+
const callSigs = propType.getCallSignatures();
|
|
3901
|
+
const kind = callSigs.length > 0 ? "method" : "property";
|
|
3902
|
+
let { description, tags } = getJSDocComment(decl, prop, checker);
|
|
3903
|
+
let { deprecated, reason: deprecationReason } = isSymbolDeprecated(prop);
|
|
3904
|
+
const arm = armDocs.get(prop.getName());
|
|
3905
|
+
if (arm) {
|
|
3906
|
+
if (!deprecated && arm.deprecated) {
|
|
3907
|
+
deprecated = true;
|
|
3908
|
+
deprecationReason = arm.deprecationReason;
|
|
3909
|
+
}
|
|
3910
|
+
if (!description)
|
|
3911
|
+
description = arm.description;
|
|
3912
|
+
}
|
|
3913
|
+
const armAlias = propType.aliasSymbol;
|
|
3914
|
+
if (!deprecated && armAlias) {
|
|
3915
|
+
({ deprecated, reason: deprecationReason } = isSymbolDeprecated(armAlias));
|
|
3916
|
+
}
|
|
3917
|
+
members.push({
|
|
3918
|
+
name: prop.getName(),
|
|
3919
|
+
kind,
|
|
3920
|
+
description,
|
|
3921
|
+
tags: tags.length > 0 ? tags : undefined,
|
|
3922
|
+
schema: kind === "property" ? buildSchema(propType, checker, ctx) : undefined,
|
|
3923
|
+
signatures: kind === "method" ? buildSignatures(callSigs, checker, ctx) : undefined,
|
|
3924
|
+
...deprecated ? { deprecated: true, deprecationReason } : {}
|
|
3925
|
+
});
|
|
3926
|
+
}
|
|
3927
|
+
return members;
|
|
3928
|
+
}
|
|
3837
3929
|
|
|
3838
3930
|
// src/schema/registry.ts
|
|
3839
3931
|
function isTypeReference(type) {
|
|
@@ -6556,6 +6648,8 @@ export {
|
|
|
6556
6648
|
calculateNextVersion,
|
|
6557
6649
|
buildSignatureString,
|
|
6558
6650
|
buildSchema,
|
|
6651
|
+
buildObjectSchema,
|
|
6652
|
+
buildFunctionSchema,
|
|
6559
6653
|
arktypeAdapter,
|
|
6560
6654
|
analyzeSpec,
|
|
6561
6655
|
TypeRegistry,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.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.41.0",
|
|
47
47
|
"picomatch": "4.0.3",
|
|
48
48
|
"typescript": "^5.0.0"
|
|
49
49
|
},
|