@zipbul/gildash 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @bun
2
2
  var L$=Object.defineProperty;var I$=(u)=>u;function D$(u,_){this[u]=I$.bind(null,_)}var A$=(u,_)=>{for(var g in _)L$(u,g,{get:_[g],enumerable:!0,configurable:!0,set:D$.bind(_,g)})};var n_=import.meta.require;import{isErr as vu}from"@zipbul/result";import Eu from"path";import{existsSync as b0}from"fs";import{err as G_,isErr as q$}from"@zipbul/result";import{Database as j$}from"bun:sqlite";import{mkdirSync as F$,unlinkSync as v_,existsSync as E_}from"fs";import{dirname as n$,join as b_}from"path";import{drizzle as G$}from"drizzle-orm/bun-sqlite";import{migrate as v$}from"drizzle-orm/bun-sqlite/migrator";class w extends Error{type;constructor(u,_,g){super(_,g);this.type=u;this.name="GildashError"}}function $u(u,_,g){return new w(u,_,g!==void 0?{cause:g}:void 0)}var Yu=".gildash",yu="gildash.db";var u_={};A$(u_,{watcherOwner:()=>T$,symbols:()=>b,symbolChangelog:()=>Ju,relations:()=>L,files:()=>o,annotations:()=>Nu});import{sql as C$}from"drizzle-orm";import{sqliteTable as Du,text as n,integer as _u,real as S$,index as Qu,primaryKey as R$,foreignKey as fu,check as k$}from"drizzle-orm/sqlite-core";var o=Du("files",{project:n("project").notNull(),filePath:n("file_path").notNull(),mtimeMs:S$("mtime_ms").notNull(),size:_u("size").notNull(),contentHash:n("content_hash").notNull(),updatedAt:n("updated_at").notNull(),lineCount:_u("line_count")},(u)=>[R$({columns:[u.project,u.filePath]})]),b=Du("symbols",{id:_u("id").primaryKey({autoIncrement:!0}),project:n("project").notNull(),filePath:n("file_path").notNull(),kind:n("kind").notNull(),name:n("name").notNull(),startLine:_u("start_line").notNull(),startColumn:_u("start_column").notNull(),endLine:_u("end_line").notNull(),endColumn:_u("end_column").notNull(),isExported:_u("is_exported").notNull().default(0),signature:n("signature"),fingerprint:n("fingerprint"),detailJson:n("detail_json"),contentHash:n("content_hash").notNull(),indexedAt:n("indexed_at").notNull(),resolvedType:n("resolved_type"),structuralFingerprint:n("structural_fingerprint")},(u)=>[Qu("idx_symbols_project_file").on(u.project,u.filePath),Qu("idx_symbols_project_kind").on(u.project,u.kind),Qu("idx_symbols_project_name").on(u.project,u.name),Qu("idx_symbols_fingerprint").on(u.project,u.fingerprint),fu({columns:[u.project,u.filePath],foreignColumns:[o.project,o.filePath]}).onDelete("cascade")]),L=Du("relations",{id:_u("id").primaryKey({autoIncrement:!0}),project:n("project").notNull(),type:n("type").notNull(),srcFilePath:n("src_file_path").notNull(),srcSymbolName:n("src_symbol_name"),dstProject:n("dst_project").notNull(),dstFilePath:n("dst_file_path").notNull(),dstSymbolName:n("dst_symbol_name"),metaJson:n("meta_json")},(u)=>[Qu("idx_relations_src").on(u.project,u.srcFilePath),Qu("idx_relations_dst").on(u.dstProject,u.dstFilePath),Qu("idx_relations_type").on(u.project,u.type),Qu("idx_relations_project_type_src").on(u.project,u.type,u.srcFilePath),fu({columns:[u.project,u.srcFilePath],foreignColumns:[o.project,o.filePath]}).onDelete("cascade"),fu({columns:[u.dstProject,u.dstFilePath],foreignColumns:[o.project,o.filePath]}).onDelete("cascade")]),Nu=Du("annotations",{id:_u("id").primaryKey({autoIncrement:!0}),project:n("project").notNull(),filePath:n("file_path").notNull(),tag:n("tag").notNull(),value:n("value").notNull().default(""),source:n("source").notNull(),symbolName:n("symbol_name"),startLine:_u("start_line").notNull(),startColumn:_u("start_column").notNull(),endLine:_u("end_line").notNull(),endColumn:_u("end_column").notNull(),indexedAt:n("indexed_at").notNull()},(u)=>[Qu("idx_annotations_project_file").on(u.project,u.filePath),Qu("idx_annotations_project_tag").on(u.project,u.tag),Qu("idx_annotations_project_symbol").on(u.project,u.symbolName),fu({columns:[u.project,u.filePath],foreignColumns:[o.project,o.filePath]}).onDelete("cascade")]),Ju=Du("symbol_changelog",{id:_u("id").primaryKey({autoIncrement:!0}),project:n("project").notNull(),changeType:n("change_type").notNull(),symbolName:n("symbol_name").notNull(),symbolKind:n("symbol_kind").notNull(),filePath:n("file_path").notNull(),oldName:n("old_name"),oldFilePath:n("old_file_path"),fingerprint:n("fingerprint"),changedAt:n("changed_at").notNull(),isFullIndex:_u("is_full_index").notNull().default(0),indexRunId:n("index_run_id").notNull()},(u)=>[Qu("idx_changelog_project_changed_at").on(u.project,u.changedAt),Qu("idx_changelog_project_name").on(u.project,u.symbolName),Qu("idx_changelog_project_run").on(u.project,u.indexRunId)]),T$=Du("watcher_owner",{id:_u("id").primaryKey(),pid:_u("pid").notNull(),startedAt:n("started_at").notNull(),heartbeatAt:n("heartbeat_at").notNull(),instanceId:n("instance_id")},(u)=>[k$("watcher_owner_singleton",C$`${u.id} = 1`)]);class __{client=null;drizzle=null;dbPath;txDepth=0;constructor(u){this.dbPath=b_(u.projectRoot,Yu,yu)}get drizzleDb(){if(!this.drizzle)throw Error("Database is not open. Call open() first.");return this.drizzle}open(){try{F$(n$(this.dbPath),{recursive:!0}),this.client=new j$(this.dbPath),this.client.run("PRAGMA journal_mode = WAL"),this.client.run("PRAGMA foreign_keys = OFF"),this.client.run("PRAGMA busy_timeout = 5000"),this.drizzle=G$(this.client,{schema:u_}),v$(this.drizzle,{migrationsFolder:b_(import.meta.dirname,"migrations")});let u=this.client.prepare("PRAGMA foreign_key_check").all();if(u.length>0)throw Error(`FK integrity violation after migration: ${JSON.stringify(u.slice(0,5))}`);this.client.run("PRAGMA foreign_keys = ON"),this.registerRegexpUdf(this.client)}catch(u){if(this.isCorruptionError(u)&&E_(this.dbPath)){this.closeClient(),v_(this.dbPath);for(let g of["-wal","-shm"]){let $=this.dbPath+g;if(E_($))v_($)}let _=this.open();if(q$(_))return G_($u("store",`Failed to recover database at ${this.dbPath}`,_.data));return _}return G_($u("store",`Failed to open database at ${this.dbPath}`,u))}}close(){this.closeClient(),this.drizzle=null}transaction(u){let _=this.requireClient();if(this.txDepth===0){this.txDepth++;try{return _.transaction(()=>u(this))()}finally{this.txDepth--}}let g=`sp_${this.txDepth++}`;_.run(`SAVEPOINT "${g}"`);try{let $=u(this);return _.run(`RELEASE SAVEPOINT "${g}"`),$}catch($){throw _.run(`ROLLBACK TO SAVEPOINT "${g}"`),_.run(`RELEASE SAVEPOINT "${g}"`),$}finally{this.txDepth--}}immediateTransaction(u){let _=this.requireClient();this.txDepth++,_.run("BEGIN IMMEDIATE");try{let g=u();return _.run("COMMIT"),g}catch(g){throw _.run("ROLLBACK"),g}finally{this.txDepth--}}getTableNames(){return this.requireClient().query("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((_)=>_.name)}selectOwner(){return this.requireClient().prepare("SELECT pid, heartbeat_at, instance_id FROM watcher_owner WHERE id = 1").get()??void 0}insertOwner(u,_){let g=new Date().toISOString();this.requireClient().prepare("INSERT INTO watcher_owner (id, pid, started_at, heartbeat_at, instance_id) VALUES (1, ?, ?, ?, ?)").run(u,g,g,_??null)}replaceOwner(u,_){let g=new Date().toISOString();this.requireClient().prepare("INSERT OR REPLACE INTO watcher_owner (id, pid, started_at, heartbeat_at, instance_id) VALUES (1, ?, ?, ?, ?)").run(u,g,g,_??null)}touchOwner(u){let _=new Date().toISOString();this.requireClient().prepare("UPDATE watcher_owner SET heartbeat_at = ? WHERE id = 1 AND pid = ?").run(_,u)}deleteOwner(u){this.requireClient().prepare("DELETE FROM watcher_owner WHERE id = 1 AND pid = ?").run(u)}registerRegexpUdf(u){let _=u;if(typeof _.function!=="function")return;_.function.call(u,"regexp",(g,$)=>{try{return new RegExp(g).test($)?1:0}catch{return 0}})}requireClient(){if(!this.client)throw Error("Database is not open. Call open() first.");return this.client}closeClient(){if(this.client)this.client.close(),this.client=null}isCorruptionError(u){if(!(u instanceof Error))return!1;let _=u.message.toLowerCase();return _.includes("malformed")||_.includes("corrupt")||_.includes("not a database")||_.includes("disk i/o error")||_.includes("sqlite_corrupt")}}import{eq as Tu,and as y_}from"drizzle-orm";class g_{db;constructor(u){this.db=u}getFile(u,_){return this.db.drizzleDb.select().from(o).where(y_(Tu(o.project,u),Tu(o.filePath,_))).get()??null}upsertFile(u){this.db.drizzleDb.insert(o).values({project:u.project,filePath:u.filePath,mtimeMs:u.mtimeMs,size:u.size,contentHash:u.contentHash,updatedAt:u.updatedAt,lineCount:u.lineCount??null}).onConflictDoUpdate({target:[o.project,o.filePath],set:{mtimeMs:u.mtimeMs,size:u.size,contentHash:u.contentHash,updatedAt:u.updatedAt,lineCount:u.lineCount??null}}).run()}getAllFiles(u){return this.db.drizzleDb.select().from(o).where(Tu(o.project,u)).all()}getFilesMap(u){let _=this.getAllFiles(u),g=new Map;for(let $ of _)g.set($.filePath,$);return g}deleteFile(u,_){this.db.drizzleDb.delete(o).where(y_(Tu(o.project,u),Tu(o.filePath,_))).run()}}import{eq as e,and as Ku,sql as Pu,count as E$}from"drizzle-orm";function Au(u){return u.replaceAll("\x00","").trim().split(/\s+/).map((_)=>_.trim()).filter((_)=>_.length>0).map((_)=>`"${_.replaceAll('"','""')}"*`).join(" ")}var f_=50;class $_{db;constructor(u){this.db=u}replaceFileSymbols(u,_,g,$){if(this.db.drizzleDb.delete(b).where(Ku(e(b.project,u),e(b.filePath,_))).run(),!$.length)return;let J=new Date().toISOString(),O=$.map((z)=>({project:u,filePath:_,kind:z.kind??"unknown",name:z.name??"",startLine:z.startLine??0,startColumn:z.startColumn??0,endLine:z.endLine??0,endColumn:z.endColumn??0,isExported:z.isExported??0,signature:z.signature??null,fingerprint:z.fingerprint??null,detailJson:z.detailJson??null,contentHash:g,indexedAt:z.indexedAt??J,resolvedType:z.resolvedType??null,structuralFingerprint:z.structuralFingerprint??null}));for(let z=0;z<O.length;z+=f_)this.db.drizzleDb.insert(b).values(O.slice(z,z+f_)).run()}getFileSymbols(u,_){return this.db.drizzleDb.select().from(b).where(Ku(e(b.project,u),e(b.filePath,_))).all()}searchByName(u,_,g={}){let $=g.limit??50,J=Au(_);if(!J)return[];return this.db.drizzleDb.select().from(b).where(Ku(Pu`${b.id} IN (SELECT rowid FROM symbols_fts WHERE symbols_fts MATCH ${J})`,e(b.project,u),g.kind?e(b.kind,g.kind):void 0)).orderBy(b.name).limit($).all()}searchByKind(u,_){return this.db.drizzleDb.select().from(b).where(Ku(e(b.project,u),e(b.kind,_))).orderBy(b.name).all()}getStats(u){let _=this.db.drizzleDb.select({symbolCount:E$(),fileCount:Pu`COUNT(DISTINCT ${b.filePath})`}).from(b).where(e(b.project,u)).get();return{symbolCount:_?.symbolCount??0,fileCount:_?.fileCount??0}}getByFingerprint(u,_){return this.db.drizzleDb.select().from(b).where(Ku(e(b.project,u),e(b.fingerprint,_))).all()}deleteFileSymbols(u,_){this.db.drizzleDb.delete(b).where(Ku(e(b.project,u),e(b.filePath,_))).run()}searchByQuery(u){let _=this.db.drizzleDb.select().from(b).where(Ku(u.ftsQuery?Pu`${b.id} IN (SELECT rowid FROM symbols_fts WHERE symbols_fts MATCH ${u.ftsQuery})`:void 0,u.exactName?e(b.name,u.exactName):void 0,u.project!==void 0?e(b.project,u.project):void 0,u.kind?e(b.kind,u.kind):void 0,u.filePath!==void 0?e(b.filePath,u.filePath):void 0,u.isExported!==void 0?e(b.isExported,u.isExported?1:0):void 0,u.decorator?Pu`${b.id} IN (SELECT s.id FROM symbols s, json_each(s.detail_json, '$.decorators') je WHERE json_extract(je.value, '$.name') = ${u.decorator})`:void 0,u.resolvedType!==void 0?e(b.resolvedType,u.resolvedType):void 0)).orderBy(b.name);if(!u.regex)return _.limit(u.limit).all();let g;try{g=new RegExp(u.regex)}catch{throw new w("validation",`Invalid regex pattern: ${u.regex}`)}let $=[];for(let J of[5,20,100]){let O=u.limit*J,z=_.limit(O).all();if($=z.filter((N)=>g.test(N.name)),$.length>=u.limit||z.length<O)return $.slice(0,u.limit)}return $.slice(0,u.limit)}}import{eq as d,and as Wu,isNull as P_,or as b$}from"drizzle-orm";class J_{db;constructor(u){this.db=u}replaceFileRelations(u,_,g){this.db.transaction(($)=>{if($.drizzleDb.delete(L).where(Wu(d(L.project,u),d(L.srcFilePath,_))).run(),!g.length)return;for(let J of g)$.drizzleDb.insert(L).values({project:u,type:J.type??"unknown",srcFilePath:J.srcFilePath??_,srcSymbolName:J.srcSymbolName??null,dstProject:J.dstProject??u,dstFilePath:J.dstFilePath??"",dstSymbolName:J.dstSymbolName??null,metaJson:J.metaJson??null}).run()})}getOutgoing(u,_,g){if(g!==void 0)return this.db.drizzleDb.select({project:L.project,type:L.type,srcFilePath:L.srcFilePath,srcSymbolName:L.srcSymbolName,dstProject:L.dstProject,dstFilePath:L.dstFilePath,dstSymbolName:L.dstSymbolName,metaJson:L.metaJson}).from(L).where(Wu(d(L.project,u),d(L.srcFilePath,_),b$(d(L.srcSymbolName,g),P_(L.srcSymbolName)))).all();return this.db.drizzleDb.select({project:L.project,type:L.type,srcFilePath:L.srcFilePath,srcSymbolName:L.srcSymbolName,dstProject:L.dstProject,dstFilePath:L.dstFilePath,dstSymbolName:L.dstSymbolName,metaJson:L.metaJson}).from(L).where(Wu(d(L.project,u),d(L.srcFilePath,_))).all()}getIncoming(u){let{dstProject:_,dstFilePath:g}=u;return this.db.drizzleDb.select({project:L.project,type:L.type,srcFilePath:L.srcFilePath,srcSymbolName:L.srcSymbolName,dstProject:L.dstProject,dstFilePath:L.dstFilePath,dstSymbolName:L.dstSymbolName,metaJson:L.metaJson}).from(L).where(Wu(d(L.dstProject,_),d(L.dstFilePath,g))).all()}getByType(u,_){return this.db.drizzleDb.select({project:L.project,type:L.type,srcFilePath:L.srcFilePath,srcSymbolName:L.srcSymbolName,dstProject:L.dstProject,dstFilePath:L.dstFilePath,dstSymbolName:L.dstSymbolName,metaJson:L.metaJson}).from(L).where(Wu(d(L.project,u),d(L.type,_))).all()}deleteFileRelations(u,_){this.db.drizzleDb.delete(L).where(Wu(d(L.project,u),d(L.srcFilePath,_))).run()}searchRelations(u){return this.db.drizzleDb.select({project:L.project,type:L.type,srcFilePath:L.srcFilePath,srcSymbolName:L.srcSymbolName,dstProject:L.dstProject,dstFilePath:L.dstFilePath,dstSymbolName:L.dstSymbolName,metaJson:L.metaJson}).from(L).where(Wu(u.project!==void 0?d(L.project,u.project):void 0,u.srcFilePath!==void 0?d(L.srcFilePath,u.srcFilePath):void 0,u.srcSymbolName!==void 0?d(L.srcSymbolName,u.srcSymbolName):void 0,u.dstProject!==void 0?d(L.dstProject,u.dstProject):void 0,u.dstFilePath!==void 0?d(L.dstFilePath,u.dstFilePath):void 0,u.dstSymbolName!==void 0?d(L.dstSymbolName,u.dstSymbolName):void 0,u.type!==void 0?d(L.type,u.type):void 0)).limit(u.limit).all()}retargetRelations(u){let{dstProject:_,oldFile:g,oldSymbol:$,newFile:J,newSymbol:O,newDstProject:z}=u,N=$===null?Wu(d(L.dstProject,_),d(L.dstFilePath,g),P_(L.dstSymbolName)):Wu(d(L.dstProject,_),d(L.dstFilePath,g),d(L.dstSymbolName,$)),Q={dstFilePath:J,dstSymbolName:O};if(z!==void 0)Q.dstProject=z;this.db.drizzleDb.update(L).set(Q).where(N).run()}}import{err as m_}from"@zipbul/result";import{subscribe as y$}from"@parcel/watcher";import Q_ from"path";var f$=["**/.git/**",`**/${Yu}/**`,"**/dist/**","**/node_modules/**"],P$=new Set(["package.json","tsconfig.json"]);function m$(u){return u.replaceAll("\\","/")}function h$(u){if(u==="update")return"change";if(u==="create")return"create";return"delete"}class N_{#u;#_;#g;#J;#$;#N;constructor(u,_=y$,g=console){this.#_=u.projectRoot,this.#g=[...f$,...u.ignorePatterns??[]],this.#J=new Set((u.extensions??[".ts",".mts",".cts"]).map(($)=>$.toLowerCase())),this.#$=_,this.#N=g}async start(u){try{this.#u=await this.#$(this.#_,(_,g)=>{if(_){this.#N.error($u("watcher","Callback error",_));return}try{for(let $ of g){let J=m$(Q_.relative(this.#_,$.path));if(J.startsWith(".."))continue;let O=Q_.basename(J),z=Q_.extname(J).toLowerCase();if(!P$.has(O)&&!this.#J.has(z))continue;if(J.endsWith(".d.ts"))continue;u({eventType:h$($.type),filePath:J})}}catch($){this.#N.error($u("watcher","Callback error",$))}},{ignore:this.#g})}catch(_){return m_($u("watcher","Failed to subscribe watcher",_))}}async close(){if(!this.#u)return;try{await this.#u.unsubscribe(),this.#u=void 0}catch(u){return m_($u("watcher","Failed to close watcher",u))}}}import z_ from"path";import{promises as x$}from"fs";var i$=["**/node_modules/**","**/.git/**",`**/${Yu}/**`,"**/dist/**"];async function mu(u){let _=[];for await(let g of x$.glob("**/package.json",{cwd:u,exclude:i$})){let $=z_.dirname(g).replaceAll("\\","/"),J=z_.join(u,g),O=await Bun.file(J).json(),z=typeof O?.name==="string"&&O.name.length>0?O.name:z_.basename($==="."?u:$);_.push({dir:$,project:z})}return _.sort((g,$)=>$.dir.length-g.dir.length),_}function a(u,_,g="default"){let $=u.replaceAll("\\","/");for(let J of _){if(J.dir===".")return J.project;if($===J.dir||$.startsWith(`${J.dir}/`))return J.project}return g}import h_ from"path";var Zu=new Map;async function p$(u){let _=Bun.file(u);if(!await _.exists())return null;try{let g=await _.text(),$=Bun.JSONC.parse(g);return typeof $==="object"&&$!==null?$:null}catch{return null}}async function qu(u){if(Zu.has(u))return Zu.get(u)??null;let _=h_.join(u,"tsconfig.json"),g=await p$(_);if(!g)return Zu.set(u,null),null;let $=typeof g.compilerOptions==="object"&&g.compilerOptions!==null?g.compilerOptions:null;if(!$)return Zu.set(u,null),null;let J=typeof $.baseUrl==="string"?$.baseUrl:null,O=typeof $.paths==="object"&&$.paths!==null?$.paths:null;if(!J&&!O)return Zu.set(u,null),null;let z=J?h_.resolve(u,J):u,N=new Map;if(O)for(let[V,W]of Object.entries(O)){if(!Array.isArray(W))continue;let U=W.filter((X)=>typeof X==="string");N.set(V,U)}let Q={baseUrl:z,paths:N};return Zu.set(u,Q),Q}function hu(u){if(u){Zu.delete(u);return}Zu.clear()}import x_ from"path";function xu(u,_){return x_.relative(u,_).replaceAll("\\","/")}function Cu(u,_){return x_.resolve(u,_)}function Ou(u){let _=Bun.hash.xxHash64(u);return BigInt.asUintN(64,BigInt(_)).toString(16).padStart(16,"0")}import{isErr as e_}from"@zipbul/result";import{err as l$}from"@zipbul/result";import{parseSync as d$}from"oxc-parser";function ju(u,_,g,$=d$){try{let{program:J,errors:O,comments:z}=$(u,_,g);return{filePath:u,program:J,errors:O,comments:z,sourceText:_}}catch(J){return l$($u("parse",`Failed to parse file: ${u}`,J))}}import{promises as c$}from"fs";import{join as r$}from"path";async function i_(u){let{projectRoot:_,extensions:g,ignorePatterns:$,fileRepo:J}=u,O=J.getFilesMap(),z=new Set,N=[],Q=[],V=$.map((U)=>new Bun.Glob(U));for await(let U of c$.glob("**/*",{cwd:_})){if(!g.some((Z)=>U.endsWith(Z)))continue;if(U.startsWith("node_modules/")||U.includes("/node_modules/"))continue;if(V.some((Z)=>Z.match(U)))continue;z.add(U);let X=r$(_,U),M=Bun.file(X),{size:I,lastModified:D}=M,T=O.get(U);if(!T){let Z=await M.text(),K=Ou(Z);N.push({filePath:U,contentHash:K,mtimeMs:D,size:I});continue}if(T.mtimeMs===D&&T.size===I){Q.push({filePath:U,contentHash:T.contentHash,mtimeMs:D,size:I});continue}let j=await M.text(),h=Ou(j);if(h===T.contentHash)Q.push({filePath:U,contentHash:h,mtimeMs:D,size:I});else N.push({filePath:U,contentHash:h,mtimeMs:D,size:I})}let W=[];for(let U of O.keys())if(!z.has(U))W.push(U);return{changed:N,unchanged:Q,deleted:W}}function iu(u){let _=[0];for(let g=0;g<u.length;g++)if(u[g]===`
3
- `)_.push(g+1);return _}function wu(u,_){let g=0,$=u.length-1;while(g<$){let J=g+$+1>>1;if(u[J]<=_)g=J;else $=J-1}return{line:g+1,column:_-u[g]}}import{err as s$}from"@zipbul/result";import{parse as a$}from"comment-parser";function pu(u){try{let _=u.trim();if(_.startsWith("/**"))_=_.slice(3);if(_.endsWith("*/"))_=_.slice(0,-2);let $=a$(`/** ${_} */`)[0]??{description:"",tags:[]};return{description:($.description??"").trim(),tags:($.tags??[]).map((J)=>({tag:J.tag??"",name:J.name??"",type:J.type??"",description:J.description??"",optional:J.optional??!1,...J.default!==void 0?{default:J.default}:{}}))}}catch(_){return s$($u("parse","Failed to parse JSDoc comment",_))}}import{isErr as t$}from"@zipbul/result";function Su(u){let{program:_,sourceText:g,comments:$}=u,J=iu(g),O=$.filter((Z)=>Z.type==="Block"&&Z.value.startsWith("*")).sort((Z,K)=>Z.end-K.end),z=_.body.map((Z)=>Z.start??0).sort((Z,K)=>Z-K);function N(Z,K){return{start:wu(J,Z),end:wu(J,K)}}function Q(Z){let K=0,B=O.length-1,R=-1;while(K<=B){let S=K+B>>>1;if(O[S].end<=Z)R=S,K=S+1;else B=S-1}if(R<0)return;let q=O[R];K=0,B=z.length-1;while(K<=B){let S=K+B>>>1,G=z[S];if(G<=q.end)K=S+1;else if(G>=Z)B=S-1;else return}return`/*${q.value}*/`}function V(Z){if(!Z)return;let K=Z.typeAnnotation??Z;return g.slice(K.start,K.end)}function W(Z){if(!Z||Z.length===0)return[];return Z.map((K)=>{let B=K.expression;if(!B)return{name:"unknown"};if(B.type==="CallExpression"){let R=B.callee?.name??B.callee?.property?.name??"unknown",q=(B.arguments??[]).map((S)=>g.slice(S.start,S.end));return{name:R,arguments:q.length>0?q:void 0}}if(B.type==="Identifier")return{name:B.name??"unknown"};return{name:g.slice(B.start,B.end)}})}function U(Z){let K=Z.type==="TSParameterProperty"?Z.parameter:Z;if(K?.type==="RestElement"){let E=`...${K.argument?.name??"unknown"}`,p=K.typeAnnotation,gu=p?V(p):void 0,r={name:E,isOptional:!1};if(gu)r.type=gu;return r}if(K?.type==="AssignmentPattern"){let{left:y,right:E}=K,p=y?.name??"unknown",gu=y?.typeAnnotation,r=gu?V(gu):void 0,uu=g.slice(E.start,E.end),Y=W(y?.decorators??[]),A={name:p,isOptional:!0,defaultValue:uu};if(r)A.type=r;if(Y.length>0)A.decorators=Y;return A}let B=K?.name??K?.pattern?.name??"unknown",R=!!K?.optional,q=K?.typeAnnotation,S=q?V(q):void 0,G=W(K?.decorators??[]),f={name:B,isOptional:R};if(S)f.type=S;if(G.length>0)f.decorators=G;return f}function X(Z,K){let B=[];if(K?.async)B.push("async");if(Z.static)B.push("static");if(Z.abstract)B.push("abstract");if(Z.readonly)B.push("readonly");if(Z.override)B.push("override");if(Z.declare)B.push("declare");if(Z.const)B.push("const");let R=Z.accessibility;if(R==="private")B.push("private");else if(R==="protected")B.push("protected");else if(R==="public")B.push("public");return B}function M(Z){let K=[];if(Z.superClass){let R=g.slice(Z.superClass.start,Z.superClass.end);K.push({kind:"extends",name:R})}let B=Z.implements??[];for(let R of B){let q=R.expression??R,S=g.slice(q.start,q.end);K.push({kind:"implements",name:S})}return K}function I(Z){let K=[];for(let B of Z.extends??[]){let R=B.expression??B,q=g.slice(R.start,R.end);K.push({kind:"extends",name:q})}return K}function D(Z){let K=[];for(let B of Z)if(B.type==="MethodDefinition"){let R=B.key?.name??"unknown",q=B.value,S=B.kind??"method",G=S==="constructor"?"constructor":S==="get"?"getter":S==="set"?"setter":"method",f=X(B,q),y=(q?.params??[]).map(U),E=V(q?.returnType),p={kind:"method",name:R,span:N(B.start,B.end),isExported:!1,methodKind:G,modifiers:f,parameters:y.length>0?y:void 0,returnType:E};K.push(p)}else if(B.type==="PropertyDefinition"){let R=B.key?.name??"unknown",q=X(B),S={kind:"property",name:R,span:N(B.start,B.end),isExported:!1,modifiers:q};K.push(S)}return K}function T(Z){let K=[];for(let B of Z)if(B.type==="TSMethodSignature"){let R=B.key?.name??"unknown",q=(B.params??[]).map(U),S=V(B.returnType);K.push({kind:"method",name:R,span:N(B.start,B.end),isExported:!1,modifiers:[],methodKind:"method",parameters:q.length>0?q:void 0,returnType:S})}else if(B.type==="TSPropertySignature"){let R=B.key?.name??"unknown",q=V(B.typeAnnotation),S={kind:"property",name:R,span:N(B.start,B.end),isExported:!1,modifiers:B.readonly?["readonly"]:[],returnType:q};K.push(S)}return K}function j(Z,K){let B=Z.type??"";if(B==="FunctionDeclaration"){let R=Z.id?.name??"default",q=(Z.params??[]).map(U),S=V(Z.returnType),G=X(Z,Z),f=W(Z.decorators??[]),y=Z.typeParameters?.params?.flatMap((p)=>{let gu=p.name?.name;return gu?[gu]:[]})||void 0,E={kind:"function",name:R,span:N(Z.start,Z.end),isExported:K,modifiers:G,parameters:q.length>0?q:void 0,returnType:S,decorators:f.length>0?f:void 0};if(y&&y.length>0)E.typeParameters=y;return E}if(B==="ClassDeclaration"||B==="ClassExpression"){let R=Z.id?.name??"default",q=M(Z),S=D(Z.body?.body??[]),G=W(Z.decorators??[]),f=X(Z,Z),y=Z.typeParameters?.params?.flatMap((p)=>{let gu=p.name?.name;return gu?[gu]:[]})||void 0,E={kind:"class",name:R,span:N(Z.start,Z.end),isExported:K,modifiers:f,heritage:q.length>0?q:void 0,members:S.length>0?S:void 0,decorators:G.length>0?G:void 0};if(y&&y.length>0)E.typeParameters=y;return E}if(B==="VariableDeclaration"){let R=[];for(let q of Z.declarations??[]){let{id:S,init:G}=q;if(S?.type==="ObjectPattern"){for(let r of S.properties??[]){let uu=r.value?.name??r.key?.name??"unknown";R.push({kind:"variable",name:uu,span:N(r.start??q.start,r.end??q.end),isExported:K,modifiers:[]})}continue}if(S?.type==="ArrayPattern"){for(let r of S.elements??[]){if(!r||r.type!=="Identifier")continue;let uu=r.name??"unknown";R.push({kind:"variable",name:uu,span:N(r.start??q.start,r.end??q.end),isExported:K,modifiers:[]})}continue}let f=S?.name??"unknown",y="variable",E,p;if(G?.type==="FunctionExpression"||G?.type==="ArrowFunctionExpression")y="function",E=(G.params??[]).map(U),p=V(G.returnType);let gu=[];R.push({kind:y,name:f,span:N(q.start,q.end),isExported:K,modifiers:gu,parameters:E,returnType:p})}if(R.length===0)return null;if(R.length===1)return R[0];return R}if(B==="TSTypeAliasDeclaration")return{kind:"type",name:Z.id?.name??"unknown",span:N(Z.start,Z.end),isExported:K,modifiers:[]};if(B==="TSInterfaceDeclaration"){let R=Z.id?.name??"unknown",q=I(Z),S=T(Z.body?.body??[]),G=Z.typeParameters?.params?.flatMap((y)=>{let E=y.name?.name;return E?[E]:[]})||void 0,f={kind:"interface",name:R,span:N(Z.start,Z.end),isExported:K,modifiers:[],heritage:q.length>0?q:void 0,members:S.length>0?S:void 0};if(G&&G.length>0)f.typeParameters=G;return f}if(B==="TSEnumDeclaration"){let R=Z.id?.name??"unknown",q=X(Z),G=(Z.body?.members??[]).map((f)=>({kind:"property",name:f.id?.name??f.id?.value??"unknown",span:N(f.start,f.end),isExported:!1,modifiers:[]}));return{kind:"enum",name:R,span:N(Z.start,Z.end),isExported:K,modifiers:q,members:G.length>0?G:void 0}}return null}let h=[];for(let Z of _.body){let K=null,B=Z,R=typeof B.type==="string"?B.type:"";if(R==="ExportNamedDeclaration"){let S=Z;if(S.declaration){if(K=j(S.declaration,!0),K&&!Array.isArray(K))K.span=N(S.start,S.end);else if(Array.isArray(K))for(let G of K)G.span=N(S.start,S.end)}}else if(R==="ExportDefaultDeclaration"){let S=Z,G=S.declaration;if(G){if(K=j(G,!0),K&&!Array.isArray(K))K.name=G.id?.name??"default",K.isExported=!0,K.span=N(S.start,S.end)}}else K=j(Z,!1);let q=Array.isArray(K)?K:K?[K]:[];for(let S of q){let G=Z.start??0,f=Q(G);if(f){let y=pu(f);if(!t$(y))S.jsDoc=y}h.push(S)}}return h}function o$(u){if(u.kind==="function"||u.kind==="method"){let _=u.parameters?.length??0,g=u.modifiers.includes("async")?1:0;return`params:${_}|async:${g}`}return null}function e$(u){let _={};if(u.jsDoc)_.jsDoc=u.jsDoc;if(u.kind==="function"||u.kind==="method"){if(u.parameters!==void 0)_.parameters=u.parameters;if(u.returnType!==void 0)_.returnType=u.returnType}if(u.heritage?.length)_.heritage=u.heritage;if(u.decorators?.length)_.decorators=u.decorators;if(u.typeParameters?.length)_.typeParameters=u.typeParameters;if(u.modifiers?.length)_.modifiers=u.modifiers;if(u.members?.length)_.members=u.members.map((g)=>{let $=g.modifiers.find((J)=>J==="private"||J==="protected"||J==="public");return{name:g.name,kind:g.methodKind??g.kind,type:g.returnType,visibility:$,isStatic:g.modifiers.includes("static")||void 0,isReadonly:g.modifiers.includes("readonly")||void 0}});return Object.keys(_).length>0?JSON.stringify(_):null}function u0(u){let _=[u.kind];if(u.modifiers.length)_.push(`mod:${[...u.modifiers].sort().join(",")}`);if(u.typeParameters?.length)_.push(`tp:${u.typeParameters.length}`);if(u.heritage?.length){let g=[...u.heritage].sort(($,J)=>$.name.localeCompare(J.name)).map(($)=>`${$.kind}:${$.name}`).join(",");_.push(`her:${g}`)}if(u.decorators?.length)_.push(`dec:${[...u.decorators].map((g)=>g.name).sort().join(",")}`);if(u.methodKind)_.push(`mk:${u.methodKind}`);if(u.parameters)_.push(`p:${u.parameters.length}`);if(u.returnType)_.push(`rt:${u.returnType}`);if(u.members?.length){let g=u.members.map(($)=>`${$.kind}:${$.modifiers.join(",")}:${$.parameters?.length??""}:${$.returnType??""}`).sort().join(";");_.push(`mem:${u.members.length}:${Ou(g)}`)}return Ou(_.join("|"))}function p_(u,_,g,$,J){let O=o$(u),z=Ou(`${_}|${u.kind}|${O??""}`),N=u0(u);return{project:g,filePath:$,kind:u.kind,name:_,startLine:u.span.start.line,startColumn:u.span.start.column,endLine:u.span.end.line,endColumn:u.span.end.column,isExported:u.isExported?1:0,signature:O,fingerprint:z,detailJson:e$(u),contentHash:J,indexedAt:new Date().toISOString(),structuralFingerprint:N}}function O_(u){let{parsed:_,project:g,filePath:$,contentHash:J,symbolRepo:O}=u,z=Su(_),N=[];for(let Q of z){N.push(p_(Q,Q.name,g,$,J));for(let V of Q.members??[])N.push(p_(V,`${Q.name}.${V.name}`,g,$,J))}O.replaceFileSymbols(g,$,J,N)}import{resolve as w_,dirname as _0,extname as g0}from"path";function Mu(u,_,g){let $=(J)=>{let O=g0(J);if(O==="")return[J+".ts",J+".d.ts",J+"/index.ts",J+"/index.d.ts",J+".mts",J+"/index.mts",J+".cts",J+"/index.cts"];if(O===".js")return[J.slice(0,-3)+".ts"];if(O===".mjs")return[J.slice(0,-4)+".mts"];if(O===".cjs")return[J.slice(0,-4)+".cts"];return[J]};if(_.startsWith(".")){let J=w_(_0(u),_);return $(J)}if(g)for(let[J,O]of g.paths){if(O.length===0)continue;let z=J.indexOf("*");if(z===-1){if(_===J){let N=[];for(let Q of O)N.push(...$(w_(g.baseUrl,Q)));return N}}else{let N=J.slice(0,z),Q=J.slice(z+1);if(_.startsWith(N)&&(Q===""||_.endsWith(Q))){let V=_.slice(N.length,Q===""?void 0:_.length-Q.length),W=[];for(let U of O)W.push(...$(w_(g.baseUrl,U.replace("*",V))));return W}}}return[]}function l_(u,_,g,$=Mu){let J=new Map,O=u.body??[];for(let z of O){if(z.type!=="ImportDeclaration")continue;let N=z.source?.value??"",Q=$(_,N,g);if(Q.length===0)continue;let V=Q[0],W=z.specifiers??[];for(let U of W)switch(U.type){case"ImportSpecifier":J.set(U.local.name,{path:V,importedName:U.imported.name});break;case"ImportDefaultSpecifier":J.set(U.local.name,{path:V,importedName:"default"});break;case"ImportNamespaceSpecifier":J.set(U.local.name,{path:V,importedName:"*"});break}}return J}var $0=new Set(["loc","start","end","scope"]);function Ru(u,_){if(!u||typeof u!=="object")return;if(Array.isArray(u)){for(let $ of u)Ru($,_);return}let g=u;_(g);for(let $ of Object.keys(g)){if($0.has($))continue;let J=g[$];if(J&&typeof J==="object")Ru(J,_)}}function d_(u){if(!u||typeof u!=="object"||Array.isArray(u))return null;let _=u;if((_.type==="StringLiteral"||_.type==="Literal")&&typeof _.value==="string")return _.value;return null}function Bu(u){if(!u||typeof u!=="object"||Array.isArray(u))return null;let _=u;if(_.type==="Identifier"){let g=_.name;return{root:g,parts:[],full:g}}if(_.type==="ThisExpression")return{root:"this",parts:[],full:"this"};if(_.type==="Super")return{root:"super",parts:[],full:"super"};if(_.type==="MemberExpression"){let g=[],$=_;while($.type==="MemberExpression"){let z=$.property;if(!z||typeof z.name!=="string")return null;g.push(z.name),$=$.object}let J;if($.type==="Identifier")J=$.name;else if($.type==="ThisExpression")J="this";else if($.type==="Super")J="super";else return null;g.reverse();let O=[J,...g].join(".");return{root:J,parts:g,full:O}}return null}function c_(u,_,g,$=Mu){let J=[],O=u.body??[];for(let z of O){if(z.type==="ImportDeclaration"){let N=z.source?.value??"",Q=$(_,N,g);if(Q.length===0)continue;let V=Q[0],W=z.importKind==="type",U=z.specifiers??[];if(U.length===0){let X={};if(W)X.isType=!0;J.push({type:W?"type-references":"imports",srcFilePath:_,srcSymbolName:null,dstFilePath:V,dstSymbolName:null,...Object.keys(X).length>0?{metaJson:JSON.stringify(X)}:{}})}else for(let X of U){let M=X.type,I=W||X.importKind==="type",D={};if(I)D.isType=!0;let T,j;if(M==="ImportDefaultSpecifier")T="default",j=X.local.name;else if(M==="ImportNamespaceSpecifier")T="*",j=X.local.name,D.importKind="namespace";else T=X.imported.name,j=X.local.name;J.push({type:I?"type-references":"imports",srcFilePath:_,srcSymbolName:j,dstFilePath:V,dstSymbolName:T,...Object.keys(D).length>0?{metaJson:JSON.stringify(D)}:{}})}continue}if(z.type==="ExportAllDeclaration"&&z.source){let N=z.source?.value??"",Q=$(_,N,g);if(Q.length===0)continue;let V=Q[0],W=z.exportKind==="type",U={isReExport:!0};if(W)U.isType=!0;J.push({type:W?"type-references":"re-exports",srcFilePath:_,srcSymbolName:null,dstFilePath:V,dstSymbolName:null,metaJson:JSON.stringify(U)});continue}if(z.type==="ExportNamedDeclaration"&&z.source){let N=z.source?.value??"",Q=$(_,N,g);if(Q.length===0)continue;let V=Q[0],W=z.exportKind==="type",M={isReExport:!0,specifiers:(z.specifiers??[]).map((I)=>({local:I.local.name,exported:I.exported.name}))};if(W)M.isType=!0;J.push({type:W?"type-references":"re-exports",srcFilePath:_,srcSymbolName:null,dstFilePath:V,dstSymbolName:null,metaJson:JSON.stringify(M)})}}return Ru(u,(z)=>{if(z.type!=="ImportExpression")return;let N=d_(z.source);if(!N)return;let Q=$(_,N,g);if(Q.length===0)return;let V=Q[0];J.push({type:"imports",srcFilePath:_,srcSymbolName:null,dstFilePath:V,dstSymbolName:null,metaJson:JSON.stringify({isDynamic:!0})})}),J}function r_(u,_,g){let $=[],J=[],O=[];function z(){if(J.length>0)return J[J.length-1]??null;return null}function N(V){if(!V)return null;let W=g.get(V.root);if(V.parts.length===0){if(W)return{dstFilePath:W.path,dstSymbolName:W.importedName,resolution:"import"};return{dstFilePath:_,dstSymbolName:V.root,resolution:"local"}}else{if(W&&W.importedName==="*"){let U=V.parts[V.parts.length-1];return{dstFilePath:W.path,dstSymbolName:U,resolution:"namespace"}}return{dstFilePath:_,dstSymbolName:V.full,resolution:"local-member"}}}function Q(V){if(!V||typeof V!=="object")return;if(Array.isArray(V)){for(let X of V)Q(X);return}let W=V,U=typeof W.type==="string"?W.type:"";if(U==="ClassDeclaration"||U==="ClassExpression"){let X=W,M=X.id?.name??"AnonymousClass";O.push(M),Q(X.body),O.pop();return}if(U==="FunctionDeclaration"){let X=W,M=X.id?.name??"anonymous";J.push(M),Q(X.body),J.pop();return}if(U==="VariableDeclarator"&&W.init&&(W.init?.type==="FunctionExpression"||W.init?.type==="ArrowFunctionExpression")){let X=W,M=X.id?.name??"anonymous";J.push(M),Q(X.init?.body??X.init),J.pop();return}if(U==="MethodDefinition"&&W.value){let X=W,M=O[O.length-1]??"",I=X.key?.name??"anonymous",D=M?`${M}.${I}`:I;J.push(D),Q(X.value?.body),J.pop();return}if(U==="FunctionExpression"||U==="ArrowFunctionExpression"){let X=z(),M=X?`${X}.<anonymous>`:"<anonymous>";J.push(M),Q(W.body),J.pop();return}if(U==="CallExpression"){let X=W,M=Bu(X.callee),I=N(M);if(I){let D=z(),T={};if(D===null)T.scope="module";$.push({type:"calls",srcFilePath:_,srcSymbolName:D,dstFilePath:I.dstFilePath,dstSymbolName:I.dstSymbolName,...Object.keys(T).length>0?{metaJson:JSON.stringify(T)}:{}})}Q(X.callee);for(let D of X.arguments??[])Q(D);return}if(U==="NewExpression"){let X=W,M=Bu(X.callee),I=N(M);if(I){let D=z(),T={isNew:!0};if(D===null)T.scope="module";$.push({type:"calls",srcFilePath:_,srcSymbolName:D,dstFilePath:I.dstFilePath,dstSymbolName:I.dstSymbolName,metaJson:JSON.stringify(T)})}for(let D of X.arguments??[])Q(D);return}for(let X of Object.keys(W)){if(X==="loc"||X==="start"||X==="end"||X==="scope")continue;let M=W[X];if(M&&typeof M==="object")Q(M)}}return Q(u),$}function s_(u,_,g){let $=[];return Ru(u,(J)=>{if(J.type==="TSInterfaceDeclaration"){let N=J.id?.name??"AnonymousInterface",Q=J.extends??[];for(let V of Q){let W=V.expression??V,U=Bu(W);if(!U)continue;let X=W_(U,_,g);$.push({type:"extends",srcFilePath:_,srcSymbolName:N,...X})}return}if(J.type!=="ClassDeclaration"&&J.type!=="ClassExpression")return;let O=J.id?.name??"AnonymousClass";if(J.superClass){let N=Bu(J.superClass);if(N){let Q=W_(N,_,g);$.push({type:"extends",srcFilePath:_,srcSymbolName:O,...Q})}}let z=J.implements??[];for(let N of z){let Q=N.expression??N,V=Bu(Q);if(!V)continue;let W=W_(V,_,g);$.push({type:"implements",srcFilePath:_,srcSymbolName:O,...W})}}),$}function W_(u,_,g){let $=g.get(u.root);if($){if($.importedName==="*"){let J=u.parts[u.parts.length-1]??u.root;return{dstFilePath:$.path,dstSymbolName:J,metaJson:JSON.stringify({isNamespaceImport:!0})}}return{dstFilePath:$.path,dstSymbolName:u.parts.length>0?u.full:$.importedName}}return{dstFilePath:_,dstSymbolName:u.full,metaJson:JSON.stringify({isLocal:!0})}}function lu(u,_,g,$=Mu){let J=l_(u,_,g,$),O=c_(u,_,g,$),z=r_(u,_,J),N=s_(u,_,J);return[...O,...z,...N]}function V_(u){let{ast:_,project:g,filePath:$,relationRepo:J,projectRoot:O,tsconfigPaths:z,knownFiles:N,boundaries:Q}=u,V=Cu(O,$),U=lu(_,V,z,N?(M,I,D)=>{let T=Mu(M,I,D);for(let j of T){let h=xu(O,j);if(Q){let Z=a(h,Q);if(N.has(`${Z}::${h}`))return[j]}else if(N.has(`${g}::${h}`))return[j]}return[]}:void 0),X=[];for(let M of U){let I=xu(O,M.dstFilePath);if(I.startsWith(".."))continue;let D=xu(O,M.srcFilePath),T=Q?a(I,Q):g;X.push({project:g,type:M.type,srcFilePath:D,srcSymbolName:M.srcSymbolName??null,dstProject:T,dstFilePath:I,dstSymbolName:M.dstSymbolName??null,metaJson:M.metaJson??null})}return J.replaceFileRelations(g,$,X),X.length}import{isErr as J0}from"@zipbul/result";var a_=/(?:^|\s)@([a-zA-Z][\w-]*\w|[a-zA-Z])\s*(.*)$/m;function Q0(u){let _=Su(u),g=[];for(let $ of _){g.push({name:$.name,startLine:$.span.start.line});for(let J of $.members??[])g.push({name:`${$.name}.${J.name}`,startLine:J.span.start.line})}return g.sort(($,J)=>$.startLine-J.startLine),g}function U_(u,_,g){let $=0,J=u.length-1;while($<=J){let O=$+J>>1;if(u[O].startLine<=_)$=O+1;else J=O-1}if($<u.length){let O=u[$];if(O.startLine-_<=g)return O.name}return null}function du(u,_,g){let $=wu(u,_),J=wu(u,g);return{start:$,end:J}}function t_(u){let{comments:_,sourceText:g}=u;if(!_.length)return[];let $=iu(g),J=Q0(u),O=[],z=[..._].sort((Q,V)=>Q.start-V.start),N=null;for(let Q of z)if(Q.type==="Block"&&Q.value.startsWith("*")){N=null;let V=`/*${Q.value}*/`,W=pu(V);if(J0(W))continue;let U=W;if(!U.tags?.length)continue;let X=wu($,Q.end),M=U_(J,X.line,3),I=g.slice(Q.start,Q.end);for(let D of U.tags){let T=[D.name,D.description].filter(Boolean).join(" "),j=`@${D.tag}`,h=I.indexOf(j),Z;if(h>=0){let K=Q.start+h,B=g.indexOf(`
3
+ `)_.push(g+1);return _}function wu(u,_){let g=0,$=u.length-1;while(g<$){let J=g+$+1>>1;if(u[J]<=_)g=J;else $=J-1}return{line:g+1,column:_-u[g]}}import{err as s$}from"@zipbul/result";import{parse as a$}from"comment-parser";function pu(u){try{let _=u.trim();if(_.startsWith("/**"))_=_.slice(3);if(_.endsWith("*/"))_=_.slice(0,-2);let $=a$(`/** ${_} */`)[0]??{description:"",tags:[]};return{description:($.description??"").trim(),tags:($.tags??[]).map((J)=>({tag:J.tag??"",name:J.name??"",type:J.type??"",description:J.description??"",optional:J.optional??!1,...J.default!==void 0?{default:J.default}:{}}))}}catch(_){return s$($u("parse","Failed to parse JSDoc comment",_))}}import{isErr as t$}from"@zipbul/result";function Su(u){let{program:_,sourceText:g,comments:$}=u,J=iu(g),O=$.filter((Z)=>Z.type==="Block"&&Z.value.startsWith("*")).sort((Z,K)=>Z.end-K.end),z=_.body.map((Z)=>Z.start??0).sort((Z,K)=>Z-K);function N(Z,K){return{start:wu(J,Z),end:wu(J,K)}}function Q(Z){let K=0,B=O.length-1,R=-1;while(K<=B){let S=K+B>>>1;if(O[S].end<=Z)R=S,K=S+1;else B=S-1}if(R<0)return;let q=O[R];K=0,B=z.length-1;while(K<=B){let S=K+B>>>1,G=z[S];if(G<=q.end)K=S+1;else if(G>=Z)B=S-1;else return}return`/*${q.value}*/`}function V(Z){if(!Z)return;let K=Z.typeAnnotation??Z;return g.slice(K.start,K.end)}function W(Z){if(!Z||Z.length===0)return[];return Z.map((K)=>{let B=K.expression;if(!B)return{name:"unknown"};if(B.type==="CallExpression"){let R=B.callee?.name??B.callee?.property?.name??"unknown",q=(B.arguments??[]).map((S)=>g.slice(S.start,S.end));return{name:R,arguments:q.length>0?q:void 0}}if(B.type==="Identifier")return{name:B.name??"unknown"};return{name:g.slice(B.start,B.end)}})}function U(Z){let K=Z.type==="TSParameterProperty"?Z.parameter:Z;if(K?.type==="RestElement"){let E=`...${K.argument?.name??"unknown"}`,p=K.typeAnnotation,gu=p?V(p):void 0,r={name:E,isOptional:!1};if(gu)r.type=gu;return r}if(K?.type==="AssignmentPattern"){let{left:y,right:E}=K,p=y?.name??"unknown",gu=y?.typeAnnotation,r=gu?V(gu):void 0,uu=g.slice(E.start,E.end),Y=W(y?.decorators??[]),A={name:p,isOptional:!0,defaultValue:uu};if(r)A.type=r;if(Y.length>0)A.decorators=Y;return A}let B=K?.name??K?.pattern?.name??"unknown",R=!!K?.optional,q=K?.typeAnnotation,S=q?V(q):void 0,G=W(K?.decorators??[]),f={name:B,isOptional:R};if(S)f.type=S;if(G.length>0)f.decorators=G;return f}function X(Z,K){let B=[];if(K?.async)B.push("async");if(Z.static)B.push("static");if(Z.abstract)B.push("abstract");if(Z.readonly)B.push("readonly");if(Z.override)B.push("override");if(Z.declare)B.push("declare");if(Z.const)B.push("const");let R=Z.accessibility;if(R==="private")B.push("private");else if(R==="protected")B.push("protected");else if(R==="public")B.push("public");return B}function M(Z){let K=[];if(Z.superClass){let R=g.slice(Z.superClass.start,Z.superClass.end);K.push({kind:"extends",name:R})}let B=Z.implements??[];for(let R of B){let q=R.expression??R,S=g.slice(q.start,q.end);K.push({kind:"implements",name:S})}return K}function I(Z){let K=[];for(let B of Z.extends??[]){let R=B.expression??B,q=g.slice(R.start,R.end);K.push({kind:"extends",name:q})}return K}function D(Z){let K=[];for(let B of Z)if(B.type==="MethodDefinition"){let R=B.key?.name??"unknown",q=B.value,S=B.kind??"method",G=S==="constructor"?"constructor":S==="get"?"getter":S==="set"?"setter":"method",f=X(B,q),y=(q?.params??[]).map(U),E=V(q?.returnType),p={kind:"method",name:R,span:N(B.start,B.end),isExported:!1,methodKind:G,modifiers:f,parameters:y.length>0?y:void 0,returnType:E};K.push(p)}else if(B.type==="PropertyDefinition"){let R=B.key?.name??"unknown",q=X(B),S={kind:"property",name:R,span:N(B.start,B.end),isExported:!1,modifiers:q};K.push(S)}return K}function T(Z){let K=[];for(let B of Z)if(B.type==="TSMethodSignature"){let R=B.key?.name??"unknown",q=(B.params??[]).map(U),S=V(B.returnType);K.push({kind:"method",name:R,span:N(B.start,B.end),isExported:!1,modifiers:[],methodKind:"method",parameters:q.length>0?q:void 0,returnType:S})}else if(B.type==="TSPropertySignature"){let R=B.key?.name??"unknown",q=V(B.typeAnnotation),S={kind:"property",name:R,span:N(B.start,B.end),isExported:!1,modifiers:B.readonly?["readonly"]:[],returnType:q};K.push(S)}return K}function j(Z,K){let B=Z.type??"";if(B==="FunctionDeclaration"||B==="TSDeclareFunction"){let R=Z.id?.name??"default",q=(Z.params??[]).map(U),S=V(Z.returnType),G=X(Z,Z),f=W(Z.decorators??[]),y=Z.typeParameters?.params?.flatMap((p)=>{let gu=p.name?.name;return gu?[gu]:[]})||void 0,E={kind:"function",name:R,span:N(Z.start,Z.end),isExported:K,modifiers:G,parameters:q.length>0?q:void 0,returnType:S,decorators:f.length>0?f:void 0};if(y&&y.length>0)E.typeParameters=y;return E}if(B==="ClassDeclaration"||B==="ClassExpression"){let R=Z.id?.name??"default",q=M(Z),S=D(Z.body?.body??[]),G=W(Z.decorators??[]),f=X(Z,Z),y=Z.typeParameters?.params?.flatMap((p)=>{let gu=p.name?.name;return gu?[gu]:[]})||void 0,E={kind:"class",name:R,span:N(Z.start,Z.end),isExported:K,modifiers:f,heritage:q.length>0?q:void 0,members:S.length>0?S:void 0,decorators:G.length>0?G:void 0};if(y&&y.length>0)E.typeParameters=y;return E}if(B==="VariableDeclaration"){let R=[];for(let q of Z.declarations??[]){let{id:S,init:G}=q;if(S?.type==="ObjectPattern"){for(let r of S.properties??[]){let uu=r.value?.name??r.key?.name??"unknown";R.push({kind:"variable",name:uu,span:N(r.start??q.start,r.end??q.end),isExported:K,modifiers:[]})}continue}if(S?.type==="ArrayPattern"){for(let r of S.elements??[]){if(!r||r.type!=="Identifier")continue;let uu=r.name??"unknown";R.push({kind:"variable",name:uu,span:N(r.start??q.start,r.end??q.end),isExported:K,modifiers:[]})}continue}let f=S?.name??"unknown",y="variable",E,p;if(G?.type==="FunctionExpression"||G?.type==="ArrowFunctionExpression")y="function",E=(G.params??[]).map(U),p=V(G.returnType);let gu=[];R.push({kind:y,name:f,span:N(q.start,q.end),isExported:K,modifiers:gu,parameters:E,returnType:p})}if(R.length===0)return null;if(R.length===1)return R[0];return R}if(B==="TSTypeAliasDeclaration")return{kind:"type",name:Z.id?.name??"unknown",span:N(Z.start,Z.end),isExported:K,modifiers:[]};if(B==="TSInterfaceDeclaration"){let R=Z.id?.name??"unknown",q=I(Z),S=T(Z.body?.body??[]),G=Z.typeParameters?.params?.flatMap((y)=>{let E=y.name?.name;return E?[E]:[]})||void 0,f={kind:"interface",name:R,span:N(Z.start,Z.end),isExported:K,modifiers:[],heritage:q.length>0?q:void 0,members:S.length>0?S:void 0};if(G&&G.length>0)f.typeParameters=G;return f}if(B==="TSEnumDeclaration"){let R=Z.id?.name??"unknown",q=X(Z),G=(Z.body?.members??[]).map((f)=>({kind:"property",name:f.id?.name??f.id?.value??"unknown",span:N(f.start,f.end),isExported:!1,modifiers:[]}));return{kind:"enum",name:R,span:N(Z.start,Z.end),isExported:K,modifiers:q,members:G.length>0?G:void 0}}return null}let h=[];for(let Z of _.body){let K=null,B=Z,R=typeof B.type==="string"?B.type:"";if(R==="ExportNamedDeclaration"){let S=Z;if(S.declaration){if(K=j(S.declaration,!0),K&&!Array.isArray(K))K.span=N(S.start,S.end);else if(Array.isArray(K))for(let G of K)G.span=N(S.start,S.end)}}else if(R==="ExportDefaultDeclaration"){let S=Z,G=S.declaration;if(G){if(K=j(G,!0),K&&!Array.isArray(K))K.name=G.id?.name??"default",K.isExported=!0,K.span=N(S.start,S.end)}}else K=j(Z,!1);let q=Array.isArray(K)?K:K?[K]:[];for(let S of q){let G=Z.start??0,f=Q(G);if(f){let y=pu(f);if(!t$(y))S.jsDoc=y}h.push(S)}}return h}function o$(u){if(u.kind==="function"||u.kind==="method"){let _=u.parameters?.length??0,g=u.modifiers.includes("async")?1:0;return`params:${_}|async:${g}`}return null}function e$(u){let _={};if(u.jsDoc)_.jsDoc=u.jsDoc;if(u.kind==="function"||u.kind==="method"){if(u.parameters!==void 0)_.parameters=u.parameters;if(u.returnType!==void 0)_.returnType=u.returnType}if(u.heritage?.length)_.heritage=u.heritage;if(u.decorators?.length)_.decorators=u.decorators;if(u.typeParameters?.length)_.typeParameters=u.typeParameters;if(u.modifiers?.length)_.modifiers=u.modifiers;if(u.members?.length)_.members=u.members.map((g)=>{let $=g.modifiers.find((J)=>J==="private"||J==="protected"||J==="public");return{name:g.name,kind:g.methodKind??g.kind,type:g.returnType,visibility:$,isStatic:g.modifiers.includes("static")||void 0,isReadonly:g.modifiers.includes("readonly")||void 0}});return Object.keys(_).length>0?JSON.stringify(_):null}function u0(u){let _=[u.kind];if(u.modifiers.length)_.push(`mod:${[...u.modifiers].sort().join(",")}`);if(u.typeParameters?.length)_.push(`tp:${u.typeParameters.length}`);if(u.heritage?.length){let g=[...u.heritage].sort(($,J)=>$.name.localeCompare(J.name)).map(($)=>`${$.kind}:${$.name}`).join(",");_.push(`her:${g}`)}if(u.decorators?.length)_.push(`dec:${[...u.decorators].map((g)=>g.name).sort().join(",")}`);if(u.methodKind)_.push(`mk:${u.methodKind}`);if(u.parameters)_.push(`p:${u.parameters.length}`);if(u.returnType)_.push(`rt:${u.returnType}`);if(u.members?.length){let g=u.members.map(($)=>`${$.kind}:${$.modifiers.join(",")}:${$.parameters?.length??""}:${$.returnType??""}`).sort().join(";");_.push(`mem:${u.members.length}:${Ou(g)}`)}return Ou(_.join("|"))}function p_(u,_,g,$,J){let O=o$(u),z=Ou(`${_}|${u.kind}|${O??""}`),N=u0(u);return{project:g,filePath:$,kind:u.kind,name:_,startLine:u.span.start.line,startColumn:u.span.start.column,endLine:u.span.end.line,endColumn:u.span.end.column,isExported:u.isExported?1:0,signature:O,fingerprint:z,detailJson:e$(u),contentHash:J,indexedAt:new Date().toISOString(),structuralFingerprint:N}}function O_(u){let{parsed:_,project:g,filePath:$,contentHash:J,symbolRepo:O}=u,z=Su(_),N=[];for(let Q of z){N.push(p_(Q,Q.name,g,$,J));for(let V of Q.members??[])N.push(p_(V,`${Q.name}.${V.name}`,g,$,J))}O.replaceFileSymbols(g,$,J,N)}import{resolve as w_,dirname as _0,extname as g0}from"path";function Mu(u,_,g){let $=(J)=>{let O=g0(J);if(O==="")return[J+".ts",J+".d.ts",J+"/index.ts",J+"/index.d.ts",J+".mts",J+"/index.mts",J+".cts",J+"/index.cts"];if(O===".js")return[J.slice(0,-3)+".ts"];if(O===".mjs")return[J.slice(0,-4)+".mts"];if(O===".cjs")return[J.slice(0,-4)+".cts"];return[J]};if(_.startsWith(".")){let J=w_(_0(u),_);return $(J)}if(g)for(let[J,O]of g.paths){if(O.length===0)continue;let z=J.indexOf("*");if(z===-1){if(_===J){let N=[];for(let Q of O)N.push(...$(w_(g.baseUrl,Q)));return N}}else{let N=J.slice(0,z),Q=J.slice(z+1);if(_.startsWith(N)&&(Q===""||_.endsWith(Q))){let V=_.slice(N.length,Q===""?void 0:_.length-Q.length),W=[];for(let U of O)W.push(...$(w_(g.baseUrl,U.replace("*",V))));return W}}}return[]}function l_(u,_,g,$=Mu){let J=new Map,O=u.body??[];for(let z of O){if(z.type!=="ImportDeclaration")continue;let N=z.source?.value??"",Q=$(_,N,g);if(Q.length===0)continue;let V=Q[0],W=z.specifiers??[];for(let U of W)switch(U.type){case"ImportSpecifier":J.set(U.local.name,{path:V,importedName:U.imported.name});break;case"ImportDefaultSpecifier":J.set(U.local.name,{path:V,importedName:"default"});break;case"ImportNamespaceSpecifier":J.set(U.local.name,{path:V,importedName:"*"});break}}return J}var $0=new Set(["loc","start","end","scope"]);function Ru(u,_){if(!u||typeof u!=="object")return;if(Array.isArray(u)){for(let $ of u)Ru($,_);return}let g=u;_(g);for(let $ of Object.keys(g)){if($0.has($))continue;let J=g[$];if(J&&typeof J==="object")Ru(J,_)}}function d_(u){if(!u||typeof u!=="object"||Array.isArray(u))return null;let _=u;if((_.type==="StringLiteral"||_.type==="Literal")&&typeof _.value==="string")return _.value;return null}function Bu(u){if(!u||typeof u!=="object"||Array.isArray(u))return null;let _=u;if(_.type==="Identifier"){let g=_.name;return{root:g,parts:[],full:g}}if(_.type==="ThisExpression")return{root:"this",parts:[],full:"this"};if(_.type==="Super")return{root:"super",parts:[],full:"super"};if(_.type==="MemberExpression"){let g=[],$=_;while($.type==="MemberExpression"){let z=$.property;if(!z||typeof z.name!=="string")return null;g.push(z.name),$=$.object}let J;if($.type==="Identifier")J=$.name;else if($.type==="ThisExpression")J="this";else if($.type==="Super")J="super";else return null;g.reverse();let O=[J,...g].join(".");return{root:J,parts:g,full:O}}return null}function c_(u,_,g,$=Mu){let J=[],O=u.body??[];for(let z of O){if(z.type==="ImportDeclaration"){let N=z.source?.value??"",Q=$(_,N,g);if(Q.length===0)continue;let V=Q[0],W=z.importKind==="type",U=z.specifiers??[];if(U.length===0){let X={};if(W)X.isType=!0;J.push({type:W?"type-references":"imports",srcFilePath:_,srcSymbolName:null,dstFilePath:V,dstSymbolName:null,...Object.keys(X).length>0?{metaJson:JSON.stringify(X)}:{}})}else for(let X of U){let M=X.type,I=W||X.importKind==="type",D={};if(I)D.isType=!0;let T,j;if(M==="ImportDefaultSpecifier")T="default",j=X.local.name;else if(M==="ImportNamespaceSpecifier")T="*",j=X.local.name,D.importKind="namespace";else T=X.imported.name,j=X.local.name;J.push({type:I?"type-references":"imports",srcFilePath:_,srcSymbolName:j,dstFilePath:V,dstSymbolName:T,...Object.keys(D).length>0?{metaJson:JSON.stringify(D)}:{}})}continue}if(z.type==="ExportAllDeclaration"&&z.source){let N=z.source?.value??"",Q=$(_,N,g);if(Q.length===0)continue;let V=Q[0],W=z.exportKind==="type",U={isReExport:!0};if(W)U.isType=!0;J.push({type:W?"type-references":"re-exports",srcFilePath:_,srcSymbolName:null,dstFilePath:V,dstSymbolName:null,metaJson:JSON.stringify(U)});continue}if(z.type==="ExportNamedDeclaration"&&z.source){let N=z.source?.value??"",Q=$(_,N,g);if(Q.length===0)continue;let V=Q[0],W=z.exportKind==="type",M={isReExport:!0,specifiers:(z.specifiers??[]).map((I)=>({local:I.local.name,exported:I.exported.name}))};if(W)M.isType=!0;J.push({type:W?"type-references":"re-exports",srcFilePath:_,srcSymbolName:null,dstFilePath:V,dstSymbolName:null,metaJson:JSON.stringify(M)})}}return Ru(u,(z)=>{if(z.type!=="ImportExpression")return;let N=d_(z.source);if(!N)return;let Q=$(_,N,g);if(Q.length===0)return;let V=Q[0];J.push({type:"imports",srcFilePath:_,srcSymbolName:null,dstFilePath:V,dstSymbolName:null,metaJson:JSON.stringify({isDynamic:!0})})}),J}function r_(u,_,g){let $=[],J=[],O=[];function z(){if(J.length>0)return J[J.length-1]??null;return null}function N(V){if(!V)return null;let W=g.get(V.root);if(V.parts.length===0){if(W)return{dstFilePath:W.path,dstSymbolName:W.importedName,resolution:"import"};return{dstFilePath:_,dstSymbolName:V.root,resolution:"local"}}else{if(W&&W.importedName==="*"){let U=V.parts[V.parts.length-1];return{dstFilePath:W.path,dstSymbolName:U,resolution:"namespace"}}return{dstFilePath:_,dstSymbolName:V.full,resolution:"local-member"}}}function Q(V){if(!V||typeof V!=="object")return;if(Array.isArray(V)){for(let X of V)Q(X);return}let W=V,U=typeof W.type==="string"?W.type:"";if(U==="ClassDeclaration"||U==="ClassExpression"){let X=W,M=X.id?.name??"AnonymousClass";O.push(M),Q(X.body),O.pop();return}if(U==="FunctionDeclaration"){let X=W,M=X.id?.name??"anonymous";J.push(M),Q(X.body),J.pop();return}if(U==="VariableDeclarator"&&W.init&&(W.init?.type==="FunctionExpression"||W.init?.type==="ArrowFunctionExpression")){let X=W,M=X.id?.name??"anonymous";J.push(M),Q(X.init?.body??X.init),J.pop();return}if(U==="MethodDefinition"&&W.value){let X=W,M=O[O.length-1]??"",I=X.key?.name??"anonymous",D=M?`${M}.${I}`:I;J.push(D),Q(X.value?.body),J.pop();return}if(U==="FunctionExpression"||U==="ArrowFunctionExpression"){let X=z(),M=X?`${X}.<anonymous>`:"<anonymous>";J.push(M),Q(W.body),J.pop();return}if(U==="CallExpression"){let X=W,M=Bu(X.callee),I=N(M);if(I){let D=z(),T={};if(D===null)T.scope="module";$.push({type:"calls",srcFilePath:_,srcSymbolName:D,dstFilePath:I.dstFilePath,dstSymbolName:I.dstSymbolName,...Object.keys(T).length>0?{metaJson:JSON.stringify(T)}:{}})}Q(X.callee);for(let D of X.arguments??[])Q(D);return}if(U==="NewExpression"){let X=W,M=Bu(X.callee),I=N(M);if(I){let D=z(),T={isNew:!0};if(D===null)T.scope="module";$.push({type:"calls",srcFilePath:_,srcSymbolName:D,dstFilePath:I.dstFilePath,dstSymbolName:I.dstSymbolName,metaJson:JSON.stringify(T)})}for(let D of X.arguments??[])Q(D);return}for(let X of Object.keys(W)){if(X==="loc"||X==="start"||X==="end"||X==="scope")continue;let M=W[X];if(M&&typeof M==="object")Q(M)}}return Q(u),$}function s_(u,_,g){let $=[];return Ru(u,(J)=>{if(J.type==="TSInterfaceDeclaration"){let N=J.id?.name??"AnonymousInterface",Q=J.extends??[];for(let V of Q){let W=V.expression??V,U=Bu(W);if(!U)continue;let X=W_(U,_,g);$.push({type:"extends",srcFilePath:_,srcSymbolName:N,...X})}return}if(J.type!=="ClassDeclaration"&&J.type!=="ClassExpression")return;let O=J.id?.name??"AnonymousClass";if(J.superClass){let N=Bu(J.superClass);if(N){let Q=W_(N,_,g);$.push({type:"extends",srcFilePath:_,srcSymbolName:O,...Q})}}let z=J.implements??[];for(let N of z){let Q=N.expression??N,V=Bu(Q);if(!V)continue;let W=W_(V,_,g);$.push({type:"implements",srcFilePath:_,srcSymbolName:O,...W})}}),$}function W_(u,_,g){let $=g.get(u.root);if($){if($.importedName==="*"){let J=u.parts[u.parts.length-1]??u.root;return{dstFilePath:$.path,dstSymbolName:J,metaJson:JSON.stringify({isNamespaceImport:!0})}}return{dstFilePath:$.path,dstSymbolName:u.parts.length>0?u.full:$.importedName}}return{dstFilePath:_,dstSymbolName:u.full,metaJson:JSON.stringify({isLocal:!0})}}function lu(u,_,g,$=Mu){let J=l_(u,_,g,$),O=c_(u,_,g,$),z=r_(u,_,J),N=s_(u,_,J);return[...O,...z,...N]}function V_(u){let{ast:_,project:g,filePath:$,relationRepo:J,projectRoot:O,tsconfigPaths:z,knownFiles:N,boundaries:Q}=u,V=Cu(O,$),U=lu(_,V,z,N?(M,I,D)=>{let T=Mu(M,I,D);for(let j of T){let h=xu(O,j);if(Q){let Z=a(h,Q);if(N.has(`${Z}::${h}`))return[j]}else if(N.has(`${g}::${h}`))return[j]}return[]}:void 0),X=[];for(let M of U){let I=xu(O,M.dstFilePath);if(I.startsWith(".."))continue;let D=xu(O,M.srcFilePath),T=Q?a(I,Q):g;X.push({project:g,type:M.type,srcFilePath:D,srcSymbolName:M.srcSymbolName??null,dstProject:T,dstFilePath:I,dstSymbolName:M.dstSymbolName??null,metaJson:M.metaJson??null})}return J.replaceFileRelations(g,$,X),X.length}import{isErr as J0}from"@zipbul/result";var a_=/(?:^|\s)@([a-zA-Z][\w-]*\w|[a-zA-Z])\s*(.*)$/m;function Q0(u){let _=Su(u),g=[];for(let $ of _){g.push({name:$.name,startLine:$.span.start.line});for(let J of $.members??[])g.push({name:`${$.name}.${J.name}`,startLine:J.span.start.line})}return g.sort(($,J)=>$.startLine-J.startLine),g}function U_(u,_,g){let $=0,J=u.length-1;while($<=J){let O=$+J>>1;if(u[O].startLine<=_)$=O+1;else J=O-1}if($<u.length){let O=u[$];if(O.startLine-_<=g)return O.name}return null}function du(u,_,g){let $=wu(u,_),J=wu(u,g);return{start:$,end:J}}function t_(u){let{comments:_,sourceText:g}=u;if(!_.length)return[];let $=iu(g),J=Q0(u),O=[],z=[..._].sort((Q,V)=>Q.start-V.start),N=null;for(let Q of z)if(Q.type==="Block"&&Q.value.startsWith("*")){N=null;let V=`/*${Q.value}*/`,W=pu(V);if(J0(W))continue;let U=W;if(!U.tags?.length)continue;let X=wu($,Q.end),M=U_(J,X.line,3),I=g.slice(Q.start,Q.end);for(let D of U.tags){let T=[D.name,D.description].filter(Boolean).join(" "),j=`@${D.tag}`,h=I.indexOf(j),Z;if(h>=0){let K=Q.start+h,B=g.indexOf(`
4
4
  `,K),R=B>=0?Math.min(B,Q.end):Q.end;Z=du($,K,R)}else Z=du($,Q.start,Q.end);O.push({tag:D.tag,value:T,source:"jsdoc",span:Z,symbolName:M})}}else if(Q.type==="Block"){N=null;let V=Q.value.split(`
5
5
  `),W=0;for(let U of V){let X=U.replace(/^\s*\*?\s?/,""),M=a_.exec(X);if(M){let I=M[1],D=M[2]?.trim()??"",T=`@${I}`,j=U.indexOf(T),h=Q.start+2+W+(j>=0?j:0),Z=Q.start+2+W+U.length,K=du($,h,Z),B=wu($,Q.end),R=U_(J,B.line,3);O.push({tag:I,value:D,source:"block",span:K,symbolName:R})}W+=U.length+1}}else{let V=Q.value,W=a_.exec(V),U=wu($,Q.start),X=wu($,Q.end);if(W){let M=W[1],I=W[2]?.trim()??"",D=`@${M}`,T=V.indexOf(D),j=Q.start+2+(T>=0?T:0),h=du($,j,Q.end),Z=U_(J,X.line,3),K={tag:M,value:I,source:"line",span:h,symbolName:Z};O.push(K),N={annotation:K,endLine:X.line}}else if(N&&U.line===N.endLine+1){let M=V.trim();if(M)N.annotation.value+=" "+M,N.annotation.span.end=wu($,Q.end),N.endLine=X.line}else N=null}return O}function Y_(u){let{parsed:_,project:g,filePath:$,annotationRepo:J}=u,O=t_(_);if(J.deleteFileAnnotations(g,$),!O.length)return 0;let z=new Date().toISOString(),N=O.map((Q)=>({project:g,filePath:$,tag:Q.tag,value:Q.value,source:Q.source,symbolName:Q.symbolName,startLine:Q.span.start.line,startColumn:Q.span.start.column,endLine:Q.span.end.line,endColumn:Q.span.end.column,indexedAt:z}));return J.insertBatch(g,$,N),O.length}function o_(u,_){let g=[],$=[],J=[];for(let[W,U]of _)if(!u.has(W))g.push({name:U.name,filePath:U.filePath,kind:U.kind,fingerprint:U.fingerprint});for(let[W,U]of u)if(!_.has(W))$.push({name:U.name,filePath:U.filePath,kind:U.kind,fingerprint:U.fingerprint});if(!g.length||!$.length)return{renamed:J,added:g,removed:$};let O=new Map,z=new Map;for(let W of g){let U=O.get(W.filePath)??[];U.push(W),O.set(W.filePath,U)}for(let W of $){let U=z.get(W.filePath)??[];U.push(W),z.set(W.filePath,U)}let N=new Set,Q=new Set;for(let[W,U]of O){let X=z.get(W);if(!X)continue;for(let M of new Set(U.map((I)=>I.kind))){let I=U.filter((Z)=>Z.kind===M&&!N.has(Z)),D=X.filter((Z)=>Z.kind===M&&!Q.has(Z));if(!I.length||!D.length)continue;let T=(Z,K)=>{return K.get(`${Z.filePath}::${Z.name}`)?.structuralFingerprint??null},j=(Z,K)=>{return K.get(`${Z.filePath}::${Z.name}`)?.startLine??0},h=new Map;for(let Z of D){let K=T(Z,u);if(!K)continue;let B=h.get(K)??[];B.push(Z),h.set(K,B)}for(let Z of I){if(N.has(Z))continue;let K=T(Z,_);if(!K)continue;let B=h.get(K);if(!B)continue;let R=B.filter((S)=>!Q.has(S));if(!R.length)continue;let q=R[0];if(R.length>1){let S=j(Z,_),G=Math.abs(j(q,u)-S);for(let f=1;f<R.length;f++){let y=Math.abs(j(R[f],u)-S);if(y<G)G=y,q=R[f]}}J.push({oldName:q.name,newName:Z.name,filePath:W,kind:M}),N.add(Z),Q.add(q)}}}let V=J.filter((W)=>!W.oldName.includes("."));for(let W of V){let U=`${W.oldName}.`,X=`${W.newName}.`,M=$.filter((D)=>D.filePath===W.filePath&&D.name.startsWith(U)&&!Q.has(D)),I=g.filter((D)=>D.filePath===W.filePath&&D.name.startsWith(X)&&!N.has(D));for(let D of M){let T=D.name.slice(U.length),j=I.find((h)=>h.name.slice(X.length)===T);if(j)J.push({oldName:D.name,newName:j.name,filePath:W.filePath,kind:D.kind}),N.add(j),Q.add(D)}}return{renamed:J,added:g.filter((W)=>!N.has(W)),removed:$.filter((W)=>!Q.has(W))}}var N0=100,ug=50;class Z_{opts;logger;callbacks=new Set;indexingLock=!1;pendingEvents=[];debounceTimer=null;currentIndexing=null;pendingFullIndex=!1;pendingFullIndexWaiters=[];tsconfigPathsRaw;boundariesRefresh=null;lastPruneAt=0;constructor(u){this.opts=u,this.logger=u.logger??console,this.tsconfigPathsRaw=qu(u.projectRoot)}get tsconfigPaths(){return this.tsconfigPathsRaw}fullIndex(){return this.startIndex(void 0,!0)}incrementalIndex(u){return this.startIndex(u,!1)}onIndexed(u){return this.callbacks.add(u),()=>this.callbacks.delete(u)}handleWatcherEvent(u){if(u.filePath.endsWith("tsconfig.json")){hu(this.opts.projectRoot),this.tsconfigPathsRaw=qu(this.opts.projectRoot),this.fullIndex().catch((_)=>{this.logger.error("[IndexCoordinator] fullIndex failed after tsconfig change:",_)});return}if(u.filePath.endsWith("package.json")){let _=this.opts.discoverProjectsFn??mu;this.boundariesRefresh=_(this.opts.projectRoot).then((g)=>{this.opts.boundaries=g})}if(this.pendingEvents.push(u),this.debounceTimer===null)this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.flushPending()},N0)}async shutdown(){if(this.debounceTimer!==null)clearTimeout(this.debounceTimer),this.debounceTimer=null;if(this.currentIndexing)await this.currentIndexing}startIndex(u,_){if(this.indexingLock){if(_)return this.pendingFullIndex=!0,new Promise(($,J)=>{this.pendingFullIndexWaiters.push({resolve:$,reject:J})});return this.currentIndexing}this.indexingLock=!0;let g=this.doIndex(u,_).then(($)=>{return this.fireCallbacks($),$}).finally(()=>{if(this.indexingLock=!1,this.currentIndexing=null,this.pendingFullIndex){this.pendingFullIndex=!1;let $=this.pendingFullIndexWaiters.splice(0);this.startIndex(void 0,!0).then((J)=>{for(let O of $)O.resolve(J)}).catch((J)=>{for(let O of $)O.reject(J)})}else if(this.pendingEvents.length>0){let $=this.pendingEvents.splice(0);this.startIndex($,!1).catch((J)=>this.logger.error("[IndexCoordinator] incremental drain error",J))}});return this.currentIndexing=g,g}async doIndex(u,_){let g=Date.now(),{fileRepo:$,symbolRepo:J,relationRepo:O,dbConnection:z}=this.opts;if(this.boundariesRefresh)await this.boundariesRefresh,this.boundariesRefresh=null;let N,Q;if(u!==void 0)N=u.filter((Y)=>Y.eventType==="create"||Y.eventType==="change").map((Y)=>({filePath:Y.filePath,contentHash:"",mtimeMs:0,size:0})),Q=u.filter((Y)=>Y.eventType==="delete").map((Y)=>Y.filePath);else{let Y=new Map;for(let C of this.opts.boundaries)for(let[k,P]of $.getFilesMap(C.project))Y.set(k,P);let A=await i_({projectRoot:this.opts.projectRoot,extensions:this.opts.extensions,ignorePatterns:this.opts.ignorePatterns,fileRepo:{getFilesMap:()=>Y}});N=A.changed,Q=A.deleted}let V=await this.tsconfigPathsRaw??void 0,W=new Map;for(let Y of Q){let A=a(Y,this.opts.boundaries),C=J.getFileSymbols(A,Y);W.set(Y,C)}let U=crypto.randomUUID(),X=new Map,M=new Map,I=(Y)=>({name:Y.name,filePath:Y.filePath,kind:Y.kind,fingerprint:Y.fingerprint,structuralFingerprint:Y.structuralFingerprint??null,startLine:Y.startLine,isExported:Y.isExported??0});if(_)for(let Y of this.opts.boundaries)for(let A of $.getAllFiles(Y.project))for(let C of J.getFileSymbols(Y.project,A.filePath))X.set(`${C.filePath}::${C.name}`,I(C));else{for(let Y of N){let A=a(Y.filePath,this.opts.boundaries);for(let C of J.getFileSymbols(A,Y.filePath))X.set(`${C.filePath}::${C.name}`,I(C))}for(let[,Y]of W)for(let A of Y)X.set(`${A.filePath}::${A.name}`,I(A))}let D=(Y)=>`${Y.type}|${Y.srcFilePath}|${Y.dstFilePath}|${Y.srcSymbolName??""}|${Y.dstSymbolName??""}|${Ou(Y.metaJson??"")}`,T=new Map;if(_)for(let Y of this.opts.boundaries)for(let A of $.getAllFiles(Y.project))for(let C of O.getOutgoing(Y.project,A.filePath))T.set(D(C),C);else{for(let Y of N){let A=a(Y.filePath,this.opts.boundaries);for(let C of O.getOutgoing(A,Y.filePath))T.set(D(C),C)}for(let Y of Q){let A=a(Y,this.opts.boundaries);for(let C of O.getOutgoing(A,Y))T.set(D(C),C)}}let{annotationRepo:j,changelogRepo:h}=this.opts,Z=()=>{for(let Y of Q){let A=a(Y,this.opts.boundaries);if(J.deleteFileSymbols(A,Y),O.deleteFileRelations(A,Y),j)j.deleteFileAnnotations(A,Y);$.deleteFile(A,Y)}},K=0,B=async()=>{let{projectRoot:Y,boundaries:A}=this.opts,{parseCache:C}=this.opts,k=0,P=0,H=0,t=[],F=[];for(let v of N)try{let l=Cu(Y,v.filePath),Uu=Bun.file(l),Iu=await Uu.text(),j_=v.contentHash||Ou(Iu),F_=a(v.filePath,A);$.upsertFile({project:F_,filePath:v.filePath,mtimeMs:Uu.lastModified,size:Uu.size,contentHash:j_,updatedAt:new Date().toISOString(),lineCount:Iu.split(`
6
6
  `).length});let eu=(this.opts.parseSourceFn??ju)(l,Iu);if(e_(eu))throw eu.data;let H$=eu;F.push({filePath:v.filePath,text:Iu,contentHash:j_,parsed:H$,project:F_})}catch(l){this.logger.error(`[IndexCoordinator] Failed to prepare ${v.filePath}:`,l),t.push(v.filePath)}let m=new Set;for(let v of A)for(let[l]of $.getFilesMap(v.project))m.add(`${v.project}::${l}`);return z.transaction(()=>{for(let v of F){if(O_({parsed:v.parsed,project:v.project,filePath:v.filePath,contentHash:v.contentHash,symbolRepo:J}),P+=V_({ast:v.parsed.program,project:v.project,filePath:v.filePath,relationRepo:O,projectRoot:Y,tsconfigPaths:V,knownFiles:m,boundaries:A}),j)H+=Y_({parsed:v.parsed,project:v.project,filePath:v.filePath,annotationRepo:j});C.set(v.filePath,v.parsed),k+=J.getFileSymbols(v.project,v.filePath).length}}),{symbols:k,relations:P,annotations:H,failedFiles:t}},R=0,q=0,S=[];if(_){let{projectRoot:Y,boundaries:A}=this.opts,{parseCache:C}=this.opts,k=[];for(let H=0;H<N.length;H+=ug){let t=N.slice(H,H+ug),F=await Promise.allSettled(t.map(async(m)=>{let v=Cu(Y,m.filePath),l=Bun.file(v),Uu=await l.text(),Iu=m.contentHash||Ou(Uu);return{filePath:m.filePath,text:Uu,contentHash:Iu,mtimeMs:l.lastModified,size:l.size}}));for(let m=0;m<F.length;m++){let v=F[m];if(v.status==="fulfilled")k.push(v.value);else this.logger.error("[IndexCoordinator] Failed to pre-read file:",v.reason),S.push(t[m].filePath)}}let P=[];z.transaction(()=>{for(let F of k){let m=a(F.filePath,A);$.deleteFile(m,F.filePath)}for(let F of Q){let m=a(F,A);if(J.deleteFileSymbols(m,F),O.deleteFileRelations(m,F),j)j.deleteFileAnnotations(m,F);$.deleteFile(m,F)}for(let F of k){let m=a(F.filePath,A);$.upsertFile({project:m,filePath:F.filePath,mtimeMs:F.mtimeMs,size:F.size,contentHash:F.contentHash,updatedAt:new Date().toISOString(),lineCount:F.text.split(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipbul/gildash",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "TypeScript code indexing and dependency graph engine for Bun",
5
5
  "license": "MIT",
6
6
  "repository": {