@openpkg-ts/sdk 0.48.1 → 0.49.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 +16 -1
- package/dist/index.js +44 -3
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1839,6 +1839,21 @@ declare function scrubImportQualifiers(text: string): string;
|
|
|
1839
1839
|
*/
|
|
1840
1840
|
declare function renderTypeText(type: ts15.Type, checker: ts15.TypeChecker, enclosing?: ts15.Node, extraFlags?: ts15.TypeFormatFlags): string;
|
|
1841
1841
|
/**
|
|
1842
|
+
* The type exactly as the author WROTE it — the annotation node's source text.
|
|
1843
|
+
* `x-ts-type` carries the resolved truth (`Omit<T, K>` expanded to its mapped
|
|
1844
|
+
* type, `InitiatorType` expanded to its union); this recovers the declared form
|
|
1845
|
+
* a docs reader recognizes.
|
|
1846
|
+
*
|
|
1847
|
+
* Restricted to NAMED references and unions — the shapes where the author wrote
|
|
1848
|
+
* a name that resolves to something else. Object literals, mapped, and
|
|
1849
|
+
* conditional bodies are excluded: they differ from their resolved text only by
|
|
1850
|
+
* formatting (a trailing `;`, `readonly T[]` vs `ReadonlyArray<T>`) or would
|
|
1851
|
+
* drag source comments into the spec, both of which are noise, not signal.
|
|
1852
|
+
*/
|
|
1853
|
+
declare function writtenTypeText(typeNode: ts15.TypeNode | undefined): string | undefined;
|
|
1854
|
+
/** The annotation TypeNode on a declaration (property, alias, parameter), if any. */
|
|
1855
|
+
declare function declaredTypeNode(decl: ts15.Declaration | undefined): ts15.TypeNode | undefined;
|
|
1856
|
+
/**
|
|
1842
1857
|
* Strip `undefined` from a union type when optionality is already expressed
|
|
1843
1858
|
* elsewhere (`required: false`, `flags.optional`). Used for both schema shape
|
|
1844
1859
|
* and x-ts-type text so neither re-encodes optionality as `| undefined`.
|
|
@@ -1948,4 +1963,4 @@ declare function findDiscriminatorProperty(unionTypes: ts15.Type[], checker: ts1
|
|
|
1948
1963
|
import ts16 from "typescript";
|
|
1949
1964
|
declare function isExported(node: ts16.Node): boolean;
|
|
1950
1965
|
declare function getNodeName(node: ts16.Node): string | undefined;
|
|
1951
|
-
export { zodAdapter, withDescription2 as withDescription, withDeprecated, validateSpec, valibotAdapter, typeboxAdapter, toToolSchema, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJsonSchema, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, stripUndefinedFromType, stripTsExtensions, 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, getValidationErrors, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExportKind, getExport2 as getExport, getDeprecationMessage, getAvailableVersions, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findMissingParamDocs, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, exportToJsonSchema, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, decoratePropertySchema, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, bundleRefs, buildSignatureString, buildSchema, buildObjectSchema, buildFunctionSchema, assertSpec, asStandardSchema, arktypeAdapter, analyzeSpec, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, ToolSchemaResult, ToolSchemaProvider, ToToolSchemaOptions, ToJsonSchemaOptions, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecError, SpecDiff, SpecDiagnostics, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaVersion, 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, LATEST_VERSION, JsonSchemaDocument, 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, BundleResult, BundleOptions, BuiltinSchema, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AsStandardSchemaOptions, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
|
1966
|
+
export { zodAdapter, writtenTypeText, withDescription2 as withDescription, withDeprecated, validateSpec, valibotAdapter, typeboxAdapter, toToolSchema, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJsonSchema, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, stripUndefinedFromType, stripTsExtensions, 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, getValidationErrors, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExportKind, getExport2 as getExport, getDeprecationMessage, getAvailableVersions, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findMissingParamDocs, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, exportToJsonSchema, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, decoratePropertySchema, declaredTypeNode, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, bundleRefs, buildSignatureString, buildSchema, buildObjectSchema, buildFunctionSchema, assertSpec, asStandardSchema, arktypeAdapter, analyzeSpec, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, ToolSchemaResult, ToolSchemaProvider, ToToolSchemaOptions, ToJsonSchemaOptions, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecError, SpecDiff, SpecDiagnostics, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaVersion, 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, LATEST_VERSION, JsonSchemaDocument, 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, BundleResult, BundleOptions, BuiltinSchema, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AsStandardSchemaOptions, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
package/dist/index.js
CHANGED
|
@@ -1993,6 +1993,22 @@ function scrubImportQualifiers(text) {
|
|
|
1993
1993
|
function renderTypeText(type, checker, enclosing, extraFlags = 0) {
|
|
1994
1994
|
return scrubImportQualifiers(checker.typeToString(type, enclosing, ts4.TypeFormatFlags.NoTruncation | extraFlags));
|
|
1995
1995
|
}
|
|
1996
|
+
function writtenTypeText(typeNode) {
|
|
1997
|
+
if (!typeNode)
|
|
1998
|
+
return;
|
|
1999
|
+
if (!ts4.isTypeReferenceNode(typeNode) && !ts4.isUnionTypeNode(typeNode))
|
|
2000
|
+
return;
|
|
2001
|
+
try {
|
|
2002
|
+
const text = scrubImportQualifiers(typeNode.getText().replace(/\s+/g, " ").replace(/^\|\s*/, "").trim());
|
|
2003
|
+
return text.length > 0 ? text : undefined;
|
|
2004
|
+
} catch {
|
|
2005
|
+
return;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
function declaredTypeNode(decl) {
|
|
2009
|
+
const withType = decl;
|
|
2010
|
+
return withType?.type;
|
|
2011
|
+
}
|
|
1996
2012
|
function stripUndefinedFromType(type, checker) {
|
|
1997
2013
|
if (!type.isUnion())
|
|
1998
2014
|
return type;
|
|
@@ -2020,6 +2036,10 @@ function decoratePropertySchema(schema, prop, propType, checker) {
|
|
|
2020
2036
|
let result = obj;
|
|
2021
2037
|
if (!derivable && !("x-ts-type" in obj)) {
|
|
2022
2038
|
result = { ...result, "x-ts-type": text };
|
|
2039
|
+
const declared = writtenTypeText(declaredTypeNode(decl));
|
|
2040
|
+
if (declared && declared !== text && !PRIMITIVES.has(declared) && !("x-ts-declared" in obj)) {
|
|
2041
|
+
result = { ...result, "x-ts-declared": declared };
|
|
2042
|
+
}
|
|
2023
2043
|
}
|
|
2024
2044
|
if (isReadonlyPropertySymbol(prop) && !("readOnly" in obj)) {
|
|
2025
2045
|
result = { ...result, readOnly: true };
|
|
@@ -2030,7 +2050,12 @@ function decoratePropertySchema(schema, prop, propType, checker) {
|
|
|
2030
2050
|
return result;
|
|
2031
2051
|
}
|
|
2032
2052
|
function shouldEmitAliasTypeText(typeNode) {
|
|
2033
|
-
|
|
2053
|
+
if (ts4.isMappedTypeNode(typeNode))
|
|
2054
|
+
return false;
|
|
2055
|
+
if (ts4.isTypeLiteralNode(typeNode)) {
|
|
2056
|
+
return typeNode.members.length > 0 && typeNode.members.every((m) => ts4.isIndexSignatureDeclaration(m));
|
|
2057
|
+
}
|
|
2058
|
+
return true;
|
|
2034
2059
|
}
|
|
2035
2060
|
var PRIMITIVES = new Set([
|
|
2036
2061
|
"string",
|
|
@@ -3232,6 +3257,10 @@ class TypeRegistry {
|
|
|
3232
3257
|
const text = renderTypeText(type, checker, decl, ts6.TypeFormatFlags.InTypeAlias);
|
|
3233
3258
|
if (!PRIMITIVES.has(text) && text !== name) {
|
|
3234
3259
|
schema["x-ts-type"] = text;
|
|
3260
|
+
const declared = writtenTypeText(declaredTypeNode(decl));
|
|
3261
|
+
if (declared && declared !== text && !PRIMITIVES.has(declared)) {
|
|
3262
|
+
schema["x-ts-declared"] = declared;
|
|
3263
|
+
}
|
|
3235
3264
|
}
|
|
3236
3265
|
}
|
|
3237
3266
|
let typeParameters;
|
|
@@ -3914,13 +3943,16 @@ function serializeEnum(node, ctx) {
|
|
|
3914
3943
|
} else if (member.initializer) {
|
|
3915
3944
|
schema = { type: member.initializer.getText() };
|
|
3916
3945
|
}
|
|
3917
|
-
const { description: memberDesc } = getJSDocComment(member);
|
|
3946
|
+
const { description: memberDesc, tags: memberTags } = getJSDocComment(member);
|
|
3947
|
+
const { deprecated: deprecated2, reason: deprecationReason2 } = isSymbolDeprecated(memberSymbol);
|
|
3918
3948
|
return {
|
|
3919
3949
|
id: memberName,
|
|
3920
3950
|
name: memberName,
|
|
3921
3951
|
kind: "enum-member",
|
|
3922
3952
|
...schema ? { schema } : {},
|
|
3923
|
-
...memberDesc ? { description: memberDesc } : {}
|
|
3953
|
+
...memberDesc ? { description: memberDesc } : {},
|
|
3954
|
+
...memberTags.length > 0 ? { tags: memberTags } : {},
|
|
3955
|
+
...deprecated2 ? { deprecated: true, deprecationReason: deprecationReason2 } : {}
|
|
3924
3956
|
};
|
|
3925
3957
|
});
|
|
3926
3958
|
return {
|
|
@@ -4247,6 +4279,9 @@ function serializeTypeAlias(node, ctx) {
|
|
|
4247
4279
|
}
|
|
4248
4280
|
} else if (isInlineFunctionAlias(node.type) && type.getCallSignatures().length > 0) {
|
|
4249
4281
|
schema = buildFunctionSchema(type.getCallSignatures(), ctx.typeChecker, ctx);
|
|
4282
|
+
if (type.getProperties().length > 0) {
|
|
4283
|
+
members = serializeResolvedMembers(type, node, ctx);
|
|
4284
|
+
}
|
|
4250
4285
|
} else if ((ts11.isMappedTypeNode(node.type) || ts11.isConditionalTypeNode(node.type)) && type.getProperties().length > 0 && type.getCallSignatures().length === 0 && !(type.flags & ts11.TypeFlags.Conditional) && !(type.flags & (ts11.TypeFlags.StringLike | ts11.TypeFlags.NumberLike))) {
|
|
4251
4286
|
schema = buildObjectSchema(type.getProperties(), ctx.typeChecker, ctx, type);
|
|
4252
4287
|
members = serializeResolvedMembers(type, node, ctx);
|
|
@@ -4260,6 +4295,10 @@ function serializeTypeAlias(node, ctx) {
|
|
|
4260
4295
|
const text = renderTypeText(type, ctx.typeChecker, node, ts11.TypeFormatFlags.InTypeAlias);
|
|
4261
4296
|
if (!PRIMITIVES.has(text) && text !== name) {
|
|
4262
4297
|
schema["x-ts-type"] = text;
|
|
4298
|
+
const declared = writtenTypeText(declaredTypeNode(node));
|
|
4299
|
+
if (declared && declared !== text && !PRIMITIVES.has(declared)) {
|
|
4300
|
+
schema["x-ts-declared"] = declared;
|
|
4301
|
+
}
|
|
4263
4302
|
}
|
|
4264
4303
|
}
|
|
4265
4304
|
return {
|
|
@@ -7837,6 +7876,7 @@ function getNodeName(node) {
|
|
|
7837
7876
|
}
|
|
7838
7877
|
export {
|
|
7839
7878
|
zodAdapter,
|
|
7879
|
+
writtenTypeText,
|
|
7840
7880
|
withDescription,
|
|
7841
7881
|
withDeprecated,
|
|
7842
7882
|
validateSpec2 as validateSpec,
|
|
@@ -7942,6 +7982,7 @@ export {
|
|
|
7942
7982
|
detectTsRuntime,
|
|
7943
7983
|
deduplicateSchemas,
|
|
7944
7984
|
decoratePropertySchema,
|
|
7985
|
+
declaredTypeNode,
|
|
7945
7986
|
createProgram,
|
|
7946
7987
|
createDocs,
|
|
7947
7988
|
categorizeBreakingChanges,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.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.49.0",
|
|
47
47
|
"picomatch": "4.0.3",
|
|
48
48
|
"typescript": "^5.0.0"
|
|
49
49
|
},
|