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