@openpkg-ts/sdk 0.35.0 → 0.35.1

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/browser.d.ts CHANGED
@@ -606,7 +606,7 @@ declare function formatConditionalType(condType: SpecConditionalType): string;
606
606
  * ```
607
607
  */
608
608
  declare function formatMappedType(mappedType: SpecMappedType): string;
609
- import { OpenPkg as OpenPkg9, SpecExport as SpecExport5, SpecExportKind as SpecExportKind5 } from "@openpkg-ts/spec";
609
+ import { OpenPkg as OpenPkg9, SpecExport as SpecExport5, SpecExportKind as SpecExportKind6 } from "@openpkg-ts/spec";
610
610
  type Predicate = (exp: SpecExport5) => boolean;
611
611
  /**
612
612
  * Chainable query builder for filtering OpenPkg exports.
@@ -619,7 +619,7 @@ declare class QueryBuilder {
619
619
  /**
620
620
  * Filter by kind(s)
621
621
  */
622
- byKind(...kinds: SpecExportKind5[]): this;
622
+ byKind(...kinds: SpecExportKind6[]): this;
623
623
  /**
624
624
  * Filter by name (exact string or regex pattern)
625
625
  */
package/dist/browser.js CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  toPagefindRecords,
26
26
  toSearchIndex,
27
27
  toSearchIndexJSON
28
- } from "./shared/chunk-skapcfq1.js";
28
+ } from "./shared/chunk-4fgxg5jj.js";
29
29
  export {
30
30
  toSearchIndexJSON,
31
31
  toSearchIndex,
package/dist/index.d.ts CHANGED
@@ -951,7 +951,7 @@ declare function formatConditionalType(condType: SpecConditionalType): string;
951
951
  * ```
952
952
  */
953
953
  declare function formatMappedType(mappedType: SpecMappedType): string;
954
- import { OpenPkg as OpenPkg10, SpecExport as SpecExport5, SpecExportKind as SpecExportKind5 } from "@openpkg-ts/spec";
954
+ import { OpenPkg as OpenPkg10, SpecExport as SpecExport5, SpecExportKind as SpecExportKind6 } from "@openpkg-ts/spec";
955
955
  type Predicate = (exp: SpecExport5) => boolean;
956
956
  /**
957
957
  * Chainable query builder for filtering OpenPkg exports.
@@ -964,7 +964,7 @@ declare class QueryBuilder {
964
964
  /**
965
965
  * Filter by kind(s)
966
966
  */
967
- byKind(...kinds: SpecExportKind5[]): this;
967
+ byKind(...kinds: SpecExportKind6[]): this;
968
968
  /**
969
969
  * Filter by name (exact string or regex pattern)
970
970
  */
@@ -1043,10 +1043,10 @@ declare function toReactString(spec: OpenPkg11, options?: {
1043
1043
  variant?: "full" | "index";
1044
1044
  componentsPath?: string;
1045
1045
  }): string;
