{"_id":"@abapify/ts-xsd","_rev":"6-d48efa96cdf452e3f4eb8ecbce40dc97","name":"@abapify/ts-xsd","dist-tags":{"latest":"0.4.1"},"versions":{"0.0.0":{"name":"@abapify/ts-xsd","version":"0.0.0","_id":"@abapify/ts-xsd@0.0.0","maintainers":[{"name":"theplenkov-npm","email":"petr.plenkov@gmail.com"}],"dist":{"shasum":"80c4e3c10c31814d746feda11e5c0fc262ac27e8","tarball":"https://registry.npmjs.org/@abapify/ts-xsd/-/ts-xsd-0.0.0.tgz","fileCount":2,"integrity":"sha512-Obzs1/6/oUUBtzT9A57O7C5BRhM93IXPajYhB0jBgvUiJlpzHkHmImZGfqpwDewZiJ5qilmqm0iexbHQ7p44ug==","signatures":[{"sig":"MEQCID3Ctu+0imnhMhWnqcnT/DdmL6ta+EnlcjxcGDanSxlXAiA3d+fnoDgZgP9Z/nRB67b4F7iMMwd8b3Z88W5bN4ydCg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":220},"_npmUser":{"name":"theplenkov-npm","email":"petr.plenkov@gmail.com"},"_npmVersion":"11.12.1","description":"Placeholder — real package is published via CI/CD (trusted publishing).","directories":{},"_nodeVersion":"24.10.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ts-xsd_0.0.0_1776719441365_0.521448216895186","host":"s3://npm-registry-packages-npm-production"}},"0.3.4":{"name":"@abapify/ts-xsd","version":"0.3.4","license":"MIT","_id":"@abapify/ts-xsd@0.3.4","maintainers":[{"name":"theplenkov-npm","email":"petr.plenkov@gmail.com"}],"homepage":"https://github.com/abapify/adt-cli/tree/main/packages/ts-xsd#readme","bugs":{"url":"https://github.com/abapify/adt-cli/issues"},"bin":{"ts-xsd":"dist/codegen/cli.mjs"},"dist":{"shasum":"9d544f34710a7dd5284a42df8414bd55dec15e50","tarball":"https://registry.npmjs.org/@abapify/ts-xsd/-/ts-xsd-0.3.4.tgz","fileCount":2,"integrity":"sha512-8oQYaKpTYgo313Gfr1z0PpQFkfMvwGc17Y3RYge95mMSnwg5g1mLf7OdB4KKehfosWzSuohx7IqQak1wbZ9DHA==","signatures":[{"sig":"MEUCIGwk6kMM57VgDDtTzOaoeQt656OOa/LgExV77m5ezzJnAiEA2lVup6bSp0SUMtQ81h0zwLpGWQ++UqsQDDLw7rFGGDY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@abapify%2fts-xsd@0.3.4","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":13456},"type":"module","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs","./generators":"./dist/generators/index.mjs","./codegen/cli":"./dist/codegen/cli.mjs","./package.json":"./package.json"},"gitHead":"6a630228129c616054aad8dfafe17c42f389986e","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ffa1c799-3e9e-4aa2-9ae4-e68e40bdb220"}},"repository":{"url":"git+https://github.com/abapify/adt-cli.git","type":"git","directory":"packages/ts-xsd"},"_npmVersion":"11.12.1","description":"Core XSD parser and builder - W3C XMLSchema 1:1 TypeScript representation","directories":{},"_nodeVersion":"24.14.1","dependencies":{"zod":"^3.24.0 || ^4.0.0","ts-morph":"*","@xmldom/xmldom":"^0.9.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ts-xsd_0.3.4_1776722398065_0.805624013694554","host":"s3://npm-registry-packages-npm-production"}},"0.3.5":{"name":"@abapify/ts-xsd","version":"0.3.5","license":"MIT","_id":"@abapify/ts-xsd@0.3.5","maintainers":[{"name":"theplenkov-npm","email":"petr.plenkov@gmail.com"}],"homepage":"https://github.com/abapify/adt-cli/tree/main/packages/ts-xsd#readme","bugs":{"url":"https://github.com/abapify/adt-cli/issues"},"bin":{"ts-xsd":"dist/codegen/cli.mjs"},"dist":{"shasum":"18c13f8f4cd296325d39517ab2a90c3021c53e46","tarball":"https://registry.npmjs.org/@abapify/ts-xsd/-/ts-xsd-0.3.5.tgz","fileCount":2,"integrity":"sha512-HXxinIf2bU33WYs1nICgXNdtiA32WHuIFpx6m0AscpEIVD2l7vNMtBJ3SM52y8k9XgQlGKelNuJ08eqIrhGZ2w==","signatures":[{"sig":"MEUCIQDmFrKUJIMhzk4YqktZeRarpxRoFwTJvRR0+O1mLT83SAIgAPs9xwzP9XYwxaua4mSnvudR+z1cfeYchtTKWTioFqU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@abapify%2fts-xsd@0.3.5","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":13456},"type":"module","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs","./generators":"./dist/generators/index.mjs","./codegen/cli":"./dist/codegen/cli.mjs","./package.json":"./package.json"},"gitHead":"185666fe6ccb304e7b08529eb376ec2493131a7a","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ffa1c799-3e9e-4aa2-9ae4-e68e40bdb220"}},"repository":{"url":"git+https://github.com/abapify/adt-cli.git","type":"git","directory":"packages/ts-xsd"},"_npmVersion":"11.12.1","description":"Core XSD parser and builder - W3C XMLSchema 1:1 TypeScript representation","directories":{},"_nodeVersion":"24.14.1","dependencies":{"zod":"^3.24.0 || ^4.0.0","ts-morph":"*","@xmldom/xmldom":"^0.9.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ts-xsd_0.3.5_1776723635896_0.7635393389870153","host":"s3://npm-registry-packages-npm-production"}},"0.3.6":{"name":"@abapify/ts-xsd","version":"0.3.6","license":"MIT","_id":"@abapify/ts-xsd@0.3.6","maintainers":[{"name":"theplenkov-npm","email":"petr.plenkov@gmail.com"}],"homepage":"https://github.com/abapify/adt-cli/tree/main/packages/ts-xsd#readme","bugs":{"url":"https://github.com/abapify/adt-cli/issues"},"bin":{"ts-xsd":"dist/codegen/cli.mjs"},"dist":{"shasum":"398262299cde6bd56cd58b7b5acc4f91426ed66f","tarball":"https://registry.npmjs.org/@abapify/ts-xsd/-/ts-xsd-0.3.6.tgz","fileCount":2,"integrity":"sha512-zVgGZRUm9gbDVjH/0ZNuRQY3zQim3Sckk2BQqlRGNNITve/TWlJzmoO4OsnwtfEtSg3cFKbsGfot3aiAujRADQ==","signatures":[{"sig":"MEUCICSxj8b4LWmHTDQ5Tmsex3ulhP4WaYScEWCdkz+dU47pAiEAmh+GvjXoL3Obm4y25gga3trrPn9Ohy0PfTbJFN9dnLo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@abapify%2fts-xsd@0.3.6","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":13456},"type":"module","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs","./generators":"./dist/generators/index.mjs","./codegen/cli":"./dist/codegen/cli.mjs","./package.json":"./package.json"},"gitHead":"489b2b4ad7c2ea972f323d4c356997ac5962ba9e","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ffa1c799-3e9e-4aa2-9ae4-e68e40bdb220"}},"repository":{"url":"git+https://github.com/abapify/adt-cli.git","type":"git","directory":"packages/ts-xsd"},"_npmVersion":"11.11.0","description":"Core XSD parser and builder - W3C XMLSchema 1:1 TypeScript representation","directories":{},"_nodeVersion":"24.14.1","dependencies":{"zod":"^3.24.0 || ^4.0.0","ts-morph":"*","@xmldom/xmldom":"^0.9.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ts-xsd_0.3.6_1776744782977_0.2739243077064286","host":"s3://npm-registry-packages-npm-production"}},"0.4.0":{"name":"@abapify/ts-xsd","version":"0.4.0","license":"MIT","_id":"@abapify/ts-xsd@0.4.0","maintainers":[{"name":"theplenkov-npm","email":"petr.plenkov@gmail.com"}],"homepage":"https://github.com/abapify/adt-cli/tree/main/packages/ts-xsd#readme","bugs":{"url":"https://github.com/abapify/adt-cli/issues"},"bin":{"ts-xsd":"dist/codegen/cli.mjs"},"dist":{"shasum":"eea51b30e4baf68ce2516b9492ef69d3c03f8948","tarball":"https://registry.npmjs.org/@abapify/ts-xsd/-/ts-xsd-0.4.0.tgz","fileCount":2,"integrity":"sha512-XXxPX738fyBdNG/C6gjLxHiemJZLT7zzyZ1hrVWuK5D1al2OAzpXt7AEDf0wSXF+XfZ2BhDXJv6CDbe8KAOKVQ==","signatures":[{"sig":"MEQCIDnWpD8/77IkcZ9vir1brXbSuHiZzhUW1JDDhdFK0swcAiBIc2APfQHK8uMkT4YYHmtSMj0t+3spt2USrZ4ebkvQZg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@abapify%2fts-xsd@0.4.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":13456},"type":"module","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs","./generators":"./dist/generators/index.mjs","./codegen/cli":"./dist/codegen/cli.mjs","./package.json":"./package.json"},"gitHead":"81dc9eea47fe419e41d246f0ec212fa78570a489","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ffa1c799-3e9e-4aa2-9ae4-e68e40bdb220"}},"repository":{"url":"git+https://github.com/abapify/adt-cli.git","type":"git","directory":"packages/ts-xsd"},"_npmVersion":"11.13.0","description":"Core XSD parser and builder - W3C XMLSchema 1:1 TypeScript representation","directories":{},"_nodeVersion":"24.16.0","dependencies":{"zod":"^3.24.0 || ^4.0.0","ts-morph":"*","@xmldom/xmldom":"^0.9.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ts-xsd_0.4.0_1780072622834_0.19302138966328997","host":"s3://npm-registry-packages-npm-production"}},"0.4.1":{"name":"@abapify/ts-xsd","version":"0.4.1","description":"Core XSD parser and builder - W3C XMLSchema 1:1 TypeScript representation","license":"MIT","publishConfig":{"access":"public"},"type":"module","types":"./dist/index.d.mts","bin":{"ts-xsd":"dist/codegen/cli.mjs"},"exports":{".":"./dist/index.mjs","./codegen/cli":"./dist/codegen/cli.mjs","./generators":"./dist/generators/index.mjs","./package.json":"./package.json"},"dependencies":{"@xmldom/xmldom":"^0.9.9","ts-morph":"*","zod":"^3.24.0 || ^4.0.0"},"repository":{"type":"git","url":"git+https://github.com/abapify/adt-cli.git","directory":"packages/ts-xsd"},"homepage":"https://github.com/abapify/adt-cli/tree/main/packages/ts-xsd#readme","bugs":{"url":"https://github.com/abapify/adt-cli/issues"},"gitHead":"9d3b996a5c760a8db67e28c4df3c30098bd29e4a","_id":"@abapify/ts-xsd@0.4.1","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-bRGWd2x+q3JveWqK25PGniz4tSYyKgmm9D9bCbRBMJV9qeVhYmr6Tr/0tR1gjHj9sxMDX+6igUIMNYlMWLjB/Q==","shasum":"97614ec8bc8ba03622e44374846b237d1c933923","tarball":"https://registry.npmjs.org/@abapify/ts-xsd/-/ts-xsd-0.4.1.tgz","fileCount":21,"unpackedSize":745966,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@abapify%2fts-xsd@0.4.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDdW82MUIdocRqP6U9gukVzWnSdV4638CcQaVQkACVlSAiAq5kvWEYxsVmYQrT3+bl86JcAvc4d6fPjOslqGURUy2Q=="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ffa1c799-3e9e-4aa2-9ae4-e68e40bdb220"}},"directories":{},"maintainers":[{"name":"theplenkov-npm","email":"petr.plenkov@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ts-xsd_0.4.1_1780074897032_0.01797785633461646"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-20T21:10:41.289Z","modified":"2026-05-29T17:14:57.602Z","0.0.0":"2026-04-20T21:10:41.501Z","0.3.4":"2026-04-20T21:59:58.189Z","0.3.5":"2026-04-20T22:20:36.033Z","0.3.6":"2026-04-21T04:13:03.231Z","0.4.0":"2026-05-29T16:37:02.972Z","0.4.1":"2026-05-29T17:14:57.282Z"},"bugs":{"url":"https://github.com/abapify/adt-cli/issues"},"license":"MIT","homepage":"https://github.com/abapify/adt-cli/tree/main/packages/ts-xsd#readme","repository":{"type":"git","url":"git+https://github.com/abapify/adt-cli.git","directory":"packages/ts-xsd"},"description":"Core XSD parser and builder - W3C XMLSchema 1:1 TypeScript representation","maintainers":[{"name":"theplenkov-npm","email":"petr.plenkov@gmail.com"}],"readme":"# ts-xsd\n\n[![version](https://img.shields.io/github/package-json/v/abapify/adt-cli?filename=packages/ts-xsd/package.json)](https://github.com/abapify/adt-cli/pkgs/npm/%40abapify%2Fts-xsd)\n\n**Core XSD parser, builder, and type inference** with **1:1 TypeScript representation** of W3C XML Schema Definition (XSD) 1.1.\n\n## Overview\n\n`ts-xsd` is a comprehensive TypeScript library for working with W3C XSD schemas. It provides:\n\n| Module      | Purpose                                                             |\n| ----------- | ------------------------------------------------------------------- |\n| **xsd**     | Parse XSD files into typed `Schema` objects, build XSD from objects |\n| **infer**   | Compile-time TypeScript type inference from schema literals         |\n| **xml**     | Parse/build XML documents using schema definitions                  |\n| **codegen** | Generate TypeScript schema literals from XSD files                  |\n\n### Key Features\n\n- **Pure W3C XSD 1.1** - Types match the official [XMLSchema.xsd](https://www.w3.org/TR/xmlschema11-1/XMLSchema.xsd) exactly\n- **Full roundtrip** - `XSD → Schema → XSD` with semantic preservation\n- **Type inference** - `InferSchema<T>` extracts TypeScript types from schema literals\n- **Shared types** - Cross-schema type resolution via `$imports`\n- **Tree-shakeable** - Only import what you need\n- **Zero runtime dependencies** - Only `@xmldom/xmldom` for DOM parsing\n\n## Installation\n\n```bash\nnpm install @abapify/ts-xsd\n# or\nbun add @abapify/ts-xsd\n```\n\n## Quick Start\n\n### Parse and Build XSD\n\n```typescript\nimport { parseXsd, buildXsd } from '@abapify/ts-xsd';\n\n// Parse XSD to typed Schema object\nconst schema = parseXsd(`\n  <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n    <xs:element name=\"person\" type=\"PersonType\"/>\n    <xs:complexType name=\"PersonType\">\n      <xs:sequence>\n        <xs:element name=\"name\" type=\"xs:string\"/>\n        <xs:element name=\"age\" type=\"xs:int\" minOccurs=\"0\"/>\n      </xs:sequence>\n    </xs:complexType>\n  </xs:schema>\n`);\n\n// Build back to XSD\nconst xsd = buildXsd(schema, { pretty: true });\n```\n\n### Type Inference from Schema Literals\n\n```typescript\nimport type { InferSchema } from '@abapify/ts-xsd';\n\n// Define schema as const literal\nconst personSchema = {\n  element: [{ name: 'person', type: 'PersonType' }],\n  complexType: [\n    {\n      name: 'PersonType',\n      sequence: {\n        element: [\n          { name: 'name', type: 'xs:string' },\n          { name: 'age', type: 'xs:int', minOccurs: 0 },\n        ],\n      },\n    },\n  ],\n} as const;\n\n// Infer TypeScript type at compile time\ntype Person = InferSchema<typeof personSchema>;\n// Result: { name: string; age?: number }\n```\n\n### Parse XML with Schema\n\n```typescript\nimport { parseXml, buildXml } from '@abapify/ts-xsd';\n\nconst xml = `<person><name>John</name><age>30</age></person>`;\nconst data = parseXml(personSchema, xml);\n// data: { name: 'John', age: 30 }\n\nconst rebuilt = buildXml(personSchema, data);\n// rebuilt: <person><name>John</name><age>30</age></person>\n```\n\n## API Reference\n\n### XSD Module\n\n```typescript\nimport { parseXsd, buildXsd, type Schema } from '@abapify/ts-xsd';\n```\n\n#### `parseXsd(xsd: string): Schema`\n\nParse an XSD XML string into a typed Schema object.\n\n```typescript\nconst schema = parseXsd(xsdString);\nconsole.log(schema.targetNamespace);\nconsole.log(schema.element?.[0].name);\n```\n\n#### `buildXsd(schema: Schema, options?: BuildOptions): string`\n\nBuild an XSD XML string from a Schema object.\n\n```typescript\nconst xsd = buildXsd(schema, {\n  prefix: 'xsd', // Namespace prefix (default: 'xs')\n  pretty: true, // Pretty print (default: true)\n  indent: '  ', // Indentation (default: '  ')\n});\n```\n\n#### `resolveImports(schema: Schema, resolver: (location: string) => Schema): Schema`\n\nResolve and link imported schemas for cross-schema type resolution.\n\n```typescript\nconst linkedSchema = resolveImports(schema, (location) => {\n  return parseXsd(fs.readFileSync(location, 'utf-8'));\n});\n```\n\n### Infer Module\n\n```typescript\nimport type { InferSchema, InferElement, SchemaLike } from '@abapify/ts-xsd';\n```\n\n#### `InferSchema<T>`\n\nInfer TypeScript type from a schema literal. Returns union of all root element types.\n\n```typescript\ntype Data = InferSchema<typeof mySchema>;\n```\n\n#### `InferElement<T, ElementName>`\n\nInfer type for a specific element by name.\n\n```typescript\ntype Person = InferElement<typeof schema, 'person'>;\n```\n\n#### Built-in Type Mapping\n\n| XSD Type                             | TypeScript |\n| ------------------------------------ | ---------- |\n| `xs:string`, `xs:token`, `xs:NCName` | `string`   |\n| `xs:int`, `xs:integer`, `xs:decimal` | `number`   |\n| `xs:boolean`                         | `boolean`  |\n| `xs:date`, `xs:dateTime`, `xs:time`  | `string`   |\n| `xs:anyURI`, `xs:QName`              | `string`   |\n| `xs:anyType`                         | `unknown`  |\n\n### XML Module\n\n```typescript\nimport { parseXml, buildXml } from '@abapify/ts-xsd';\n```\n\n#### `parseXml<T>(schema: SchemaLike, xml: string): T`\n\nParse XML string using schema definition.\n\n#### `buildXml<T>(schema: SchemaLike, data: T): string`\n\nBuild XML string from data using schema definition.\n\n### Codegen Module\n\n```typescript\nimport { generateSchemaLiteral, generateInterfaces } from '@abapify/ts-xsd';\n```\n\n#### `generateSchemaLiteral(xsd: string, options?: GenerateOptions): string`\n\nGenerate TypeScript schema literal from XSD content.\n\n```typescript\nconst code = generateSchemaLiteral(xsdContent, {\n  name: 'PersonSchema',\n  features: { $xmlns: true, $imports: true },\n  exclude: ['annotation'],\n});\n// export default { ... } as const;\n```\n\n#### `generateInterfaces(schema: Schema, options?: GenerateInterfacesOptions): GenerateInterfacesResult`\n\nGenerate TypeScript interfaces from parsed schema. Returns an object with `code` property containing the generated TypeScript code.\n\n```typescript\nconst { code } = generateInterfaces(schema, {\n  flatten: true, // Inline all nested types (default: false)\n  addJsDoc: true, // Add JSDoc comments\n  rootTypeName: 'MySchema', // Custom root type name\n});\n```\n\n## Schema Structure\n\nThe `Schema` type is a 1:1 TypeScript representation of W3C XSD:\n\n```typescript\ninterface Schema {\n  // Namespace\n  targetNamespace?: string;\n  elementFormDefault?: 'qualified' | 'unqualified';\n  attributeFormDefault?: 'qualified' | 'unqualified';\n\n  // Composition\n  import?: Import[];\n  include?: Include[];\n\n  // Declarations\n  element?: TopLevelElement[];\n  complexType?: TopLevelComplexType[];\n  simpleType?: TopLevelSimpleType[];\n  group?: NamedGroup[];\n  attributeGroup?: NamedAttributeGroup[];\n\n  // Extensions (non-W3C, prefixed with $)\n  $xmlns?: { [prefix: string]: string };\n  $imports?: Schema[]; // Resolved imported schemas\n  $filename?: string; // Source filename\n}\n```\n\n### Cross-Schema Type Resolution\n\nLink schemas together for cross-schema type resolution:\n\n```typescript\nconst adtcore = parseXsd(adtcoreXsd);\nconst classes = parseXsd(classesXsd);\n\n// Link schemas via $imports\nconst linkedClasses = {\n  ...classes,\n  $imports: [adtcore],\n};\n\n// Now InferSchema can resolve types from adtcore\ntype AbapClass = InferSchema<typeof linkedClasses>;\n```\n\n## Type Inference Deep Dive\n\n### How It Works\n\nThe type inference system uses TypeScript's conditional types to:\n\n1. **Find root elements** - Extract element declarations from schema\n2. **Resolve type references** - Look up `complexType` and `simpleType` by name\n3. **Handle inheritance** - Process `complexContent/extension` for type inheritance\n4. **Map XSD to TS** - Convert XSD types to TypeScript equivalents\n5. **Handle optionality** - `minOccurs=\"0\"` → optional property\n6. **Handle arrays** - `maxOccurs=\"unbounded\"` → array type\n\n### Example: Complex Schema\n\n```typescript\nconst schema = {\n  $imports: [baseSchema],\n  element: [{ name: 'order', type: 'OrderType' }],\n  complexType: [\n    {\n      name: 'OrderType',\n      complexContent: {\n        extension: {\n          base: 'base:BaseEntity', // Inherits from imported schema\n          sequence: {\n            element: [\n              { name: 'items', type: 'ItemType', maxOccurs: 'unbounded' },\n              { name: 'total', type: 'xs:decimal' },\n            ],\n          },\n        },\n      },\n    },\n    {\n      name: 'ItemType',\n      sequence: {\n        element: [\n          { name: 'sku', type: 'xs:string' },\n          { name: 'quantity', type: 'xs:int' },\n        ],\n      },\n    },\n  ],\n} as const;\n\ntype Order = InferSchema<typeof schema>;\n// Result:\n// {\n//   ...BaseEntity,  // Inherited properties\n//   items: { sku: string; quantity: number }[];\n//   total: number;\n// }\n```\n\n## Architecture\n\n```\n@abapify/ts-xsd\n├── src/\n│   ├── index.ts           # Main exports\n│   ├── xsd/               # XSD parsing, building, resolution\n│   │   ├── types.ts       # W3C 1:1 type definitions\n│   │   ├── parse.ts       # XSD XML → Schema parser\n│   │   ├── build.ts       # Schema → XSD XML builder\n│   │   ├── resolve.ts     # Schema resolver (merges imports, expands inheritance)\n│   │   ├── traverser.ts   # OO schema traversal with W3C types\n│   │   ├── loader.ts      # XSD file loading with import resolution\n│   │   ├── schema-like.ts # Runtime schema type guards\n│   │   └── helpers.ts     # Utility functions\n│   ├── infer/             # Compile-time type inference\n│   │   └── types.ts       # InferSchema<T>, InferElement<T>\n│   ├── xml/               # XML parsing/building with schemas\n│   │   ├── parse.ts       # XML → Object parser\n│   │   ├── build.ts       # Object → XML builder\n│   │   ├── typed.ts       # Typed schema wrapper\n│   │   └── dom-utils.ts   # DOM manipulation utilities\n│   ├── walker/            # Schema traversal utilities\n│   │   └── index.ts       # walkElements, walkComplexTypes, findSubstitutes\n│   ├── codegen/           # Code generation\n│   │   ├── generate.ts    # Schema literal generator\n│   │   ├── interface-generator.ts  # Interface generator API\n│   │   ├── ts-morph.ts    # TypeScript AST manipulation\n│   │   ├── runner.ts      # Config-based codegen runner\n│   │   └── cli.ts         # CLI interface\n│   └── generators/        # Generator plugins\n│       ├── raw-schema.ts  # Schema literal generator\n│       ├── interfaces.ts  # TypeScript interfaces generator\n│       ├── typed-schemas.ts # Typed schema exports\n│       └── index-barrel.ts # Index file generator\n```\n\n### Key Components\n\n| Component     | Purpose                                                                            |\n| ------------- | ---------------------------------------------------------------------------------- |\n| **Resolver**  | Merges `$imports`, expands `complexContent/extension`, handles `substitutionGroup` |\n| **Traverser** | OO traversal with real W3C XSD types (SchemaTraverser class)                       |\n| **Walker**    | Functional iteration over schema elements, types, groups                           |\n| **Loader**    | File-based XSD loading with automatic import resolution                            |\n\n## Design Principles\n\n1. **Pure W3C XSD** - No invented properties or conveniences\n2. **Type safety** - Full TypeScript support with inference\n3. **Minimal dependencies** - Only `@xmldom/xmldom`\n4. **Tree-shakeable** - Import only what you need\n5. **Tested against W3C** - Verified with official XMLSchema.xsd\n\n## Testing\n\n```bash\n# Run all tests\nnpx nx test ts-xsd\n\n# Run with coverage\nnpx nx test:coverage ts-xsd\n```\n\nTests include:\n\n- Unit tests for parser, builder, and inference\n- Integration tests with real XSD files\n- W3C XMLSchema.xsd roundtrip verification\n\n## Related Packages\n\n- **[@abapify/adt-schemas](../adt-schemas)** - SAP ADT schemas using ts-xsd\n- **[@abapify/adt-contracts](../adt-contracts)** - REST contracts for SAP ADT APIs\n- **[@abapify/adt-plugin-abapgit](../adt-plugin-abapgit)** - abapGit plugin schemas\n\n## Documentation\n\n- **[Codegen Guide](./docs/codegen.md)** - Comprehensive code generation documentation\n- **[AGENTS.md](./AGENTS.md)** - AI agent guidelines\n\n## References\n\n- [W3C XML Schema 1.1 Part 1: Structures](https://www.w3.org/TR/xmlschema11-1/)\n- [XMLSchema.xsd](https://www.w3.org/TR/xmlschema11-1/XMLSchema.xsd)\n\n## License\n\nMIT\n","readmeFilename":"README.md"}