{"version":3,"file":"index.mjs","names":[],"sources":["../src/format.ts","../src/generator.ts","../src/schema-index.ts","../src/naming.ts","../src/generate.ts"],"sourcesContent":["import type { JSONSchema } from \"json-schema-typed/draft-2020-12\";\n\nconst IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\n/** a property key, quoted when it is not a valid identifier */\nexport function propertyKey(key: string): string {\n  return IDENTIFIER.test(key) ? key : JSON.stringify(key);\n}\n\n/** TypeScript literal type of a JSON value (for `const` and `enum`) */\nexport function literalType(value: unknown): string {\n  if (value === null) return \"null\";\n  switch (typeof value) {\n    case \"string\":\n      return JSON.stringify(value);\n    case \"number\":\n    case \"boolean\":\n      return String(value);\n    case \"object\": {\n      if (Array.isArray(value)) return `[${value.map(literalType).join(\", \")}]`;\n      const entries = Object.entries(value as Record<string, unknown>);\n      if (entries.length === 0) return \"Record<string, never>\";\n      return `{ ${entries.map(([k, v]) => `${propertyKey(k)}: ${literalType(v)}`).join(\"; \")} }`;\n    }\n    default:\n      return \"unknown\";\n  }\n}\n\nexport function joinUnion(members: ReadonlySet<string>): string {\n  let out = \"\";\n  for (const member of members) out = out.length === 0 ? member : `${out} | ${member}`;\n  return out.length === 0 ? \"never\" : out;\n}\n\n/** whether the expression contains a top-level union/intersection */\nexport function isCompound(expression: string): boolean {\n  let depth = 0;\n  let quote: string | undefined;\n  for (let i = 0; i < expression.length; i++) {\n    const char = expression[i]!;\n    if (quote !== undefined) {\n      if (char === \"\\\\\") i++;\n      else if (char === quote) quote = undefined;\n      continue;\n    }\n    switch (char) {\n      case '\"':\n      case \"'\":\n        quote = char;\n        break;\n      case \"{\":\n      case \"[\":\n      case \"(\":\n      case \"<\":\n        depth++;\n        break;\n      case \"}\":\n      case \"]\":\n      case \")\":\n      case \">\":\n        depth--;\n        break;\n      case \"|\":\n      case \"&\":\n        if (depth === 0) return true;\n        break;\n    }\n  }\n  return false;\n}\n\nexport function wrapCompound(expression: string): string {\n  return isCompound(expression) ? `(${expression})` : expression;\n}\n\n/** JSDoc block built from a schema's annotations, undefined when empty */\nexport function jsdoc(\n  schema: JSONSchema,\n  indent: string,\n  includeTitle: boolean,\n): string | undefined {\n  if (typeof schema !== \"object\" || schema === null) return undefined;\n\n  const lines: string[] = [];\n  if (includeTitle && typeof schema.title === \"string\" && schema.title.length > 0) {\n    lines.push(schema.title);\n  }\n  if (typeof schema.description === \"string\" && schema.description.length > 0) {\n    lines.push(...schema.description.split(\"\\n\"));\n  }\n\n  const tags: string[] = [];\n  if (schema.deprecated === true) tags.push(\"@deprecated\");\n  if (schema.default !== undefined) tags.push(`@default ${JSON.stringify(schema.default)}`);\n  if (Array.isArray(schema.examples)) {\n    for (const example of schema.examples) tags.push(`@example ${JSON.stringify(example)}`);\n  }\n\n  if (lines.length === 0 && tags.length === 0) return undefined;\n  if (tags.length > 0) {\n    if (lines.length > 0) lines.push(\"\");\n    lines.push(...tags);\n  }\n\n  const escaped = lines.map((line) => line.replaceAll(\"*/\", \"*\\\\/\"));\n  if (escaped.length === 1) return `${indent}/** ${escaped[0]} */`;\n  const body = escaped.map((line) => `${indent} *${line.length > 0 ? ` ${line}` : \"\"}`);\n  return `${indent}/**\\n${body.join(\"\\n\")}\\n${indent} */`;\n}\n","import type { JSONSchema } from \"json-schema-typed/draft-2020-12\";\nimport { isCompound, joinUnion, jsdoc, literalType, propertyKey, wrapCompound } from \"./format\";\nimport type { SchemaObject } from \"./schema-index\";\n\n/** options shared by every generator */\nexport interface CommonOptions {\n  /**\n   * Name of the generated root type.\n   *\n   * Defaults to the schema's `title` (converted to PascalCase), or `\"Schema\"`.\n   */\n  name?: string;\n\n  /**\n   * Indentation unit for the generated code.\n   *\n   * @default \"  \"\n   */\n  tab?: string;\n\n  /**\n   * Include properties marked `readOnly` (e.g. server-assigned fields).\n   *\n   * When included, they keep a `readonly` modifier in the output.\n   *\n   * @default false\n   */\n  readOnly?: boolean;\n\n  /**\n   * Include properties marked `writeOnly` (e.g. passwords).\n   *\n   * @default false\n   */\n  writeOnly?: boolean;\n}\n\nexport interface Declaration {\n  name: string;\n  schema: JSONSchema;\n}\n\n/**\n * Shared conversion engine: turns schemas into TypeScript declarations.\n *\n * Subclasses decide how the root declarations are seeded and what a `$ref`\n * means (resolve it through an index, or reject it for dereferenced input).\n */\nexport abstract class Generator {\n  /** schema objects that received a named declaration */\n  protected readonly names = new Map<SchemaObject, string>();\n  private readonly usedNames = new Set<string>();\n  protected readonly declarations: Declaration[] = [];\n  private readonly interfaceLike = new WeakMap<SchemaObject, boolean>();\n  private readonly INDENT: string;\n  private readonly includeReadOnly: boolean;\n  private readonly includeWriteOnly: boolean;\n\n  constructor(\n    protected readonly root: JSONSchema,\n    options: CommonOptions,\n  ) {\n    this.INDENT = options.tab ?? \"  \";\n    this.includeReadOnly = options.readOnly ?? false;\n    this.includeWriteOnly = options.writeOnly ?? false;\n  }\n\n  /** the named type a `$ref`/`$dynamicRef` in `source` points to */\n  protected abstract refExpression(ref: string, source: SchemaObject): string;\n\n  /** whether an `allOf` member can appear in an interface `extends` clause */\n  protected abstract isExtendableRef(member: JSONSchema, seen: Set<SchemaObject>): boolean;\n\n  protected emitAll(): string {\n    const out: string[] = [];\n    // emitting a declaration may declare new ones (e.g. `$ref` to a nested schema)\n    for (let i = 0; i < this.declarations.length; i++) {\n      out.push(this.emitDeclaration(this.declarations[i]!));\n    }\n    return `${out.join(\"\\n\\n\")}\\n`;\n  }\n\n  protected claimName(desired: string): string {\n    let name = desired;\n    let attempt = 2;\n    while (this.usedNames.has(name)) name = `${desired}${attempt++}`;\n    this.usedNames.add(name);\n    return name;\n  }\n\n  /** assign a named declaration to a schema object, reusing an existing one */\n  protected declare(schema: SchemaObject, desired: string): string {\n    const existing = this.names.get(schema);\n    if (existing !== undefined) return existing;\n    const name = this.claimName(desired);\n    this.names.set(schema, name);\n    this.declarations.push({ name, schema });\n    return name;\n  }\n\n  /** type expression for a schema at a usage site (property, array item, ...) */\n  protected expressionFor(schema: JSONSchema, indent: string): string {\n    if (typeof schema === \"boolean\") return schema ? \"unknown\" : \"never\";\n    return this.names.get(schema) ?? this.intersectionOf(this.typeParts(schema, indent));\n  }\n\n  /**\n   * The type of a schema as intersection parts, each part being a union of\n   * members. Kept structured so declarations can format long unions nicely.\n   */\n  private typeParts(schema: SchemaObject, indent: string): Set<string>[] {\n    const parts: Set<string>[] = [];\n    if (typeof schema.$ref === \"string\") {\n      parts.push(new Set([this.refExpression(schema.$ref, schema)]));\n    }\n    if (typeof schema.$dynamicRef === \"string\") {\n      parts.push(new Set([this.refExpression(schema.$dynamicRef, schema)]));\n    }\n\n    if (Array.isArray(schema.allOf)) {\n      for (const member of schema.allOf) {\n        parts.push(new Set([this.expressionFor(member, indent)]));\n      }\n    }\n\n    const own = this.ownType(schema, indent);\n    if (own !== undefined) parts.push(own);\n\n    for (const list of [schema.anyOf, schema.oneOf]) {\n      if (Array.isArray(list) && list.length > 0) {\n        parts.push(this.unionOf(list, indent));\n      }\n    }\n\n    // `if/then/else` validates one of the two branches, approximate as a union\n    if (schema.if !== undefined && schema.then !== undefined && schema.else !== undefined) {\n      parts.push(this.unionOf([schema.then, schema.else], indent));\n    }\n\n    // `unknown` adds nothing to an intersection\n    const known = parts.filter((part) => !(part.size === 1 && part.has(\"unknown\")));\n    return known.length > 0 ? known : parts.slice(0, 1);\n  }\n\n  /** join intersection parts into a single expression */\n  private intersectionOf(parts: readonly Set<string>[]): string {\n    if (parts.length === 0) return \"unknown\";\n    if (parts.length === 1) return joinUnion(parts[0]!);\n    return parts\n      .map((part) => {\n        const union = joinUnion(part);\n        return part.size > 1 || isCompound(union) ? `(${union})` : union;\n      })\n      .join(\" & \");\n  }\n\n  /** deduplicated union of the given subschemas, collapsed when a member is `unknown` */\n  private unionOf(schemas: readonly JSONSchema[], indent: string): Set<string> {\n    const members = new Set<string>();\n    for (const member of schemas) {\n      const out = this.expressionFor(member, indent);\n      if (out === \"unknown\") return new Set([\"unknown\"]);\n      members.add(out);\n    }\n    return members;\n  }\n\n  /** the union derived from `const`, `enum` or `type` (undefined when absent) */\n  private ownType(schema: SchemaObject, indent: string): Set<string> | undefined {\n    const members = new Set<string>();\n\n    if (schema.const !== undefined) {\n      members.add(literalType(schema.const));\n      return members;\n    }\n\n    if (Array.isArray(schema.enum)) {\n      if (schema.enum.length === 0) {\n        members.add(\"never\");\n        return members;\n      }\n\n      for (const value of schema.enum) members.add(literalType(value));\n      return members;\n    }\n\n    let types: string[];\n    if (typeof schema.type === \"string\") {\n      types = [schema.type];\n    } else if (Array.isArray(schema.type)) {\n      types = schema.type as string[];\n    } else {\n      // infer the type from present keywords\n      types = [];\n      if (\n        schema.properties !== undefined ||\n        schema.patternProperties !== undefined ||\n        schema.additionalProperties !== undefined\n      ) {\n        types.push(\"object\");\n      }\n      if (schema.items !== undefined || schema.prefixItems !== undefined) {\n        types.push(\"array\");\n      }\n      if (types.length === 0) return undefined;\n    }\n\n    for (const type of types) members.add(this.namedType(type, schema, indent));\n    return members;\n  }\n\n  /** TypeScript type for a single JSON Schema `type` keyword value */\n  private namedType(type: string, schema: SchemaObject, indent: string): string {\n    switch (type) {\n      case \"string\":\n        return \"string\";\n      case \"number\":\n      case \"integer\":\n        return \"number\";\n      case \"boolean\":\n        return \"boolean\";\n      case \"null\":\n        return \"null\";\n      case \"object\":\n        return this.objectType(schema, indent);\n      case \"array\":\n        return this.arrayType(schema, indent);\n      default:\n        return \"unknown\";\n    }\n  }\n\n  /** whether a property is kept, given the `readOnly`/`writeOnly` options */\n  private keepsProperty(property: JSONSchema): boolean {\n    if (typeof property !== \"object\" || property === null) return true;\n    if (property.readOnly === true) return this.includeReadOnly;\n    if (property.writeOnly === true) return this.includeWriteOnly;\n    return true;\n  }\n\n  private objectType(schema: SchemaObject, indent: string): string {\n    const properties =\n      schema.properties && typeof schema.properties === \"object\"\n        ? Object.entries(schema.properties).filter(([, property]) => this.keepsProperty(property))\n        : [];\n    const patterns =\n      schema.patternProperties && typeof schema.patternProperties === \"object\"\n        ? Object.values(schema.patternProperties)\n        : [];\n    const additional = schema.additionalProperties;\n    const inner = indent + this.INDENT;\n\n    // index signature value type, when the schema allows extra properties\n    const extra = new Set<string>();\n    for (const pattern of patterns) extra.add(this.expressionFor(pattern, inner));\n    if (additional === true) extra.add(\"unknown\");\n    else if (typeof additional === \"object\") extra.add(this.expressionFor(additional, inner));\n\n    if (properties.length === 0) {\n      if (extra.size > 0) return `Record<string, ${joinUnion(extra)}>`;\n      if (additional === false) return \"Record<string, never>\";\n      return \"Record<string, unknown>\";\n    }\n\n    const required = new Set(schema.required);\n    const hasIndex = extra.size > 0;\n    const lines: string[] = [];\n    let hasOptional = false;\n\n    for (const [key, property] of properties) {\n      const doc = jsdoc(property, inner, true);\n      if (doc !== undefined) {\n        if (lines.length > 0) lines.push(\"\");\n        lines.push(doc);\n      }\n      const readonly =\n        typeof property === \"object\" && property !== null && property.readOnly === true\n          ? \"readonly \"\n          : \"\";\n      const optional = required.has(key) ? \"\" : \"?\";\n      if (optional) hasOptional = true;\n      const value = this.expressionFor(property, inner);\n      // include the property types so the index signature stays compatible\n      if (hasIndex) extra.add(value);\n      lines.push(`${inner}${readonly}${propertyKey(key)}${optional}: ${value};`);\n    }\n\n    if (hasIndex) {\n      if (hasOptional) extra.add(\"undefined\");\n      lines.push(`${inner}[key: string]: ${extra.has(\"unknown\") ? \"unknown\" : joinUnion(extra)};`);\n    }\n\n    return `{\\n${lines.join(\"\\n\")}\\n${indent}}`;\n  }\n\n  private arrayType(schema: SchemaObject, indent: string): string {\n    const items = schema.items as JSONSchema | undefined;\n\n    if (Array.isArray(schema.prefixItems) && schema.prefixItems.length > 0) {\n      const members = schema.prefixItems.map((member) =>\n        this.expressionFor(member as JSONSchema, indent),\n      );\n      if (items !== false) {\n        const rest =\n          items === undefined || items === true ? \"unknown\" : this.expressionFor(items, indent);\n        members.push(`...${wrapCompound(rest)}[]`);\n      }\n      return `[${members.join(\", \")}]`;\n    }\n\n    if (items === undefined || items === true) return \"unknown[]\";\n    if (items === false) return \"never[]\";\n    return `${wrapCompound(this.expressionFor(items, indent))}[]`;\n  }\n\n  private emitDeclaration(declaration: Declaration): string {\n    const { name, schema } = declaration;\n    const doc = jsdoc(schema, \"\", false);\n    let body: string;\n\n    if (typeof schema === \"boolean\") {\n      body = `export type ${name} = ${schema ? \"unknown\" : \"never\"};`;\n    } else if (this.isInterfaceLike(schema)) {\n      const parents = Array.isArray(schema.allOf)\n        ? schema.allOf.map((member) => {\n            const parent = member as SchemaObject;\n            return this.refExpression(parent.$ref!, parent);\n          })\n        : [];\n      const heritage = parents.length > 0 ? ` extends ${parents.join(\", \")}` : \"\";\n      body = `export interface ${name}${heritage} ${this.objectType(schema, \"\")}`;\n    } else {\n      const parts = this.typeParts(schema, \"\");\n      const union = parts.length === 1 ? parts[0]! : undefined;\n      const multiline =\n        union !== undefined && union.size > 1 && (union.size > 2 || joinUnion(union).length > 70);\n      body = multiline\n        ? `export type ${name} =\\n${Array.from(union, (member) => `${this.INDENT}| ${member}`).join(\"\\n\")};`\n        : `export type ${name} = ${this.intersectionOf(parts)};`;\n    }\n\n    return doc !== undefined ? `${doc}\\n${body}` : body;\n  }\n\n  /** whether a declaration can be emitted as `interface` (optionally with `extends`) */\n  protected isInterfaceLike(schema: SchemaObject, seen = new Set<SchemaObject>()): boolean {\n    const memo = this.interfaceLike.get(schema);\n    if (memo !== undefined) return memo;\n    if (seen.has(schema)) return false;\n    seen.add(schema);\n\n    const result = this.computeInterfaceLike(schema, seen);\n    this.interfaceLike.set(schema, result);\n    return result;\n  }\n\n  private computeInterfaceLike(schema: SchemaObject, seen: Set<SchemaObject>): boolean {\n    if (\n      schema.$ref !== undefined ||\n      schema.$dynamicRef !== undefined ||\n      schema.const !== undefined ||\n      schema.enum !== undefined ||\n      schema.anyOf !== undefined ||\n      schema.oneOf !== undefined\n    ) {\n      return false;\n    }\n    if (typeof schema.type === \"string\" ? schema.type !== \"object\" : schema.type !== undefined) {\n      return false;\n    }\n    // an object whose properties are all hidden by the access filter is emitted\n    // through the `Record<…>` type path instead of an empty interface\n    if (\n      !schema.properties ||\n      !Object.values(schema.properties).some((p) => this.keepsProperty(p))\n    ) {\n      return false;\n    }\n    if (schema.allOf === undefined) return true;\n    if (!Array.isArray(schema.allOf)) return false;\n\n    return schema.allOf.every((member) => this.isExtendableRef(member, seen));\n  }\n}\n","import type { JSONSchema } from \"json-schema-typed/draft-2020-12\";\n\nexport type SchemaObject = Exclude<JSONSchema, boolean>;\n\n/** base URI assigned to documents without an `$id` */\nconst DEFAULT_BASE = \"schema://local/schema.json\";\n\n/** keywords containing subschemas, and the shape of their value */\nconst SUBSCHEMA_KEYWORDS = new Map<string, \"one\" | \"list\" | \"map\">([\n  [\"additionalProperties\", \"one\"],\n  [\"contains\", \"one\"],\n  [\"propertyNames\", \"one\"],\n  [\"if\", \"one\"],\n  [\"then\", \"one\"],\n  [\"else\", \"one\"],\n  [\"not\", \"one\"],\n  [\"items\", \"one\"],\n  [\"unevaluatedItems\", \"one\"],\n  [\"unevaluatedProperties\", \"one\"],\n  [\"contentSchema\", \"one\"],\n  [\"allOf\", \"list\"],\n  [\"anyOf\", \"list\"],\n  [\"oneOf\", \"list\"],\n  [\"prefixItems\", \"list\"],\n  [\"$defs\", \"map\"],\n  [\"definitions\", \"map\"],\n  [\"properties\", \"map\"],\n  [\"patternProperties\", \"map\"],\n  [\"dependentSchemas\", \"map\"],\n]);\n\n/** invoke `visit` for each subschema directly nested in `schema` */\nexport function forEachSubschema(schema: SchemaObject, visit: (sub: JSONSchema) => void): void {\n  const record = schema as Record<string, unknown>;\n  for (const key in record) {\n    const kind = SUBSCHEMA_KEYWORDS.get(key);\n    if (kind === undefined) continue;\n    const value = record[key];\n    if (kind === \"one\") {\n      visit(value as JSONSchema);\n    } else if (kind === \"list\") {\n      if (Array.isArray(value)) {\n        for (const item of value) visit(item as JSONSchema);\n      }\n    } else if (typeof value === \"object\" && value !== null) {\n      const map = value as Record<string, JSONSchema>;\n      for (const entry in map) visit(map[entry]!);\n    }\n  }\n}\n\n/**\n * Index of a bundled schema document: registers every schema resource\n * (`$id`), anchor (`$anchor`/`$dynamicAnchor`) and the base URI in effect for\n * each subschema, so internal `$ref`s can be resolved.\n */\nexport class SchemaIndex {\n  /** URI of the document itself, references in `GenerateOptions.ref` resolve against it */\n  readonly rootUri: string;\n\n  /** schema resources keyed by canonical URI */\n  private readonly resources = new Map<string, JSONSchema>();\n  /** anchor targets keyed by `<resource uri>#<anchor>` */\n  private readonly anchors = new Map<string, SchemaObject>();\n  /**\n   * Base URI in effect for each subschema. Only populated inside embedded\n   * `$id` resources; everything else uses the root URI, so for the common\n   * single-resource document this stays empty.\n   */\n  private readonly bases = new WeakMap<SchemaObject, string>();\n  /** memoized resolutions keyed by base URI, then by reference */\n  private readonly resolutions = new Map<string, Map<string, JSONSchema>>();\n\n  constructor(root: JSONSchema) {\n    this.rootUri =\n      typeof root === \"object\" && typeof root.$id === \"string\"\n        ? withoutFragment(resolveUri(root.$id, DEFAULT_BASE))\n        : DEFAULT_BASE;\n    this.resources.set(this.rootUri, root);\n    this.walk(root, this.rootUri);\n  }\n\n  /** base URI in effect for a subschema of the document */\n  baseUri(schema: SchemaObject): string {\n    return this.bases.get(schema) ?? this.rootUri;\n  }\n\n  /** resolve a `$ref` against the base URI of its enclosing schema */\n  resolve(ref: string, baseUri: string): JSONSchema {\n    let perBase = this.resolutions.get(baseUri);\n    if (perBase === undefined) {\n      perBase = new Map();\n      this.resolutions.set(baseUri, perBase);\n    }\n    let target = perBase.get(ref);\n    if (target === undefined) {\n      target = this.resolveNew(ref, baseUri);\n      perBase.set(ref, target);\n    }\n    return target;\n  }\n\n  private resolveNew(ref: string, baseUri: string): JSONSchema {\n    const resolved = resolveUri(ref, baseUri);\n    const hash = resolved.indexOf(\"#\");\n    const uri = hash === -1 ? resolved : resolved.slice(0, hash);\n    const fragment = hash === -1 ? \"\" : resolved.slice(hash + 1);\n\n    // a plain name fragment refers to an anchor within the resource\n    if (fragment.length > 0 && !fragment.startsWith(\"/\")) {\n      const anchored = this.anchors.get(`${uri}#${decodeURIComponent(fragment)}`);\n      if (anchored === undefined) {\n        throw new Error(`Cannot resolve $ref \"${ref}\": unknown anchor \"${fragment}\".`);\n      }\n      return anchored;\n    }\n\n    const resource = this.resources.get(uri);\n    if (resource === undefined) {\n      throw new Error(\n        `Cannot resolve $ref \"${ref}\": external references are not supported, bundle them into the schema first.`,\n      );\n    }\n    return fragment.length === 0 ? resource : resolvePointer(resource, fragment, ref);\n  }\n\n  /** register the resources, anchors and base URIs of a (sub)schema */\n  private walk(schema: JSONSchema, baseUri: string): void {\n    if (typeof schema !== \"object\" || schema === null) return;\n    let base = baseUri;\n    if (typeof schema.$id === \"string\") {\n      base = withoutFragment(resolveUri(schema.$id, baseUri));\n      this.resources.set(base, schema);\n    }\n    if (base !== this.rootUri) this.bases.set(schema, base);\n    if (typeof schema.$anchor === \"string\") {\n      this.anchors.set(`${base}#${schema.$anchor}`, schema);\n    }\n    if (typeof schema.$dynamicAnchor === \"string\") {\n      this.anchors.set(`${base}#${schema.$dynamicAnchor}`, schema);\n    }\n\n    forEachSubschema(schema, (sub) => this.walk(sub, base));\n  }\n}\n\nfunction resolveUri(uri: string, base: string): string {\n  // fragment-only references are the common case, skip the URL machinery\n  if (uri.startsWith(\"#\")) return base + uri;\n  try {\n    return new URL(uri, base).href;\n  } catch {\n    return uri;\n  }\n}\n\nfunction withoutFragment(uri: string): string {\n  const hash = uri.indexOf(\"#\");\n  return hash === -1 ? uri : uri.slice(0, hash);\n}\n\nconst POINTER_CHARS_RE = /~1|~0/g;\nconst POINTER_CHARS = {\n  \"~0\": \"~\",\n  \"~1\": \"/\",\n};\n\n/** follow a JSON pointer fragment (`/$defs/user`) through a resource */\nfunction resolvePointer(resource: JSONSchema, pointer: string, ref: string): JSONSchema {\n  let current: unknown = resource;\n  for (const token of pointer.split(\"/\")) {\n    if (token.length === 0) continue;\n    const key = decodeURIComponent(token).replaceAll(\n      POINTER_CHARS_RE,\n      (v) => POINTER_CHARS[v as never],\n    );\n\n    if (Array.isArray(current)) {\n      current = current[Number(key)];\n    } else if (typeof current === \"object\" && current !== null) {\n      current = (current as Record<string, unknown>)[key];\n    } else {\n      current = undefined;\n    }\n    if (current === undefined) {\n      throw new Error(`Cannot resolve $ref \"${ref}\": no value at that location.`);\n    }\n  }\n  return current as JSONSchema;\n}\n\nexport function getRefTail(ref: string): string | undefined {\n  return /([^\\/#?]+)$/.exec(ref)?.[1];\n}\n","import type { JSONSchema } from \"json-schema-typed/draft-2020-12\";\nimport { getRefTail, type SchemaObject } from \"./schema-index\";\n\nexport function toPascalCase(input: string): string {\n  const words = input.match(/[A-Za-z0-9]+/g);\n  if (!words) return \"Type\";\n  let name = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(\"\");\n  if (/^[0-9]/.test(name)) name = `_${name}`;\n  return name;\n}\n\n/** pick a readable name for a `$defs` entry */\nexport function defName(key: string, def: JSONSchema): string {\n  // bundled schemas are often keyed by their URI, use the last path segment instead\n  if (key.includes(\"://\") || key.startsWith(\"/\")) {\n    const tail = getRefTail(key);\n    if (tail) return toPascalCase(tail.replace(/\\.[a-z0-9]+$/i, \"\"));\n    if (typeof def === \"object\" && typeof def.title === \"string\") {\n      return toPascalCase(def.title);\n    }\n    return \"Type\";\n  }\n  return toPascalCase(key);\n}\n\n/** pick a readable type name for the target of a reference */\nexport function refNameHint(ref: string, target: SchemaObject): string {\n  if (typeof target.title === \"string\" && target.title.length > 0) {\n    return toPascalCase(target.title);\n  }\n  const tail = getRefTail(ref);\n  if (tail === undefined) return \"Schema\";\n  return toPascalCase(decodeURIComponent(tail).replace(/\\.[a-z0-9]+$/i, \"\"));\n}\n","import type { JSONSchema } from \"json-schema-typed/draft-2020-12\";\nimport { type CommonOptions, Generator } from \"./generator\";\nimport { defName, refNameHint, toPascalCase } from \"./naming\";\nimport { forEachSubschema, SchemaIndex, type SchemaObject } from \"./schema-index\";\n\nexport interface GenerateOptions extends CommonOptions {\n  /**\n   * Generate only the schema this reference points to (along with everything\n   * it depends on) instead of the entire document.\n   *\n   * Accepts any `$ref`-style reference, resolved against the schema root:\n   * a JSON pointer (`#/$defs/user`), an anchor (`#user`), or the `$id` of a\n   * bundled subschema (`https://example.com/user.json`).\n   */\n  ref?: string;\n}\n\nexport interface GenerateFromDereferencedOptions extends CommonOptions {\n  /**\n   * Return the original location of a schema object as a `$ref`-style pointer\n   * (e.g. `#/$defs/user`), or `undefined` for inline/anonymous schemas.\n   *\n   * Dereferencing discards the `$ref` structure, so shared and recursive\n   * schemas are only recognizable by object identity. This callback restores\n   * their canonical location, which is used to generate readable type names.\n   */\n  getRawPath?: (schema: JSONSchema) => string | undefined;\n}\n\n/**\n * Generate TypeScript definitions from a JSON Schema (draft 2020-12).\n *\n * The schema doesn't need to be dereferenced, but external references must be\n * bundled into the document (e.g. under `$defs`) beforehand.\n */\nexport function generate(schema: JSONSchema, options: GenerateOptions = {}): string {\n  return new DocumentGenerator(schema, options).run();\n}\n\n/**\n * Generate TypeScript definitions from a **dereferenced** JSON Schema.\n *\n * Every schema reached more than once (shared or recursive) becomes its own\n * named declaration; pass {@link GenerateFromDereferencedOptions.getRawPath}\n * to give those declarations readable names.\n */\nexport function generateFromDereferenced(\n  schema: JSONSchema,\n  options: GenerateFromDereferencedOptions = {},\n): string {\n  return new DereferencedGenerator(schema, options).run();\n}\n\n/** keywords besides `type` that make a `$ref` sibling contribute to the generated type */\nconst REF_SIBLING_KEYWORDS = [\n  \"enum\",\n  \"const\",\n  \"properties\",\n  \"patternProperties\",\n  \"additionalProperties\",\n  \"propertyNames\",\n  \"items\",\n  \"prefixItems\",\n  \"allOf\",\n  \"anyOf\",\n  \"oneOf\",\n] as const;\n\n/** generates from a bundled document, resolving `$ref`s through a {@link SchemaIndex} */\nclass DocumentGenerator extends Generator {\n  private readonly index: SchemaIndex;\n\n  constructor(\n    root: JSONSchema,\n    private readonly options: GenerateOptions,\n  ) {\n    super(root, options);\n    this.index = new SchemaIndex(root);\n  }\n\n  run(): string {\n    this.declareRoots(this.options.ref);\n    return this.emitAll();\n  }\n\n  /** the named type a `$ref` points to, declaring it on first use */\n  protected refExpression(ref: string, source: SchemaObject): string {\n    const target = this.index.resolve(ref, this.index.baseUri(source));\n    if (typeof target === \"boolean\") return target ? \"unknown\" : \"never\";\n    return this.names.get(target) ?? this.declare(target, refNameHint(ref, target));\n  }\n\n  /**\n   * Whether an `allOf` member is a plain `$ref` to a schema that is emitted\n   * as an interface itself, anything else cannot appear in `extends`.\n   */\n  protected isExtendableRef(member: JSONSchema, seen: Set<SchemaObject>): boolean {\n    if (typeof member !== \"object\" || member === null) return false;\n    if (typeof member.$ref !== \"string\") return false;\n    if (REF_SIBLING_KEYWORDS.some((keyword) => member[keyword] !== undefined)) return false;\n\n    let target: JSONSchema;\n    try {\n      target = this.index.resolve(member.$ref, this.index.baseUri(member));\n    } catch {\n      return false;\n    }\n    if (typeof target !== \"object\" || target === null) return false;\n    return this.isInterfaceLike(target, seen);\n  }\n\n  /** declare the requested subtype, or the document root and its `$defs` */\n  private declareRoots(ref: string | undefined): void {\n    const rootName = this.options.name;\n    if (ref !== undefined) {\n      const target = this.index.resolve(ref, this.index.rootUri);\n      if (typeof target === \"boolean\") {\n        this.declarations.push({ name: this.claimName(rootName ?? \"Schema\"), schema: target });\n      } else {\n        this.declare(target, rootName ?? refNameHint(ref, target));\n      }\n      return;\n    }\n\n    const root = this.root;\n    if (typeof root === \"boolean\") {\n      this.declarations.push({ name: this.claimName(rootName ?? \"Schema\"), schema: root });\n      return;\n    }\n\n    this.declare(\n      root,\n      rootName ?? (typeof root.title === \"string\" ? toPascalCase(root.title) : \"Schema\"),\n    );\n    if (root.$defs && typeof root.$defs === \"object\") {\n      for (const [key, def] of Object.entries(root.$defs)) {\n        if (typeof def === \"object\" && def !== null) {\n          this.declare(def, defName(key, def));\n        } else {\n          this.declarations.push({ name: this.claimName(defName(key, def)), schema: def });\n        }\n      }\n    }\n  }\n}\n\n/**\n * Generates from a dereferenced schema, where recursion and reuse are\n * expressed by shared object identity instead of `$ref`.\n */\nclass DereferencedGenerator extends Generator {\n  constructor(\n    root: JSONSchema,\n    private readonly options: GenerateFromDereferencedOptions,\n  ) {\n    super(root, options);\n  }\n\n  run(): string {\n    const root = this.root;\n    if (typeof root === \"boolean\") {\n      this.declarations.push({ name: this.claimName(this.options.name ?? \"Schema\"), schema: root });\n    } else {\n      this.declare(root, this.options.name ?? this.pickName(root, \"Schema\"));\n      const entered = new Set<SchemaObject>([root]);\n      const visit = (schema: JSONSchema): void => {\n        if (typeof schema !== \"object\" || schema === null) return;\n        if (entered.has(schema)) {\n          if (!this.names.has(schema)) this.declare(schema, this.pickName(schema, \"Type\"));\n          return;\n        }\n        entered.add(schema);\n        forEachSubschema(schema, visit);\n      };\n      forEachSubschema(root, visit);\n    }\n\n    return this.emitAll();\n  }\n\n  /** a dereferenced schema must not contain references */\n  protected refExpression(ref: string): never {\n    throw new Error(\n      `generateFromDereferenced received a schema containing $ref \"${ref}\"; dereference it first, or use generate() instead.`,\n    );\n  }\n\n  /** without `$ref` there is nothing to place in an `extends` clause */\n  protected isExtendableRef(): boolean {\n    return false;\n  }\n\n  /** name a schema from its raw path, then `title`, then a fallback */\n  private pickName(schema: SchemaObject, fallback: string): string {\n    const path = this.options.getRawPath?.(schema);\n    if (path !== undefined) return refNameHint(path, schema);\n    if (typeof schema.title === \"string\" && schema.title.length > 0) {\n      return toPascalCase(schema.title);\n    }\n    return fallback;\n  }\n}\n"],"mappings":";AAEA,MAAM,aAAa;;AAGnB,SAAgB,YAAY,KAAqB;CAC/C,OAAO,WAAW,KAAK,GAAG,IAAI,MAAM,KAAK,UAAU,GAAG;AACxD;;AAGA,SAAgB,YAAY,OAAwB;CAClD,IAAI,UAAU,MAAM,OAAO;CAC3B,QAAQ,OAAO,OAAf;EACE,KAAK,UACH,OAAO,KAAK,UAAU,KAAK;EAC7B,KAAK;EACL,KAAK,WACH,OAAO,OAAO,KAAK;EACrB,KAAK,UAAU;GACb,IAAI,M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