{"version":3,"sources":["../src/type-generator.ts"],"sourcesContent":["import { readFileSync, existsSync, readdirSync, mkdirSync } from \"fs\";\nimport { join, relative, dirname } from \"path\";\nimport { initSync, parse } from \"es-module-lexer\";\nimport { writeFileIfChanged } from \"./write-file-if-changed\";\nimport { registerAPIRouteShape } from \"./api/route-shape\";\nimport { isFarmAPIRouteFileName } from \"./api/route-files\";\n\nlet moduleLexerInitialized = false;\n\nconst API_CLIENT_METHOD_SEGMENTS = new Set([\n  \"get\",\n  \"head\",\n  \"query\",\n  \"post\",\n  \"put\",\n  \"delete\",\n  \"patch\",\n  \"options\",\n]);\n\nexport interface APIRouteInfo {\n  path: string;\n  methods: string[];\n  filePath: string;\n  relativePath: string;\n}\n\nexport class APITypeGenerator {\n  private appDirs: string[];\n\n  constructor(appDir: string | readonly string[]) {\n    this.appDirs = Array.isArray(appDir) ? [...appDir] : [appDir as string];\n  }\n\n  /**\n   * Scan all API route files and extract route information\n   */\n  scanAPIRoutes(): APIRouteInfo[] {\n    const methodSources = new Map<string, Map<string, APIRouteInfo>>();\n\n    for (const appDir of this.appDirs) {\n      const apiDir = join(appDir, \"api\");\n      if (!existsSync(apiDir)) continue;\n\n      const discovered: APIRouteInfo[] = [];\n      this.scanDirectory(apiDir, appDir, discovered);\n      for (const route of discovered) {\n        const routeMethods = methodSources.get(route.path) ?? new Map<string, APIRouteInfo>();\n        for (const method of route.methods) {\n          routeMethods.set(method, route);\n        }\n        methodSources.set(route.path, routeMethods);\n      }\n    }\n\n    const routes: APIRouteInfo[] = [];\n    for (const [routePath, methods] of methodSources) {\n      const routesByFile = new Map<string, APIRouteInfo>();\n      for (const [method, route] of methods) {\n        const existing = routesByFile.get(route.filePath);\n        if (existing) {\n          existing.methods.push(method);\n        } else {\n          routesByFile.set(route.filePath, {\n            ...route,\n            path: routePath,\n            methods: [method],\n          });\n        }\n      }\n      routes.push(...routesByFile.values());\n    }\n\n    return routes.sort(\n      (left, right) =>\n        left.path.localeCompare(right.path) || left.filePath.localeCompare(right.filePath),\n    );\n  }\n\n  private scanDirectory(dir: string, appDir: string, routes: APIRouteInfo[], basePath = \"\") {\n    const items = readdirSync(dir, { withFileTypes: true });\n\n    for (const item of items) {\n      const fullPath = join(dir, item.name);\n\n      if (item.isDirectory()) {\n        const newBasePath = basePath ? `${basePath}/${item.name}` : item.name;\n        this.scanDirectory(fullPath, appDir, routes, newBasePath);\n      } else if (isFarmAPIRouteFileName(item.name)) {\n        const routeInfo = this.extractRouteInfo(fullPath, appDir, basePath);\n        if (routeInfo) {\n          routes.push(routeInfo);\n        }\n      }\n    }\n  }\n\n  private extractRouteInfo(\n    filePath: string,\n    appDir: string,\n    basePath: string,\n  ): APIRouteInfo | null {\n    try {\n      const content = readFileSync(filePath, \"utf-8\");\n      const methods = this.extractExportedMethods(content);\n\n      if (methods.length === 0) {\n        return null;\n      }\n\n      const relativePath = relative(appDir, filePath);\n      const apiPath = basePath ? `/api/${basePath}` : \"/api\";\n\n      return {\n        path: apiPath,\n        methods,\n        filePath,\n        relativePath,\n      };\n    } catch (error) {\n      console.warn(`Failed to read route file ${filePath}:`, error);\n      return null;\n    }\n  }\n\n  private extractExportedMethods(content: string): string[] {\n    if (!moduleLexerInitialized) {\n      initSync();\n      moduleLexerInitialized = true;\n    }\n    const httpMethods = [\"GET\", \"HEAD\", \"QUERY\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"];\n    const [, exports] = parse(content);\n    const valueExports = new Set(\n      exports\n        .filter((specifier) => !this.isTypeOnlyExportSpecifier(content, specifier.s))\n        .map((specifier) => specifier.n),\n    );\n    return httpMethods.filter((method) => valueExports.has(method));\n  }\n\n  private isTypeOnlyExportSpecifier(content: string, exportNameStart: number): boolean {\n    let cursor = exportNameStart - 1;\n\n    while (cursor >= 0) {\n      while (cursor >= 0 && /\\s/.test(content[cursor])) cursor--;\n\n      if (content.slice(cursor - 1, cursor + 1) === \"*/\") {\n        const commentStart = content.lastIndexOf(\"/*\", cursor - 1);\n        if (commentStart >= 0) {\n          cursor = commentStart - 1;\n          continue;\n        }\n      }\n\n      const lineStart = content.lastIndexOf(\"\\n\", cursor) + 1;\n      const lineCommentStart = content.indexOf(\"//\", lineStart);\n      if (lineCommentStart >= 0 && lineCommentStart <= cursor) {\n        cursor = lineCommentStart - 1;\n        continue;\n      }\n\n      break;\n    }\n\n    const tokenEnd = cursor + 1;\n    while (cursor >= 0 && /[A-Za-z0-9_$]/.test(content[cursor])) cursor--;\n    return content.slice(cursor + 1, tokenEnd) === \"type\";\n  }\n\n  /**\n   * Generate TypeScript code for the API router\n   */\n  generateAPIRouter(\n    routes: APIRouteInfo[],\n    options: {\n      outFile?: string;\n      pluginConfigs?: readonly string[];\n      pluginRoutes?: readonly { path: string; method: string }[];\n    } = {},\n  ): string {\n    const imports: string[] = [];\n    const pluginTypes: string[] = [];\n    if (options.pluginConfigs?.length) {\n      imports.push('import type { PluginAPIRouter } from \"@farm.js/core/api\";');\n      options.pluginConfigs.forEach((filePath, index) => {\n        const importPath = this.getRouteImportPath({ filePath } as APIRouteInfo, options.outFile);\n        imports.push(`import type FarmPluginConfig${index} from ${JSON.stringify(importPath)};`);\n        pluginTypes.push(`PluginAPIRouter<typeof FarmPluginConfig${index}>`);\n      });\n    }\n\n    // Group routes by path to handle multiple methods\n    const routeGroups = new Map<string, APIRouteInfo[]>();\n\n    for (const route of routes) {\n      const key = route.path;\n      if (!routeGroups.has(key)) {\n        routeGroups.set(key, []);\n      }\n      routeGroups.get(key)!.push(route);\n    }\n\n    const routeMethodsByPath = new Map<string, Set<string>>();\n    for (const [routePath, routeList] of routeGroups) {\n      const cleanPath = routePath === \"/api\" ? \"\" : routePath.replace(/^\\/api\\//, \"\");\n      routeMethodsByPath.set(\n        cleanPath,\n        new Set(routeList.flatMap((route) => route.methods.map((method) => method.toLowerCase()))),\n      );\n    }\n    for (const route of options.pluginRoutes ?? []) {\n      const cleanPath = route.path === \"/api\" ? \"\" : route.path.replace(/^\\/api\\//, \"\");\n      const methods = routeMethodsByPath.get(cleanPath) ?? new Set<string>();\n      methods.add(route.method.toLowerCase());\n      routeMethodsByPath.set(cleanPath, methods);\n    }\n\n    // Build nested structure\n    const nestedStructure: any = {};\n    const usedRouteNames = new Map<string, number>();\n\n    for (const [path, routeList] of routeGroups) {\n      const routeName = this.uniqueRouteName(path, usedRouteNames);\n      const cleanPath = path === \"/api\" ? \"\" : path.replace(/^\\/api\\//, \"\");\n      const parts = cleanPath ? cleanPath.split(\"/\") : [];\n\n      // Keep the final source for each method, matching runtime layer precedence.\n      const methodSources = new Map<string, APIRouteInfo>();\n      for (const route of routeList) {\n        for (const method of route.methods) methodSources.set(method, route);\n      }\n      const allMethods = [...methodSources.keys()];\n\n      // Generate imports\n      for (const method of allMethods) {\n        const importPath = this.getRouteImportPath(methodSources.get(method)!, options.outFile);\n        const importName = `${method}_${routeName}`;\n        imports.push(\n          `import type { ${method} as ${importName} } from ${JSON.stringify(importPath)};`,\n        );\n      }\n\n      if (parts.length === 0) {\n        for (const method of allMethods) {\n          const importName = `${method}_${routeName}`;\n          const methodName = method.toLowerCase();\n          nestedStructure[methodName] = `typeof ${importName}`;\n        }\n      } else {\n        const hasMethodCollision = parts.some((part, index) => {\n          if (part === \"$params\" || (index === 0 && part === \"integrations\")) return true;\n          if (!API_CLIENT_METHOD_SEGMENTS.has(part)) return false;\n          const parentPath = parts.slice(0, index).join(\"/\");\n          return routeMethodsByPath.get(parentPath)?.has(part) === true;\n        });\n        const typePath = hasMethodCollision ? [`/${cleanPath}`] : parts;\n        // Build nested object\n        let current = nestedStructure;\n        for (let i = 0; i < typePath.length; i++) {\n          const part = typePath[i];\n          if (i === typePath.length - 1) {\n            // Last part - add methods\n            current[part] = {};\n            for (const method of allMethods) {\n              const importName = `${method}_${routeName}`;\n              const methodName = method.toLowerCase();\n              current[part][methodName] = `typeof ${importName}`;\n            }\n          } else {\n            // Intermediate part - create nested object\n            if (!current[part]) {\n              current[part] = {};\n            }\n            current = current[part];\n          }\n        }\n      }\n    }\n\n    // Convert nested structure to TypeScript code\n    const typeExports = this.structureToTypeString(nestedStructure, 1);\n    const manifest = new Map<string, Set<string>>();\n    const shapes = new Map();\n    for (const route of routes) {\n      registerAPIRouteShape(shapes, route.path, route.filePath, \"app\");\n      const methods = manifest.get(route.path) ?? new Set<string>();\n      for (const method of route.methods) methods.add(method);\n      manifest.set(route.path, methods);\n    }\n    for (const route of options.pluginRoutes ?? []) {\n      registerAPIRouteShape(shapes, route.path, `plugin:${route.path}`, \"app\");\n      const methods = manifest.get(route.path) ?? new Set<string>();\n      if (methods.has(route.method))\n        throw new Error(`Duplicate API route for ${route.method} ${route.path}`);\n      methods.add(route.method);\n      manifest.set(route.path, methods);\n    }\n    const routeManifest = [...manifest]\n      .sort(([a], [b]) => a.localeCompare(b))\n      .map(([path, methods]) => ({ path, methods: [...methods].sort() }));\n    const manifestSource = routeManifest.length\n      ? `[\\n${routeManifest\n          .map(\n            ({ path, methods }) =>\n              `  {\\n    path: ${JSON.stringify(path)},\\n    methods: [${methods.map((method) => JSON.stringify(method)).join(\", \")}],\\n  },`,\n          )\n          .join(\"\\n\")}\\n]`\n      : \"[]\";\n\n    return `/**\n * Auto-generated API router types\n * This file is automatically generated - do not edit manually\n *\n * Server modules are imported only as types. Runtime data contains paths and methods only.\n */\n\n${imports.join(\"\\n\")}\n\n// Type-only representation of your API routes\nexport type APIRouter = ${pluginTypes.length ? `${pluginTypes.join(\" & \")} & ` : \"\"}{\n${typeExports}\n};\n\n// Pass this schema-free manifest to createApiClients({ routes: apiRoutes }).\nexport const apiRoutes = ${manifestSource} as const;\n`;\n  }\n\n  private getRouteImportPath(route: APIRouteInfo, outFile?: string): string {\n    if (!outFile) {\n      return `../app/${route.relativePath.replace(/\\\\/g, \"/\").replace(/\\.(ts|tsx|js|jsx)$/, \"\")}`;\n    }\n\n    const relativeImport = relative(dirname(outFile), route.filePath)\n      .replace(/\\\\/g, \"/\")\n      .replace(/\\.(ts|tsx|js|jsx)$/, \"\");\n    return relativeImport.startsWith(\".\") ? relativeImport : `./${relativeImport}`;\n  }\n\n  private pathToRouteName(path: string): string {\n    // Replace (not strip) invalid identifier characters, so /api/id and\n    // /api/[id] do not normalize to the same name.\n    return (path === \"/api\" ? \"root\" : path.replace(/^\\/api\\//, \"\"))\n      .replace(/\\//g, \"_\")\n      .replace(/[^a-zA-Z0-9_]/g, \"_\");\n  }\n\n  private uniqueRouteName(path: string, usedNames: Map<string, number>): string {\n    const base = this.pathToRouteName(path);\n    const seen = usedNames.get(base);\n    usedNames.set(base, (seen ?? 0) + 1);\n    // Suffix any remaining collision so the generated import aliases are\n    // always distinct identifiers.\n    return seen ? `${base}_${seen + 1}` : base;\n  }\n\n  private structureToTypeString(obj: any, indent: number): string {\n    const spaces = \"  \".repeat(indent);\n    const lines: string[] = [];\n\n    for (const [key, value] of Object.entries(obj)) {\n      const propertyKey = this.toTypePropertyKey(key);\n\n      if (typeof value === \"string\") {\n        // It's a type reference\n        lines.push(`${spaces}${propertyKey}: ${value};`);\n      } else if (typeof value === \"object\") {\n        // It's a nested object\n        lines.push(`${spaces}${propertyKey}: {`);\n        lines.push(this.structureToTypeString(value, indent + 1));\n        lines.push(`${spaces}};`);\n      }\n    }\n\n    return lines.join(\"\\n\");\n  }\n\n  private toTypePropertyKey(key: string): string {\n    return /^[$A-Z_][0-9A-Z_$]*$/i.test(key) ? key : JSON.stringify(key);\n  }\n\n  private getBaseExportName(path: string): string {\n    const cleanPath = path.replace(/^\\/api\\//, \"\");\n\n    if (cleanPath === \"\") {\n      return \"api\";\n    }\n\n    // Convert path to nested structure\n    // /api/auth/login -> ['auth', 'login']\n    return cleanPath;\n  }\n\n  private getExportName(path: string, method: string): string {\n    const cleanPath = path.replace(/^\\/api\\//, \"\");\n\n    if (cleanPath === \"\") {\n      return method.toLowerCase();\n    }\n\n    const parts = cleanPath.split(\"/\");\n    if (parts.length === 1) {\n      // For single-level paths like /api/hello, just use the path name\n      return parts[0];\n    }\n\n    // For nested paths like /api/auth/login, create nested structure\n    // This matches the expected API client usage: api.auth.login()\n    return parts.join(\".\");\n  }\n\n  /**\n   * Generate the API index file\n   */\n  generateAPIIndex(outputPath: string): void {\n    const routes = this.scanAPIRoutes();\n    const content = this.generateAPIRouter(routes, { outFile: outputPath });\n\n    mkdirSync(dirname(outputPath), { recursive: true });\n    writeFileIfChanged(outputPath, content);\n    console.log(`✅ Generated API types for ${routes.length} routes`);\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,cAAc,YAAY,aAAa,iBAAiB;AACjE,SAAS,MAAM,UAAU,eAAe;AACxC,SAAS,UAAU,aAAa;AAKhC,IAAI,yBAAyB;AAE7B,IAAM,6BAA6B,oBAAI,IAAI;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AASM,IAAM,oBAAN,MAAM,kBAAiB;AAAA,EAG5B,YAAY,QAAoC;AAC9C,SAAK,UAAU,MAAM,QAAQ,MAAM,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,MAAgB;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAgC;AAC9B,UAAM,gBAAgB,oBAAI,IAAuC;AAEjE,eAAW,UAAU,KAAK,SAAS;AACjC,YAAM,SAAS,KAAK,QAAQ,KAAK;AACjC,UAAI,CAAC,WAAW,MAAM,EAAG;AAEzB,YAAM,aAA6B,CAAC;AACpC,WAAK,cAAc,QAAQ,QAAQ,UAAU;AAC7C,iBAAW,SAAS,YAAY;AAC9B,cAAM,eAAe,cAAc,IAAI,MAAM,IAAI,KAAK,oBAAI,IAA0B;AACpF,mBAAW,UAAU,MAAM,SAAS;AAClC,uBAAa,IAAI,QAAQ,KAAK;AAAA,QAChC;AACA,sBAAc,IAAI,MAAM,MAAM,YAAY;AAAA,MAC5C;AAAA,IACF;AAEA,UAAM,SAAyB,CAAC;AAChC,eAAW,CAAC,WAAW,OAAO,KAAK,eAAe;A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