1046
- import { OpenPkg as OpenPkg12, SpecExportKind as SpecExportKind6 } from "@openpkg-ts/spec";
1046
+ import { OpenPkg as OpenPkg12, SpecExportKind as SpecExportKind7 } from "@openpkg-ts/spec";
1047
1047
  type FilterCriteria = {
1048
1048
  /** Filter by kinds */
1049
- kinds?: SpecExportKind6[];
1049
+ kinds?: SpecExportKind7[];
1050
1050
  /** Filter by names (exact match) */
1051
1051
  names?: string[];
1052
1052
  /** Filter by IDs */
@@ -1218,7 +1218,7 @@ declare function resolveExportTarget(symbol: ts3.Symbol, checker: ts3.TypeChecke
1218
1218
  targetSymbol: ts3.Symbol;
1219
1219
  isTypeOnly: boolean;
1220
1220
  };
1221
- import { SpecExample, SpecSource, SpecTag, SpecTypeParameter as SpecTypeParameter2 } from "@openpkg-ts/spec";
1221
+ import { SpecExample, SpecExportKind as SpecExportKind8, SpecSource, SpecTag, SpecTypeParameter as SpecTypeParameter2 } from "@openpkg-ts/spec";
1222
1222
  import ts4 from "typescript";
1223
1223
  declare function getJSDocComment(node: ts4.Node, symbol?: ts4.Symbol, checker?: ts4.TypeChecker): {
1224
1224
  description?: string;
@@ -1248,6 +1248,8 @@ declare function isSymbolDeprecated(symbol: ts4.Symbol | undefined): {
1248
1248
  deprecated: boolean;
1249
1249
  reason?: string;
1250
1250
  };
1251
+ /** Classify a declaration node into an kind */
1252
+ declare function getExportKind(declaration: ts4.Declaration, type: ts4.Type): SpecExportKind8;
1251
1253
  /**
1252
1254
  * Target version for JSON Schema generation.
1253
1255
  * @see https://standardschema.dev/json-schema
@@ -1469,6 +1471,11 @@ declare class CacheManager<
1469
1471
  */
1470
1472
  set(key: K, value: V): void;
1471
1473
  /**
1474
+ * Get cached value or compute, cache, and return it.
1475
+ * Unlike has()+get(), this correctly updates LRU order in a single operation.
1476
+ */
1477
+ getOrCompute(key: K, compute: () => V): V;
1478
+ /**
1472
1479
  * Delete a specific key from the cache.
1473
1480
  */
1474
1481
  delete(key: K): boolean;
@@ -1630,6 +1637,7 @@ import ts15 from "typescript";
1630
1637
  * Used for types that have specific serialization formats.
1631
1638
  */
1632
1639
  declare const BUILTIN_TYPE_SCHEMAS: Record<string, SpecSchema2>;
1640
+ declare const PRIMITIVES: Set<string>;
1633
1641
  declare const ARRAY_PROTOTYPE_METHODS: Set<string>;
1634
1642
  /**
1635
1643
  * Check if a name is a primitive type
@@ -1662,7 +1670,7 @@ declare function ensureNonEmptySchema(schema: SpecSchema2, type: ts15.Type, chec
1662
1670
  * Uses $ref for named types and typeArguments for generics.
1663
1671
  * Guarantees non-empty schema output via ensureNonEmptySchema wrapper.
1664
1672
  */
1665
- declare function buildSchema(type: ts15.Type, checker: ts15.TypeChecker, ctx?: SerializerContext, _depth?: number): SpecSchema2;
1673
+ declare function buildSchema(type: ts15.Type, checker: ts15.TypeChecker, ctx?: SerializerContext): SpecSchema2;
1666
1674
  /**
1667
1675
  * Check if a schema is a pure $ref (only has $ref property)
1668
1676
  */
@@ -1756,4 +1764,4 @@ declare function normalizeMembers(members: SpecMember3[], options?: NormalizeOpt
1756
1764
  import ts16 from "typescript";
1757
1765
  declare function isExported(node: ts16.Node): boolean;
1758
1766
  declare function getNodeName(node: ts16.Node): string | undefined;
1759
- export { zodAdapter, withDescription2 as withDescription, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toReactString, toReact, 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, 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, ReactLayoutOptions, QueryBuilder, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, 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 };
1767
+ export { zodAdapter, withDescription2 as withDescription, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toReactString, toReact, 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, ReactLayoutOptions, QueryBuilder, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, PRIMITIVES, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, 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
@@ -1,7 +1,10 @@
1
1
  import {
2
+ KIND_ORDER,
2
3
  QueryBuilder,
3
4
  analyzeSpec,
4
5
  buildSignatureString,
6
+ filterExports,
7
+ findExport,
5
8
  findMissingParamDocs,
6
9
  formatBadges,
7
10
  formatConditionalType,
@@ -14,6 +17,7 @@ import {
14
17
  getMemberBadges,
15
18
  getMethods,
16
19
  getProperties,
20
+ groupByKind,
17
21
  groupByVisibility,
18
22
  hasDeprecatedTag,
19
23
  isMethod,
@@ -25,7 +29,7 @@ import {
25
29
  toPagefindRecords,
26
30
  toSearchIndex,
27
31
  toSearchIndexJSON
28
- } from "./shared/chunk-skapcfq1.js";
32
+ } from "./shared/chunk-4fgxg5jj.js";
29
33
 
30
34
  // src/primitives/diff.ts
31
35
  import {
@@ -69,13 +73,13 @@ function mergeConfig(fileConfig, cliOptions) {
69
73
  if (!fileConfig) {
70
74
  return cliOptions;
71
75
  }
72
- return {
73
- externals: {
74
- include: cliOptions.externals?.include ?? fileConfig.externals?.include,
75
- exclude: cliOptions.externals?.exclude ?? fileConfig.externals?.exclude,
76
- depth: cliOptions.externals?.depth ?? fileConfig.externals?.depth
77
- }
76
+ const externals = {
77
+ include: cliOptions.externals?.include ?? fileConfig.externals?.include,
78
+ exclude: cliOptions.externals?.exclude ?? fileConfig.externals?.exclude,
79
+ depth: cliOptions.externals?.depth ?? fileConfig.externals?.depth
78
80
  };
81
+ const hasExternals = externals.include || externals.exclude || externals.depth !== undefined;
82
+ return hasExternals ? { externals } : {};
79
83
  }
80
84
  // src/core/loader.ts
81
85
  import * as fs2 from "node:fs";
@@ -345,10 +349,7 @@ function renderExport(exp) {
345
349
  function toHTML(spec, options = {}) {
346
350
  const { includeStyles = true, fullDocument = true, customCSS = "" } = options;
347
351
  if (options.export) {
348
- const exp = spec.exports.find((e) => e.name === options.export || e.id === options.export);
349
- if (!exp) {
350
- throw new Error(`Export not found: ${options.export}`);
351
- }
352
+ const exp = findExport(spec, options.export);
352
353
  const content2 = renderExport(exp);
353
354
  if (!fullDocument)
354
355
  return content2;
@@ -373,24 +374,17 @@ function toHTML(spec, options = {}) {
373
374
  }
374
375
  let specExports = spec.exports;
375
376
  if (options.exports?.length) {
376
- const ids = new Set(options.exports);
377
- specExports = spec.exports.filter((e) => ids.has(e.name) || ids.has(e.id));
377
+ specExports = filterExports(spec, options.exports);
378
378
  }
379
379
  const title = options.title || `${spec.meta.name} API Reference`;
380
380
  const description = spec.meta.description ? `<p>${escapeHTML(spec.meta.description)}</p>` : "";
381
- const byKind = {};
382
- for (const exp of specExports) {
383
- if (!byKind[exp.kind])
384
- byKind[exp.kind] = [];
385
- byKind[exp.kind].push(exp);
386
- }
381
+ const byKind = groupByKind(specExports);
387
382
  const navItems = Object.entries(byKind).map(([kind, exports]) => {
388
383
  const links = exports.map((e) => `<a href="#${e.id}">${escapeHTML(e.name)}</a>`).join("");
389
384
  return `<li><strong>${kind}s:</strong> ${links}</li>`;
390
385
  }).join("");
391
386
  const nav = `<nav><ul>${navItems}</ul></nav>`;
392
- const kindOrder = ["function", "class", "interface", "type", "enum", "variable"];
393
- const sections = kindOrder.filter((kind) => byKind[kind]?.length).map((kind) => {
387
+ const sections = KIND_ORDER.filter((kind) => byKind[kind]?.length).map((kind) => {
394
388
  const exports = byKind[kind].map(renderExport).join("");
395
389
  return `
396
390
  <section class="kind-section">
@@ -516,24 +510,14 @@ function simplifyExport(exp) {
516
510
  }
517
511
  function toJSON(spec, options = {}) {
518
512
  if (options.export) {
519
- const exp = spec.exports.find((e) => e.name === options.export || e.id === options.export);
520
- if (!exp) {
521
- throw new Error(`Export not found: ${options.export}`);
522
- }
523
- return simplifyExport(exp);
513
+ return simplifyExport(findExport(spec, options.export));
524
514
  }
525
515
  let specExports = spec.exports;
526
516
  if (options.exports?.length) {
527
- const ids = new Set(options.exports);
528
- specExports = spec.exports.filter((e) => ids.has(e.name) || ids.has(e.id));
517
+ specExports = filterExports(spec, options.exports);
529
518
  }
530
519
  const exports = specExports.map(simplifyExport);
531
- const byKind = {};
532
- for (const exp of exports) {
533
- if (!byKind[exp.kind])
534
- byKind[exp.kind] = [];
535
- byKind[exp.kind].push(exp);
536
- }
520
+ const byKind = groupByKind(exports);
537
521
  return {
538
522
  name: spec.meta.name,
539
523
  version: spec.meta.version,
@@ -876,16 +860,11 @@ function exportToMarkdown(exp, options = {}) {
876
860
  }
877
861
  function toMarkdown(spec, options = {}) {
878
862
  if (options.export) {
879
- const exp = spec.exports.find((e) => e.name === options.export || e.id === options.export);
880
- if (!exp) {
881
- throw new Error(`Export not found: ${options.export}`);
882
- }
883
- return exportToMarkdown(exp, options);
863
+ return exportToMarkdown(findExport(spec, options.export), options);
884
864
  }
885
865
  let specExports = spec.exports;
886
866
  if (options.exports?.length) {
887
- const ids = new Set(options.exports);
888
- specExports = spec.exports.filter((e) => ids.has(e.name) || ids.has(e.id));
867
+ specExports = filterExports(spec, options.exports);
889
868
  if (specExports.length === 0)
890
869
  return "";
891
870
  }
@@ -914,14 +893,8 @@ function toMarkdown(spec, options = {}) {
914
893
  parts.push(spec.meta.description);
915
894
  parts.push("");
916
895
  }
917
- const byKind = {};
918
- for (const exp of specExports) {
919
- if (!byKind[exp.kind])
920
- byKind[exp.kind] = [];
921
- byKind[exp.kind].push(exp);
922
- }
923
- const kindOrder = ["function", "class", "interface", "type", "enum", "variable"];
924
- for (const kind of kindOrder) {
896
+ const byKind = groupByKind(specExports);
897
+ for (const kind of KIND_ORDER) {
925
898
  const exports = byKind[kind];
926
899
  if (!exports?.length)
927
900
  continue;
@@ -1024,21 +997,9 @@ function toGenericNav(spec, options) {
1024
997
  });
1025
998
  }
1026
999
  if (groupBy === "kind") {
1027
- const kindOrder = [
1028
- "function",
1029
- "class",
1030
- "interface",
1031
- "type",
1032
- "enum",
1033
- "variable",
1034
- "namespace",
1035
- "module",
1036
- "reference",
1037
- "external"
1038
- ];
1039
1000
  groups.sort((a, b) => {
1040
- const aIdx = kindOrder.indexOf(a.title.toLowerCase().replace(/s$/, ""));
1041
- const bIdx = kindOrder.indexOf(b.title.toLowerCase().replace(/s$/, ""));
1001
+ const aIdx = KIND_ORDER.indexOf(a.title.toLowerCase().replace(/s$/, ""));
1002
+ const bIdx = KIND_ORDER.indexOf(b.title.toLowerCase().replace(/s$/, ""));
1042
1003
  return aIdx - bIdx;
1043
1004
  });
1044
1005
  }
@@ -1926,6 +1887,23 @@ function getParamDescription(propertyName, jsdocTags, inferredAlias) {
1926
1887
  }
1927
1888
  return;
1928
1889
  }
1890
+ function extractVarianceModifiers(modifiers) {
1891
+ if (!modifiers)
1892
+ return {};
1893
+ let hasIn = false;
1894
+ let hasOut = false;
1895
+ let isConst;
1896
+ for (const mod of modifiers) {
1897
+ if (mod.kind === ts2.SyntaxKind.InKeyword)
1898
+ hasIn = true;
1899
+ if (mod.kind === ts2.SyntaxKind.OutKeyword)
1900
+ hasOut = true;
1901
+ if (mod.kind === ts2.SyntaxKind.ConstKeyword)
1902
+ isConst = true;
1903
+ }
1904
+ const variance = hasIn && hasOut ? "inout" : hasIn ? "in" : hasOut ? "out" : undefined;
1905
+ return { variance, isConst };
1906
+ }
1929
1907
  function extractTypeParameters(node, checker) {
1930
1908
  if (!node.typeParameters || node.typeParameters.length === 0) {
1931
1909
  return;
@@ -1942,27 +1920,7 @@ function extractTypeParameters(node, checker) {
1942
1920
  const defType = checker.getTypeAtLocation(tp.default);
1943
1921
  defaultType = checker.typeToString(defType);
1944
1922
  }
1945
- let variance;
1946
- let isConst;
1947
- const modifiers = ts2.getModifiers(tp);
1948
- if (modifiers) {
1949
- let hasIn = false;
1950
- let hasOut = false;
1951
- for (const mod of modifiers) {
1952
- if (mod.kind === ts2.SyntaxKind.InKeyword)
1953
- hasIn = true;
1954
- if (mod.kind === ts2.SyntaxKind.OutKeyword)
1955
- hasOut = true;
1956
- if (mod.kind === ts2.SyntaxKind.ConstKeyword)
1957
- isConst = true;
1958
- }
1959
- if (hasIn && hasOut)
1960
- variance = "inout";
1961
- else if (hasIn)
1962
- variance = "in";
1963
- else if (hasOut)
1964
- variance = "out";
1965
- }
1923
+ const { variance, isConst } = extractVarianceModifiers(ts2.getModifiers(tp));
1966
1924
  return {
1967
1925
  name,
1968
1926
  ...constraint ? { constraint } : {},
@@ -2027,25 +1985,7 @@ function extractTypeParametersFromSignature(signature, checker) {
2027
1985
  const declarations = tpSymbol?.getDeclarations() ?? [];
2028
1986
  for (const decl of declarations) {
2029
1987
  if (ts2.isTypeParameterDeclaration(decl)) {
2030
- const modifiers = ts2.getModifiers(decl);
2031
- if (modifiers) {
2032
- let hasIn = false;
2033
- let hasOut = false;
2034
- for (const mod of modifiers) {
2035
- if (mod.kind === ts2.SyntaxKind.InKeyword)
2036
- hasIn = true;
2037
- if (mod.kind === ts2.SyntaxKind.OutKeyword)
2038
- hasOut = true;
2039
- if (mod.kind === ts2.SyntaxKind.ConstKeyword)
2040
- isConst = true;
2041
- }
2042
- if (hasIn && hasOut)
2043
- variance = "inout";
2044
- else if (hasIn)
2045
- variance = "in";
2046
- else if (hasOut)
2047
- variance = "out";
2048
- }
1988
+ ({ variance, isConst } = extractVarianceModifiers(ts2.getModifiers(decl)));
2049
1989
  break;
2050
1990
  }
2051
1991
  }
@@ -2058,6 +1998,23 @@ function extractTypeParametersFromSignature(signature, checker) {
2058
1998
  };
2059
1999
  });
2060
2000
  }
2001
+ function getExportKind(declaration, type) {
2002
+ if (ts2.isFunctionDeclaration(declaration) || ts2.isFunctionExpression(declaration))
2003
+ return "function";
2004
+ if (ts2.isClassDeclaration(declaration))
2005
+ return "class";
2006
+ if (ts2.isInterfaceDeclaration(declaration))
2007
+ return "interface";
2008
+ if (ts2.isTypeAliasDeclaration(declaration))
2009
+ return "type";
2010
+ if (ts2.isEnumDeclaration(declaration))
2011
+ return "enum";
2012
+ if (ts2.isModuleDeclaration(declaration) || ts2.isNamespaceExport(declaration))
2013
+ return "namespace";
2014
+ if (ts2.isVariableDeclaration(declaration) && type.getCallSignatures().length > 0)
2015
+ return "function";
2016
+ return "variable";
2017
+ }
2061
2018
 
2062
2019
  // src/types/parameters.ts
2063
2020
  import ts4 from "typescript";
@@ -2088,6 +2045,9 @@ var BUILTIN_TYPE_SCHEMAS = {
2088
2045
  BigInt64Array: { type: "string", format: "byte" },
2089
2046
  BigUint64Array: { type: "string", format: "byte" }
2090
2047
  };
2048
+ function setSchemaExtension(schema, key, value) {
2049
+ schema[key] = value;
2050
+ }
2091
2051
  var PRIMITIVES = new Set([
2092
2052
  "string",
2093
2053
  "number",
@@ -2263,7 +2223,7 @@ function ensureNonEmptySchema(schema, type, checker) {
2263
2223
  }
2264
2224
  return schema;
2265
2225
  }
2266
- function buildSchema(type, checker, ctx, _depth = 0) {
2226
+ function buildSchema(type, checker, ctx) {
2267
2227
  const schema = buildSchemaInternal(type, checker, ctx);
2268
2228
  return ensureNonEmptySchema(schema, type, checker);
2269
2229
  }
@@ -2454,7 +2414,7 @@ function buildSchemaInternal(type, checker, ctx) {
2454
2414
  typeArguments: typeArgs.map((t) => buildSchema(t, checker, ctx))
2455
2415
  };
2456
2416
  if (packageOrigin) {
2457
- schema2["x-ts-package"] = packageOrigin;
2417
+ setSchemaExtension(schema2, "x-ts-package", packageOrigin);
2458
2418
  }
2459
2419
  return schema2;
2460
2420
  });
@@ -2464,7 +2424,7 @@ function buildSchemaInternal(type, checker, ctx) {
2464
2424
  typeArguments: typeArgs.map((t) => buildSchema(t, checker, ctx))
2465
2425
  };
2466
2426
  if (packageOrigin) {
2467
- schema["x-ts-package"] = packageOrigin;
2427
+ setSchemaExtension(schema, "x-ts-package", packageOrigin);
2468
2428
  }
2469
2429
  return schema;
2470
2430
  }
@@ -2485,7 +2445,7 @@ function buildSchemaInternal(type, checker, ctx) {
2485
2445
  typeArguments: aliasTypeArgs.map((t) => buildSchema(t, checker, ctx))
2486
2446
  };
2487
2447
  if (packageOrigin) {
2488
- schema2["x-ts-package"] = packageOrigin;
2448
+ setSchemaExtension(schema2, "x-ts-package", packageOrigin);
2489
2449
  }
2490
2450
  return schema2;
2491
2451
  });
@@ -2495,7 +2455,7 @@ function buildSchemaInternal(type, checker, ctx) {
2495
2455
  typeArguments: aliasTypeArgs.map((t) => buildSchema(t, checker, ctx))
2496
2456
  };
2497
2457
  if (packageOrigin) {
2498
- schema["x-ts-package"] = packageOrigin;
2458
+ setSchemaExtension(schema, "x-ts-package", packageOrigin);
2499
2459
  }
2500
2460
  return schema;
2501
2461
  }
@@ -2518,7 +2478,7 @@ function buildSchemaInternal(type, checker, ctx) {
2518
2478
  const packageOrigin = getTypeOrigin(type, checker);
2519
2479
  const schema = { $ref: `#/types/${name}` };
2520
2480
  if (packageOrigin) {
2521
- schema["x-ts-package"] = packageOrigin;
2481
+ setSchemaExtension(schema, "x-ts-package", packageOrigin);
2522
2482
  }
2523
2483
  return schema;
2524
2484
  }
@@ -2585,7 +2545,7 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
2585
2545
  ...required.length > 0 ? { required } : {}
2586
2546
  };
2587
2547
  if (Object.keys(props).length === 0 && originalType) {
2588
- schema["x-ts-type"] = checker.typeToString(originalType);
2548
+ setSchemaExtension(schema, "x-ts-type", checker.typeToString(originalType));
2589
2549
  }
2590
2550
  return schema;
2591
2551
  };
@@ -2884,20 +2844,6 @@ import ts6 from "typescript";
2884
2844
 
2885
2845
  // src/ast/registry.ts
2886
2846
  import ts5 from "typescript";
2887
- var PRIMITIVES2 = new Set([
2888
- "string",
2889
- "number",
2890
- "boolean",
2891
- "void",
2892
- "any",
2893
- "undefined",
2894
- "null",
2895
- "never",
2896
- "unknown",
2897
- "object",
2898
- "symbol",
2899
- "bigint"
2900
- ]);
2901
2847
  var BUILTINS = new Set([
2902
2848
  "Array",
2903
2849
  "ArrayBuffer",
@@ -2997,7 +2943,7 @@ class TypeRegistry {
2997
2943
  if (!symbol)
2998
2944
  return;
2999
2945
  const name = symbol.getName();
3000
- if (PRIMITIVES2.has(name))
2946
+ if (PRIMITIVES.has(name))
3001
2947
  return;
3002
2948
  if (BUILTINS.has(name))
3003
2949
  return;
@@ -3246,6 +3192,32 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
3246
3192
  };
3247
3193
  }
3248
3194
 
3195
+ // src/serializers/shared.ts
3196
+ function extractExportMetadata(node, symbol, checker, jsdocNode) {
3197
+ const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
3198
+ const { description, tags, examples } = getJSDocComment(jsdocNode ?? node, symbol, checker);
3199
+ const source = getSourceLocation(node, node.getSourceFile());
3200
+ return { description, tags, examples, source, deprecated, deprecationReason };
3201
+ }
3202
+ function buildSignatures(callSignatures, checker, ctx) {
3203
+ return callSignatures.map((sig, index) => {
3204
+ const params = extractParameters(sig, ctx);
3205
+ const returnType = checker.getReturnTypeOfSignature(sig);
3206
+ registerReferencedTypes(returnType, ctx);
3207
+ const sigDoc = getJSDocForSignature(sig, checker);
3208
+ const sigTypeParams = extractTypeParametersFromSignature(sig, checker);
3209
+ return {
3210
+ parameters: params.length > 0 ? params : undefined,
3211
+ returns: { schema: buildSchema(returnType, checker, ctx) },
3212
+ ...sigDoc.description ? { description: sigDoc.description } : {},
3213
+ ...sigDoc.tags.length > 0 ? { tags: sigDoc.tags } : {},
3214
+ ...sigDoc.examples.length > 0 ? { examples: sigDoc.examples } : {},
3215
+ ...sigTypeParams ? { typeParameters: sigTypeParams } : {},
3216
+ ...callSignatures.length > 1 ? { overloadIndex: index } : {}
3217
+ };
3218
+ });
3219
+ }
3220
+
3249
3221
  // src/serializers/classes.ts
3250
3222
  function serializeClass(node, ctx) {
3251
3223
  const { typeChecker: checker } = ctx;
@@ -3253,10 +3225,7 @@ function serializeClass(node, ctx) {
3253
3225
  const name = symbol?.getName() ?? node.name?.getText();
3254
3226
  if (!name)
3255
3227
  return null;
3256
- const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
3257
- const declSourceFile = node.getSourceFile();
3258
- const { description, tags, examples } = getJSDocComment(node, symbol, checker);
3259
- const source = getSourceLocation(node, declSourceFile);
3228
+ const { description, tags, examples, source, deprecated, deprecationReason } = extractExportMetadata(node, symbol, checker);
3260
3229
  const typeParameters = extractTypeParameters(node, checker);
3261
3230
  const members = [];
3262
3231
  const signatures = [];
@@ -3407,24 +3376,7 @@ function serializeMethod(node, ctx) {
3407
3376
  }
3408
3377
  const type = checker.getTypeAtLocation(node);
3409
3378
  const callSignatures = type.getCallSignatures();
3410
- const signatures = callSignatures.map((sig, index) => {
3411
- const params = extractParameters(sig, ctx);
3412
- const returnType = checker.getReturnTypeOfSignature(sig);
3413
- registerReferencedTypes(returnType, ctx);
3414
- const sigDoc = getJSDocForSignature(sig, checker);
3415
- const sigTypeParams = extractTypeParametersFromSignature(sig, checker);
3416
- return {
3417
- parameters: params.length > 0 ? params : undefined,
3418
- returns: {
3419
- schema: buildSchema(returnType, checker, ctx)
3420
- },
3421
- ...sigDoc.description ? { description: sigDoc.description } : {},
3422
- ...sigDoc.tags.length > 0 ? { tags: sigDoc.tags } : {},
3423
- ...sigDoc.examples.length > 0 ? { examples: sigDoc.examples } : {},
3424
- ...sigTypeParams ? { typeParameters: sigTypeParams } : {},
3425
- ...callSignatures.length > 1 ? { overloadIndex: index } : {}
3426
- };
3427
- });
3379
+ const signatures = buildSignatures(callSignatures, checker, ctx);
3428
3380
  const flags = {};
3429
3381
  if (isStatic(node))
3430
3382
  flags.static = true;
@@ -3542,10 +3494,7 @@ function serializeEnum(node, ctx) {
3542
3494
  const name = symbol?.getName() ?? node.name?.getText();
3543
3495
  if (!name)
3544
3496
  return null;
3545
- const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
3546
- const declSourceFile = node.getSourceFile();
3547
- const { description, tags, examples } = getJSDocComment(node, symbol, checker);
3548
- const source = getSourceLocation(node, declSourceFile);
3497
+ const { description, tags, examples, source, deprecated, deprecationReason } = extractExportMetadata(node, symbol, checker);
3549
3498
  const members = node.members.map((member) => {
3550
3499
  const memberSymbol = checker.getSymbolAtLocation(member.name);
3551
3500
  const memberName = memberSymbol?.getName() ?? member.name.getText();
@@ -3615,10 +3564,7 @@ function serializeFunctionExport(node, ctx, nameOverride) {
3615
3564
  const name = nameOverride ?? symbol?.getName() ?? node.name?.getText();
3616
3565
  if (!name)
3617
3566
  return null;
3618
- const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
3619
- const declSourceFile = node.getSourceFile();
3620
- const { description, tags, examples } = getJSDocComment(node, symbol, ctx.typeChecker);
3621
- const source = getSourceLocation(node, declSourceFile);
3567
+ const { description, tags, examples, source, deprecated, deprecationReason } = extractExportMetadata(node, symbol, ctx.typeChecker);
3622
3568
  const typeParameters = extractTypeParameters(node, ctx.typeChecker);
3623
3569
  const type = ctx.typeChecker.getTypeAtLocation(node);
3624
3570
  const callSignatures = type.getCallSignatures();
@@ -3658,10 +3604,7 @@ function serializeInterface(node, ctx) {
3658
3604
  const name = symbol?.getName() ?? node.name?.getText();
3659
3605
  if (!name)
3660
3606
  return null;
3661
- const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
3662
- const declSourceFile = node.getSourceFile();
3663
- const { description, tags, examples } = getJSDocComment(node, symbol, checker);
3664
- const source = getSourceLocation(node, declSourceFile);
3607
+ const { description, tags, examples, source, deprecated, deprecationReason } = extractExportMetadata(node, symbol, checker);
3665
3608
  const typeParameters = extractTypeParameters(node, checker);
3666
3609
  const members = [];
3667
3610
  const methodsByName = new Map;
@@ -3770,24 +3713,7 @@ function serializeMethodSignature(node, ctx) {
3770
3713
  const { description, tags } = getJSDocComment(node);
3771
3714
  const type = checker.getTypeAtLocation(node);
3772
3715
  const callSignatures = type.getCallSignatures();
3773
- const signatures = callSignatures.map((sig, index) => {
3774
- const params = extractParameters(sig, ctx);
3775
- const returnType = checker.getReturnTypeOfSignature(sig);
3776
- registerReferencedTypes(returnType, ctx);
3777
- const sigDoc = getJSDocForSignature(sig, checker);
3778
- const sigTypeParams = extractTypeParametersFromSignature(sig, checker);
3779
- return {
3780
- parameters: params.length > 0 ? params : undefined,
3781
- returns: {
3782
- schema: buildSchema(returnType, checker, ctx)
3783
- },
3784
- ...sigDoc.description ? { description: sigDoc.description } : {},
3785
- ...sigDoc.tags.length > 0 ? { tags: sigDoc.tags } : {},
3786
- ...sigDoc.examples.length > 0 ? { examples: sigDoc.examples } : {},
3787
- ...sigTypeParams ? { typeParameters: sigTypeParams } : {},
3788
- ...callSignatures.length > 1 ? { overloadIndex: index } : {}
3789
- };
3790
- });
3716
+ const signatures = buildSignatures(callSignatures, checker, ctx);
3791
3717
  const flags = {};
3792
3718
  if (node.questionToken)
3793
3719
  flags.optional = true;
@@ -3879,10 +3805,7 @@ function serializeTypeAlias(node, ctx) {
3879
3805
  const name = symbol?.getName() ?? node.name?.getText();
3880
3806
  if (!name)
3881
3807
  return null;
3882
- const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
3883
- const declSourceFile = node.getSourceFile();
3884
- const { description, tags, examples } = getJSDocComment(node, symbol, ctx.typeChecker);
3885
- const source = getSourceLocation(node, declSourceFile);
3808
+ const { description, tags, examples, source, deprecated, deprecationReason } = extractExportMetadata(node, symbol, ctx.typeChecker);
3886
3809
  const typeParameters = extractTypeParameters(node, ctx.typeChecker);
3887
3810
  const type = ctx.typeChecker.getTypeAtLocation(node);
3888
3811
  registerReferencedTypes(type, ctx);
@@ -4075,10 +3998,7 @@ function serializeVariable(node, statement, ctx) {
4075
3998
  const name = symbol?.getName() ?? node.name.getText();
4076
3999
  if (!name)
4077
4000
  return null;
4078
- const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
4079
- const declSourceFile = node.getSourceFile();
4080
- const { description, tags, examples } = getJSDocComment(statement, symbol, ctx.typeChecker);
4081
- const source = getSourceLocation(node, declSourceFile);
4001
+ const { description, tags, examples, source, deprecated, deprecationReason } = extractExportMetadata(node, symbol, ctx.typeChecker, statement);
4082
4002
  const type = ctx.typeChecker.getTypeAtLocation(node);
4083
4003
  const schemaExtraction = extractSchemaType(type, ctx.typeChecker);
4084
4004
  const typeToSerialize = schemaExtraction?.outputType ?? type;
@@ -4693,7 +4613,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
4693
4613
  const sourceFile = declaration.getSourceFile();
4694
4614
  const { line } = sourceFile.getLineAndCharacterOfPosition(declaration.getStart());
4695
4615
  const description = getDescriptionPreview(targetSymbol, checker);
4696
- const deprecated = isSymbolDeprecated(targetSymbol);
4616
+ const { deprecated } = isSymbolDeprecated(targetSymbol);
4697
4617
  const reexport = isReexport || sourceFile !== entrySourceFile;
4698
4618
  return {
4699
4619
  name,
@@ -4705,37 +4625,6 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
4705
4625
  ...reexport ? { reexport: true } : {}
4706
4626
  };
4707
4627
  }
4708
- function getExportKind(declaration, type) {
4709
- if (ts12.isSourceFile(declaration)) {
4710
- return "namespace";
4711
- }
4712
- if (ts12.isFunctionDeclaration(declaration) || ts12.isFunctionExpression(declaration)) {
4713
- return "function";
4714
- }
4715
- if (ts12.isClassDeclaration(declaration)) {
4716
- return "class";
4717
- }
4718
- if (ts12.isInterfaceDeclaration(declaration)) {
4719
- return "interface";
4720
- }
4721
- if (ts12.isTypeAliasDeclaration(declaration)) {
4722
- return "type";
4723
- }
4724
- if (ts12.isEnumDeclaration(declaration)) {
4725
- return "enum";
4726
- }
4727
- if (ts12.isModuleDeclaration(declaration) || ts12.isNamespaceExport(declaration)) {
4728
- return "namespace";
4729
- }
4730
- if (ts12.isVariableDeclaration(declaration)) {
4731
- const callSigs = type.getCallSignatures();
4732
- if (callSigs.length > 0) {
4733
- return "function";
4734
- }
4735
- return "variable";
4736
- }
4737
- return "variable";
4738
- }
4739
4628
  function getDescriptionPreview(symbol, checker) {
4740
4629
  const docs = symbol.getDocumentationComment(checker);
4741
4630
  if (docs.length === 0)
@@ -5120,10 +5009,16 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5120
5009
  result.errors.push(`Failed to parse extraction output: ${e}`);
5121
5010
  }
5122
5011
  if (stdoutTruncated) {
5123
- result.warnings.push({ code: "OUTPUT_TRUNCATED", message: "stdout exceeded 10MB buffer limit" });
5012
+ result.warnings.push({
5013
+ code: "OUTPUT_TRUNCATED",
5014
+ message: "stdout exceeded 10MB buffer limit"
5015
+ });
5124
5016
  }
5125
5017
  if (stderrTruncated) {
5126
- result.warnings.push({ code: "OUTPUT_TRUNCATED", message: "stderr exceeded 10MB buffer limit" });
5018
+ result.warnings.push({
5019
+ code: "OUTPUT_TRUNCATED",
5020
+ message: "stderr exceeded 10MB buffer limit"
5021
+ });
5127
5022
  }
5128
5023
  resolve2(result);
5129
5024
  });
@@ -5274,10 +5169,16 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
5274
5169
  result.errors.push(`Failed to parse extraction output: ${e}`);
5275
5170
  }
5276
5171
  if (stdoutTruncated) {
5277
- result.warnings.push({ code: "OUTPUT_TRUNCATED", message: "stdout exceeded 10MB buffer limit" });
5172
+ result.warnings.push({
5173
+ code: "OUTPUT_TRUNCATED",
5174
+ message: "stdout exceeded 10MB buffer limit"
5175
+ });
5278
5176
  }
5279
5177
  if (stderrTruncated) {
5280
- result.warnings.push({ code: "OUTPUT_TRUNCATED", message: "stderr exceeded 10MB buffer limit" });
5178
+ result.warnings.push({
5179
+ code: "OUTPUT_TRUNCATED",
5180
+ message: "stderr exceeded 10MB buffer limit"
5181
+ });
5281
5182
  }
5282
5183
  resolve2(result);
5283
5184
  });
@@ -5375,30 +5276,6 @@ function findPackageJson(resolvedPath, packageName) {
5375
5276
  }
5376
5277
  return;
5377
5278
  }
5378
- function determineExportKind(symbol, checker) {
5379
- const declarations = symbol.declarations ?? [];
5380
- const decl = declarations[0];
5381
- if (!decl)
5382
- return "variable";
5383
- if (ts14.isFunctionDeclaration(decl) || ts14.isFunctionExpression(decl))
5384
- return "function";
5385
- if (ts14.isClassDeclaration(decl))
5386
- return "class";
5387
- if (ts14.isInterfaceDeclaration(decl))
5388
- return "interface";
5389
- if (ts14.isTypeAliasDeclaration(decl))
5390
- return "type";
5391
- if (ts14.isEnumDeclaration(decl))
5392
- return "enum";
5393
- if (ts14.isModuleDeclaration(decl))
5394
- return "namespace";
5395
- if (ts14.isVariableDeclaration(decl)) {
5396
- const type = checker.getTypeAtLocation(decl);
5397
- if (type.getCallSignatures().length > 0)
5398
- return "function";
5399
- }
5400
- return "variable";
5401
- }
5402
5279
  function extractExternalExport(exportName, resolvedModule, program, ctx, visited) {
5403
5280
  const key = `${resolvedModule.resolvedPath}:${exportName}`;
5404
5281
  if (visited.has(key)) {
@@ -5434,7 +5311,8 @@ function extractExternalExport(exportName, resolvedModule, program, ctx, visited
5434
5311
  resolvedSymbol = aliased;
5435
5312
  }
5436
5313
  }
5437
- const kind = determineExportKind(resolvedSymbol, checker);
5314
+ const decl = (resolvedSymbol.declarations ?? [])[0];
5315
+ const kind = decl ? getExportKind(decl, checker.getTypeAtLocation(decl)) : "variable";
5438
5316
  const docComment = resolvedSymbol.getDocumentationComment(checker);
5439
5317
  const description = docComment.length > 0 ? docComment.map((c) => c.text).join(`
5440
5318
  `) : undefined;
@@ -5453,24 +5331,7 @@ function extractExternalExport(exportName, resolvedModule, program, ctx, visited
5453
5331
  const type = checker.getTypeOfSymbol(resolvedSymbol);
5454
5332
  const callSignatures = type.getCallSignatures();
5455
5333
  if (callSignatures.length > 0) {
5456
- const signatures = callSignatures.map((sig, index) => {
5457
- const params = extractParameters(sig, ctx);
5458
- const returnType = checker.getReturnTypeOfSignature(sig);
5459
- registerReferencedTypes(returnType, ctx);
5460
- const returnSchema = buildSchema(returnType, checker, ctx);
5461
- const sigDoc = getJSDocForSignature(sig, checker);
5462
- const sigTypeParams = extractTypeParametersFromSignature(sig, checker);
5463
- return {
5464
- parameters: params,
5465
- returns: { schema: returnSchema },
5466
- ...sigDoc.description && { description: sigDoc.description },
5467
- ...sigDoc.tags.length > 0 && { tags: sigDoc.tags },
5468
- ...sigDoc.examples.length > 0 && { examples: sigDoc.examples },
5469
- ...sigTypeParams && { typeParameters: sigTypeParams },
5470
- ...callSignatures.length > 1 && { overloadIndex: index }
5471
- };
5472
- });
5473
- specExport.signatures = signatures;
5334
+ specExport.signatures = buildSignatures(callSignatures, checker, ctx);
5474
5335
  }
5475
5336
  } else if (kind === "interface" || kind === "type" || kind === "class") {
5476
5337
  const type = checker.getTypeOfSymbol(resolvedSymbol);
@@ -5565,6 +5426,21 @@ class CacheManager {
5565
5426
  };
5566
5427
  this.cache.set(key, entry);
5567
5428
  }
5429
+ getOrCompute(key, compute) {
5430
+ const entry = this.cache.get(key);
5431
+ if (entry) {
5432
+ if (entry.expiresAt && Date.now() > entry.expiresAt) {
5433
+ this.cache.delete(key);
5434
+ } else {
5435
+ this.cache.delete(key);
5436
+ this.cache.set(key, entry);
5437
+ return entry.value;
5438
+ }
5439
+ }
5440
+ const value = compute();
5441
+ this.set(key, value);
5442
+ return value;
5443
+ }
5568
5444
  delete(key) {
5569
5445
  return this.cache.delete(key);
5570
5446
  }
@@ -5604,55 +5480,36 @@ function getRegexCache() {
5604
5480
  return regexCache;
5605
5481
  }
5606
5482
  function findTypeDefinition(typeName, program, sourceFile) {
5607
- if (typeDefinitionCache.has(typeName)) {
5608
- return typeDefinitionCache.get(typeName);
5609
- }
5610
- const checker = program.getTypeChecker();
5611
- const findInNode = (node) => {
5612
- if ((ts15.isInterfaceDeclaration(node) || ts15.isTypeAliasDeclaration(node) || ts15.isClassDeclaration(node) || ts15.isEnumDeclaration(node)) && node.name?.text === typeName) {
5613
- const sf = node.getSourceFile();
5614
- return sf.fileName;
5615
- }
5616
- return ts15.forEachChild(node, findInNode);
5617
- };
5618
- const entryResult = findInNode(sourceFile);
5619
- if (entryResult) {
5620
- typeDefinitionCache.set(typeName, entryResult);
5621
- return entryResult;
5622
- }
5623
- for (const sf of program.getSourceFiles()) {
5624
- if (sf.isDeclarationFile && !sf.fileName.includes("node_modules")) {
5625
- const result = findInNode(sf);
5626
- if (result) {
5627
- typeDefinitionCache.set(typeName, result);
5628
- return result;
5483
+ return typeDefinitionCache.getOrCompute(typeName, () => {
5484
+ const checker = program.getTypeChecker();
5485
+ const findInNode = (node) => {
5486
+ if ((ts15.isInterfaceDeclaration(node) || ts15.isTypeAliasDeclaration(node) || ts15.isClassDeclaration(node) || ts15.isEnumDeclaration(node)) && node.name?.text === typeName) {
5487
+ return node.getSourceFile().fileName;
5488
+ }
5489
+ return ts15.forEachChild(node, findInNode);
5490
+ };
5491
+ const entryResult = findInNode(sourceFile);
5492
+ if (entryResult)
5493
+ return entryResult;
5494
+ for (const sf of program.getSourceFiles()) {
5495
+ if (sf.isDeclarationFile && !sf.fileName.includes("node_modules")) {
5496
+ const result = findInNode(sf);
5497
+ if (result)
5498
+ return result;
5629
5499
  }
5630
5500
  }
5631
- }
5632
- const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
5633
- if (symbol?.declarations?.[0]) {
5634
- const result = symbol.declarations[0].getSourceFile().fileName;
5635
- typeDefinitionCache.set(typeName, result);
5636
- return result;
5637
- }
5638
- typeDefinitionCache.set(typeName, undefined);
5639
- return;
5501
+ const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
5502
+ return symbol?.declarations?.[0]?.getSourceFile().fileName;
5503
+ });
5640
5504
  }
5641
5505
  function hasInternalTag(typeName, program, sourceFile) {
5642
- const cached = internalTagCache.get(typeName);
5643
- if (cached !== undefined) {
5644
- return cached;
5645
- }
5646
- const checker = program.getTypeChecker();
5647
- const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
5648
- if (!symbol) {
5649
- internalTagCache.set(typeName, false);
5650
- return false;
5651
- }
5652
- const jsTags = symbol.getJsDocTags();
5653
- const isInternal = jsTags.some((tag) => tag.name === "internal");
5654
- internalTagCache.set(typeName, isInternal);
5655
- return isInternal;
5506
+ return internalTagCache.getOrCompute(typeName, () => {
5507
+ const checker = program.getTypeChecker();
5508
+ const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
5509
+ if (!symbol)
5510
+ return false;
5511
+ return symbol.getJsDocTags().some((tag) => tag.name === "internal");
5512
+ });
5656
5513
  }
5657
5514
 
5658
5515
  // src/builder/verification.ts
@@ -6017,7 +5874,7 @@ async function extract(options) {
6017
5874
  }
6018
5875
  continue;
6019
5876
  }
6020
- const exp = serializeDeclaration2(declaration, symbol, targetSymbol, exportName, ctx, isTypeOnly);
5877
+ const exp = serializeDeclaration2(declaration, symbol, exportName, ctx, isTypeOnly);
6021
5878
  if (exp) {
6022
5879
  exports.push(exp);
6023
5880
  tracker.status = "success";
@@ -6150,7 +6007,7 @@ async function extract(options) {
6150
6007
  clearTypeDefinitionCache();
6151
6008
  }
6152
6009
  }
6153
- function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportName, ctx, isTypeOnly = false) {
6010
+ function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTypeOnly = false) {
6154
6011
  let result = null;
6155
6012
  if (ts16.isFunctionDeclaration(declaration)) {
6156
6013
  result = serializeFunctionExport(declaration, ctx);
@@ -6172,33 +6029,7 @@ function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportN
6172
6029
  result = serializeVariable(declaration, varStatement, ctx);
6173
6030
  }
6174
6031
  }
6175
- } else if (ts16.isNamespaceExport(declaration) || ts16.isModuleDeclaration(declaration)) {
6176
- try {
6177
- result = serializeNamespaceExport(exportSymbol, exportName, ctx);
6178
- } catch {
6179
- result = {
6180
- id: exportName,
6181
- name: exportName,
6182
- kind: "namespace",
6183
- tags: [],
6184
- members: [],
6185
- examples: []
6186
- };
6187
- }
6188
- } else if (ts16.isNamespaceImport(declaration)) {
6189
- try {
6190
- result = serializeNamespaceExport(exportSymbol, exportName, ctx);
6191
- } catch {
6192
- result = {
6193
- id: exportName,
6194
- name: exportName,
6195
- kind: "namespace",
6196
- tags: [],
6197
- members: [],
6198
- examples: []
6199
- };
6200
- }
6201
- } else if (ts16.isSourceFile(declaration)) {
6032
+ } else if (ts16.isNamespaceExport(declaration) || ts16.isModuleDeclaration(declaration) || ts16.isNamespaceImport(declaration) || ts16.isSourceFile(declaration)) {
6202
6033
  try {
6203
6034
  result = serializeNamespaceExport(exportSymbol, exportName, ctx);
6204
6035
  } catch {
@@ -6289,23 +6120,7 @@ function serializeNamespaceMember(symbol, memberName, ctx) {
6289
6120
  `) || undefined;
6290
6121
  let signatures;
6291
6122
  if (kind === "function" && callSignatures.length > 0) {
6292
- signatures = callSignatures.map((sig, index) => {
6293
- const params = extractParameters(sig, ctx);
6294
- const returnType = checker.getReturnTypeOfSignature(sig);
6295
- registerReferencedTypes(returnType, ctx);
6296
- const returnSchema = buildSchema(returnType, ctx.typeChecker, ctx);
6297
- const sigDoc = getJSDocForSignature(sig, checker);
6298
- const sigTypeParams = extractTypeParametersFromSignature(sig, ctx.typeChecker);
6299
- return {
6300
- parameters: params,
6301
- returns: { schema: returnSchema },
6302
- ...sigDoc.description ? { description: sigDoc.description } : {},
6303
- ...sigDoc.tags.length > 0 ? { tags: sigDoc.tags } : {},
6304
- ...sigDoc.examples.length > 0 ? { examples: sigDoc.examples } : {},
6305
- ...sigTypeParams ? { typeParameters: sigTypeParams } : {},
6306
- ...callSignatures.length > 1 ? { overloadIndex: index } : {}
6307
- };
6308
- });
6123
+ signatures = buildSignatures(callSignatures, checker, ctx);
6309
6124
  }
6310
6125
  let schema;
6311
6126
  if (kind !== "function") {
@@ -6423,11 +6238,12 @@ async function getPackageMeta(entryFile, baseDir) {
6423
6238
  // src/primitives/spec.ts
6424
6239
  var extractSpec = extract;
6425
6240
  // src/types/utils.ts
6241
+ import ts17 from "typescript";
6426
6242
  function isExported(node) {
6427
6243
  const modifiers = node.modifiers;
6428
6244
  if (!modifiers)
6429
6245
  return false;
6430
- return modifiers.some((m) => m.kind === 95);
6246
+ return modifiers.some((m) => m.kind === ts17.SyntaxKind.ExportKeyword);
6431
6247
  }
6432
6248
  function getNodeName(node) {
6433
6249
  if ("name" in node && node.name) {
@@ -6501,6 +6317,7 @@ export {
6501
6317
  getMethods,
6502
6318
  getMemberBadges,
6503
6319
  getJSDocComment,
6320
+ getExportKind,
6504
6321
  getExport,
6505
6322
  getDeprecationMessage,
6506
6323
  toMarkdown as generateDocs,
@@ -6539,6 +6356,7 @@ export {
6539
6356
  analyzeSpec,
6540
6357
  TypeRegistry,
6541
6358
  QueryBuilder,
6359
+ PRIMITIVES,
6542
6360
  CacheManager,
6543
6361
  CONFIG_FILENAME,
6544
6362
  BUILTIN_TYPE_SCHEMAS,
@@ -98,6 +98,9 @@ function formatBadges(badges) {
98
98
  }
99
99
 
100
100
  // src/core/query.ts
101
+ import {
102
+ DISPLAY_KIND_ORDER
103
+ } from "@openpkg-ts/spec";
101
104
  function formatFunctionSchema(schema) {
102
105
  const sigs = schema["x-ts-signatures"];
103
106
  if (!sigs?.length)
@@ -171,6 +174,14 @@ function formatSchema(schema, options) {
171
174
  }
172
175
  return "object";
173
176
  }
177
+ if ("const" in schema && schema.const !== undefined) {
178
+ const v = schema.const;
179
+ return withPackage(typeof v === "string" ? `"${v}"` : String(v));
180
+ }
181
+ if ("enum" in schema && Array.isArray(schema.enum)) {
182
+ const vals = schema.enum.map((v) => typeof v === "string" ? `"${v}"` : String(v));
183
+ return withPackage(vals.join(" | "));
184
+ }
174
185
  if ("type" in schema && typeof schema.type === "string") {
175
186
  return withPackage(schema.type);
176
187
  }
@@ -279,6 +290,22 @@ function groupByVisibility(members) {
279
290
  function sortByName(items) {
280
291
  return [...items].sort((a, b) => a.name.localeCompare(b.name));
281
292
  }
293
+ var KIND_ORDER = [
294
+ ...DISPLAY_KIND_ORDER,
295
+ "namespace",
296
+ "module",
297
+ "reference",
298
+ "external"
299
+ ];
300
+ function groupByKind(items) {
301
+ const groups = {};
302
+ for (const item of items) {
303
+ if (!groups[item.kind])
304
+ groups[item.kind] = [];
305
+ groups[item.kind].push(item);
306
+ }
307
+ return groups;
308
+ }
282
309
  function formatConditionalType(condType) {
283
310
  const check = formatSchema(condType.checkType);
284
311
  const ext = formatSchema(condType.extendsType);
@@ -303,6 +330,16 @@ function formatMappedType(mappedType) {
303
330
  }
304
331
  return `{ ${readonlyMod}[${keyStr}]${optionalMod}: ${valueStr} }`;
305
332
  }
333
+ function findExport(spec, name) {
334
+ const exp = spec.exports.find((e) => e.name === name || e.id === name);
335
+ if (!exp)
336
+ throw new Error(`Export not found: ${name}`);
337
+ return exp;
338
+ }
339
+ function filterExports(spec, names) {
340
+ const ids = new Set(names);
341
+ return spec.exports.filter((e) => ids.has(e.name) || ids.has(e.id));
342
+ }
306
343
 
307
344
  // src/core/search.ts
308
345
  var defaultSlugify = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
@@ -388,7 +425,7 @@ function buildContent(exp, options = {}) {
388
425
  }
389
426
  return parts.join(" ");
390
427
  }
391
- function createSearchRecord(exp, _packageName, options = {}) {
428
+ function createSearchRecord(exp, options = {}) {
392
429
  const { baseUrl = "/api", slugify = defaultSlugify } = options;
393
430
  return {
394
431
  id: exp.id,
@@ -403,7 +440,7 @@ function createSearchRecord(exp, _packageName, options = {}) {
403
440
  };
404
441
  }
405
442
  function toSearchIndex(spec, options = {}) {
406
- const records = spec.exports.map((exp) => createSearchRecord(exp, spec.meta.name, options));
443
+ const records = spec.exports.map((exp) => createSearchRecord(exp, options));
407
444
  return {
408
445
  records,
409
446
  version: spec.meta.version || "0.0.0",
@@ -549,4 +586,4 @@ function query(spec) {
549
586
  return new QueryBuilder(spec);
550
587
  }
551
588
 
552
- export { hasDeprecatedTag, getDeprecationMessage, findMissingParamDocs, analyzeSpec, getMemberBadges, formatBadges, formatSchema, formatTypeParameters, formatParameters, formatReturnType, buildSignatureString, resolveTypeRef, isMethod, isProperty, getMethods, getProperties, groupByVisibility, sortByName, formatConditionalType, formatMappedType, toSearchIndex, toPagefindRecords, toAlgoliaRecords, toSearchIndexJSON, QueryBuilder, query };
589
+ export { hasDeprecatedTag, getDeprecationMessage, findMissingParamDocs, analyzeSpec, getMemberBadges, formatBadges, formatSchema, formatTypeParameters, formatParameters, formatReturnType, buildSignatureString, resolveTypeRef, isMethod, isProperty, getMethods, getProperties, groupByVisibility, sortByName, KIND_ORDER, groupByKind, formatConditionalType, formatMappedType, findExport, filterExports, toSearchIndex, toPagefindRecords, toAlgoliaRecords, toSearchIndexJSON, QueryBuilder, query };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/sdk",
3
- "version": "0.35.0",
3
+ "version": "0.35.1",
4
4
  "description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",
@@ -42,7 +42,7 @@
42
42
  "test": "bun test"
43
43
  },
44
44
  "dependencies": {
45
- "@openpkg-ts/spec": "^0.34.1",
45
+ "@openpkg-ts/spec": "^0.35.1",
46
46
  "picomatch": "4.0.3",
47
47
  "typescript": "^5.0.0"
48
48
  },