{"version":3,"sources":["../src/codegen/index.ts","../src/codegen/parser.ts","../src/core/filesystem.ts","../src/codegen/generator.ts","../src/codegen/watcher.ts"],"sourcesContent":["export * from './parser';\nexport * from './generator';\nexport * from './watcher';\n","import * as path from 'path';\nimport * as ts from 'typescript';\nimport type {\n    RpcManifest,\n    RpcMethodManifest,\n    RpcParameterManifest,\n    RpcServiceManifest,\n} from '../rpc/types';\n\nexport interface RouteInfo {\n    method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n    path: string;\n    handler: string;\n    controllerName: string;\n}\n\nexport interface ControllerInfo {\n    name: string;\n    prefix: string;\n    routes: RouteInfo[];\n}\n\nconst RPC_SERVICE_DECORATORS = new Set(['RpcService', 'WextsRpcService']);\nconst RPC_METHOD_DECORATORS = new Set(['RpcMethod', 'WextsRpc']);\nconst REQUIRE_AUTH_DECORATORS = new Set(['RequireAuth']);\n\n/**\n * Parse NestJS controllers to extract Fusion metadata\n */\nexport class NestJSParser {\n    private program: ts.Program;\n\n    constructor(private projectPath: string) {\n        const configPath = ts.findConfigFile(projectPath, ts.sys.fileExists, 'tsconfig.json');\n        if (!configPath) {\n            throw new Error('tsconfig.json not found');\n        }\n\n        const config = ts.readConfigFile(configPath, ts.sys.readFile);\n        const parsedConfig = ts.parseJsonConfigFileContent(\n            config.config,\n            ts.sys,\n            path.dirname(configPath)\n        );\n\n        this.program = ts.createProgram(parsedConfig.fileNames, parsedConfig.options);\n    }\n\n    /**\n     * Find all controllers with @FusionController decorator\n     */\n    findFusionControllers(): ControllerInfo[] {\n        const controllers: ControllerInfo[] = [];\n        const sourceFiles = this.program.getSourceFiles();\n\n        for (const sourceFile of sourceFiles) {\n            if (sourceFile.fileName.includes('node_modules')) continue;\n            if (!sourceFile.fileName.includes('.controller.ts')) continue;\n\n            const fileControllers = this.parseSourceFile(sourceFile);\n            controllers.push(...fileControllers);\n        }\n\n        return controllers;\n    }\n\n    findRpcManifest(): RpcManifest {\n        const services: RpcServiceManifest[] = [];\n\n        for (const sourceFile of this.program.getSourceFiles()) {\n            if (sourceFile.fileName.includes('node_modules')) continue;\n            if (!sourceFile.fileName.endsWith('.ts')) continue;\n            if (sourceFile.fileName.endsWith('.d.ts')) continue;\n\n            services.push(...this.parseRpcServices(sourceFile));\n        }\n\n        services.sort((a, b) => a.name.localeCompare(b.name));\n        for (const service of services) {\n            service.methods.sort((a, b) => a.name.localeCompare(b.name));\n        }\n\n        if (services.length === 0) {\n            return {\n                schemaVersion: 1,\n                services,\n            };\n        }\n\n        return {\n            schemaVersion: 1,\n            services,\n        };\n    }\n\n    private parseSourceFile(sourceFile: ts.SourceFile): ControllerInfo[] {\n        const controllers: ControllerInfo[] = [];\n\n        ts.forEachChild(sourceFile, (node) => {\n            if (ts.isClassDeclaration(node) && node.name) {\n                const controllerInfo = this.parseController(node);\n                if (controllerInfo) {\n                    controllers.push(controllerInfo);\n                }\n            }\n        });\n\n        return controllers;\n    }\n\n    private parseController(classNode: ts.ClassDeclaration): ControllerInfo | null {\n        const decorators = ts.getDecorators(classNode);\n        if (!decorators) return null;\n\n        let controllerPrefix = '';\n        let isFusionController = false;\n\n        // Check for @FusionController decorator\n        for (const decorator of decorators) {\n            const expr = decorator.expression;\n            if (ts.isCallExpression(expr) && ts.isIdentifier(expr.expression)) {\n                const decoratorName = expr.expression.text;\n\n                if (decoratorName === 'FusionController') {\n                    isFusionController = true;\n                    if (expr.arguments.length > 0) {\n                        const arg = expr.arguments[0];\n                        if (ts.isStringLiteral(arg)) {\n                            controllerPrefix = arg.text;\n                        }\n                    }\n                }\n            }\n        }\n\n        if (!isFusionController) return null;\n\n        const routes = this.parseRoutes(classNode);\n        const className = classNode.name?.text || 'Unknown';\n\n        return {\n            name: className,\n            prefix: controllerPrefix,\n            routes: routes.map(r => ({ ...r, controllerName: className })),\n        };\n    }\n\n    private parseRoutes(classNode: ts.ClassDeclaration): RouteInfo[] {\n        const routes: RouteInfo[] = [];\n\n        classNode.members.forEach((member) => {\n            if (ts.isMethodDeclaration(member)) {\n                const decorators = ts.getDecorators(member);\n                if (!decorators) return;\n\n                for (const decorator of decorators) {\n                    const expr = decorator.expression;\n                    if (ts.isCallExpression(expr) && ts.isIdentifier(expr.expression)) {\n                        const decoratorName = expr.expression.text;\n\n                        let method: RouteInfo['method'] | null = null;\n                        let routePath = '';\n\n                        // Map decorator to HTTP method\n                        if (decoratorName === 'FusionGet') method = 'GET';\n                        else if (decoratorName === 'FusionPost') method = 'POST';\n                        else if (decoratorName === 'FusionPut') method = 'PUT';\n                        else if (decoratorName === 'FusionDelete') method = 'DELETE';\n\n                        if (method) {\n                            // Get route path from decorator argument\n                            if (expr.arguments.length > 0) {\n                                const arg = expr.arguments[0];\n                                if (ts.isStringLiteral(arg)) {\n                                    routePath = arg.text;\n                                }\n                            }\n\n                            const handlerName = (member.name as ts.Identifier).text;\n\n                            routes.push({\n                                method,\n                                path: routePath,\n                                handler: handlerName,\n                                controllerName: '', // Will be set by caller\n                            });\n                        }\n                    }\n                }\n            }\n        });\n\n        return routes;\n    }\n\n    private parseRpcServices(sourceFile: ts.SourceFile): RpcServiceManifest[] {\n        const services: RpcServiceManifest[] = [];\n        const rootDir = path.resolve(this.projectPath);\n\n        ts.forEachChild(sourceFile, (node) => {\n            if (!ts.isClassDeclaration(node) || !node.name) return;\n\n            const serviceDecorator = this.findDecorator(node, RPC_SERVICE_DECORATORS);\n            if (!serviceDecorator) return;\n\n            const className = node.name.text;\n            const serviceOptions = this.readDecoratorOptions(serviceDecorator);\n            const classRequiresAuth = serviceOptions.requireAuth || this.hasDecorator(node, REQUIRE_AUTH_DECORATORS);\n            const serviceName = serviceOptions.name || toStableServiceName(className);\n            const methods = this.parseRpcMethods(node, classRequiresAuth, sourceFile);\n\n            if (methods.length === 0) return;\n\n            services.push({\n                name: serviceName,\n                className,\n                importPath: toPosixPath(path.relative(rootDir, sourceFile.fileName).replace(/\\.ts$/, '')),\n                requireAuth: classRequiresAuth,\n                methods,\n            });\n        });\n\n        return services;\n    }\n\n    private parseRpcMethods(classNode: ts.ClassDeclaration, classRequiresAuth: boolean, sourceFile: ts.SourceFile): RpcMethodManifest[] {\n        const methods: RpcMethodManifest[] = [];\n\n        for (const member of classNode.members) {\n            if (!ts.isMethodDeclaration(member)) continue;\n            if (!ts.isIdentifier(member.name)) continue;\n\n            const methodDecorator = this.findDecorator(member, RPC_METHOD_DECORATORS);\n            if (!methodDecorator) continue;\n\n            const handlerName = member.name.text;\n            const methodOptions = this.readDecoratorOptions(methodDecorator);\n            const requireAuth = classRequiresAuth || methodOptions.requireAuth || this.hasDecorator(member, REQUIRE_AUTH_DECORATORS);\n\n            methods.push({\n                name: methodOptions.name || handlerName,\n                handlerName,\n                requireAuth,\n                parameters: member.parameters.map((parameter) => this.parseParameter(parameter, sourceFile)),\n                returnType: member.type ? getNodeText(member.type, sourceFile) : 'unknown',\n            });\n        }\n\n        return methods;\n    }\n\n    private parseParameter(parameter: ts.ParameterDeclaration, sourceFile: ts.SourceFile): RpcParameterManifest {\n        return {\n            name: ts.isIdentifier(parameter.name) ? parameter.name.text : parameter.name.getText(),\n            type: parameter.type ? getNodeText(parameter.type, sourceFile) : 'unknown',\n            optional: Boolean(parameter.questionToken || parameter.initializer),\n        };\n    }\n\n    private findDecorator(\n        node: ts.ClassDeclaration | ts.MethodDeclaration,\n        names: Set<string>\n    ): ts.Decorator | undefined {\n        const decorators = ts.getDecorators(node);\n        if (!decorators) return undefined;\n\n        return decorators.find((decorator) => {\n            const name = getDecoratorName(decorator);\n            return Boolean(name && names.has(name));\n        });\n    }\n\n    private hasDecorator(\n        node: ts.ClassDeclaration | ts.MethodDeclaration,\n        names: Set<string>\n    ): boolean {\n        return Boolean(this.findDecorator(node, names));\n    }\n\n    private readDecoratorOptions(decorator: ts.Decorator): { name?: string; requireAuth?: boolean } {\n        const expression = decorator.expression;\n        if (!ts.isCallExpression(expression)) return {};\n\n        const firstArg = expression.arguments[0];\n        if (!firstArg) return {};\n\n        if (ts.isStringLiteral(firstArg)) {\n            return { name: firstArg.text };\n        }\n\n        if (!ts.isObjectLiteralExpression(firstArg)) return {};\n\n        const result: { name?: string; requireAuth?: boolean } = {};\n\n        for (const property of firstArg.properties) {\n            if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) continue;\n\n            if (property.name.text === 'name' && ts.isStringLiteral(property.initializer)) {\n                result.name = property.initializer.text;\n            }\n\n            if (property.name.text === 'requireAuth') {\n                if (property.initializer.kind === ts.SyntaxKind.TrueKeyword) {\n                    result.requireAuth = true;\n                } else if (property.initializer.kind === ts.SyntaxKind.FalseKeyword) {\n                    result.requireAuth = false;\n                }\n            }\n        }\n\n        return result;\n    }\n}\n\nfunction getDecoratorName(decorator: ts.Decorator): string | undefined {\n    const expression = decorator.expression;\n    if (ts.isIdentifier(expression)) return expression.text;\n    if (ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)) {\n        return expression.expression.text;\n    }\n\n    return undefined;\n}\n\nfunction toStableServiceName(className: string): string {\n    const withoutSuffix = className.replace(/(Service|Controller)$/, '');\n    return withoutSuffix.charAt(0).toLowerCase() + withoutSuffix.slice(1);\n}\n\nfunction toPosixPath(filePath: string): string {\n    return filePath.split(path.sep).join(path.posix.sep);\n}\n\nfunction getNodeText(node: ts.Node, sourceFile: ts.SourceFile): string {\n    return sourceFile.text.slice(node.getStart(sourceFile), node.getEnd());\n}\n","import * as fs from 'fs';\nimport * as path from 'path';\nimport { promisify } from 'util';\n\nconst readFile = promisify(fs.readFile);\nconst writeFile = promisify(fs.writeFile);\nconst mkdir = promisify(fs.mkdir);\nconst access = promisify(fs.access);\n\nexport class FileSystem {\n    /**\n     * Read file as string\n     */\n    async readFile(filePath: string, encoding: BufferEncoding = 'utf-8'): Promise<string> {\n        return readFile(filePath, encoding);\n    }\n\n    /**\n     * Write file\n     */\n    async writeFile(filePath: string, content: string): Promise<void> {\n        // Ensure directory exists\n        await this.ensureDir(path.dirname(filePath));\n        return writeFile(filePath, content, 'utf-8');\n    }\n\n    /**\n     * Read JSON file\n     */\n    async readJSON<T = any>(filePath: string): Promise<T> {\n        const content = await this.readFile(filePath);\n        return JSON.parse(content);\n    }\n\n    /**\n     * Write JSON file\n     */\n    async writeJSON(filePath: string, data: any, pretty: boolean = true): Promise<void> {\n        const content = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);\n        return this.writeFile(filePath, content);\n    }\n\n    /**\n     * Check if file/directory exists\n     */\n    async exists(filePath: string): Promise<boolean> {\n        try {\n            await access(filePath, fs.constants.F_OK);\n            return true;\n        } catch {\n            return false;\n        }\n    }\n\n    /**\n     * Ensure directory exists (create if not)\n     */\n    async ensureDir(dirPath: string): Promise<void> {\n        if (!(await this.exists(dirPath))) {\n            await mkdir(dirPath, { recursive: true });\n        }\n    }\n\n    /**\n     * Copy file\n     */\n    async copyFile(src: string, dest: string): Promise<void> {\n        const content = await this.readFile(src);\n        await this.writeFile(dest, content);\n    }\n\n    /**\n     * Read directory\n     */\n    readDir(dirPath: string): Promise<string[]> {\n        return promisify(fs.readdir)(dirPath);\n    }\n}\n\n// Export singleton\nexport const filesystem = new FileSystem();\n","import { filesystem } from '../core/filesystem';\nimport * as path from 'path';\nimport type { RpcManifest, RpcMethodManifest, RpcServiceManifest } from '../rpc/types';\nimport { NestJSParser } from './parser';\nimport { WextsCodegenError } from '../errors';\n\nexport interface GenerateOptions {\n    outputPath: string;\n    manifest: RpcManifest;\n    manifestFileName?: string;\n    clientFileName?: string;\n}\n\nexport interface GenerateRpcOptions {\n    projectPath: string;\n    outputPath: string;\n    manifestFileName?: string;\n    clientFileName?: string;\n}\n\n/**\n * Generate TypeScript API client from controller metadata\n */\nexport class ClientGenerator {\n    async generate(options: GenerateOptions): Promise<void> {\n        const {\n            manifest,\n            outputPath,\n            manifestFileName = 'wexts.rpc.manifest.json',\n            clientFileName = 'client.ts',\n        } = options;\n\n        if (manifest.services.length === 0) {\n            throw new WextsCodegenError({\n                code: 'WEXTS_CODEGEN_NO_SERVICES',\n                message: 'No Wexts RPC services found. Add @RpcService() to a Nest provider and @RpcMethod() to at least one method.',\n                suggestedFix: 'Add a decorated RPC service, then run `wexts generate -p apps/api -o apps/web/lib/wexts`.',\n                docsSlug: 'codegen',\n            });\n        }\n\n        const sortedManifest = sortManifest(manifest);\n        const clientCode = this.generateRpcClientCode(sortedManifest);\n        await filesystem.writeJSON(path.join(outputPath, manifestFileName), sortedManifest, true);\n        await filesystem.writeFile(path.join(outputPath, clientFileName), clientCode);\n\n        const indexCode = `export * from './client';\\n`;\n        await filesystem.writeFile(path.join(outputPath, 'index.ts'), indexCode);\n    }\n\n    private generateRpcClientCode(manifest: RpcManifest): string {\n        const manifestJson = JSON.stringify(manifest, null, 2);\n\n        return `import { createWextsRpcClient, type WextsRpcClientOptions } from 'wexts/client';\nimport type { RpcManifest } from 'wexts/rpc';\n\nconst manifest = ${manifestJson} satisfies RpcManifest;\n\n${this.generateClientInterface(manifest)}\n\nexport function createWextsClient(options?: WextsRpcClientOptions): WextsClient {\n  return createWextsRpcClient(manifest, options) as unknown as WextsClient;\n}\n\nexport const wexts = createWextsClient();\n`;\n    }\n\n    private generateClientInterface(manifest: RpcManifest): string {\n        const services = manifest.services.map((service) => this.generateServiceInterface(service)).join('\\n');\n        return `export interface WextsClient {\\n${services}}\\n`;\n    }\n\n    private generateServiceInterface(service: RpcServiceManifest): string {\n        const methods = service.methods.map((method) => `    ${method.name}: (${this.parametersToSignature(method)}) => Promise<${normalizeReturnType(method.returnType)}>;`).join('\\n');\n        return `  ${service.name}: {\\n${methods}\\n  };\\n`;\n    }\n\n    private parametersToSignature(method: RpcMethodManifest): string {\n        return method.parameters\n            .map((parameter) => `${parameter.name}${parameter.optional ? '?' : ''}: ${parameter.type}`)\n            .join(', ');\n    }\n}\n\nexport async function generateRpcClient(options: GenerateRpcOptions): Promise<RpcManifest> {\n    const parser = new NestJSParser(options.projectPath);\n    const manifest = parser.findRpcManifest();\n    const generator = new ClientGenerator();\n    await generator.generate({\n        manifest,\n        outputPath: options.outputPath,\n        manifestFileName: options.manifestFileName,\n        clientFileName: options.clientFileName,\n    });\n\n    return sortManifest(manifest);\n}\n\nfunction sortManifest(manifest: RpcManifest): RpcManifest {\n    return {\n        schemaVersion: 1,\n        services: [...manifest.services]\n            .sort((a, b) => a.name.localeCompare(b.name))\n            .map((service) => ({\n                ...service,\n                methods: [...service.methods].sort((a, b) => a.name.localeCompare(b.name)),\n            })),\n    };\n}\n\nfunction normalizeReturnType(returnType: string): string {\n    const match = returnType.match(/^Promise<(.+)>$/);\n    return match?.[1] ?? returnType;\n}\n","import * as chokidar from 'chokidar';\nimport { logger } from '../core/logger';\nimport { generateRpcClient } from './generator';\n\nexport interface WatchOptions {\n    projectPath: string;\n    outputPath: string;\n    pattern?: string;\n}\n\n/**\n * Watch NestJS controllers and regenerate client on changes\n */\nexport class CodegenWatcher {\n    private watcher: chokidar.FSWatcher | null = null;\n\n    async watch(options: WatchOptions): Promise<void> {\n        const { projectPath, outputPath, pattern = '**/*.controller.ts' } = options;\n\n        logger.info('👀 Watching for controller changes...');\n\n        // Initial generation\n        await this.generateClient(projectPath, outputPath);\n\n        // Watch for changes\n        this.watcher = chokidar.watch(pattern, {\n            cwd: projectPath,\n            ignored: /node_modules/,\n            persistent: true,\n        });\n\n        this.watcher.on('change', async (path) => {\n            logger.info(`📝 Controller changed: ${path}`);\n            await this.generateClient(projectPath, outputPath);\n        });\n\n        this.watcher.on('add', async (path) => {\n            logger.info(`➕ New controller: ${path}`);\n            await this.generateClient(projectPath, outputPath);\n        });\n\n        this.watcher.on('unlink', async (path) => {\n            logger.info(`➖ Controller removed: ${path}`);\n            await this.generateClient(projectPath, outputPath);\n        });\n    }\n\n    async stop(): Promise<void> {\n        if (this.watcher) {\n            await this.watcher.close();\n            this.watcher = null;\n        }\n    }\n\n    private async generateClient(projectPath: string, outputPath: string): Promise<void> {\n        try {\n            const manifest = await generateRpcClient({ projectPath, outputPath });\n            logger.success(`Generated client for ${manifest.services.length} RPC service(s)`);\n        } catch (error: any) {\n            logger.error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,KAAAA,EAAM;AAC5C,YAAM,KAAKL,eAAeL,aAAaC,UAAAA;IAC3C,CAAA;AAEA,SAAKJ,QAAQY,GAAG,OAAO,OAAOC,UAAAA;AAC1BP,aAAOC,KAAK,0BAAqBM,KAAAA,EAAM;AACvC,YAAM,KAAKL,eAAeL,aAAaC,UAAAA;IAC3C,CAAA;AAEA,SAAKJ,QAAQY,GAAG,UAAU,OAAOC,UAAAA;AAC7BP,aAAOC,KAAK,8BAAyBM,KAAAA,EAAM;AAC3C,YAAM,KAAKL,eAAeL,aAAaC,UAAAA;IAC3C,CAAA;EACJ;EAEA,MAAMU,OAAsB;AACxB,QAAI,KAAKd,SAAS;AACd,YAAM,KAAKA,QAAQe,MAAK;AACxB,WAAKf,UAAU;IACnB;EACJ;EAEA,MAAcQ,eAAeL,aAAqBC,YAAmC;AACjF,QAAI;AACA,YAAMY,WAAW,MAAMC,kBAAkB;QAAEd;QAAaC;MAAW,CAAA;AACnEE,aAAOY,QAAQ,wBAAwBF,SAASG,SAASC,MAAM,iBAAiB;IACpF,SAASC,OAAY;AACjBf,aAAOe,MAAM,8BAA8BA,MAAMC,OAAO;IAC5D;EACJ;AACJ;","names":["path","ts","RPC_SERVICE_DECORATORS","Set","RPC_METHOD_DECORATORS","REQUIRE_AUTH_DECORATORS","NestJSParser","program","projectPath","configPath","findConfigFile","sys","fileExists","Error","config","readConfigFile","readFile","parsedConfig","parseJsonConfigFileContent","dirname","createProgram","fileNames","options","findFusionControllers","controllers","sourceFiles","getSourceFiles","sourceFile","fileName","includes","fileControllers","parseSourceFile","push","findRpcManifest","services","endsWith","parseRpcServices","sort","a","b","name","localeCompare","service","methods","length","schemaVersion","ts","forEachChild","node","isClassDeclaration","controllerInfo","parseController","classNode","decorators","getDecorators","controllerPrefix","isFusionController","decorator","expr","expression","isCallExpression","isIdentifier","decoratorName","text","arguments","arg","isStringLiteral","routes","parseRoutes","className","prefix","map","r","controllerName","members","forEach","member","isMethodDeclaration","method","routePath","handlerName","path","handler","rootDir","resolve","serviceDecorator","findDecorator","serviceOptions","readDecoratorOptions","classRequiresAuth","requireAuth","hasDecorator","serviceName","toStableServiceName","parseRpcMethods","importPath","toPosixPath","relative","replace","methodDecorator","methodOptions","parameters","parameter","parseParameter","returnType","type","getNodeText","getText","optional","Boolean","questionToken","initializer","names","undefined","find","getDecoratorName","has","firstArg","isObjectLiteralExpression","result","property","properties","isPropertyAssignment","kind","SyntaxKind","TrueKeyword","FalseKeyword","withoutSuffix","charAt","toLowerCase","slice","filePath","split","sep","join","posix","getStart","getEnd","fs","path","promisify","readFile","promisify","writeFile","mkdir","access","FileSystem","filePath","encoding","content","ensureDir","dirname","readJSON","JSON","parse","writeJSON","data","pretty","stringify","exists","constants","F_OK","dirPath","recursive","copyFile","src","dest","readDir","readdir","filesystem","path","ClientGenerator","generate","options","manifest","outputPath","manifestFileName","clientFileName","services","length","WextsCodegenError","code","message","suggestedFix","docsSlug","sortedManifest","sortManifest","clientCode","generateRpcClientCode","filesystem","writeJSON","join","writeFile","indexCode","manifestJson","JSON","stringify","generateClientInterface","map","service","generateServiceInterface","methods","method","name","parametersToSignature","normalizeReturnType","returnType","parameters","parameter","optional","type","generateRpcClient","parser","NestJSParser","projectPath","findRpcManifest","generator","schemaVersion","sort","a","b","localeCompare","match","chokidar","CodegenWatcher","watcher","watch","options","projectPath","outputPath","pattern","logger","info","generateClient","cwd","ignored","persistent","on","path","stop","close","manifest","generateRpcClient","success","services","length","error","message"]}