@openpkg-ts/sdk 0.1.0 → 0.30.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.
Files changed (4) hide show
  1. package/README.md +106 -81
  2. package/dist/index.d.ts +1377 -43
  3. package/dist/index.js +5816 -1921
  4. package/package.json +22 -22
package/dist/index.d.ts CHANGED
@@ -1,55 +1,1389 @@
1
- interface OpenPkgOptions {
2
- includePrivate?: boolean;
3
- followImports?: boolean;
4
- maxDepth?: number;
1
+ import { BreakingSeverity, CategorizedBreaking, calculateNextVersion, categorizeBreakingChanges, diffSpec, diffSpec as diffSpec2, MemberChangeInfo, recommendSemverBump, SemverBump, SemverRecommendation, SpecDiff } from "@openpkg-ts/spec";
2
+ import { SpecMember } from "@openpkg-ts/spec";
3
+ /**
4
+ * Extract badge strings from a member's visibility and flags.
5
+ * Handles: visibility (if not public), static, readonly, async, abstract
6
+ */
7
+ declare function getMemberBadges(member: SpecMember): string[];
8
+ /**
9
+ * Format badges array into a display string (space-separated).
10
+ */
11
+ declare function formatBadges(badges: string[]): string;
12
+ import { OpenPkg as OpenPkg6, SpecExport as SpecExport2, SpecExportKind as SpecExportKind4, SpecType } from "@openpkg-ts/spec";
13
+ import { OpenPkg } from "@openpkg-ts/spec";
14
+ interface HTMLOptions {
15
+ /** Page title override */
16
+ title?: string;
17
+ /** Include inline styles */
18
+ includeStyles?: boolean;
19
+ /** Custom CSS to inject */
20
+ customCSS?: string;
21
+ /** Custom head content */
22
+ headContent?: string;
23
+ /** Wrap in full HTML document */
24
+ fullDocument?: boolean;
25
+ /** Export to render (single mode) */
26
+ export?: string;
27
+ }
28
+ /**
29
+ * Render spec to standalone HTML page.
30
+ *
31
+ * @param spec - The OpenPkg spec to render
32
+ * @param options - HTML rendering options
33
+ * @returns Complete HTML document or fragment
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { createDocs } from '@openpkg-ts/sdk'
38
+ *
39
+ * const docs = createDocs('./openpkg.json')
40
+ *
41
+ * // Full HTML page
42
+ * const html = docs.toHTML({ includeStyles: true })
43
+ * fs.writeFileSync('api.html', html)
44
+ *
45
+ * // Single export, no document wrapper
46
+ * const fragment = docs.toHTML({ export: 'greet', fullDocument: false })
47
+ * ```
48
+ */
49
+ declare function toHTML2(spec: OpenPkg, options?: HTMLOptions): string;
50
+ import { OpenPkg as OpenPkg2, SpecExportKind } from "@openpkg-ts/spec";
51
+ interface JSONOptions {
52
+ /** Include raw spec data alongside simplified data */
53
+ includeRaw?: boolean;
54
+ /** Export to render (single mode) */
55
+ export?: string;
56
+ /** Include computed fields (signatures, formatted types) */
57
+ computed?: boolean;
58
+ /** Flatten nested structures */
59
+ flatten?: boolean;
60
+ }
61
+ interface SimplifiedParameter {
62
+ name: string;
63
+ type: string;
64
+ required: boolean;
65
+ description?: string;
66
+ default?: unknown;
67
+ rest?: boolean;
68
+ }
69
+ interface SimplifiedReturn {
70
+ type: string;
71
+ description?: string;
72
+ }
73
+ interface SimplifiedSignature {
74
+ parameters: SimplifiedParameter[];
75
+ returns?: SimplifiedReturn;
76
+ description?: string;
77
+ typeParameters?: string[];
78
+ }
79
+ interface SimplifiedMember {
80
+ name: string;
81
+ kind: "property" | "method";
82
+ type?: string;
83
+ description?: string;
84
+ visibility?: "public" | "protected" | "private";
85
+ signature?: SimplifiedSignature;
86
+ }
87
+ interface SimplifiedExample {
88
+ code: string;
89
+ title?: string;
90
+ description?: string;
91
+ language?: string;
92
+ }
93
+ interface SimplifiedExport {
94
+ id: string;
95
+ name: string;
96
+ kind: SpecExportKind;
97
+ signature: string;
98
+ description?: string;
99
+ deprecated: boolean;
100
+ tags: Array<{
101
+ name: string;
102
+ text: string;
103
+ }>;
104
+ parameters?: SimplifiedParameter[];
105
+ returns?: SimplifiedReturn;
106
+ members?: SimplifiedMember[];
107
+ examples?: SimplifiedExample[];
108
+ extends?: string;
109
+ implements?: string[];
110
+ sourceFile?: string;
111
+ sourceLine?: number;
112
+ }
113
+ interface SimplifiedSpec {
114
+ name: string;
115
+ version?: string;
116
+ description?: string;
117
+ exports: SimplifiedExport[];
118
+ byKind: Record<SpecExportKind, SimplifiedExport[]>;
119
+ totalExports: number;
120
+ }
121
+ /**
122
+ * Render spec to simplified JSON structure.
123
+ *
124
+ * @param spec - The OpenPkg spec to simplify
125
+ * @param options - JSON rendering options
126
+ * @returns Simplified spec or single structure
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { createDocs } from '@openpkg-ts/sdk'
131
+ *
132
+ * const docs = createDocs('./openpkg.json')
133
+ *
134
+ * // Full spec as simplified JSON
135
+ * const json = docs.toJSON()
136
+ * // { name, version, exports: [...], byKind: {...} }
137
+ *
138
+ * // Single * const fnJson = docs.toJSON({ export: 'greet' })
139
+ * // { id, name, kind, signature, parameters, returns, ... }
140
+ * ```
141
+ */
142
+ declare function toJSON2(spec: OpenPkg2, options?: JSONOptions): SimplifiedSpec | SimplifiedExport;
143
+ /**
144
+ * Serialize to JSON string with formatting.
145
+ *
146
+ * @param spec - The OpenPkg spec to serialize
147
+ * @param options - JSON options plus pretty formatting option
148
+ * @returns JSON string
149
+ */
150
+ declare function toJSONString(spec: OpenPkg2, options?: JSONOptions & {
151
+ pretty?: boolean;
152
+ }): string;
153
+ import { OpenPkg as OpenPkg3, SpecExport } from "@openpkg-ts/spec";
154
+ interface MarkdownOptions {
155
+ /** Include frontmatter in output */
156
+ frontmatter?: boolean;
157
+ /** Sections to include */
158
+ sections?: {
159
+ signature?: boolean;
160
+ description?: boolean;
161
+ parameters?: boolean;
162
+ returns?: boolean;
163
+ examples?: boolean;
164
+ members?: boolean;
165
+ properties?: boolean;
166
+ methods?: boolean;
167
+ };
168
+ /** Custom frontmatter fields */
169
+ customFrontmatter?: Record<string, unknown>;
170
+ /** Use code fences for signatures */
171
+ codeSignatures?: boolean;
172
+ /** Heading level offset (0 = starts at h1, 1 = starts at h2) */
173
+ headingOffset?: number;
174
+ }
175
+ interface ExportMarkdownOptions extends MarkdownOptions {
176
+ /** Export to render */
177
+ export?: string;
178
+ }
179
+ /**
180
+ * Render a single to MDX.
181
+ *
182
+ * @param exp - The to render
183
+ * @param options - Markdown rendering options
184
+ * @returns MDX string with frontmatter
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * const mdx = exportToMarkdown(fn, {
189
+ * frontmatter: true,
190
+ * codeSignatures: true,
191
+ * sections: { examples: true }
192
+ * })
193
+ * ```
194
+ */
195
+ declare function exportToMarkdown(exp: SpecExport, options?: MarkdownOptions): string;
196
+ /**
197
+ * Render entire spec to MDX.
198
+ *
199
+ * @param spec - The OpenPkg spec to render
200
+ * @param options - Markdown options, optionally with name for single mode
201
+ * @returns MDX string
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * import { createDocs } from '@openpkg-ts/sdk'
206
+ *
207
+ * const docs = createDocs('./openpkg.json')
208
+ *
209
+ * // Full spec
210
+ * const fullMdx = docs.toMarkdown()
211
+ *
212
+ * // Single * const fnMdx = docs.toMarkdown({ export: 'greet' })
213
+ * ```
214
+ */
215
+ declare function toMarkdown2(spec: OpenPkg3, options?: ExportMarkdownOptions): string;
216
+ import { OpenPkg as OpenPkg4, SpecExportKind as SpecExportKind2 } from "@openpkg-ts/spec";
217
+ type NavFormat = "fumadocs" | "docusaurus" | "generic";
218
+ type GroupBy = "kind" | "module" | "tag" | "none";
219
+ interface NavOptions {
220
+ /** Output format */
221
+ format?: NavFormat;
222
+ /** How to group exports */
223
+ groupBy?: GroupBy;
224
+ /** Base path for links */
225
+ basePath?: string;
226
+ /** Custom slug generator */
227
+ slugify?: (name: string) => string;
228
+ /** Include index pages for groups */
229
+ includeGroupIndex?: boolean;
230
+ /** Custom kind labels */
231
+ kindLabels?: Partial<Record<SpecExportKind2, string>>;
232
+ /** Sort exports alphabetically */
233
+ sortAlphabetically?: boolean;
234
+ }
235
+ interface NavItem {
236
+ title: string;
237
+ href?: string;
238
+ items?: NavItem[];
239
+ }
240
+ interface NavGroup {
241
+ title: string;
242
+ items: NavItem[];
243
+ index?: string;
244
+ }
245
+ interface GenericNav {
246
+ title: string;
247
+ groups: NavGroup[];
248
+ items: NavItem[];
249
+ }
250
+ interface FumadocsMetaItem {
251
+ title: string;
252
+ pages?: string[];
253
+ defaultOpen?: boolean;
254
+ }
255
+ interface FumadocsMeta {
256
+ root?: boolean;
257
+ title?: string;
258
+ pages?: (string | FumadocsMetaItem)[];
259
+ }
260
+ interface DocusaurusSidebarItem {
261
+ type: "category" | "doc" | "link";
262
+ label: string;
263
+ items?: DocusaurusSidebarItem[];
264
+ id?: string;
265
+ href?: string;
266
+ }
267
+ type DocusaurusSidebar = DocusaurusSidebarItem[];
268
+ /**
269
+ * Generate navigation structure for doc frameworks.
270
+ *
271
+ * @param spec - The OpenPkg spec
272
+ * @param options - Navigation options including format and grouping
273
+ * @returns Navigation structure in requested format
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * import { createDocs } from '@openpkg-ts/sdk'
278
+ *
279
+ * const docs = createDocs('./openpkg.json')
280
+ *
281
+ * // Generic nav
282
+ * const nav = docs.toNavigation({ format: 'generic', groupBy: 'kind' })
283
+ *
284
+ * // Fumadocs meta.json
285
+ * const meta = docs.toNavigation({ format: 'fumadocs' })
286
+ *
287
+ * // Docusaurus sidebar
288
+ * const sidebar = docs.toNavigation({ format: 'docusaurus' })
289
+ * ```
290
+ */
291
+ declare function toNavigation2(spec: OpenPkg4, options?: NavOptions): GenericNav | FumadocsMeta | DocusaurusSidebar;
292
+ /**
293
+ * Generate Fumadocs meta.json file content.
294
+ *
295
+ * @param spec - The OpenPkg spec
296
+ * @param options - Navigation options (format is forced to fumadocs)
297
+ * @returns JSON string for meta.json file
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * const meta = toFumadocsMetaJSON(spec, { groupBy: 'kind' })
302
+ * fs.writeFileSync('docs/api/meta.json', meta)
303
+ * ```
304
+ */
305
+ declare function toFumadocsMetaJSON(spec: OpenPkg4, options?: Omit<NavOptions, "format">): string;
306
+ /**
307
+ * Generate Docusaurus sidebar config.
308
+ *
309
+ * @param spec - The OpenPkg spec
310
+ * @param options - Navigation options (format is forced to docusaurus)
311
+ * @returns JavaScript module.exports string for sidebars.js
312
+ *
313
+ * @example
314
+ * ```ts
315
+ * const sidebar = toDocusaurusSidebarJS(spec, { basePath: 'api' })
316
+ * fs.writeFileSync('sidebars.js', sidebar)
317
+ * ```
318
+ */
319
+ declare function toDocusaurusSidebarJS(spec: OpenPkg4, options?: Omit<NavOptions, "format">): string;
320
+ import { OpenPkg as OpenPkg5, SpecExportKind as SpecExportKind3 } from "@openpkg-ts/spec";
321
+ interface SearchOptions {
322
+ /** Base URL for search result links */
323
+ baseUrl?: string;
324
+ /** Custom slug generator */
325
+ slugify?: (name: string) => string;
326
+ /** Include type signatures in search content */
327
+ includeSignatures?: boolean;
328
+ /** Include member names in search content */
329
+ includeMembers?: boolean;
330
+ /** Include parameter names in search content */
331
+ includeParameters?: boolean;
332
+ /** Weight multipliers for ranking */
333
+ weights?: {
334
+ name?: number;
335
+ description?: number;
336
+ signature?: number;
337
+ tags?: number;
338
+ };
339
+ }
340
+ interface PagefindRecord {
341
+ url: string;
342
+ content: string;
343
+ word_count: number;
344
+ filters: Record<string, string[]>;
345
+ meta: {
346
+ title: string;
347
+ kind?: string;
348
+ description?: string;
349
+ signature?: string;
350
+ };
351
+ anchors?: Array<{
352
+ element: string;
353
+ id: string;
354
+ text: string;
355
+ }>;
356
+ weighted_sections?: Array<{
357
+ weight: number;
358
+ text: string;
359
+ }>;
360
+ }
361
+ interface AlgoliaRecord {
362
+ objectID: string;
363
+ name: string;
364
+ kind: SpecExportKind3;
365
+ description?: string;
366
+ signature: string;
367
+ content: string;
368
+ tags: string[];
369
+ deprecated: boolean;
370
+ url: string;
371
+ hierarchy: {
372
+ lvl0: string;
373
+ lvl1: string;
374
+ lvl2?: string;
375
+ };
376
+ _rankingInfo?: {
377
+ nbTypos: number;
378
+ words: number;
379
+ };
380
+ }
381
+ interface SearchRecord {
382
+ id: string;
383
+ name: string;
384
+ kind: SpecExportKind3;
385
+ signature: string;
386
+ description?: string;
387
+ content: string;
388
+ keywords: string[];
389
+ url: string;
390
+ deprecated: boolean;
391
+ }
392
+ interface SearchIndex {
393
+ records: SearchRecord[];
394
+ version: string;
395
+ generatedAt: string;
396
+ packageName: string;
397
+ }
398
+ /**
399
+ * Generate search index from spec.
400
+ *
401
+ * @param spec - The OpenPkg spec to index
402
+ * @param options - Search index configuration
403
+ * @returns Search index with records for each *
404
+ * @example
405
+ * ```ts
406
+ * import { createDocs } from '@openpkg-ts/sdk'
407
+ *
408
+ * const docs = createDocs('./openpkg.json')
409
+ * const index = docs.toSearchIndex({ baseUrl: '/api' })
410
+ * // { records: [...], version: '1.0.0', packageName: 'my-lib' }
411
+ * ```
412
+ */
413
+ declare function toSearchIndex2(spec: OpenPkg5, options?: SearchOptions): SearchIndex;
414
+ /**
415
+ * Generate Pagefind-compatible records.
416
+ *
417
+ * @param spec - The OpenPkg spec to index
418
+ * @param options - Search configuration including weights
419
+ * @returns Array of Pagefind-compatible search records
420
+ *
421
+ * @example
422
+ * ```ts
423
+ * const records = toPagefindRecords(spec, {
424
+ * baseUrl: '/docs/api',
425
+ * weights: { name: 10, description: 5 }
426
+ * })
427
+ * ```
428
+ */
429
+ declare function toPagefindRecords2(spec: OpenPkg5, options?: SearchOptions): PagefindRecord[];
430
+ /**
431
+ * Generate Algolia-compatible records.
432
+ *
433
+ * @param spec - The OpenPkg spec to index
434
+ * @param options - Search configuration
435
+ * @returns Array of Algolia-compatible search records with hierarchy
436
+ *
437
+ * @example
438
+ * ```ts
439
+ * const records = toAlgoliaRecords(spec, { baseUrl: '/api' })
440
+ * // Upload to Algolia index
441
+ * ```
442
+ */
443
+ declare function toAlgoliaRecords2(spec: OpenPkg5, options?: SearchOptions): AlgoliaRecord[];
444
+ /**
445
+ * Serialize search index to JSON string.
446
+ *
447
+ * @param spec - The OpenPkg spec to index
448
+ * @param options - Search options plus pretty formatting option
449
+ * @returns JSON string of search index
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * const json = toSearchIndexJSON(spec, { pretty: true })
454
+ * fs.writeFileSync('search-index.json', json)
455
+ * ```
456
+ */
457
+ declare function toSearchIndexJSON(spec: OpenPkg5, options?: SearchOptions & {
458
+ pretty?: boolean;
459
+ }): string;
460
+ interface LoadOptions {
461
+ /** Path to openpkg.json file or the spec object directly */
462
+ input: string | OpenPkg6;
463
+ }
464
+ interface DocsInstance {
465
+ /** The parsed OpenPkg spec */
466
+ spec: OpenPkg6;
467
+ /** Get an by its ID */
468
+ getExport(id: string): SpecExport2 | undefined;
469
+ /** Get a type definition by its ID */
470
+ getType(id: string): SpecType | undefined;
471
+ /** Get all exports of a specific kind */
472
+ getExportsByKind(kind: SpecExportKind4): SpecExport2[];
473
+ /** Get all exports */
474
+ getAllExports(): SpecExport2[];
475
+ /** Get all type definitions */
476
+ getAllTypes(): SpecType[];
477
+ /** Get exports by JSDoc tag (e.g., '@beta', '@internal') */
478
+ getExportsByTag(tagName: string): SpecExport2[];
479
+ /** Search exports by name or description */
480
+ search(query: string): SpecExport2[];
481
+ /** Get exports belonging to a specific module/namespace */
482
+ getModule(moduleName: string): SpecExport2[];
483
+ /** Get deprecated exports */
484
+ getDeprecated(): SpecExport2[];
485
+ /** Get exports grouped by kind */
486
+ groupByKind(): Record<SpecExportKind4, SpecExport2[]>;
487
+ /** Render spec or single to MDX */
488
+ toMarkdown(options?: ExportMarkdownOptions): string;
489
+ /** Render spec or single to HTML */
490
+ toHTML(options?: HTMLOptions): string;
491
+ /** Render spec or single to JSON structure */
492
+ toJSON(options?: JSONOptions): SimplifiedSpec | SimplifiedExport;
493
+ /** Generate navigation structure */
494
+ toNavigation(options?: NavOptions): GenericNav | FumadocsMeta | DocusaurusSidebar;
495
+ /** Generate search index */
496
+ toSearchIndex(options?: SearchOptions): SearchIndex;
497
+ /** Generate Pagefind-compatible records */
498
+ toPagefindRecords(options?: SearchOptions): PagefindRecord[];
499
+ /** Generate Algolia-compatible records */
500
+ toAlgoliaRecords(options?: SearchOptions): AlgoliaRecord[];
501
+ }
502
+ /**
503
+ * Loads an OpenPkg spec from file or object.
504
+ *
505
+ * @example
506
+ * ```ts
507
+ * import { loadSpec } from '@openpkg-ts/sdk'
508
+ *
509
+ * // From spec object
510
+ * import spec from './openpkg.json'
511
+ * const docs = loadSpec(spec)
512
+ * ```
513
+ */
514
+ declare function loadSpec(spec: OpenPkg6): DocsInstance;
515
+ /**
516
+ * Creates a docs instance for querying and rendering API documentation.
517
+ *
518
+ * @example
519
+ * ```ts
520
+ * import { createDocs } from '@openpkg-ts/sdk'
521
+ *
522
+ * // From file path
523
+ * const docs = createDocs('./openpkg.json')
524
+ *
525
+ * // From spec object
526
+ * import spec from './openpkg.json'
527
+ * const docs = createDocs(spec)
528
+ *
529
+ * // Query
530
+ * docs.getExport('useState')
531
+ * docs.getExportsByKind('function')
532
+ * docs.getExportsByTag('@beta')
533
+ * docs.search('hook')
534
+ * ```
535
+ */
536
+ declare function createDocs(input: string | OpenPkg6): DocsInstance;
537
+ import { OpenPkg as OpenPkg7, SpecExport as SpecExport3, SpecMember as SpecMember2, SpecSchema, SpecSignature, SpecType as SpecType2, SpecTypeParameter } from "@openpkg-ts/spec";
538
+ interface FormatSchemaOptions {
539
+ /** Include package attribution for external types */
540
+ includePackage?: boolean;
541
+ }
542
+ /**
543
+ * Format a schema to a human-readable type string.
544
+ *
545
+ * @param schema - The schema to format
546
+ * @param options - Formatting options
547
+ * @returns Formatted type string
548
+ *
549
+ * @example
550
+ * ```ts
551
+ * formatSchema({ type: 'string' }) // 'string'
552
+ * formatSchema({ $ref: '#/types/User' }) // 'User'
553
+ * formatSchema({ anyOf: [{ type: 'string' }, { type: 'number' }] }) // 'string | number'
554
+ * formatSchema({ type: 'integer', 'x-ts-type': 'bigint' }) // 'bigint'
555
+ * formatSchema({ 'x-ts-type': 'Response', 'x-ts-package': 'express' }, { includePackage: true }) // 'Response (from express)'
556
+ * ```
557
+ */
558
+ declare function formatSchema(schema: SpecSchema | undefined, options?: FormatSchemaOptions): string;
559
+ /**
560
+ * Format type parameters to a string like `<T, U extends string>`.
561
+ *
562
+ * @param typeParams - Array of type parameters
563
+ * @returns Formatted type parameters string or empty string
564
+ *
565
+ * @example
566
+ * ```ts
567
+ * formatTypeParameters([{ name: 'T' }]) // '<T>'
568
+ * formatTypeParameters([{ name: 'T', constraint: 'object' }]) // '<T extends object>'
569
+ * formatTypeParameters([{ name: 'T', default: 'unknown' }]) // '<T = unknown>'
570
+ * formatTypeParameters([{ name: 'T', variance: 'in' }]) // '<in T>'
571
+ * ```
572
+ */
573
+ declare function formatTypeParameters(typeParams?: SpecTypeParameter[]): string;
574
+ /**
575
+ * Format function parameters to a string like `(a: string, b?: number)`.
576
+ *
577
+ * @param sig - The signature containing parameters
578
+ * @returns Formatted parameters string
579
+ *
580
+ * @example
581
+ * ```ts
582
+ * formatParameters({ parameters: [{ name: 'id', schema: { type: 'string' } }] })
583
+ * // '(id: string)'
584
+ * ```
585
+ */
586
+ declare function formatParameters(sig?: SpecSignature): string;
587
+ /**
588
+ * Format return type from signature.
589
+ *
590
+ * @param sig - The signature containing return type
591
+ * @returns Formatted return type string
592
+ *
593
+ * @example
594
+ * ```ts
595
+ * formatReturnType({ returns: { schema: { type: 'Promise', items: { type: 'string' } } } })
596
+ * // 'Promise<string>'
597
+ * ```
598
+ */
599
+ declare function formatReturnType(sig?: SpecSignature): string;
600
+ /**
601
+ * Build a full signature string for an export.
602
+ *
603
+ * @param exp - The to build a signature for
604
+ * @param sigIndex - Index of signature to use for overloaded functions
605
+ * @returns Complete signature string
606
+ *
607
+ * @example
608
+ * ```ts
609
+ * buildSignatureString({ kind: 'function', name: 'greet', signatures: [...] })
610
+ * // 'function greet(name: string): string'
611
+ *
612
+ * buildSignatureString({ kind: 'class', name: 'Logger', extends: 'EventEmitter' })
613
+ * // 'class Logger extends EventEmitter'
614
+ * ```
615
+ */
616
+ declare function buildSignatureString(exp: SpecExport3, sigIndex?: number): string;
617
+ /**
618
+ * Resolve a type reference to its definition.
619
+ *
620
+ * @param ref - Type reference string (e.g., '#/types/User')
621
+ * @param spec - The OpenPkg spec containing type definitions
622
+ * @returns The resolved type definition or undefined
623
+ *
624
+ * @example
625
+ * ```ts
626
+ * resolveTypeRef('#/types/User', spec)
627
+ * // { id: 'User', name: 'User', kind: 'interface', ... }
628
+ * ```
629
+ */
630
+ declare function resolveTypeRef(ref: string, spec: OpenPkg7): SpecType2 | undefined;
631
+ /**
632
+ * Check if a member is a method (has signatures).
633
+ *
634
+ * @param member - The member to check
635
+ * @returns True if the member is a method
636
+ *
637
+ * @example
638
+ * ```ts
639
+ * isMethod({ name: 'foo', signatures: [{ parameters: [] }] }) // true
640
+ * isMethod({ name: 'bar', schema: { type: 'string' } }) // false
641
+ * ```
642
+ */
643
+ declare function isMethod(member: SpecMember2): boolean;
644
+ /**
645
+ * Check if a member is a property (no signatures).
646
+ *
647
+ * @param member - The member to check
648
+ * @returns True if the member is a property
649
+ */
650
+ declare function isProperty(member: SpecMember2): boolean;
651
+ /**
652
+ * Get methods from members list.
653
+ *
654
+ * @param members - Array of members to filter
655
+ * @returns Array of method members
656
+ */
657
+ declare function getMethods(members?: SpecMember2[]): SpecMember2[];
658
+ /**
659
+ * Get properties from members list.
660
+ *
661
+ * @param members - Array of members to filter
662
+ * @returns Array of property members
663
+ */
664
+ declare function getProperties(members?: SpecMember2[]): SpecMember2[];
665
+ /**
666
+ * Group members by visibility (public, protected, private).
667
+ *
668
+ * @param members - Array of members to group
669
+ * @returns Object with public, protected, and private arrays
670
+ *
671
+ * @example
672
+ * ```ts
673
+ * const groups = groupByVisibility(classExport.members)
674
+ * groups.public // [{ name: 'foo', visibility: 'public' }]
675
+ * groups.private // [{ name: 'bar', visibility: 'private' }]
676
+ * ```
677
+ */
678
+ declare function groupByVisibility(members?: SpecMember2[]): {
679
+ public: SpecMember2[];
680
+ protected: SpecMember2[];
681
+ private: SpecMember2[];
682
+ };
683
+ /**
684
+ * Sort exports alphabetically by name.
685
+ *
686
+ * @param items - Array of items with a name property
687
+ * @returns New sorted array
688
+ */
689
+ declare function sortByName<T extends {
690
+ name: string;
691
+ }>(items: T[]): T[];
692
+ /**
693
+ * Conditional type structure from the spec.
694
+ */
695
+ interface SpecConditionalType {
696
+ checkType: SpecSchema;
697
+ extendsType: SpecSchema;
698
+ trueType: SpecSchema;
699
+ falseType: SpecSchema;
700
+ }
701
+ /**
702
+ * Mapped type structure from the spec.
703
+ */
704
+ interface SpecMappedType {
705
+ keyType: SpecSchema;
706
+ valueType: SpecSchema;
707
+ readonly?: boolean | "add" | "remove";
708
+ optional?: boolean | "add" | "remove";
709
+ }
710
+ /**
711
+ * Format a conditional type to a human-readable string.
712
+ *
713
+ * @param condType - The conditional type structure
714
+ * @returns Formatted conditional type string
715
+ *
716
+ * @example
717
+ * ```ts
718
+ * formatConditionalType({
719
+ * checkType: { 'x-ts-type': 'T' },
720
+ * extendsType: { type: 'string' },
721
+ * trueType: { type: 'boolean', const: true },
722
+ * falseType: { type: 'boolean', const: false }
723
+ * })
724
+ * // 'T extends string ? true : false'
725
+ * ```
726
+ */
727
+ declare function formatConditionalType(condType: SpecConditionalType): string;
728
+ /**
729
+ * Format a mapped type to a human-readable string.
730
+ *
731
+ * @param mappedType - The mapped type structure
732
+ * @returns Formatted mapped type string
733
+ *
734
+ * @example
735
+ * ```ts
736
+ * formatMappedType({
737
+ * keyType: { 'x-ts-type': 'K in keyof T' },
738
+ * valueType: { 'x-ts-type': 'T[K]' },
739
+ * readonly: true
740
+ * })
741
+ * // '{ readonly [K in keyof T]: T[K] }'
742
+ * ```
743
+ */
744
+ declare function formatMappedType(mappedType: SpecMappedType): string;
745
+ import { SpecExport as SpecExport4, SpecType as SpecType3 } from "@openpkg-ts/spec";
746
+ interface GetExportOptions {
747
+ /** Entry point file path */
748
+ entryFile: string;
749
+ /** Export name to get */
750
+ exportName: string;
751
+ /** Base directory for resolution */
752
+ baseDir?: string;
753
+ /** Optional in-memory content (for testing) */
754
+ content?: string;
755
+ /** Max depth for type resolution */
756
+ maxTypeDepth?: number;
757
+ }
758
+ interface GetExportResult {
759
+ /** The spec, or null if not found */
760
+ export: SpecExport4 | null;
761
+ /** Related types referenced by the */
762
+ types: SpecType3[];
763
+ /** Errors encountered */
764
+ errors: string[];
765
+ }
766
+ /**
767
+ * Get detailed spec for a single */
768
+ declare function getExport2(options: GetExportOptions): Promise<GetExportResult>;
769
+ interface ListExportsOptions {
770
+ /** Entry point file path */
771
+ entryFile: string;
772
+ /** Base directory for resolution */
773
+ baseDir?: string;
774
+ /** Optional in-memory content (for testing) */
775
+ content?: string;
776
+ }
777
+ interface ExportItem {
778
+ /** Export name */
779
+ name: string;
780
+ /** Export kind */
781
+ kind: "function" | "class" | "interface" | "type" | "enum" | "variable" | "namespace";
782
+ /** Source file path */
783
+ file: string;
784
+ /** Line number (1-indexed) */
785
+ line: number;
786
+ /** JSDoc description (first line, max 80 chars) */
787
+ description?: string;
788
+ /** Whether is deprecated */
789
+ deprecated?: boolean;
790
+ /** Whether this is a re-from another module */
791
+ reexport?: boolean;
792
+ }
793
+ interface ListExportsResult {
794
+ exports: ExportItem[];
795
+ errors: string[];
796
+ }
797
+ /**
798
+ * List all exports from a TypeScript entry point
799
+ */
800
+ declare function listExports(options: ListExportsOptions): Promise<ListExportsResult>;
801
+ import { OpenPkg as OpenPkg8 } from "@openpkg-ts/spec";
802
+ interface ExtractOptions {
803
+ entryFile: string;
804
+ baseDir?: string;
805
+ content?: string;
806
+ maxTypeDepth?: number;
807
+ maxExternalTypeDepth?: number;
5
808
  resolveExternalTypes?: boolean;
809
+ schemaExtraction?: "static" | "hybrid";
810
+ /** Target JSON Schema dialect for runtime schema extraction */
811
+ schemaTarget?: "draft-2020-12" | "draft-07" | "openapi-3.0";
812
+ /** Include $schema URL in output */
813
+ includeSchema?: boolean;
814
+ /** Only extract these exports (supports * wildcards) */
815
+ only?: string[];
816
+ /** Ignore these exports (supports * wildcards) */
817
+ ignore?: string[];
818
+ /** Progress callback for tracking extraction progress */
819
+ onProgress?: (current: number, total: number, item: string) => void;
820
+ /** Whether source is a .d.ts file (degraded mode - TSDoc may be missing) */
821
+ isDtsSource?: boolean;
6
822
  }
7
- import { z } from "zod";
8
- import { OpenPkg } from "@openpkg-ts/spec";
9
- declare const openPkgSchema: z.ZodTypeAny;
10
- type OpenPkgSpec = OpenPkg;
11
- declare function extractPackageSpec(entryFile: string, packageDir?: string, content?: string, options?: OpenPkgOptions): Promise<OpenPkgSpec>;
12
- interface FilterOptions {
13
- include?: string[];
14
- exclude?: string[];
823
+ interface ExtractResult {
824
+ spec: OpenPkg8;
825
+ diagnostics: Diagnostic[];
826
+ forgottenExports?: ForgottenExport[];
827
+ /** Metadata about runtime schema extraction (when schemaExtraction: 'hybrid') */
828
+ runtimeSchemas?: {
829
+ /** Number of schema exports found */
830
+ extracted: number;
831
+ /** Number of schemas successfully merged with static types */
832
+ merged: number;
833
+ /** Schema vendors detected (e.g., 'zod', 'arktype', 'valibot', 'typebox') */
834
+ vendors: string[];
835
+ /** Any errors encountered during runtime extraction */
836
+ errors: string[];
837
+ /** Extraction method used: 'compiled' or 'direct-ts (runtime)' */
838
+ method?: string;
839
+ };
840
+ /** Degraded mode info when extracting from .d.ts files */
841
+ degradedMode?: {
842
+ reason: "dts-source";
843
+ stats: {
844
+ exportsWithoutDescription: number;
845
+ paramsWithoutDocs: number;
846
+ missingExamples: number;
847
+ };
848
+ };
849
+ /** Export verification comparing discovered vs extracted */
850
+ verification?: ExportVerification;
15
851
  }
16
852
  interface Diagnostic {
17
853
  message: string;
18
854
  severity: "error" | "warning" | "info";
855
+ code?: string;
856
+ suggestion?: string;
19
857
  location?: {
20
- file: string
21
- line?: number
22
- column?: number
858
+ file?: string;
859
+ line?: number;
860
+ column?: number;
23
861
  };
24
862
  }
25
- interface AnalysisResult {
26
- spec: OpenPkgSpec;
27
- diagnostics: Diagnostic[];
28
- metadata: AnalysisMetadata;
863
+ /** Context tracking for type references in public API */
864
+ interface TypeReference2 {
865
+ typeName: string;
866
+ exportName: string;
867
+ location: "return" | "parameter" | "property" | "extends" | "type-parameter";
868
+ path?: string;
29
869
  }
30
- interface AnalysisMetadata {
31
- baseDir: string;
32
- configPath?: string;
33
- packageJsonPath?: string;
34
- hasNodeModules: boolean;
870
+ /** Structured data for forgotten exports */
871
+ interface ForgottenExport {
872
+ name: string;
873
+ definedIn?: string;
874
+ referencedBy: TypeReference2[];
875
+ isExternal: boolean;
876
+ fix?: string;
877
+ }
878
+ /** Tracks status of each discovered through serialization pipeline */
879
+ interface ExportTracker {
880
+ name: string;
881
+ discovered: boolean;
882
+ status: "pending" | "success" | "skipped" | "failed";
883
+ skipReason?: "filtered" | "no-declaration" | "internal";
884
+ error?: string;
885
+ kind?: string;
886
+ }
887
+ /** Verification result comparing discovered vs extracted exports */
888
+ interface ExportVerification {
889
+ /** Total exports discovered by TypeScript */
890
+ discovered: number;
891
+ /** Exports successfully extracted */
892
+ extracted: number;
893
+ /** Exports skipped (filtered, no-declaration, internal) */
894
+ skipped: number;
895
+ /** Exports that failed during serialization */
896
+ failed: number;
897
+ /** Delta: discovered - extracted */
898
+ delta: number;
899
+ details: {
900
+ skipped: Array<{
901
+ name: string;
902
+ reason: "filtered" | "no-declaration" | "internal";
903
+ }>;
904
+ failed: Array<{
905
+ name: string;
906
+ error: string;
907
+ }>;
908
+ };
909
+ }
910
+ /**
911
+ * Extract full OpenPkg spec from a TypeScript entry point
912
+ *
913
+ * @example
914
+ * ```typescript
915
+ * import { extractSpec } from '@openpkg-ts/sdk';
916
+ *
917
+ * const result = await extractSpec({
918
+ * entryFile: './src/index.ts'
919
+ * });
920
+ *
921
+ * console.log(result.spec.exports.length);
922
+ * ```
923
+ */
924
+ declare const extractSpec: (options: ExtractOptions) => Promise<ExtractResult>;
925
+ import { SpecType as SpecType4 } from "@openpkg-ts/spec";
926
+ import ts2 from "typescript";
927
+ import ts from "typescript";
928
+ interface SerializerContext {
929
+ typeChecker: ts.TypeChecker;
930
+ program: ts.Program;
931
+ sourceFile: ts.SourceFile;
932
+ maxTypeDepth: number;
933
+ maxExternalTypeDepth: number;
934
+ currentDepth: number;
35
935
  resolveExternalTypes: boolean;
936
+ typeRegistry: TypeRegistry;
937
+ exportedIds: Set<string>;
938
+ /** Track visited types to prevent infinite recursion */
939
+ visitedTypes: Set<ts.Type>;
940
+ /** Flag to indicate we're processing tuple elements - skip Array prototype methods */
941
+ inTupleElement?: boolean;
942
+ }
943
+ declare class TypeRegistry {
944
+ private types;
945
+ private processing;
946
+ add(type: SpecType4): void;
947
+ get(id: string): SpecType4 | undefined;
948
+ has(id: string): boolean;
949
+ getAll(): SpecType4[];
950
+ /**
951
+ * Register a type from a ts.Type with structured schema.
952
+ * Returns the type ID if registered, undefined if skipped.
953
+ */
954
+ registerType(type: ts2.Type, ctx: SerializerContext): string | undefined;
955
+ /**
956
+ * Build a SpecType with structured schema using buildSchema.
957
+ */
958
+ private buildSpecType;
959
+ /**
960
+ * Check if schema is a self-referential $ref
961
+ */
962
+ private isSelfRef;
963
+ /**
964
+ * Build object schema from type properties (for interfaces/classes)
965
+ */
966
+ private buildObjectSchemaFromType;
967
+ }
968
+ import ts3 from "typescript";
969
+ /**
970
+ * Check if an symbol is a type-only (type { X }).
971
+ */
972
+ declare function isTypeOnlyExport(symbol: ts3.Symbol): boolean;
973
+ /**
974
+ * Follows aliases back to the declaration that carries the type info.
975
+ */
976
+ declare function resolveExportTarget(symbol: ts3.Symbol, checker: ts3.TypeChecker): {
977
+ declaration?: ts3.Declaration;
978
+ targetSymbol: ts3.Symbol;
979
+ isTypeOnly: boolean;
980
+ };
981
+ import { SpecExample, SpecSource, SpecTag, SpecTypeParameter as SpecTypeParameter2 } from "@openpkg-ts/spec";
982
+ import ts4 from "typescript";
983
+ declare function getJSDocComment(node: ts4.Node, symbol?: ts4.Symbol, checker?: ts4.TypeChecker): {
984
+ description?: string;
985
+ tags: SpecTag[];
986
+ examples: SpecExample[];
987
+ };
988
+ declare function getSourceLocation(node: ts4.Node, sourceFile: ts4.SourceFile): SpecSource;
989
+ /**
990
+ * Get description for a destructured parameter property from JSDoc @param tags.
991
+ * Matches patterns like:
992
+ * - @param paramName - exact match
993
+ * - @param opts.paramName - dotted notation with alias
994
+ * - @param {type} paramName - type annotation format
995
+ */
996
+ declare function getParamDescription(propertyName: string, jsdocTags: readonly ts4.JSDocTag[], inferredAlias?: string): string | undefined;
997
+ type DeclarationWithTypeParams = ts4.FunctionDeclaration | ts4.ClassDeclaration | ts4.InterfaceDeclaration | ts4.TypeAliasDeclaration | ts4.MethodDeclaration | ts4.ArrowFunction;
998
+ /**
999
+ * Extract type parameters from declarations like `<T extends Base, K = Default>`
1000
+ * Also captures variance annotations (in/out) and const modifier.
1001
+ */
1002
+ declare function extractTypeParameters(node: DeclarationWithTypeParams, checker: ts4.TypeChecker): SpecTypeParameter2[] | undefined;
1003
+ /**
1004
+ * Check if a symbol is marked as deprecated via @deprecated JSDoc tag.
1005
+ */
1006
+ declare function isSymbolDeprecated(symbol: ts4.Symbol | undefined): boolean;
1007
+ /**
1008
+ * Target version for JSON Schema generation.
1009
+ * @see https://standardschema.dev/json-schema
1010
+ */
1011
+ type StandardJSONSchemaTarget = "draft-2020-12" | "draft-07" | "openapi-3.0" | (string & {});
1012
+ /**
1013
+ * Options for JSON Schema generation methods.
1014
+ */
1015
+ interface StandardJSONSchemaOptions {
1016
+ /** Specifies the target version of the generated JSON Schema */
1017
+ readonly target: StandardJSONSchemaTarget;
1018
+ /** Vendor-specific parameters */
1019
+ readonly libraryOptions?: Record<string, unknown>;
1020
+ }
1021
+ /**
1022
+ * Standard JSON Schema v1 interface.
1023
+ * @see https://standardschema.dev/json-schema
1024
+ */
1025
+ interface StandardJSONSchemaV1<
1026
+ Input = unknown,
1027
+ Output = Input
1028
+ > {
1029
+ "~standard": {
1030
+ /** The version number of the standard (always 1) */
1031
+ version: 1;
1032
+ /** The vendor name of the schema library */
1033
+ vendor: string;
1034
+ /** Inferred types (optional) */
1035
+ types?: {
1036
+ input: Input;
1037
+ output: Output;
1038
+ };
1039
+ /** JSON Schema conversion methods */
1040
+ jsonSchema: {
1041
+ /** Converts input type to JSON Schema */
1042
+ input: (options: StandardJSONSchemaOptions) => Record<string, unknown>;
1043
+ /** Converts output type to JSON Schema */
1044
+ output: (options: StandardJSONSchemaOptions) => Record<string, unknown>;
1045
+ };
1046
+ };
1047
+ }
1048
+ /**
1049
+ * Result of extracting Standard Schema from an export.
1050
+ */
1051
+ interface StandardSchemaExtractionResult {
1052
+ exportName: string;
1053
+ vendor: string;
1054
+ outputSchema: Record<string, unknown>;
1055
+ inputSchema?: Record<string, unknown>;
1056
+ }
1057
+ /**
1058
+ * Options for runtime Standard Schema extraction.
1059
+ */
1060
+ interface ExtractStandardSchemasOptions {
1061
+ /** Timeout in milliseconds (default: 10000) */
1062
+ timeout?: number;
1063
+ /** JSON Schema target version (default: 'draft-2020-12') */
1064
+ target?: StandardJSONSchemaTarget;
1065
+ /** Vendor-specific options to pass through */
1066
+ libraryOptions?: Record<string, unknown>;
1067
+ }
1068
+ /**
1069
+ * Result of Standard Schema extraction.
1070
+ */
1071
+ interface StandardSchemaExtractionOutput {
1072
+ schemas: Map<string, StandardSchemaExtractionResult>;
1073
+ errors: string[];
1074
+ }
1075
+ /**
1076
+ * Check if an object implements StandardJSONSchemaV1.
1077
+ * This is a static type guard - doesn't require runtime.
1078
+ */
1079
+ declare function isStandardJSONSchema(obj: unknown): obj is StandardJSONSchemaV1;
1080
+ /**
1081
+ * TypeScript runtime configuration.
1082
+ */
1083
+ interface TsRuntime {
1084
+ /** Command to execute */
1085
+ cmd: string;
1086
+ /** Arguments to pass before the script path */
1087
+ args: string[];
1088
+ /** Human-readable name */
1089
+ name: string;
1090
+ }
1091
+ /**
1092
+ * Detect available TypeScript runtime.
1093
+ * Checks in order: Node 22+ native, bun, tsx, ts-node.
1094
+ * Returns null if no TS runtime is available.
1095
+ */
1096
+ declare function detectTsRuntime(): TsRuntime | null;
1097
+ /**
1098
+ * Extract Standard Schema from a TypeScript file directly.
1099
+ * Uses detected TS runtime (bun, tsx, ts-node, or node 22+).
1100
+ *
1101
+ * @param tsFilePath - Path to TypeScript file
1102
+ * @param options - Extraction options
1103
+ * @returns Extraction results
1104
+ */
1105
+ declare function extractStandardSchemasFromTs(tsFilePath: string, options?: ExtractStandardSchemasOptions): Promise<StandardSchemaExtractionOutput>;
1106
+ /**
1107
+ * Resolve compiled JS path from TypeScript source.
1108
+ * Reads tsconfig.json for outDir and tries multiple output patterns.
1109
+ * Supports .js, .mjs, and .cjs extensions.
1110
+ */
1111
+ declare function resolveCompiledPath(tsPath: string, baseDir: string): string | null;
1112
+ /**
1113
+ * Extract Standard Schema JSON Schemas from a compiled JS module.
1114
+ *
1115
+ * **Security Note**: This executes the module in a subprocess.
1116
+ * Only use with trusted code (user's own packages).
1117
+ *
1118
+ * @param compiledJsPath - Path to compiled .js file
1119
+ * @param options - Extraction options
1120
+ * @returns Extraction results with schemas and any errors
1121
+ */
1122
+ declare function extractStandardSchemas(compiledJsPath: string, options?: ExtractStandardSchemasOptions): Promise<StandardSchemaExtractionOutput>;
1123
+ /**
1124
+ * Result info from extractStandardSchemasFromProject
1125
+ */
1126
+ interface ProjectExtractionInfo {
1127
+ /** How schemas were extracted */
1128
+ method: "compiled" | "direct-ts";
1129
+ /** Runtime used (for direct-ts) */
1130
+ runtime?: string;
1131
+ /** Path that was used */
1132
+ path: string;
1133
+ }
1134
+ /**
1135
+ * Extended options for project extraction
1136
+ */
1137
+ interface ExtractFromProjectOptions extends ExtractStandardSchemasOptions {
1138
+ /** Prefer direct TS execution even if compiled JS exists */
1139
+ preferDirectTs?: boolean;
1140
+ }
1141
+ /**
1142
+ * Extended result for project extraction
1143
+ */
1144
+ interface ProjectExtractionOutput extends StandardSchemaExtractionOutput {
1145
+ /** Info about how extraction was performed */
1146
+ info?: ProjectExtractionInfo;
1147
+ }
1148
+ /**
1149
+ * Extract Standard Schema from a TypeScript project.
1150
+ *
1151
+ * Tries in order:
1152
+ * 1. Compiled JS (if found)
1153
+ * 2. Direct TypeScript execution (if TS runtime available)
1154
+ *
1155
+ * @param entryFile - TypeScript entry file path
1156
+ * @param baseDir - Project base directory
1157
+ * @param options - Extraction options
1158
+ */
1159
+ declare function extractStandardSchemasFromProject(entryFile: string, baseDir: string, options?: ExtractFromProjectOptions): Promise<ProjectExtractionOutput>;
1160
+ declare function extract(options: ExtractOptions): Promise<ExtractResult>;
1161
+ import ts5 from "typescript";
1162
+ interface ProgramOptions {
1163
+ entryFile: string;
1164
+ baseDir?: string;
1165
+ content?: string;
1166
+ }
1167
+ interface ProgramResult {
1168
+ program: ts5.Program;
1169
+ compilerHost: ts5.CompilerHost;
1170
+ compilerOptions: ts5.CompilerOptions;
1171
+ sourceFile?: ts5.SourceFile;
1172
+ configPath?: string;
1173
+ /** Resolved project references (workspace packages) */
1174
+ projectReferences?: ts5.ResolvedProjectReference[];
1175
+ }
1176
+ declare function createProgram({ entryFile, baseDir, content }: ProgramOptions): ProgramResult;
1177
+ import * as TS from "typescript";
1178
+ /**
1179
+ * A schema adapter can detect and extract output types from a specific
1180
+ * schema validation library.
1181
+ */
1182
+ interface SchemaAdapter {
1183
+ /** Unique identifier for this adapter */
1184
+ readonly id: string;
1185
+ /** npm package name(s) this adapter handles */
1186
+ readonly packages: readonly string[];
1187
+ /**
1188
+ * Check if a type matches this adapter's schema library.
1189
+ * Should be fast - called for every export.
1190
+ */
1191
+ matches(type: TS.Type, checker: TS.TypeChecker): boolean;
1192
+ /**
1193
+ * Extract the output type from a schema type.
1194
+ * Returns null if extraction fails.
1195
+ */
1196
+ extractOutputType(type: TS.Type, checker: TS.TypeChecker): TS.Type | null;
1197
+ /**
1198
+ * Extract the input type from a schema type (optional).
1199
+ * Useful for transforms where input differs from output.
1200
+ */
1201
+ extractInputType?(type: TS.Type, checker: TS.TypeChecker): TS.Type | null;
1202
+ }
1203
+ /**
1204
+ * Result of schema type extraction
1205
+ */
1206
+ interface SchemaExtractionResult {
1207
+ /** The adapter that matched */
1208
+ adapter: SchemaAdapter;
1209
+ /** The extracted output type */
1210
+ outputType: TS.Type;
1211
+ /** The extracted input type (if different from output) */
1212
+ inputType?: TS.Type;
1213
+ }
1214
+ /**
1215
+ * Utility: Check if type is an object type reference (has type arguments)
1216
+ */
1217
+ declare function isTypeReference(type: TS.Type): type is TS.TypeReference;
1218
+ /**
1219
+ * Utility: Remove undefined/null from a union type
1220
+ */
1221
+ declare function getNonNullableType(type: TS.Type): TS.Type;
1222
+ declare function registerAdapter(adapter: SchemaAdapter): void;
1223
+ declare function findAdapter(type: TS.Type, checker: TS.TypeChecker): SchemaAdapter | undefined;
1224
+ declare function isSchemaType(type: TS.Type, checker: TS.TypeChecker): boolean;
1225
+ declare function extractSchemaType(type: TS.Type, checker: TS.TypeChecker): SchemaExtractionResult | null;
1226
+ declare const arktypeAdapter: SchemaAdapter;
1227
+ declare const typeboxAdapter: SchemaAdapter;
1228
+ declare const valibotAdapter: SchemaAdapter;
1229
+ declare const zodAdapter: SchemaAdapter;
1230
+ import { SpecExport as SpecExport6 } from "@openpkg-ts/spec";
1231
+ import ts6 from "typescript";
1232
+ declare function serializeClass(node: ts6.ClassDeclaration, ctx: SerializerContext): SpecExport6 | null;
1233
+ import { SpecExport as SpecExport7 } from "@openpkg-ts/spec";
1234
+ import ts7 from "typescript";
1235
+ declare function serializeEnum(node: ts7.EnumDeclaration, ctx: SerializerContext): SpecExport7 | null;
1236
+ import { SpecExport as SpecExport8 } from "@openpkg-ts/spec";
1237
+ import ts8 from "typescript";
1238
+ declare function serializeFunctionExport(node: ts8.FunctionDeclaration | ts8.ArrowFunction, ctx: SerializerContext): SpecExport8 | null;
1239
+ import { SpecExport as SpecExport9 } from "@openpkg-ts/spec";
1240
+ import ts9 from "typescript";
1241
+ declare function serializeInterface(node: ts9.InterfaceDeclaration, ctx: SerializerContext): SpecExport9 | null;
1242
+ import { SpecExport as SpecExport10 } from "@openpkg-ts/spec";
1243
+ import ts10 from "typescript";
1244
+ declare function serializeTypeAlias(node: ts10.TypeAliasDeclaration, ctx: SerializerContext): SpecExport10 | null;
1245
+ import { SpecExport as SpecExport11 } from "@openpkg-ts/spec";
1246
+ import ts11 from "typescript";
1247
+ declare function serializeVariable(node: ts11.VariableDeclaration, statement: ts11.VariableStatement, ctx: SerializerContext): SpecExport11 | null;
1248
+ import { SpecSignatureParameter } from "@openpkg-ts/spec";
1249
+ import ts12 from "typescript";
1250
+ declare function extractParameters(signature: ts12.Signature, ctx: SerializerContext): SpecSignatureParameter[];
1251
+ /**
1252
+ * Recursively register types referenced by a ts.Type.
1253
+ * Uses ctx.visitedTypes to prevent infinite recursion on circular types.
1254
+ */
1255
+ declare function registerReferencedTypes(type: ts12.Type, ctx: SerializerContext, depth?: number): void;
1256
+ import { SpecSchema as SpecSchema2 } from "@openpkg-ts/spec";
1257
+ import ts13 from "typescript";
1258
+ /**
1259
+ * Built-in type schemas with JSON Schema format hints.
1260
+ * Used for types that have specific serialization formats.
1261
+ */
1262
+ declare const BUILTIN_TYPE_SCHEMAS: Record<string, SpecSchema2>;
1263
+ declare const ARRAY_PROTOTYPE_METHODS: Set<string>;
1264
+ /**
1265
+ * Check if a name is a primitive type
1266
+ */
1267
+ declare function isPrimitiveName(name: string): boolean;
1268
+ /**
1269
+ * Get the origin package name for a type if it comes from node_modules.
1270
+ * Returns undefined for types defined in the current project.
1271
+ *
1272
+ * @example
1273
+ * getTypeOrigin(trpcRouterType) // Returns '@trpc/server'
1274
+ * getTypeOrigin(localUserType) // Returns undefined
1275
+ */
1276
+ declare function getTypeOrigin(type: ts13.Type, _checker: ts13.TypeChecker): string | undefined;
1277
+ /**
1278
+ * Check if a name is a built-in generic type
1279
+ */
1280
+ declare function isBuiltinGeneric(name: string): boolean;
1281
+ /**
1282
+ * Check if a type is anonymous (no meaningful symbol name)
1283
+ */
1284
+ declare function isAnonymous(type: ts13.Type): boolean;
1285
+ /**
1286
+ * Ensure schema is non-empty — fallback to x-ts-type string representation if empty.
1287
+ * Never emit {} as a schema; always include meaningful type info.
1288
+ */
1289
+ declare function ensureNonEmptySchema(schema: SpecSchema2, type: ts13.Type, checker: ts13.TypeChecker): SpecSchema2;
1290
+ /**
1291
+ * Build a structured SpecSchema from a TypeScript type.
1292
+ * Uses $ref for named types and typeArguments for generics.
1293
+ * Guarantees non-empty schema output via ensureNonEmptySchema wrapper.
1294
+ */
1295
+ declare function buildSchema(type: ts13.Type, checker: ts13.TypeChecker, ctx?: SerializerContext, _depth?: number): SpecSchema2;
1296
+ /**
1297
+ * Check if a schema is a pure $ref (only has $ref property)
1298
+ */
1299
+ declare function isPureRefSchema(schema: SpecSchema2): schema is {
1300
+ $ref: string;
1301
+ };
1302
+ /**
1303
+ * Add description to a schema, handling $ref properly.
1304
+ * For pure $ref schemas, wraps in allOf to preserve the reference.
1305
+ */
1306
+ declare function withDescription(schema: SpecSchema2, description: string): SpecSchema2;
1307
+ /**
1308
+ * Check if a schema represents the 'any' type
1309
+ */
1310
+ declare function schemaIsAny(schema: SpecSchema2): boolean;
1311
+ /**
1312
+ * Deep equality comparison for schemas
1313
+ */
1314
+ declare function schemasAreEqual(left: SpecSchema2, right: SpecSchema2): boolean;
1315
+ /**
1316
+ * Remove duplicate schemas from an array while preserving order.
1317
+ */
1318
+ declare function deduplicateSchemas(schemas: SpecSchema2[]): SpecSchema2[];
1319
+ /**
1320
+ * Find a discriminator property in a union of object types (tagged union pattern).
1321
+ * A valid discriminator has a unique literal value in each union member.
1322
+ */
1323
+ declare function findDiscriminatorProperty(unionTypes: ts13.Type[], checker: ts13.TypeChecker): string | undefined;
1324
+ import { SpecExport as SpecExport12, SpecMember as SpecMember3, SpecSchema as SpecSchema3, SpecType as SpecType5 } from "@openpkg-ts/spec";
1325
+ /**
1326
+ * Options for schema normalization
1327
+ */
1328
+ interface NormalizeOptions {
1329
+ /** Include $schema field in output */
1330
+ includeSchemaField?: boolean;
1331
+ /** Target JSON Schema dialect (default: 'draft-2020-12') */
1332
+ dialect?: "draft-2020-12" | "draft-07";
36
1333
  }
37
- interface AnalyzeOptions {
38
- filters?: FilterOptions;
39
- }
40
- declare class OpenPkg2 {
41
- private readonly options;
42
- constructor(options?: OpenPkgOptions);
43
- analyze(code: string, fileName?: string, analyzeOptions?: AnalyzeOptions): Promise<OpenPkgSpec>;
44
- analyzeFile(filePath: string, analyzeOptions?: AnalyzeOptions): Promise<OpenPkgSpec>;
45
- analyzeProject(entryPath: string, analyzeOptions?: AnalyzeOptions): Promise<OpenPkgSpec>;
46
- analyzeWithDiagnostics(code: string, fileName?: string, analyzeOptions?: AnalyzeOptions): Promise<AnalysisResult>;
47
- analyzeFileWithDiagnostics(filePath: string, analyzeOptions?: AnalyzeOptions): Promise<AnalysisResult>;
48
- private normalizeDiagnostic;
49
- private mapSeverity;
50
- private normalizeMetadata;
51
- private applySpecFilters;
52
- }
53
- declare function analyze(code: string, options?: AnalyzeOptions): Promise<OpenPkgSpec>;
54
- declare function analyzeFile(filePath: string, options?: AnalyzeOptions): Promise<OpenPkgSpec>;
55
- export { openPkgSchema, extractPackageSpec, analyzeFile, analyze, OpenPkgSpec, OpenPkgOptions, OpenPkg2 as OpenPkg, FilterOptions, Diagnostic, AnalyzeOptions, AnalysisResult };
1334
+ /**
1335
+ * JSON Schema 2020-12 compatible output type.
1336
+ * Uses Record<string, unknown> for flexibility since JSON Schema is highly polymorphic.
1337
+ */
1338
+ type JSONSchema = Record<string, unknown>;
1339
+ /**
1340
+ * Normalize a SpecSchema to JSON Schema 2020-12.
1341
+ *
1342
+ * @param schema - The SpecSchema to normalize
1343
+ * @param options - Normalization options
1344
+ * @returns JSON Schema 2020-12 compatible schema
1345
+ */
1346
+ declare function normalizeSchema(schema: SpecSchema3, options?: NormalizeOptions): JSONSchema;
1347
+ /**
1348
+ * Normalize a SpecExport, normalizing its schema and nested schemas.
1349
+ *
1350
+ * For interfaces and classes, this function will:
1351
+ * 1. Normalize any existing schema
1352
+ * 2. Normalize member schemas
1353
+ * 3. Generate a JSON Schema from members if members exist (populates `schema` field)
1354
+ */
1355
+ declare function normalizeExport(exp: SpecExport12, options?: NormalizeOptions): SpecExport12;
1356
+ /**
1357
+ * Normalize a SpecType, normalizing its schema and nested schemas.
1358
+ *
1359
+ * For interfaces and classes, this function will:
1360
+ * 1. Normalize any existing schema
1361
+ * 2. Normalize member schemas
1362
+ * 3. Generate a JSON Schema from members if members exist (populates `schema` field)
1363
+ */
1364
+ declare function normalizeType(type: SpecType5, options?: NormalizeOptions): SpecType5;
1365
+ /**
1366
+ * Convert a members array to JSON Schema properties format.
1367
+ *
1368
+ * This function transforms the SpecMember[] array representation used by
1369
+ * interfaces/classes into a JSON Schema 2020-12 object schema with properties,
1370
+ * required array, and additionalProperties.
1371
+ *
1372
+ * Member Kind Mappings:
1373
+ * | Member Kind | JSON Schema Output |
1374
+ * |--------------------|-------------------------------------------------------|
1375
+ * | property | Direct schema in properties |
1376
+ * | method | { "x-ts-function": true, "x-ts-signatures": [...] } |
1377
+ * | getter | Schema in properties (read-only via extension) |
1378
+ * | setter | Schema in properties (write-only via extension) |
1379
+ * | index | additionalProperties schema |
1380
+ *
1381
+ * @param members - The members array from an interface/class
1382
+ * @param options - Normalization options
1383
+ * @returns JSON Schema object with properties, required, and additionalProperties
1384
+ */
1385
+ declare function normalizeMembers(members: SpecMember3[], options?: NormalizeOptions): JSONSchema;
1386
+ import ts14 from "typescript";
1387
+ declare function isExported(node: ts14.Node): boolean;
1388
+ declare function getNodeName(node: ts14.Node): string | undefined;
1389
+ export { zodAdapter, 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, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, loadSpec, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isProperty, isPrimitiveName, isMethod, isExported, isBuiltinGeneric, isAnonymous, groupByVisibility, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExport2 as getExport, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findDiscriminatorProperty, findAdapter, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, buildSignatureString, buildSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecDiff, SpecConditionalType, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaExtractionResult, SchemaAdapter, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, Diagnostic, CategorizedBreaking, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };