@abapify/ts-xsd 0.4.0 → 0.4.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.
@@ -0,0 +1,1183 @@
1
+ import { $ as Notation, A as ComplexContentExtension, B as Group, C as Any, D as Attribute, E as Assertion, F as Element, G as Keyref, H as Import, I as ExplicitGroup, J as LocalComplexType, K as List, L as Facet, M as ComplexType, N as DefaultOpenContent, O as AttributeGroupRef, P as Documentation, Q as NamedGroup, R as Field, S as Annotation, T as Appinfo, U as Include, V as GroupRef, W as Key, X as LocalSimpleType, Y as LocalElement, Z as NamedAttributeGroup, _ as TransformContext, _t as Union, a as getSubstitutes, at as Schema, b as Alternative, c as CodegenConfig, ct as SimpleContent, d as GeneratorPlugin, dt as SimpleType, et as OpenAttrs, f as HookContext, ft as SimpleTypeRestriction, g as SourceInfo, gt as TopLevelSimpleType, h as SourceConfig, ht as TopLevelElement, i as ResolveOptions, it as Redefine, j as ComplexContentRestriction, k as ComplexContent, l as FinalizeContext, lt as SimpleContentExtension, m as SetupContext, mt as TopLevelComplexType, n as RunnerResult, nt as Override, o as resolveSchema, ot as SchemaAttrs, p as SchemaInfo, pt as TopLevelAttribute, q as LocalAttribute, r as runCodegen, rt as Pattern, s as AfterAllContext, st as Selector, t as RunnerOptions, tt as OpenContent, u as GeneratedFile, ut as SimpleContentRestriction, v as defineConfig, vt as Unique, w as AnyAttribute, x as Annotated, y as All, yt as XmlnsDeclarations, z as FormChoice } from "./runner-C4_p2y5e.mjs";
2
+ import { Project, SourceFile } from "ts-morph";
3
+
4
+ //#region src/xsd/schema-like.d.ts
5
+ /**
6
+ * Schema-Like Types for Type Inference
7
+ *
8
+ * These are minimal type constraints designed to work with `as const` schema literals.
9
+ * They are intentionally looser than the full W3C types in xsd/types.ts to allow
10
+ * TypeScript's compile-time type inference to work correctly.
11
+ *
12
+ * Key differences from xsd/types.ts:
13
+ * - All arrays are `readonly` for `as const` compatibility
14
+ * - Properties are optional and loosely typed
15
+ * - Designed for compile-time inference, not runtime validation
16
+ */
17
+ /**
18
+ * Non-W3C extensions for schema composition and namespace handling.
19
+ * Properties prefixed with $ are clearly non-W3C.
20
+ */
21
+ type SchemaExtensions = {
22
+ /**
23
+ * Namespace prefix declarations (xmlns:prefix -> namespace URI).
24
+ * Extracted from XML namespace attributes, not part of XSD spec.
25
+ * Prefixed with $ to indicate this is NOT a W3C XSD property.
26
+ */
27
+ readonly $xmlns?: {
28
+ readonly [prefix: string]: string;
29
+ };
30
+ /**
31
+ * Original filename/path of this schema.
32
+ * Used to reconstruct $imports relationships from schemaLocation references.
33
+ * Prefixed with $ to indicate this is NOT a W3C XSD property.
34
+ */
35
+ readonly $filename?: string;
36
+ /**
37
+ * Resolved imported schemas for cross-schema type resolution.
38
+ * Actual schema objects that can be searched for type definitions.
39
+ * Use this to link schemas that import each other (xs:import - different namespace).
40
+ */
41
+ readonly $imports?: readonly SchemaLike[];
42
+ /**
43
+ * Resolved included schemas for same-namespace type resolution.
44
+ * Content from xs:include is in the same namespace as the including schema.
45
+ * Walker traverses both $imports and $includes for type lookups.
46
+ */
47
+ readonly $includes?: readonly SchemaLike[];
48
+ };
49
+ /** Minimal schema shape for inference - W3C Schema properties plus extensions */
50
+ type SchemaLike = SchemaExtensions & {
51
+ readonly targetNamespace?: string;
52
+ readonly elementFormDefault?: string;
53
+ readonly attributeFormDefault?: string;
54
+ readonly version?: string;
55
+ readonly id?: string;
56
+ readonly blockDefault?: string;
57
+ readonly finalDefault?: string;
58
+ readonly 'xml:lang'?: string;
59
+ readonly element?: readonly ElementLike[];
60
+ readonly complexType?: readonly ComplexTypeLike[] | {
61
+ readonly [name: string]: ComplexTypeLike;
62
+ };
63
+ readonly simpleType?: readonly SimpleTypeLike[] | {
64
+ readonly [name: string]: SimpleTypeLike;
65
+ };
66
+ readonly group?: readonly unknown[];
67
+ readonly attributeGroup?: readonly unknown[];
68
+ readonly notation?: readonly unknown[];
69
+ readonly annotation?: readonly unknown[];
70
+ readonly include?: readonly unknown[];
71
+ readonly import?: readonly unknown[];
72
+ readonly redefine?: readonly RedefineLike[];
73
+ readonly override?: readonly OverrideLike[];
74
+ readonly defaultOpenContent?: unknown;
75
+ };
76
+ type AnnotationLike = {
77
+ readonly documentation?: readonly unknown[];
78
+ readonly appinfo?: readonly unknown[];
79
+ };
80
+ type ElementLike = {
81
+ readonly name?: string;
82
+ readonly ref?: string;
83
+ readonly type?: string;
84
+ readonly minOccurs?: number | string;
85
+ readonly maxOccurs?: number | string | 'unbounded';
86
+ readonly default?: string;
87
+ readonly fixed?: string;
88
+ readonly id?: string;
89
+ readonly abstract?: boolean;
90
+ readonly nillable?: boolean;
91
+ readonly substitutionGroup?: string;
92
+ readonly complexType?: ComplexTypeLike;
93
+ readonly simpleType?: SimpleTypeLike;
94
+ readonly annotation?: AnnotationLike;
95
+ readonly key?: readonly unknown[];
96
+ readonly keyref?: readonly unknown[];
97
+ readonly unique?: readonly unknown[];
98
+ };
99
+ type ComplexTypeLike = {
100
+ readonly name?: string;
101
+ readonly id?: string;
102
+ readonly abstract?: boolean;
103
+ readonly mixed?: boolean;
104
+ readonly sequence?: GroupLike;
105
+ readonly choice?: GroupLike;
106
+ readonly all?: GroupLike;
107
+ readonly group?: GroupRefLike;
108
+ readonly attribute?: readonly AttributeLike[];
109
+ readonly attributeGroup?: readonly unknown[];
110
+ readonly anyAttribute?: AnyAttributeLike;
111
+ readonly complexContent?: {
112
+ readonly extension?: ExtensionLike;
113
+ readonly restriction?: ExtensionLike;
114
+ };
115
+ readonly simpleContent?: {
116
+ readonly extension?: SimpleExtensionLike;
117
+ readonly restriction?: unknown;
118
+ };
119
+ readonly annotation?: AnnotationLike;
120
+ };
121
+ type GroupLike = {
122
+ readonly minOccurs?: number | string;
123
+ readonly maxOccurs?: number | string | 'unbounded';
124
+ readonly element?: readonly ElementLike[];
125
+ readonly choice?: readonly GroupLike[];
126
+ readonly sequence?: readonly GroupLike[];
127
+ readonly group?: readonly GroupRefLike[];
128
+ readonly any?: readonly unknown[];
129
+ readonly annotation?: AnnotationLike;
130
+ };
131
+ type GroupRefLike = {
132
+ readonly ref?: string;
133
+ readonly minOccurs?: number | string;
134
+ readonly maxOccurs?: number | string | 'unbounded';
135
+ };
136
+ type AttributeLike = {
137
+ readonly name?: string;
138
+ readonly ref?: string;
139
+ readonly type?: string;
140
+ readonly use?: 'prohibited' | 'optional' | 'required';
141
+ readonly default?: string;
142
+ readonly fixed?: string;
143
+ readonly id?: string;
144
+ readonly simpleType?: SimpleTypeLike;
145
+ readonly annotation?: AnnotationLike;
146
+ };
147
+ type AnyAttributeLike = {
148
+ readonly namespace?: string;
149
+ readonly processContents?: 'strict' | 'lax' | 'skip';
150
+ };
151
+ type ExtensionLike = {
152
+ readonly base?: string;
153
+ readonly sequence?: GroupLike;
154
+ readonly choice?: GroupLike;
155
+ readonly all?: GroupLike;
156
+ readonly group?: GroupRefLike;
157
+ readonly attribute?: readonly AttributeLike[];
158
+ readonly attributeGroup?: readonly unknown[];
159
+ readonly anyAttribute?: AnyAttributeLike;
160
+ readonly annotation?: AnnotationLike;
161
+ };
162
+ type SimpleExtensionLike = {
163
+ readonly base?: string;
164
+ readonly attribute?: readonly AttributeLike[];
165
+ readonly attributeGroup?: readonly unknown[];
166
+ readonly anyAttribute?: AnyAttributeLike;
167
+ };
168
+ type SimpleTypeLike = {
169
+ readonly name?: string;
170
+ readonly id?: string;
171
+ readonly annotation?: AnnotationLike;
172
+ readonly restriction?: {
173
+ readonly base?: string;
174
+ readonly enumeration?: readonly {
175
+ value: string;
176
+ }[];
177
+ readonly pattern?: readonly unknown[];
178
+ readonly minLength?: readonly unknown[];
179
+ readonly maxLength?: readonly unknown[];
180
+ readonly minInclusive?: readonly unknown[];
181
+ readonly maxInclusive?: readonly unknown[];
182
+ readonly minExclusive?: readonly unknown[];
183
+ readonly maxExclusive?: readonly unknown[];
184
+ readonly whiteSpace?: readonly unknown[];
185
+ readonly simpleType?: SimpleTypeLike;
186
+ };
187
+ readonly list?: {
188
+ readonly itemType?: string;
189
+ readonly simpleType?: SimpleTypeLike;
190
+ };
191
+ readonly union?: {
192
+ readonly memberTypes?: string;
193
+ readonly simpleType?: readonly SimpleTypeLike[];
194
+ };
195
+ };
196
+ /**
197
+ * xs:redefine - Redefine types from an included schema (XSD 1.0)
198
+ * Types defined here override the original definitions from schemaLocation.
199
+ */
200
+ type RedefineLike = {
201
+ readonly id?: string;
202
+ readonly schemaLocation?: string;
203
+ readonly annotation?: readonly AnnotationLike[];
204
+ readonly simpleType?: readonly SimpleTypeLike[];
205
+ readonly complexType?: readonly ComplexTypeLike[];
206
+ readonly group?: readonly unknown[];
207
+ readonly attributeGroup?: readonly unknown[];
208
+ };
209
+ /**
210
+ * xs:override - Override types from an included schema (XSD 1.1)
211
+ * More powerful than redefine - can override elements, attributes, notations.
212
+ */
213
+ type OverrideLike = {
214
+ readonly id?: string;
215
+ readonly schemaLocation?: string;
216
+ readonly annotation?: readonly AnnotationLike[];
217
+ readonly simpleType?: readonly SimpleTypeLike[];
218
+ readonly complexType?: readonly ComplexTypeLike[];
219
+ readonly group?: readonly unknown[];
220
+ readonly attributeGroup?: readonly unknown[];
221
+ readonly element?: readonly ElementLike[];
222
+ readonly attribute?: readonly AttributeLike[];
223
+ readonly notation?: readonly unknown[];
224
+ };
225
+ //#endregion
226
+ //#region src/xsd/parse.d.ts
227
+ /**
228
+ * Parse an XSD string to a typed Schema object
229
+ */
230
+ declare function parseXsd(xml: string): Schema;
231
+ //#endregion
232
+ //#region src/xsd/build.d.ts
233
+ interface BuildOptions {
234
+ /** XML namespace prefix for XSD elements (default: 'xs') */
235
+ prefix?: string;
236
+ /** Pretty print with indentation (default: true) */
237
+ pretty?: boolean;
238
+ /** Indentation string (default: ' ') */
239
+ indent?: string;
240
+ }
241
+ /**
242
+ * Build an XSD string from a typed Schema object
243
+ */
244
+ declare function buildXsd(schema: Schema, options?: BuildOptions): string;
245
+ //#endregion
246
+ //#region src/xsd/helpers.d.ts
247
+ /**
248
+ * Resolve $imports for a schema by matching import schemaLocation to $filename.
249
+ *
250
+ * @param schema - The schema to resolve imports for
251
+ * @param availableSchemas - Array of schemas that may be imported
252
+ * @returns A new schema object with $imports populated
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const orderSchema = parseXsd(orderXsd);
257
+ * const commonSchema = { ...parseXsd(commonXsd), $filename: 'common.xsd' };
258
+ *
259
+ * // orderSchema has: import: [{ schemaLocation: 'common.xsd', ... }]
260
+ * const resolved = resolveImports(orderSchema, [commonSchema]);
261
+ * // resolved.$imports = [commonSchema]
262
+ * ```
263
+ */
264
+ declare function resolveImports<T extends Schema>(schema: T, availableSchemas: readonly Schema[]): T & {
265
+ $imports: readonly Schema[];
266
+ };
267
+ /**
268
+ * Resolve $imports for multiple schemas, linking them together.
269
+ *
270
+ * @param schemas - Array of schemas to link together
271
+ * @returns Array of schemas with $imports populated
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * const schemas = [
276
+ * { ...parseXsd(orderXsd), $filename: 'order.xsd' },
277
+ * { ...parseXsd(commonXsd), $filename: 'common.xsd' },
278
+ * ];
279
+ * const linked = linkSchemas(schemas);
280
+ * // Each schema now has $imports resolved
281
+ * ```
282
+ */
283
+ declare function linkSchemas<T extends Schema>(schemas: readonly T[]): (T & {
284
+ $imports: readonly Schema[];
285
+ })[];
286
+ //#endregion
287
+ //#region src/xsd/loader.d.ts
288
+ /** Function to load XSD content from a schemaLocation path */
289
+ type XsdLoader = (schemaLocation: string, basePath: string) => string | null;
290
+ /** Options for schema loading */
291
+ interface LoaderOptions {
292
+ /** Base directory for resolving relative paths */
293
+ basePath?: string;
294
+ /** Custom loader function (default: reads from filesystem) */
295
+ loader?: XsdLoader;
296
+ /**
297
+ * Automatically link schemaLocation references (default: false)
298
+ * Populates $imports/$includes with actual Schema objects.
299
+ * The schema structure is preserved - use this when you need cross-schema type resolution.
300
+ */
301
+ autoLink?: boolean;
302
+ /**
303
+ * Fully resolve the schema after linking (default: false)
304
+ * Flattens all imports/includes into a single self-contained schema.
305
+ * Use this when you need a single schema with all types merged.
306
+ * Implies autoLink: true.
307
+ */
308
+ autoResolve?: boolean;
309
+ /** Throw error if referenced schema cannot be loaded (default: false) */
310
+ throwOnMissing?: boolean;
311
+ }
312
+ /**
313
+ * Default XSD loader - reads from filesystem
314
+ */
315
+ declare function defaultLoader(schemaLocation: string, basePath: string): string | null;
316
+ /**
317
+ * Load and parse a single XSD file.
318
+ *
319
+ * @param schemaPath - Path to the XSD file
320
+ * @param options - Loader options
321
+ * @param options.autoLink - Populate $imports/$includes with loaded schemas (preserves structure)
322
+ * @param options.autoResolve - Flatten into single schema with all types merged (implies autoLink)
323
+ * @returns Parsed schema
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * // Just parse - no linking
328
+ * const schema = loadSchema('/path/to/schema.xsd');
329
+ *
330
+ * // Link - populate $imports/$includes (preserves multi-schema structure)
331
+ * const linked = loadSchema('/path/to/schema.xsd', { autoLink: true });
332
+ * // linked.$imports contains actual Schema objects
333
+ *
334
+ * // Resolve - flatten everything into one schema
335
+ * const resolved = loadSchema('/path/to/schema.xsd', { autoResolve: true });
336
+ * // resolved has all types merged, no $imports/$includes
337
+ * ```
338
+ */
339
+ declare function loadSchema(schemaPath: string, options?: LoaderOptions): Schema;
340
+ /**
341
+ * Load and parse XSD content from a string.
342
+ */
343
+ declare function parseSchemaContent(content: string, filename?: string): Schema;
344
+ /**
345
+ * Create a schema loader function that can be passed to the resolver.
346
+ * The resolver will call this to load schemas referenced by schemaLocation.
347
+ */
348
+ declare function createSchemaLoader(basePath: string, loader?: XsdLoader): (schemaLocation: string) => Schema | null;
349
+ /** Options for schema linking */
350
+ interface LinkOptions {
351
+ /** Base directory for resolving relative schemaLocation paths */
352
+ basePath: string;
353
+ /** Custom loader function (default: reads from filesystem) */
354
+ loader?: XsdLoader;
355
+ /** Whether to throw on missing schemas (default: false - skip missing) */
356
+ throwOnMissing?: boolean;
357
+ }
358
+ /**
359
+ * Link a schema by resolving all schemaLocation references.
360
+ *
361
+ * Processes:
362
+ * - xs:import → populates $imports
363
+ * - xs:include → populates $includes
364
+ * - xs:redefine → loads base schema, keeps redefinitions in redefine array
365
+ * - xs:override → loads base schema, keeps overrides in override array
366
+ *
367
+ * @param schema - Schema to link (will be mutated with $imports/$includes)
368
+ * @param options - Link options including basePath for resolving paths
369
+ * @returns The same schema with $imports and $includes populated
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * const schema = parseXsd(xsdContent);
374
+ * linkSchema(schema, { basePath: '/path/to/xsd/files' });
375
+ * // schema.$imports and schema.$includes are now populated
376
+ * ```
377
+ */
378
+ declare function linkSchema(schema: Schema, options: LinkOptions): Schema;
379
+ /**
380
+ * Load and link a schema from a file path.
381
+ * Convenience function that combines loadSchema + linkSchema.
382
+ *
383
+ * @param schemaPath - Path to the XSD file
384
+ * @param options - Optional loader options
385
+ * @returns Fully linked schema with $imports and $includes populated
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * const schema = loadAndLinkSchema('/path/to/schema.xsd');
390
+ * // schema.$imports and schema.$includes are populated
391
+ * // Ready for type inference or resolution
392
+ * ```
393
+ */
394
+ declare function loadAndLinkSchema(schemaPath: string, options?: Omit<LoaderOptions, 'basePath'>): Schema;
395
+ //#endregion
396
+ //#region src/xsd/traverser.d.ts
397
+ /** Source of a node in the schema hierarchy */
398
+ type NodeSource = 'direct' | 'redefine' | 'override' | 'include' | 'import';
399
+ /** Traversal options */
400
+ interface TraverseOptions {
401
+ /** Include $imports in traversal (default: true) */
402
+ readonly includeImports?: boolean;
403
+ /** Include $includes in traversal (default: true) */
404
+ readonly includeIncludes?: boolean;
405
+ /** Maximum depth to traverse (default: unlimited) */
406
+ readonly maxDepth?: number;
407
+ }
408
+ /**
409
+ * Base class for OO schema traversal using real W3C XSD types.
410
+ *
411
+ * Subclass and override the `on*` methods you need.
412
+ * Context is available via `this` - no parameter passing needed.
413
+ */
414
+ declare abstract class SchemaTraverser {
415
+ /** Root schema being traversed */
416
+ protected rootSchema: Schema;
417
+ /** Current schema being visited */
418
+ protected currentSchema: Schema;
419
+ /** Source of current node (direct, redefine, override, include, import) */
420
+ protected source: NodeSource;
421
+ /** Depth in schema hierarchy (0 = root) */
422
+ protected depth: number;
423
+ /** Traversal options */
424
+ protected options: Required<TraverseOptions>;
425
+ /** Visited schemas (prevents infinite loops) */
426
+ private readonly visited;
427
+ /**
428
+ * Traverse a schema and all its imports/includes.
429
+ * Override `on*` methods to handle specific node types.
430
+ */
431
+ traverse(schema: Schema, options?: TraverseOptions): this;
432
+ /** Called when entering a schema */
433
+ protected onEnterSchema(_schema: Schema): void;
434
+ /** Called when leaving a schema */
435
+ protected onLeaveSchema(_schema: Schema): void;
436
+ /** Called for each top-level complexType */
437
+ protected onComplexType(_ct: TopLevelComplexType): void;
438
+ /** Called for each top-level simpleType */
439
+ protected onSimpleType(_st: TopLevelSimpleType): void;
440
+ /** Called for each top-level element */
441
+ protected onElement(_element: TopLevelElement): void;
442
+ /** Called for each top-level attribute */
443
+ protected onAttribute(_attr: TopLevelAttribute): void;
444
+ /** Called for each named group */
445
+ protected onGroup(_group: NamedGroup): void;
446
+ /** Called for each named attributeGroup */
447
+ protected onAttributeGroup(_group: NamedAttributeGroup): void;
448
+ /** Called for each redefine block */
449
+ protected onRedefine(_redefine: Redefine): void;
450
+ /** Called for each override block */
451
+ protected onOverride(_override: Override): void;
452
+ private traverseSchema;
453
+ private traverseSchemaChildren;
454
+ private traverseRedefines;
455
+ private traverseOverrides;
456
+ private traverseIncludes;
457
+ private traverseImports;
458
+ }
459
+ /** Result of schema resolution */
460
+ interface ResolvedSchema {
461
+ readonly complexTypes: Map<string, {
462
+ ct: TopLevelComplexType;
463
+ schema: Schema;
464
+ }>;
465
+ readonly simpleTypes: Map<string, {
466
+ st: TopLevelSimpleType;
467
+ schema: Schema;
468
+ }>;
469
+ readonly elements: Map<string, {
470
+ element: TopLevelElement;
471
+ schema: Schema;
472
+ }>;
473
+ readonly attributes: Map<string, {
474
+ attr: TopLevelAttribute;
475
+ schema: Schema;
476
+ }>;
477
+ readonly groups: Map<string, {
478
+ group: NamedGroup;
479
+ schema: Schema;
480
+ }>;
481
+ readonly attributeGroups: Map<string, {
482
+ group: NamedAttributeGroup;
483
+ schema: Schema;
484
+ }>;
485
+ readonly xmlns: Map<string, string>;
486
+ readonly substitutionGroups: Map<string, TopLevelElement[]>;
487
+ }
488
+ /**
489
+ * Resolves a schema hierarchy into a flat structure.
490
+ * All types are collected into Maps for O(1) lookup.
491
+ *
492
+ * Precedence rules:
493
+ * - redefine/override types take precedence over original
494
+ * - root schema types take precedence over imported/included
495
+ */
496
+ declare class SchemaResolver extends SchemaTraverser {
497
+ readonly complexTypes: Map<string, {
498
+ ct: TopLevelComplexType;
499
+ schema: Schema;
500
+ }>;
501
+ readonly simpleTypes: Map<string, {
502
+ st: TopLevelSimpleType;
503
+ schema: Schema;
504
+ }>;
505
+ readonly elements: Map<string, {
506
+ element: TopLevelElement;
507
+ schema: Schema;
508
+ }>;
509
+ readonly attributes: Map<string, {
510
+ attr: TopLevelAttribute;
511
+ schema: Schema;
512
+ }>;
513
+ readonly groups: Map<string, {
514
+ group: NamedGroup;
515
+ schema: Schema;
516
+ }>;
517
+ readonly attributeGroups: Map<string, {
518
+ group: NamedAttributeGroup;
519
+ schema: Schema;
520
+ }>;
521
+ readonly xmlns: Map<string, string>;
522
+ readonly substitutionGroups: Map<string, TopLevelElement[]>;
523
+ /** Get the resolved schema structure */
524
+ getResolved(): ResolvedSchema;
525
+ protected onEnterSchema(schema: Schema): void;
526
+ protected onComplexType(ct: TopLevelComplexType): void;
527
+ protected onSimpleType(st: TopLevelSimpleType): void;
528
+ protected onElement(element: TopLevelElement): void;
529
+ protected onAttribute(attr: TopLevelAttribute): void;
530
+ protected onGroup(group: NamedGroup): void;
531
+ protected onAttributeGroup(group: NamedAttributeGroup): void;
532
+ }
533
+ /**
534
+ * Resolve a schema hierarchy into a flat structure.
535
+ * Convenience function that creates a SchemaResolver and returns the result.
536
+ */
537
+ declare function resolveSchemaTypes(schema: Schema, options?: TraverseOptions): ResolvedSchema;
538
+ //#endregion
539
+ //#region src/infer/infer.d.ts
540
+ /**
541
+ * Infer TypeScript type from a W3C Schema.
542
+ *
543
+ * For schemas with multiple root elements, returns a union of all possible
544
+ * document types. Use type guards or discriminated unions to narrow.
545
+ *
546
+ * @example
547
+ * ```typescript
548
+ * const schema = {
549
+ * element: [
550
+ * { name: 'Person', type: 'PersonType' },
551
+ * { name: 'Company', type: 'CompanyType' }
552
+ * ],
553
+ * complexType: [...]
554
+ * } as const;
555
+ *
556
+ * type Data = InferSchema<typeof schema>;
557
+ * // PersonType | CompanyType (union of all root element types)
558
+ * ```
559
+ */
560
+ type InferSchema<T extends SchemaLike> = T['element'] extends readonly ElementLike[] ? InferRootElementTypes<T['element'], T> : unknown;
561
+ /**
562
+ * Infer union of all root element types (content only, not wrapped).
563
+ * Each root element's type is inferred and combined into a union.
564
+ * Use InferParsedSchema for parse() return type which wraps with element name.
565
+ */
566
+ type InferRootElementTypes<E extends readonly ElementLike[], T extends SchemaLike> = E[number] extends infer El ? El extends ElementLike ? El extends {
567
+ type: infer TypeName;
568
+ } ? TypeName extends string ? InferTypeName<TypeName, T> : El extends {
569
+ name: infer N;
570
+ } ? N extends string ? InferTypeName<N, T> : unknown : unknown : El extends {
571
+ name: infer N;
572
+ } ? N extends string ? InferTypeName<N, T> : unknown : unknown : unknown : unknown;
573
+ /**
574
+ * Infer wrapped type for parse() function output.
575
+ * Returns { ElementName: ContentType } to match parse() runtime behavior.
576
+ *
577
+ * @example
578
+ * ```typescript
579
+ * const result = parse(schema, xml);
580
+ * // result is { Person: { firstName: string, ... } }
581
+ * ```
582
+ */
583
+ type InferParsedSchema<T extends SchemaLike> = T['element'] extends readonly ElementLike[] ? InferWrappedRootElementTypes<T['element'], T> : unknown;
584
+ /**
585
+ * Infer wrapped root element types for parse() output.
586
+ * Each root element's type is wrapped with its name: { ElementName: ContentType }
587
+ */
588
+ type InferWrappedRootElementTypes<E extends readonly ElementLike[], T extends SchemaLike> = E[number] extends infer El ? El extends ElementLike ? El extends {
589
+ name: infer N;
590
+ } ? N extends string ? El extends {
591
+ type: infer TypeName;
592
+ } ? TypeName extends string ? { [K in N]: InferTypeName<TypeName, T> } : { [K in N]: InferTypeName<N, T> } : { [K in N]: InferTypeName<N, T> } : unknown : unknown : unknown : unknown;
593
+ /**
594
+ * Infer TypeScript type for a specific element by name.
595
+ *
596
+ * @example
597
+ * ```typescript
598
+ * type Person = InferElement<typeof schema, 'Person'>;
599
+ * ```
600
+ */
601
+ type InferElement<T extends SchemaLike, ElementName extends string> = FindByName<T['element'], ElementName> extends infer Found ? Found extends {
602
+ type: infer TypeName;
603
+ } ? TypeName extends string ? InferTypeName<TypeName, T> : InferTypeName<ElementName, T> : Found extends {
604
+ name: ElementName;
605
+ } ? InferTypeName<ElementName, T> : never : never;
606
+ /**
607
+ * Infer all elements as a union type.
608
+ *
609
+ * @example
610
+ * ```typescript
611
+ * type AnyElement = InferAllElements<typeof schema>;
612
+ * // Person | Address | ...
613
+ * ```
614
+ */
615
+ type InferAllElements<T extends SchemaLike> = T['element'] extends readonly {
616
+ name: string;
617
+ type?: string;
618
+ }[] ? T['element'][number] extends {
619
+ type?: infer TypeName;
620
+ } ? TypeName extends string ? InferTypeName<TypeName, T> : never : never : never;
621
+ /** Strip any namespace prefix from a type name (e.g., "tns:PersonType" -> "PersonType") */
622
+ type StripNsPrefix<T extends string> = T extends `${string}:${infer LocalName}` ? LocalName : T;
623
+ /** Resolve a type name to its TypeScript type */
624
+ type InferTypeName<TypeName extends string, T extends SchemaLike> = TypeName extends `xs:${infer BuiltIn}` | `xsd:${infer BuiltIn}` ? InferBuiltInType<BuiltIn> : TypeName extends keyof XsdBuiltInTypes ? XsdBuiltInTypes[TypeName] : FindComplexTypeWithSchema<StripNsPrefix<TypeName>, T> extends infer Result ? Result extends {
625
+ type: infer CT;
626
+ schema: infer S;
627
+ } ? CT extends ComplexTypeLike ? S extends SchemaLike ? InferComplexType<CT, S> : unknown : unknown : FindSimpleTypeWithSchema<StripNsPrefix<TypeName>, T> extends infer STResult ? STResult extends {
628
+ type: infer ST;
629
+ schema: infer _S;
630
+ } ? ST extends SimpleTypeLike ? InferSimpleType<ST> : unknown : unknown : unknown : unknown;
631
+ /** Find a complexType by name (searches in schema and $imports) */
632
+ type FindComplexType<Name extends string, T extends SchemaLike> = FindComplexTypeLocal<Name, T> extends infer Local ? [Local] extends [never] ? FindComplexTypeInImports<Name, T> : Local : never;
633
+ /** Find complexType WITH the schema it was found in (for proper context in inheritance) */
634
+ type FindComplexTypeWithSchema<Name extends string, T extends SchemaLike> = FindComplexTypeLocal<Name, T> extends infer Local ? [Local] extends [never] ? FindComplexTypeInImportsWithSchema<Name, T> : {
635
+ type: Local;
636
+ schema: T;
637
+ } : never;
638
+ /** Find complexType in $imports, returning both type and schema */
639
+ type FindComplexTypeInImportsWithSchema<Name extends string, T extends SchemaLike> = T['$imports'] extends readonly SchemaLike[] ? FindComplexTypeInSchemaArrayWithSchema<Name, T['$imports']> : never;
640
+ /** Search through array of schemas for complexType, returning both type and schema */
641
+ type FindComplexTypeInSchemaArrayWithSchema<Name extends string, Schemas extends readonly SchemaLike[]> = Schemas extends readonly [infer First, ...infer Rest] ? First extends SchemaLike ? FindComplexTypeWithSchema<Name, First> extends infer Found ? [Found] extends [never] ? Rest extends readonly SchemaLike[] ? FindComplexTypeInSchemaArrayWithSchema<Name, Rest> : never : Found extends {
642
+ type: ComplexTypeLike;
643
+ schema: SchemaLike;
644
+ } ? Found : Rest extends readonly SchemaLike[] ? FindComplexTypeInSchemaArrayWithSchema<Name, Rest> : never : never : never : never;
645
+ /** Find complexType in current schema only */
646
+ type FindComplexTypeLocal<Name extends string, T extends SchemaLike> = T['complexType'] extends readonly ComplexTypeLike[] ? FindInArray<T['complexType'], {
647
+ name: Name;
648
+ }> : T['complexType'] extends {
649
+ readonly [key: string]: ComplexTypeLike;
650
+ } ? Name extends keyof T['complexType'] ? T['complexType'][Name] : never : never;
651
+ /** Find complexType in $imports (recursive) */
652
+ type FindComplexTypeInImports<Name extends string, T extends SchemaLike> = T['$imports'] extends readonly SchemaLike[] ? FindComplexTypeInSchemaArray<Name, T['$imports']> : never;
653
+ /** Search through array of schemas for complexType */
654
+ type FindComplexTypeInSchemaArray<Name extends string, Schemas extends readonly SchemaLike[]> = Schemas extends readonly [infer First, ...infer Rest] ? First extends SchemaLike ? FindComplexType<Name, First> extends infer Found ? [Found] extends [never] ? Rest extends readonly SchemaLike[] ? FindComplexTypeInSchemaArray<Name, Rest> : never : Found : never : never : never;
655
+ /** Find a simpleType by name (searches in schema and $imports) */
656
+ type FindSimpleType<Name extends string, T extends SchemaLike> = FindSimpleTypeLocal<Name, T> extends infer Local ? [Local] extends [never] ? FindSimpleTypeInImports<Name, T> : Local : never;
657
+ /** Find simpleType in current schema only */
658
+ type FindSimpleTypeLocal<Name extends string, T extends SchemaLike> = T['simpleType'] extends readonly SimpleTypeLike[] ? FindInArray<T['simpleType'], {
659
+ name: Name;
660
+ }> : T['simpleType'] extends {
661
+ readonly [key: string]: SimpleTypeLike;
662
+ } ? Name extends keyof T['simpleType'] ? T['simpleType'][Name] : never : never;
663
+ /** Find simpleType in $imports (recursive) */
664
+ type FindSimpleTypeInImports<Name extends string, T extends SchemaLike> = T['$imports'] extends readonly SchemaLike[] ? FindSimpleTypeInSchemaArray<Name, T['$imports']> : never;
665
+ /** Search through array of schemas for simpleType */
666
+ type FindSimpleTypeInSchemaArray<Name extends string, Schemas extends readonly SchemaLike[]> = Schemas extends readonly [infer First, ...infer Rest] ? First extends SchemaLike ? FindSimpleType<Name, First> extends infer Found ? [Found] extends [never] ? Rest extends readonly SchemaLike[] ? FindSimpleTypeInSchemaArray<Name, Rest> : never : Found : never : never : never;
667
+ /** Find simpleType WITH the schema it was found in */
668
+ type FindSimpleTypeWithSchema<Name extends string, T extends SchemaLike> = FindSimpleTypeLocal<Name, T> extends infer Local ? [Local] extends [never] ? FindSimpleTypeInImportsWithSchema<Name, T> : {
669
+ type: Local;
670
+ schema: T;
671
+ } : never;
672
+ /** Find simpleType in $imports, returning both type and schema */
673
+ type FindSimpleTypeInImportsWithSchema<Name extends string, T extends SchemaLike> = T['$imports'] extends readonly SchemaLike[] ? FindSimpleTypeInSchemaArrayWithSchema<Name, T['$imports']> : never;
674
+ /** Search through array of schemas for simpleType, returning both type and schema */
675
+ type FindSimpleTypeInSchemaArrayWithSchema<Name extends string, Schemas extends readonly SchemaLike[]> = Schemas extends readonly [infer First, ...infer Rest] ? First extends SchemaLike ? FindSimpleTypeWithSchema<Name, First> extends infer Found ? [Found] extends [never] ? Rest extends readonly SchemaLike[] ? FindSimpleTypeInSchemaArrayWithSchema<Name, Rest> : never : Found extends {
676
+ type: SimpleTypeLike;
677
+ schema: SchemaLike;
678
+ } ? Found : Rest extends readonly SchemaLike[] ? FindSimpleTypeInSchemaArrayWithSchema<Name, Rest> : never : never : never : never;
679
+ /** Infer type from a complexType definition */
680
+ type InferComplexType<CT extends ComplexTypeLike, T extends SchemaLike> = CT['complexContent'] extends {
681
+ extension: infer Ext;
682
+ } ? Ext extends ExtensionLike ? InferExtension<Ext, T> & InferComplexTypeContent<CT, T> : InferComplexTypeContent<CT, T> : CT['simpleContent'] extends {
683
+ extension: infer Ext;
684
+ } ? Ext extends SimpleExtensionLike ? InferSimpleContentExtension<Ext, T> : InferComplexTypeContent<CT, T> : InferComplexTypeContent<CT, T>;
685
+ /** Infer content from complexType (sequence, choice, all, attributes) */
686
+ type InferComplexTypeContent<CT extends ComplexTypeLike, T extends SchemaLike> = InferGroup<CT['sequence'], T> & InferGroup<CT['all'], T> & InferChoice<CT['choice'], T> & InferAttributes<CT['attribute']>;
687
+ /** Empty object type for conditional fallbacks - use {} not Record<string, never> to avoid intersection issues */
688
+ type EmptyObject = {};
689
+ /** Infer from complexContent/extension */
690
+ type InferExtension<Ext extends ExtensionLike, T extends SchemaLike> = (Ext['base'] extends string ? InferTypeName<Ext['base'], T> : EmptyObject) & InferGroup<Ext['sequence'], T> & InferGroup<Ext['all'], T> & InferChoice<Ext['choice'], T> & InferAttributes<Ext['attribute']>;
691
+ /** Infer from simpleContent/extension (text content + attributes) */
692
+ type InferSimpleContentExtension<Ext extends SimpleExtensionLike, _T extends SchemaLike> = (Ext['base'] extends string ? {
693
+ $value: InferBuiltInType<StripPrefix<Ext['base']>>;
694
+ } : EmptyObject) & InferAttributes<Ext['attribute']>;
695
+ /** Infer from a group (sequence or all) */
696
+ type InferGroup<G, T extends SchemaLike> = G extends GroupLike ? InferElements<G['element'], T> & InferNestedSequences<G['sequence'], T> & InferNestedChoices<G['choice'], T> : EmptyObject;
697
+ /** Infer from choice (union of possibilities) */
698
+ type InferChoice<G, T extends SchemaLike> = G extends GroupLike ? Partial<InferElements<G['element'], T>> : EmptyObject;
699
+ /** Infer nested sequences */
700
+ type InferNestedSequences<S, T extends SchemaLike> = S extends readonly GroupLike[] ? UnionToIntersection<InferGroup<S[number], T>> : EmptyObject;
701
+ /** Infer nested choices */
702
+ type InferNestedChoices<C, T extends SchemaLike> = C extends readonly GroupLike[] ? Partial<UnionToIntersection<InferGroup<C[number], T>>> : EmptyObject;
703
+ /** Infer from element array */
704
+ type InferElements<E, T extends SchemaLike> = E extends readonly ElementLike[] ? InferRequiredElements<E, T> & InferOptionalElements<E, T> : EmptyObject;
705
+ /** Find element by name or ref (after stripping prefix) */
706
+ type FindElementByName<E extends readonly ElementLike[], K extends string> = Extract<E[number], {
707
+ name: K;
708
+ }> extends never ? E[number] extends infer El ? El extends {
709
+ ref: infer R;
710
+ } ? R extends string ? StripPrefix<R> extends K ? El : never : never : never : never : Extract<E[number], {
711
+ name: K;
712
+ }>;
713
+ /** Infer required elements (minOccurs != 0) */
714
+ type InferRequiredElements<E extends readonly ElementLike[], T extends SchemaLike> = { [K in ExtractRequiredElementNames<E>]: InferElementType<FindElementByName<E, K>, T> };
715
+ /** Infer optional elements (minOccurs = 0) */
716
+ type InferOptionalElements<E extends readonly ElementLike[], T extends SchemaLike> = { [K in ExtractOptionalElementNames<E>]?: InferElementType<FindElementByName<E, K>, T> };
717
+ /** Get element name - handles both name and ref (strips prefix from ref) */
718
+ type GetElementName<El> = El extends {
719
+ name: infer N;
720
+ } ? N extends string ? N : never : El extends {
721
+ ref: infer R;
722
+ } ? R extends string ? StripPrefix<R> : never : never;
723
+ /** Check if element is optional (minOccurs is 0 or '0') */
724
+ type ElementIsOptional<El> = El extends {
725
+ minOccurs: infer M;
726
+ } ? M extends 0 | '0' ? true : false : false;
727
+ /** Extract names of required elements (distributive over union) */
728
+ type ExtractRequiredElementNames<E extends readonly ElementLike[]> = { [K in keyof E]: E[K] extends ElementLike ? ElementIsOptional<E[K]> extends true ? never : GetElementName<E[K]> : never }[number];
729
+ /** Extract names of optional elements (distributive over union) */
730
+ type ExtractOptionalElementNames<E extends readonly ElementLike[]> = { [K in keyof E]: E[K] extends ElementLike ? ElementIsOptional<E[K]> extends true ? GetElementName<E[K]> : never : never }[number];
731
+ /** Infer type for a single element */
732
+ type InferElementType<El extends ElementLike, T extends SchemaLike> = El extends {
733
+ ref: infer Ref;
734
+ } ? Ref extends string ? WrapArray<InferElementRef<Ref, T>, El> : WrapArray<unknown, El> : El extends {
735
+ complexType: infer CT;
736
+ } ? CT extends ComplexTypeLike ? WrapArray<InferComplexType<CT, T>, El> : WrapArray<unknown, El> : El extends {
737
+ simpleType: infer ST;
738
+ } ? ST extends SimpleTypeLike ? WrapArray<InferSimpleType<ST>, El> : WrapArray<unknown, El> : El extends {
739
+ type: infer TypeName;
740
+ } ? TypeName extends string ? WrapArray<InferTypeName<TypeName, T>, El> : WrapArray<unknown, El> : WrapArray<unknown, El>;
741
+ /** Infer type for an element reference - looks up the element in schema or $imports */
742
+ type InferElementRef<Ref extends string, T extends SchemaLike> = FindByName<T['element'], StripPrefix<Ref>> extends infer Found ? [Found] extends [never] ? InferElementFromImports<Ref, T> : Found extends ElementLike ? InferFoundElement<Found, T> : unknown : unknown;
743
+ /** Infer type from a found element */
744
+ type InferFoundElement<Found extends ElementLike, T extends SchemaLike> = Found extends {
745
+ type: infer TypeName;
746
+ } ? TypeName extends string ? InferTypeName<TypeName, T> : unknown : Found extends {
747
+ complexType: infer CT;
748
+ } ? CT extends ComplexTypeLike ? InferComplexType<CT, T> : unknown : unknown;
749
+ /** Try to find and infer element from $imports */
750
+ type InferElementFromImports<Ref extends string, T extends SchemaLike> = FindElementInImports<Ref, T['$imports']> extends infer ImportedEl ? [ImportedEl] extends [never] ? unknown : ImportedEl extends ElementLike ? InferFoundElement<ImportedEl, T> : unknown : unknown;
751
+ /** Find element in $imports array */
752
+ type FindElementInImports<Ref extends string, Imports> = Imports extends readonly SchemaLike[] ? Imports[number] extends infer S ? S extends SchemaLike ? FindByName<S['element'], StripPrefix<Ref>> : never : never : never;
753
+ /** Wrap in array if maxOccurs > 1 or unbounded */
754
+ type WrapArray<T, El extends ElementLike> = El extends {
755
+ maxOccurs: 'unbounded' | infer Max;
756
+ } ? Max extends 'unbounded' ? T[] : Max extends number ? Max extends 0 | 1 ? T : T[] : Max extends '0' | '1' ? T : Max extends `${number}` ? T[] : T : T;
757
+ /** Infer from attribute array */
758
+ type InferAttributes<A> = A extends readonly AttributeLike[] ? InferRequiredAttributes<A> & InferOptionalAttributes<A> : EmptyObject;
759
+ /** Infer required attributes (use="required") */
760
+ type InferRequiredAttributes<A extends readonly AttributeLike[]> = { [K in ExtractRequiredAttributeNames<A>]: InferAttributeType<Extract<A[number], {
761
+ name: K;
762
+ }>> };
763
+ /** Infer optional attributes (use != "required") */
764
+ type InferOptionalAttributes<A extends readonly AttributeLike[]> = { [K in ExtractOptionalAttributeNames<A>]?: InferAttributeType<Extract<A[number], {
765
+ name: K;
766
+ }>> };
767
+ /** Extract names of required attributes */
768
+ type ExtractRequiredAttributeNames<A extends readonly AttributeLike[]> = A[number] extends infer Attr ? Attr extends {
769
+ name: infer N;
770
+ use: 'required';
771
+ } ? N extends string ? N : never : never : never;
772
+ /** Extract names of optional attributes */
773
+ type ExtractOptionalAttributeNames<A extends readonly AttributeLike[]> = A[number] extends infer Attr ? Attr extends {
774
+ name: infer N;
775
+ use?: infer Use;
776
+ } ? Use extends 'required' ? never : N extends string ? N : never : never : never;
777
+ /** Infer type for a single attribute */
778
+ type InferAttributeType<Attr extends AttributeLike> = Attr extends {
779
+ type: infer TypeName;
780
+ } ? TypeName extends string ? InferBuiltInType<StripPrefix<TypeName>> : string : string;
781
+ /** Infer from simpleType (enums, restrictions) */
782
+ type InferSimpleType<ST extends SimpleTypeLike> = ST extends {
783
+ restriction: {
784
+ enumeration: readonly {
785
+ value: infer V;
786
+ }[];
787
+ };
788
+ } ? V extends string ? V : string : ST extends {
789
+ restriction: {
790
+ base: infer Base;
791
+ };
792
+ } ? Base extends string ? InferBuiltInType<StripPrefix<Base>> : string : string;
793
+ /** Map XSD built-in types to TypeScript */
794
+ type XsdBuiltInTypes = {
795
+ string: string;
796
+ normalizedString: string;
797
+ token: string;
798
+ language: string;
799
+ Name: string;
800
+ NCName: string;
801
+ ID: string;
802
+ IDREF: string;
803
+ IDREFS: string[];
804
+ ENTITY: string;
805
+ ENTITIES: string[];
806
+ NMTOKEN: string;
807
+ NMTOKENS: string[];
808
+ boolean: boolean;
809
+ base64Binary: string;
810
+ hexBinary: string;
811
+ float: number;
812
+ double: number;
813
+ decimal: number;
814
+ integer: number;
815
+ nonPositiveInteger: number;
816
+ negativeInteger: number;
817
+ long: number;
818
+ int: number;
819
+ short: number;
820
+ byte: number;
821
+ nonNegativeInteger: number;
822
+ unsignedLong: number;
823
+ unsignedInt: number;
824
+ unsignedShort: number;
825
+ unsignedByte: number;
826
+ positiveInteger: number;
827
+ date: string;
828
+ time: string;
829
+ dateTime: string;
830
+ duration: string;
831
+ gYear: string;
832
+ gYearMonth: string;
833
+ gMonth: string;
834
+ gMonthDay: string;
835
+ gDay: string;
836
+ anyURI: string;
837
+ QName: string;
838
+ NOTATION: string;
839
+ anyType: unknown;
840
+ anySimpleType: string | number | boolean;
841
+ };
842
+ /** Infer built-in type by name */
843
+ type InferBuiltInType<Name extends string> = Name extends keyof XsdBuiltInTypes ? XsdBuiltInTypes[Name] : unknown;
844
+ /** Strip any namespace prefix (e.g., xs:string -> string, atom:link -> link) */
845
+ type StripPrefix<T extends string> = T extends `${string}:${infer Rest}` ? Rest : T;
846
+ /** Find item in array by partial match */
847
+ type FindInArray<Arr, Match> = Arr extends readonly [infer First, ...infer Rest] ? First extends Match ? First : FindInArray<Rest, Match> : Arr extends readonly (infer Item)[] ? Item extends Match ? Extract<Item, Match> : never : never;
848
+ /**
849
+ * Find item in array by name property.
850
+ * Works with both literal types ('abapClass') and widened types (string).
851
+ * For widened arrays where name is `string`, returns the full item union.
852
+ */
853
+ type FindByName<Arr, Name extends string> = Arr extends readonly [infer First, ...infer Rest] ? First extends {
854
+ name: Name;
855
+ } ? First : First extends {
856
+ name: string;
857
+ } ? Name extends First['name'] ? First : FindByName<Rest, Name> : FindByName<Rest, Name> : Arr extends readonly (infer Item)[] ? Item extends {
858
+ name: infer ItemName;
859
+ } ? ItemName extends string ? string extends ItemName ? Item : Name extends ItemName ? Item : never : never : never : never;
860
+ /** Convert union to intersection */
861
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
862
+ //#endregion
863
+ //#region src/codegen/generate.d.ts
864
+ /**
865
+ * Schema Literal Generator
866
+ *
867
+ * Transforms a parsed Schema object into a TypeScript literal string
868
+ * that preserves type information for InferSchema<T>.
869
+ */
870
+ interface GenerateOptions {
871
+ /** Variable name for the exported schema */
872
+ name?: string;
873
+ /** Add JSDoc comment */
874
+ comment?: string;
875
+ /** Pretty print with indentation */
876
+ pretty?: boolean;
877
+ /** Indentation string (default: ' ') */
878
+ indent?: string;
879
+ /**
880
+ * Enable specific $ metadata features in output.
881
+ * - `$xmlns`: Keep `$xmlns` in output (already parsed as $xmlns)
882
+ * - `$imports`: Rename `import` → `$imports` for schema linking
883
+ * - `$filename`: Include `$filename` (uses `name` option + '.xsd')
884
+ *
885
+ * @example
886
+ * ```typescript
887
+ * features: { $xmlns: true, $imports: true, $filename: true }
888
+ * ```
889
+ */
890
+ features?: {
891
+ /** Keep `$xmlns` in output */$xmlns?: boolean; /** Rename `import` → `$imports` for schema linking */
892
+ $imports?: boolean; /** Include `$filename` (uses `name` + '.xsd') */
893
+ $filename?: boolean;
894
+ };
895
+ /**
896
+ * Property names to exclude from output.
897
+ * Useful for removing annotations, documentation, etc.
898
+ *
899
+ * @example
900
+ * ```typescript
901
+ * exclude: ['annotation'] // Remove all annotation elements
902
+ * ```
903
+ */
904
+ exclude?: string[];
905
+ /** Resolver for import paths (schemaLocation -> module path) */
906
+ importResolver?: (schemaLocation: string) => string | null;
907
+ /**
908
+ * Generate isolatedDeclarations-compatible output.
909
+ * Uses `satisfies Schema as const` instead of just `as const`.
910
+ */
911
+ isolatedDeclarations?: boolean;
912
+ /** Use single quotes for string literals and property names */
913
+ singleQuote?: boolean;
914
+ }
915
+ /**
916
+ * Generate a TypeScript literal string from XSD content.
917
+ *
918
+ * @param xsdContent - XSD file content as string
919
+ * @param options - Generation options
920
+ * @returns TypeScript code with schema as const literal
921
+ *
922
+ * @example
923
+ * ```typescript
924
+ * const xsd = `<xs:schema>...</xs:schema>`;
925
+ * const code = generateSchemaLiteral(xsd, { name: 'PersonSchema' });
926
+ * // export const PersonSchema = { ... } as const;
927
+ * ```
928
+ */
929
+ declare function generateSchemaLiteral(xsdContent: string, options?: GenerateOptions): string;
930
+ /**
931
+ * Generate a complete TypeScript file from XSD content.
932
+ *
933
+ * @param xsdContent - XSD file content as string
934
+ * @param options - Generation options
935
+ * @returns Complete TypeScript file content
936
+ */
937
+ declare function generateSchemaFile(xsdContent: string, options?: GenerateOptions): string;
938
+ //#endregion
939
+ //#region src/codegen/ts-morph.d.ts
940
+ /**
941
+ * Resolver function for loading schemas by schemaLocation.
942
+ * @param schemaLocation - The schemaLocation path from the import element
943
+ * @param basePath - Optional base path for resolving relative paths
944
+ * @returns The resolved Schema, or undefined if not found
945
+ */
946
+ type SchemaLocationResolver = (schemaLocation: string, basePath?: string) => Schema | undefined;
947
+ interface SchemaToSourceFileOptions {
948
+ /** Custom root type name. Pass null to disable root type generation. */
949
+ rootTypeName?: string | null;
950
+ /** Add JSDoc comments */
951
+ addJsDoc?: boolean;
952
+ /** Existing project to use */
953
+ project?: Project;
954
+ /** Base path for loading schemaLocation imports */
955
+ basePath?: string;
956
+ /**
957
+ * Resolver function for loading schemas by schemaLocation.
958
+ * If provided, will be called for each `import` element with a schemaLocation.
959
+ * The resolved schemas will be processed like $imports.
960
+ */
961
+ schemaLocationResolver?: SchemaLocationResolver;
962
+ }
963
+ //#endregion
964
+ //#region src/codegen/interface-generator.d.ts
965
+ interface GenerateInterfacesOptions extends SchemaToSourceFileOptions {
966
+ /**
967
+ * If true, generates a single flattened type with all nested types inlined.
968
+ * If false (default), generates interfaces with imports and extends.
969
+ */
970
+ flatten?: boolean;
971
+ /**
972
+ * Additional source files to include for resolving imports when flattening.
973
+ * These are typically the generated source files from $imports schemas.
974
+ */
975
+ additionalSourceFiles?: SourceFile[];
976
+ }
977
+ interface GenerateInterfacesResult {
978
+ /** The generated TypeScript code */
979
+ code: string;
980
+ /** The ts-morph SourceFile */
981
+ sourceFile: SourceFile;
982
+ /** The root type name */
983
+ rootTypeName: string | undefined;
984
+ /** The ts-morph Project (useful for further manipulation) */
985
+ project: Project;
986
+ }
987
+ /**
988
+ * Derive root type name from schema filename.
989
+ * e.g., 'packagesV1.xsd' -> 'PackagesV1Schema'
990
+ */
991
+ declare function deriveRootTypeName(filename?: string): string | undefined;
992
+ /**
993
+ * Generate TypeScript interfaces from a schema.
994
+ *
995
+ * @param schema - The schema to generate interfaces from
996
+ * @param options - Generation options
997
+ * @returns Generated TypeScript code and metadata
998
+ *
999
+ * @example
1000
+ * // Generate interfaces with imports and extends
1001
+ * const { code } = generateInterfaces(schema);
1002
+ *
1003
+ * @example
1004
+ * // Generate a single flattened type with all nested types inlined
1005
+ * const { code } = generateInterfaces(schema, {
1006
+ * flatten: true,
1007
+ * additionalSourceFiles: [baseSchemaSourceFile]
1008
+ * });
1009
+ */
1010
+ declare function generateInterfaces(schema: Schema, options?: GenerateInterfacesOptions): GenerateInterfacesResult;
1011
+ //#endregion
1012
+ //#region src/xml/parse.d.ts
1013
+ /**
1014
+ * Parse XML string to typed object using schema definition
1015
+ */
1016
+ declare function parse<T extends SchemaLike>(schema: T, xml: string): InferParsedSchema<T>;
1017
+ //#endregion
1018
+ //#region src/xml/build-utils.d.ts
1019
+ interface BuildOptions$1 {
1020
+ /** Include XML declaration (default: true) */
1021
+ xmlDecl?: boolean;
1022
+ /** XML encoding (default: utf-8) */
1023
+ encoding?: string;
1024
+ /** Pretty print with indentation (default: false) */
1025
+ pretty?: boolean;
1026
+ /** Namespace prefix to use (default: from schema or none) */
1027
+ prefix?: string;
1028
+ /** Root element name to use (default: auto-detect from data) */
1029
+ rootElement?: string;
1030
+ }
1031
+ //#endregion
1032
+ //#region src/xml/build.d.ts
1033
+ /**
1034
+ * Build XML string from typed object using schema definition
1035
+ */
1036
+ declare function build<T extends SchemaLike>(schema: T, data: unknown, options?: BuildOptions$1): string;
1037
+ //#endregion
1038
+ //#region src/xml/typed.d.ts
1039
+ /**
1040
+ * Typed schema instance with parse/build methods
1041
+ */
1042
+ interface TypedSchema<T, S extends SchemaLike = SchemaLike> {
1043
+ /** The data type - use with typeof for type extraction */
1044
+ readonly _type: T;
1045
+ /** The underlying raw schema */
1046
+ readonly schema: S;
1047
+ /** Parse XML string to typed object */
1048
+ parse(xml: string): T;
1049
+ /** Build typed object to XML string */
1050
+ build(data: T, options?: BuildOptions$1): string;
1051
+ }
1052
+ /** Resolve data type: use explicit T if provided, otherwise infer from schema */
1053
+ type ResolveDataType<T, S extends SchemaLike> = unknown extends T ? InferSchema<S> : T;
1054
+ /** Extract the data type from a TypedSchema */
1055
+ type InferTypedSchema<T extends TypedSchema<unknown>> = T['_type'];
1056
+ /**
1057
+ * Create a typed schema wrapper
1058
+ *
1059
+ * @param schema - Raw schema literal (with `as const`)
1060
+ * @returns Typed schema with parse/build methods
1061
+ *
1062
+ * @example
1063
+ * ```typescript
1064
+ * // Infer type from schema
1065
+ * const personSchema = typedSchema(rawPersonSchema);
1066
+ * const person = personSchema.parse(xml);
1067
+ *
1068
+ * // Or with explicit type
1069
+ * const personSchema = typedSchema<PersonType>(rawPersonSchema);
1070
+ * ```
1071
+ */
1072
+ declare function typedSchema<T = unknown, S extends SchemaLike = SchemaLike>(schema: S): TypedSchema<ResolveDataType<T, S>, S>;
1073
+ //#endregion
1074
+ //#region src/walker/index.d.ts
1075
+ /** Result of walking complexTypes */
1076
+ type ComplexTypeEntry = {
1077
+ readonly ct: ComplexTypeLike;
1078
+ readonly schema: SchemaLike;
1079
+ };
1080
+ /** Result of walking simpleTypes */
1081
+ type SimpleTypeEntry = {
1082
+ readonly st: SimpleTypeLike;
1083
+ readonly schema: SchemaLike;
1084
+ };
1085
+ /** Result of walking elements */
1086
+ type ElementEntry = {
1087
+ readonly element: ElementLike; /** Element is optional (minOccurs=0 or inside choice) */
1088
+ readonly optional: boolean; /** Element is array (maxOccurs > 1 or unbounded) */
1089
+ readonly array: boolean; /** Source group type */
1090
+ readonly source: 'sequence' | 'choice' | 'all' | 'extension'; /** Schema where the element is defined (for namespace prefix resolution) */
1091
+ readonly schema: SchemaLike;
1092
+ };
1093
+ /** Result of walking attributes */
1094
+ type AttributeEntry = {
1095
+ readonly attribute: AttributeLike; /** Attribute is required (use="required") */
1096
+ readonly required: boolean; /** Schema where the attribute is defined (for namespace prefix resolution) */
1097
+ readonly schema: SchemaLike;
1098
+ };
1099
+ /** Result of walking top-level elements */
1100
+ type TopLevelElementEntry = {
1101
+ readonly element: ElementLike;
1102
+ readonly schema: SchemaLike;
1103
+ };
1104
+ /** Options for schema-level walkers */
1105
+ type WalkOptions = {
1106
+ /** Only recurse into $includes, not $imports (default: false) */readonly includesOnly?: boolean;
1107
+ };
1108
+ /**
1109
+ * Walk all complexTypes in a schema and its $imports/$includes (depth-first).
1110
+ *
1111
+ * @param schema - Root schema to start from
1112
+ * @param options - Walk options (e.g., includesOnly to skip $imports)
1113
+ * @yields ComplexType with the schema it was found in
1114
+ *
1115
+ * @example
1116
+ * ```typescript
1117
+ * function findComplexType(name: string, schema: SchemaLike) {
1118
+ * for (const { ct, schema: s } of walkComplexTypes(schema)) {
1119
+ * if (ct.name === name) return { type: ct, schema: s };
1120
+ * }
1121
+ * }
1122
+ * ```
1123
+ */
1124
+ declare function walkComplexTypes(schema: SchemaLike, options?: WalkOptions): Generator<ComplexTypeEntry>;
1125
+ /**
1126
+ * Walk all simpleTypes in a schema and its $imports/$includes.
1127
+ */
1128
+ declare function walkSimpleTypes(schema: SchemaLike, options?: WalkOptions): Generator<SimpleTypeEntry>;
1129
+ /**
1130
+ * Walk all top-level elements in a schema and its $imports/$includes.
1131
+ */
1132
+ declare function walkTopLevelElements(schema: SchemaLike, options?: WalkOptions): Generator<TopLevelElementEntry>;
1133
+ /**
1134
+ * Find a complexType by name, searching schema and $imports.
1135
+ * Returns both the type AND the schema it was found in (important for inheritance).
1136
+ */
1137
+ declare function findComplexType(name: string, schema: SchemaLike): ComplexTypeEntry | undefined;
1138
+ /**
1139
+ * Find a simpleType by name, searching schema and $imports.
1140
+ */
1141
+ declare function findSimpleType(name: string, schema: SchemaLike): SimpleTypeEntry | undefined;
1142
+ /**
1143
+ * Find a top-level element by name, searching schema and $imports.
1144
+ */
1145
+ declare function findElement(name: string, schema: SchemaLike): TopLevelElementEntry | undefined;
1146
+ /**
1147
+ * Walk all elements in a complexType, handling:
1148
+ * - sequence, choice, all groups
1149
+ * - Nested groups (recursive)
1150
+ * - complexContent/extension inheritance
1151
+ * - Group references
1152
+ *
1153
+ * @param ct - ComplexType to walk
1154
+ * @param schema - Schema context (for resolving base types and group refs)
1155
+ * @yields Elements with metadata (optional, array, source)
1156
+ */
1157
+ declare function walkElements(ct: ComplexTypeLike, schema: SchemaLike): Generator<ElementEntry>;
1158
+ /**
1159
+ * Walk all attributes in a complexType, handling:
1160
+ * - Direct attributes
1161
+ * - complexContent/extension attributes
1162
+ * - simpleContent/extension attributes
1163
+ * - Inherited attributes from base type
1164
+ * - AttributeGroup references
1165
+ */
1166
+ declare function walkAttributes(ct: ComplexTypeLike, schema: SchemaLike): Generator<AttributeEntry>;
1167
+ /**
1168
+ * Strip namespace prefix from a QName (e.g., "tns:PersonType" -> "PersonType")
1169
+ */
1170
+ declare function stripNsPrefix(name: string): string;
1171
+ /**
1172
+ * Check if an element is abstract
1173
+ */
1174
+ declare function isAbstractElement(element: ElementLike): boolean;
1175
+ /**
1176
+ * Find all elements that substitute for a given abstract element.
1177
+ * This handles XSD substitution groups where concrete elements can
1178
+ * substitute for an abstract element.
1179
+ */
1180
+ declare function findSubstitutes(abstractElementName: string, schema: SchemaLike): ElementLike[];
1181
+ //#endregion
1182
+ export { AfterAllContext, All, Alternative, Annotated, Annotation, AnnotationLike, Any, AnyAttribute, AnyAttributeLike, Appinfo, Assertion, Attribute, AttributeEntry, AttributeGroupRef, AttributeLike, type BuildOptions, CodegenConfig, ComplexContent, ComplexContentExtension, ComplexContentRestriction, ComplexType, ComplexTypeEntry, ComplexTypeLike, DefaultOpenContent, Documentation, Element, ElementEntry, ElementLike, ExplicitGroup, ExtensionLike, ExtractOptionalAttributeNames, ExtractOptionalElementNames, ExtractRequiredAttributeNames, ExtractRequiredElementNames, Facet, Field, FinalizeContext, FindByName, FindComplexType, FindComplexTypeInImports, FindComplexTypeInImportsWithSchema, FindComplexTypeInSchemaArray, FindComplexTypeInSchemaArrayWithSchema, FindComplexTypeLocal, FindComplexTypeWithSchema, FindInArray, FindSimpleType, FindSimpleTypeInImports, FindSimpleTypeInImportsWithSchema, FindSimpleTypeInSchemaArray, FindSimpleTypeInSchemaArrayWithSchema, FindSimpleTypeLocal, FindSimpleTypeWithSchema, FormChoice, type GenerateInterfacesOptions, type GenerateInterfacesResult, GeneratedFile, GeneratorPlugin, Group, GroupLike, GroupRef, GroupRefLike, HookContext, Import, Include, InferAllElements, InferAttributeType, InferAttributes, InferBuiltInType, InferChoice, InferComplexType, InferComplexTypeContent, InferElement, InferElementType, InferElements, InferExtension, InferGroup, InferNestedChoices, InferNestedSequences, InferOptionalAttributes, InferOptionalElements, InferParsedSchema, InferRequiredAttributes, InferRequiredElements, InferRootElementTypes, InferSchema, InferSimpleContentExtension, InferSimpleType, InferTypeName, type InferTypedSchema, InferWrappedRootElementTypes, Key, Keyref, LinkOptions, List, LoaderOptions, LocalAttribute, LocalComplexType, LocalElement, LocalSimpleType, NamedAttributeGroup, NamedGroup, NodeSource, Notation, OpenAttrs, OpenContent, Override, OverrideLike, Pattern, Redefine, RedefineLike, ResolveOptions, ResolvedSchema, type RunnerOptions, type RunnerResult, Schema, SchemaAttrs, SchemaExtensions, SchemaInfo, SchemaLike, SchemaResolver, SchemaTraverser, Selector, SetupContext, SimpleContent, SimpleContentExtension, SimpleContentRestriction, SimpleExtensionLike, SimpleType, SimpleTypeEntry, SimpleTypeLike, SimpleTypeRestriction, SourceConfig, SourceInfo, StripNsPrefix, StripPrefix, TopLevelAttribute, TopLevelComplexType, TopLevelElement, TopLevelElementEntry, TopLevelSimpleType, TransformContext, TraverseOptions, type TypedSchema, Union, UnionToIntersection, Unique, WalkOptions, WrapArray, type BuildOptions$1 as XmlBuildOptions, XmlnsDeclarations, XsdBuiltInTypes, XsdLoader, build as buildXml, buildXsd, createSchemaLoader, defaultLoader, defineConfig, deriveRootTypeName, findComplexType, findElement, findSimpleType, findSubstitutes, generateInterfaces, generateSchemaFile, generateSchemaLiteral, getSubstitutes, isAbstractElement, linkSchema, linkSchemas, loadAndLinkSchema, loadSchema, parseXsd as parse, parseXsd, parseSchemaContent, parse as parseXml, resolveImports, resolveSchema, resolveSchemaTypes, runCodegen, stripNsPrefix, typedSchema, walkAttributes, walkComplexTypes, walkElements, walkSimpleTypes, walkTopLevelElements };
1183
+ //# sourceMappingURL=index.d.mts.map