@hey-api/codegen-core 0.3.3 → 0.4.0

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.
package/README.md CHANGED
@@ -15,17 +15,13 @@
15
15
  <a href="https://github.com/hey-api/openapi-ts/issues">Issues</a>
16
16
  <span>&nbsp;•&nbsp;</span>
17
17
  <a href="https://heyapi.dev/openapi-ts/community/contributing">Contribute</a>
18
- <span>&nbsp;•&nbsp;</span>
19
- <a href="https://heyapi.dev/openapi-ts/community/spotlight#core-team">Join Core Team</a>
20
18
  </p>
21
19
 
22
20
  <br/>
23
21
 
24
22
  ## Dashboard
25
23
 
26
- Hey API is an ecosystem of products helping you build better APIs. Superpower your codegen and APIs with Hey API Platform.
27
-
28
- [Sign In](https://app.heyapi.dev) to Hey API Platform.
24
+ Access your projects and OpenAPI specifications in the [Hey API Platform](https://app.heyapi.dev/).
29
25
 
30
26
  ## Contributing
31
27
 
@@ -52,7 +48,7 @@ Help Hey API stay around for the long haul by becoming a [sponsor](https://githu
52
48
  </picture>
53
49
  </a>
54
50
  <br/>
55
- Best-in-class SDKs and MCP for your API.
51
+ Best-in-class developer interfaces for your API.
56
52
  <br/>
57
53
  <a href="https://kutt.it/pkEZyc" style="text-decoration:none;" target="_blank">
58
54
  stainless.com
@@ -60,6 +56,23 @@ Help Hey API stay around for the long haul by becoming a [sponsor](https://githu
60
56
  </p>
61
57
  <p></p>
62
58
  </td>
59
+ <td align="center">
60
+ <p></p>
61
+ <p>
62
+ <a href="https://kutt.it/QM9Q2N" target="_blank">
63
+ <picture height="50px">
64
+ <img alt="Opencode logo" height="50px" src="https://heyapi.dev/opencode-logo-wordmark.svg">
65
+ </picture>
66
+ </a>
67
+ <br/>
68
+ The open source coding agent.
69
+ <br/>
70
+ <a href="https://kutt.it/QM9Q2N" style="text-decoration:none;" target="_blank">
71
+ opencode.ai
72
+ </a>
73
+ </p>
74
+ <p></p>
75
+ </td>
63
76
  </tr>
64
77
  </tbody>
65
78
  </table>
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:path`);c=s(c);const l=({file:e,modulePath:t,symbol:n,symbolFile:r})=>{let i=[],a=[],o={aliases:{},from:t};if(n.importKind&&(n.importKind===`default`?(o.defaultBinding=n.placeholder,n.kind===`type`&&(o.typeDefaultBinding=!0)):n.importKind===`namespace`&&(o.namespaceBinding=n.placeholder,n.kind===`type`&&(o.typeNamespaceBinding=!0))),n.importKind===`named`||!i.length&&!o.defaultBinding&&!o.namespaceBinding){let t=n.placeholder,s=e.resolvedNames.get(n.id);if(s){let e=r.resolvedNames.get(n.id);e?e!==s&&(t=e,o.aliases[t]=s):n.name&&s!==n.name&&(t=n.name,o.aliases[t]=n.placeholder)}i.push(t),n.kind===`type`&&a.push(t)}for(let e of a)i.includes(e)||i.push(e);return o.names=i,o.typeNames=a,o},u=(e,t)=>{e.aliases={...e.aliases,...t.aliases},t.defaultBinding!==void 0&&(e.defaultBinding=t.defaultBinding),e.names=[...new Set([...e.names??[],...t.names??[]])],t.namespaceBinding!==void 0&&(e.namespaceBinding=t.namespaceBinding),t.typeDefaultBinding!==void 0&&(e.typeDefaultBinding=t.typeDefaultBinding),e.typeNames=[...new Set([...e.typeNames??[],...t.typeNames??[]])],t.typeNamespaceBinding!==void 0&&(e.typeNamespaceBinding=t.typeNamespaceBinding)};var d=class{map=new Map;reverse=new Map;delete(e){let t=this.map.get(e);return t!==void 0&&this.reverse.delete(t),this.map.delete(e)}deleteValue(e){let t=this.reverse.get(e);return t!==void 0&&this.map.delete(t),this.reverse.delete(e)}entries(){return this.map.entries()}get(e){return this.map.get(e)}getKey(e){return this.reverse.get(e)}hasKey(e){return this.map.has(e)}hasValue(e){return this.reverse.has(e)}keys(){return this.map.keys()}set(e,t){let n=this.map.get(e);n!==void 0&&n!==t&&this.reverse.delete(n);let r=this.reverse.get(t);return r!==void 0&&r!==e&&this.map.delete(r),this.map.set(e,t),this.reverse.set(t,e),this}get size(){return this.map.size}values(){return this.map.values()}[Symbol.iterator](){return this.map[Symbol.iterator]()}},f=class{_id=0;referenceOrder=new Set;registerOrder=new Set;selectorToId=new Map;values=new Map;get(e){let t=this.identifierToFile(e);if(t.id!==void 0)return this.values.get(t.id);let n=t.selector===void 0?void 0:JSON.stringify(t.selector);if(n){let e=this.selectorToId.get(n);if(e!==void 0)return this.values.get(e)}}get id(){return this._id++}identifierToFile(e){return typeof e==`number`?{id:e}:{selector:e}}isRegistered(e){let t=this.get(e);return t?this.registerOrder.has(t.id):!1}reference(e){let t=this.identifierToFile(e);return this.register(t)}*referenced(){for(let e of this.referenceOrder.values())yield this.values.get(e)}register(e){if(e.id!==void 0){let t=this.values.get(e.id);if(!t)throw Error(`File with ID ${e.id} not found. To register a new file, leave the ID undefined.`);return t}let t=Object.keys(e).some(e=>![`id`,`selector`].includes(e)),n,r=e.selector===void 0?void 0:JSON.stringify(e.selector);if(r){let e=this.selectorToId.get(r);if(e!==void 0){if(n=this.values.get(e),!n)throw Error(`File with ID ${e} not found. The selector ${r} matched an ID, but there was no result. This is likely an issue with the application logic.`);if(!t)return n}}let i=n?.id===void 0?this.id:n.id;return n={...n,...e,id:i,resolvedNames:n?.resolvedNames??new d,symbols:n?.symbols??{body:[],exports:[],imports:[]}},this.values.set(i,n),t?(this.registerOrder.add(i),this.referenceOrder.has(i)&&this.referenceOrder.delete(i)):this.referenceOrder.add(i),r&&this.selectorToId.set(r,i),n}*registered(){for(let e of this.registerOrder.values())yield this.values.get(e)}};const p=e=>`_heyapi_${e}_`,m=e=>e.slice(8,-1),h=()=>new RegExp(p(`\\d+`),`g`),g=(e,t)=>e.replace(h(),e=>t(Number.parseInt(m(e),10))||e);var _=class{_id=0;indices=new Map;nodes=new Map;queryCache=new Map;queryCacheDependencies=new Map;registerOrder=new Set;stubCache=new Map;stubs=new Set;values=new Map;get(e){return typeof e==`number`?this.values.get(e):this.query(e)[0]}getValue(e){return this.nodes.get(e)}hasValue(e){return this.nodes.has(e)}get id(){return this._id++}isRegistered(e){let t=this.get(e);return t?this.registerOrder.has(t.id):!1}query(e){let t=this.buildCacheKey(e),n=this.queryCache.get(t);if(n)return n.map(e=>this.values.get(e));let r=[],i=this.buildIndexKeySpace(e),a=new Set,o=!1;for(let e of i){a.add(this.serializeIndexEntry(e));let t=this.indices.get(e[0]);if(!t){o=!0;break}let n=t.get(e[1]);if(!n){o=!0;break}r.push(n)}if(o||!r.length)return this.queryCacheDependencies.set(t,a),this.queryCache.set(t,[]),[];let s=new Set(r[0]);for(let e of r.slice(1))s=new Set([...s].filter(t=>e.has(t)));let c=[...s];return this.queryCacheDependencies.set(t,a),this.queryCache.set(t,c),c.map(e=>this.values.get(e))}reference(e){let[t]=this.query(e);if(t)return t;let n=this.buildCacheKey(e),r=this.stubCache.get(n);if(r!==void 0)return this.values.get(r);let i=this.id,a={id:i,meta:e,placeholder:p(String(i))};return this.values.set(a.id,a),this.stubs.add(a.id),this.stubCache.set(n,a.id),a}register(e){let t=e.id===void 0?this.id:e.id,n={...e,id:t,placeholder:e.placeholder??p(String(t))};if(this.values.set(n.id,n),this.registerOrder.add(n.id),n.meta){let e=this.buildIndexKeySpace(n.meta);this.indexSymbol(n.id,e),this.invalidateCache(e),this.replaceStubs(n,e)}return n}*registered(){for(let e of this.registerOrder.values())yield this.values.get(e)}setValue(e,t){return this.nodes.set(e,t)}buildCacheKey(e){return this.buildIndexKeySpace(e).map(e=>this.serializeIndexEntry(e)).sort().join(`|`)}buildIndexKeySpace(e,t=``){let n=[];for(let[r,i]of Object.entries(e)){let e=t?`${t}.${r}`:r;i&&typeof i==`object`&&!Array.isArray(i)?n.push(...this.buildIndexKeySpace(i,e)):n.push([e,i])}return n}indexSymbol(e,t){for(let[n,r]of t){this.indices.has(n)||this.indices.set(n,new Map);let t=this.indices.get(n),i=t.get(r)??new Set;i.add(e),t.set(r,i)}}invalidateCache(e){let t=e.map(e=>this.serializeIndexEntry(e));for(let[e,n]of this.queryCacheDependencies.entries())for(let r of t)if(n.has(r)){this.queryCacheDependencies.delete(e),this.queryCache.delete(e);break}}isSubset(e,t){let n=new Map(t);for(let[t,r]of e)if(!n.has(t)||n.get(t)!==r)return!1;return!0}replaceStubs(e,t){for(let n of this.stubs.values()){let r=this.values.get(n);if(r?.meta&&this.isSubset(this.buildIndexKeySpace(r.meta),t)){let t=this.buildCacheKey(r.meta);this.stubCache.delete(t),this.values.set(n,Object.assign(r,e)),this.stubs.delete(n)}}}serializeIndexEntry(e){return`${e[0]}:${JSON.stringify(e[1])}`}};const v=`@`;var y=class{symbolIdToFileIds=new Map;defaultFileName;files=new f;fileName;renderers={};root;symbols=new _;constructor({defaultFileName:e,fileName:t,renderers:n,root:r}){this.defaultFileName=e??`main`,this.fileName=typeof t==`string`?()=>t:t,this.renderers=n,this.root=r}getRenderer(e){return e.extension?this.renderers[e.extension]:void 0}prepareFiles(){for(let e of this.symbols.registered()){let t=this.symbolToFileSelector(e),n=this.files.reference(t);n.symbols.body.push(e.id);let r=this.symbolIdToFileIds.get(e.id)??new Set;if(r.add(n.id),this.symbolIdToFileIds.set(e.id,r),e.exportFrom)for(let t of e.exportFrom){let r=[t],i=this.files.reference(r);i.id!==n.id&&i.symbols.exports.push(e.id)}}for(let e of this.files.referenced()){if(!e.selector)continue;if(e.selector[0]===`@`){let t=e.selector[1];if(!t){this.files.register({external:!0,selector:e.selector});continue}let n=c.default.extname(t);if(!n){this.files.register({external:!0,path:t,selector:e.selector});continue}this.files.register({extension:n,external:!0,path:t,selector:e.selector});continue}let t=e.selector.slice(0,-1),n=e.selector[e.selector.length-1];n=this.fileName?.(n)||n,this.files.register({extension:`.ts`,name:n,path:c.default.resolve(this.root,...t,`${n}.ts`),selector:e.selector})}}render(e){this.prepareFiles();let t=new Map;for(let n of this.files.registered()){if(n.external||!n.path)continue;let r=this.getRenderer(n);r&&t.set(n.id,{content:r.renderSymbols(n,this,e),path:n.path})}for(let[n,r]of t.entries()){let i=this.files.get(n),a=this.getRenderer(i).renderFile(r.content,i,this,e);a?t.set(i.id,{...r,content:a}):t.delete(i.id)}return Array.from(t.values())}symbolIdToFiles(e){let t=this.symbolIdToFileIds.get(e);return Array.from(t??[]).map(e=>this.files.get(e))}symbolToFileSelector(e){if(e.external)return[`@`,e.external];let t=e.getFilePath?.(e);return t?t.split(`/`):[this.defaultFileName]}};exports.Project=y,exports.createBinding=l,exports.mergeBindings=u,exports.renderIds=g;
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`ansi-colors`);c=s(c);let l=require(`color-support`);l=s(l);let u=require(`node:path`);u=s(u);const d=`heyapi.file`,f=`heyapi.node`,p=`heyapi.symbol`;c.default.enabled=(0,l.default)().hasBasic;const m={analyzer:c.default.greenBright,dsl:c.default.cyanBright,file:c.default.yellowBright,registry:c.default.blueBright,symbol:c.default.magentaBright};function h(e,t){let n=process.env.DEBUG;if(!n)return;let r=n.split(`,`).map(e=>e.trim().toLowerCase());if(!(r.includes(`*`)||r.includes(`heyapi:*`)||r.includes(`heyapi:${t}`)||r.includes(t)))return;let i=(m[t]??c.default.whiteBright)(`heyapi:${t}`);console.debug(`${i} ${e}`)}var g=class{_exports=[];_extension;_finalPath;_imports=[];_language;_logicalFilePath;_name;_nodes=[];_renderer;"~brand"=`heyapi.file`;allNames=new Map;external;id;project;topLevelNames=new Map;constructor(e,t,n){this.external=e.external??!1,this.id=t,e.language!==void 0&&(this._language=e.language),this._logicalFilePath=e.logicalFilePath.split(u.default.sep).join(`/`),e.name!==void 0&&(this._name=e.name),this.project=n}get exports(){return[...this._exports]}get extension(){if(this._extension)return this._extension;let e=this.language,t=e?this.project.extensions[e]:void 0;if(t&&t[0])return t[0]}get finalPath(){return this._finalPath?this._finalPath:[...this._logicalFilePath?this._logicalFilePath.split(`/`).slice(0,-1):[],`${this.name}${this.extension??``}`].join(`/`)}get imports(){return[...this._imports]}get language(){if(this._language)return this._language;if(this._nodes[0])return this._nodes[0].language}get logicalFilePath(){return this._logicalFilePath}get name(){if(this._name)return this._name;let e=this._logicalFilePath.split(`/`).pop();if(e)return e;let t=`File ${this.toString()} has no name`;throw h(t,`file`),Error(t)}get nodes(){return[...this._nodes]}get renderer(){return this._renderer}addExport(e){this._exports.push(e)}addImport(e){this._imports.push(e)}addNode(e){this._nodes.push(e),e.file=this}setExtension(e){this._extension=e}setFinalPath(e){this._finalPath=e}setLanguage(e){this._language=e}setName(e){this._name=e}setRenderer(e){this._renderer=e}toString(){return`[File ${this._logicalFilePath}#${this.id}]`}};function _(e,t){return!e||typeof e!=`object`?!1:e[`~brand`]===t}function v(e){return!e||typeof e!=`object`?!1:_(e,f)}function y(e){return _(e[`~ref`],f)}function b(e){return _(e,p)}function x(e){return _(e[`~ref`],p)}const S={c:[`.c`],"c#":[`.cs`],"c++":[`.cpp`,`.hpp`],css:[`.css`],dart:[`.dart`],go:[`.go`],haskell:[`.hs`],html:[`.html`],java:[`.java`],javascript:[`.js`,`.jsx`],json:[`.json`],kotlin:[`.kt`],lua:[`.lua`],markdown:[`.md`],matlab:[`.m`],perl:[`.pl`],php:[`.php`],python:[`.py`],r:[`.r`],ruby:[`.rb`],rust:[`.rs`],scala:[`.scala`],shell:[`.sh`],sql:[`.sql`],swift:[`.swift`],typescript:[`.ts`,`.tsx`],yaml:[`.yaml`,`.yml`]},C=({attempt:e,baseName:t})=>e===0?t:`${t}${e+1}`,w=({attempt:e,baseName:t})=>e===0?t:`${t}_${e+1}`,T={php:w,python:w,ruby:w};var E=class{_id=0;_values=new Map;project;constructor(e){this.project=e}get(e){return this._values.get(this.createFileKey(e))}isRegistered(e){return this._values.has(this.createFileKey(e))}get nextId(){return this._id++}register(e){let t=this.createFileKey(e),n=this._values.get(t);return n?e.name&&n.setName(e.name):n=new g(e,this.nextId,this.project),this._values.set(t,n),n}*registered(){for(let e of this._values.values())yield e}createFileKey(e){let t=e.logicalFilePath.split(u.default.sep).join(`/`);return`${e.external?`ext:`:``}${t}${e.language?`:${e.language}`:``}`}};const D=e=>({"~ref":e}),O=e=>{let t={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=D(e[n]));return t},k=e=>e?.[`~ref`],A=e=>{let t={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=k(e[n]));return t},j=e=>typeof e==`object`&&!!e&&`~ref`in e;var M=class{list=[];add(e){return this.list.push(D(e))-1}*all(){for(let e of this.list){let t=k(e);t&&(yield t)}}remove(e){this.list[e]=D(null)}update(e,t){this.list[e]=D(t)}};function N(e,t){if(e===`interface`&&t===`interface`)return!0;if(e===`interface`&&t===`type`||e===`type`&&t===`interface`||e===`type`&&t===`type`)return!1;if(e===`interface`&&t===`class`||e===`class`&&t===`interface`||e===`enum`&&t===`namespace`||e===`namespace`&&t===`enum`||e===`class`&&t===`namespace`||e===`namespace`&&t===`class`||e===`namespace`&&t===`namespace`)return!0;if(e===`enum`&&t===`enum`)return!1;if(e===`function`&&t===`namespace`||e===`namespace`&&t===`function`)return!0;let n=new Set([`class`,`enum`,`function`,`var`]),r=n.has(e),i=n.has(t);if(r&&i)return!1;let a=new Set([`interface`,`type`]);return a.has(e),a.has(t),!0}const P=e=>({children:[],localNames:new Map,parent:e,symbols:[]});var F=class{scopes=P();symbol;scope=this.scopes;constructor(e){this.symbol=e}addDependency(e){this.symbol!==k(e)&&this.scope.symbols.push(e)}analyze(e){let t=j(e)?e:D(e);x(t)?this.addDependency(t):y(t)&&k(t).analyze(this)}localNames(e){let t=new Map;for(let[n,r]of e.localNames)t.set(n,new Set(r));if(e.parent){let n=this.localNames(e.parent);for(let[e,r]of n)if(!t.has(e))t.set(e,r);else{let n=t.get(e);for(let e of r)n.add(e)}}return t}popScope(){this.scope=this.scope.parent??this.scope}pushScope(){let e=P(this.scope);this.scope.children.push(e),this.scope=e}walkScopes(e,t=this.scopes){this.scope=t;for(let n of t.symbols)e(n,t);for(let n of t.children)t=n,this.walkScopes(e,t);this.scope=this.scopes}},I=class{nodeCache=new WeakMap;analyzeNode(e){let t=this.nodeCache.get(e);if(t)return t;let n=new F(e.symbol);return e.analyze(n),this.nodeCache.set(e,n),n}analyze(e,t){for(let n of e){let e=this.analyzeNode(n);t?.(e,n)}}};const L=e=>e===`type`||e===`interface`;var R=class{analyzer=new I;cacheResolvedNames=new Set;project;constructor(e){this.project=e}plan(e){this.cacheResolvedNames.clear(),this.allocateFiles(),this.assignLocalNames(),this.resolveFilePaths(e),this.planExports(),this.planImports()}allocateFiles(){this.analyzer.analyze(this.project.nodes.all(),(e,t)=>{let n=t.symbol;if(!n)return;let r=this.project.files.register(this.symbolToFileIn(n));r.addNode(t),n.setFile(r);for(let e of n.exportFrom)this.project.files.register({external:!1,language:r.language,logicalFilePath:e});e.walkScopes(e=>{let t=k(e);if(t.external&&t.isCanonical&&!t.file){let e=this.project.files.register(this.symbolToFileIn(t));t.setFile(e)}})})}assignLocalNames(){this.analyzer.analyze(this.project.nodes.all(),(e,t)=>{let n=t.symbol;n&&this.assignTopLevelName(n,e)}),this.analyzer.analyze(this.project.nodes.all(),(e,t)=>{let n=t.file;n&&e.walkScopes(t=>{let r=k(t);r.file||this.assignLocalName(r,e,{scopesToUpdate:[n.allNames]})})})}resolveFilePaths(e){for(let t of this.project.files.registered()){if(t.external)continue;let n=this.project.fileName?.(t.name)||t.name;t.setName(n);let r=t.finalPath;r&&t.setFinalPath(u.default.resolve(this.project.root,r));let i={file:t,meta:e,project:this.project},a=this.project.renderers.find(e=>e.supports(i));a&&t.setRenderer(a)}}planExports(){let e=new Map,t=new Map;this.analyzer.analyze(this.project.nodes.all(),(n,r)=>{if(!r.exported)return;let i=r.symbol;if(!i)return;let a=r.file;if(a)for(let o of i.exportFrom){let s=this.project.files.register({external:!1,language:r.language,logicalFilePath:o});if(s.id===a.id)continue;let c=e.get(s);c||(c=new Map,e.set(s,c));let l=this.project.symbols.register({exported:!0,external:i.external,importKind:i.importKind,kind:i.kind,name:i.finalName});l.setFile(s),t.set(l.id,a),this.assignTopLevelName(l,n);let u=c.get(l.finalName);u||(u={kinds:new Set,symbol:l},c.set(l.finalName,u)),u.kinds.add(l.kind)}});for(let[n,r]of e){let e=new Map;for(let[,n]of r){let r=t.get(n.symbol.id),i=e.get(r);i||={canExportAll:!0,exports:[],from:r,isTypeOnly:!0};let a=[...n.kinds].every(e=>L(e)),o=n.symbol.finalName;i.exports.push({exportedName:o,isTypeOnly:a,kind:n.symbol.importKind,sourceName:n.symbol.name}),n.symbol.name!==n.symbol.finalName&&(i.canExportAll=!1),a||(i.isTypeOnly=!1),e.set(r,i)}for(let[,t]of e)n.addExport(t)}}planImports(){let e=new Map;this.analyzer.analyze(this.project.nodes.all(),t=>{let n=t.symbol;if(!n)return;let r=n.file;if(!r)return;let i=e.get(r);i||(i=new Map,e.set(r,i)),t.walkScopes(e=>{let n=k(e);if(!n.file||n.file.id===r.id)return;n.external&&this.assignTopLevelName(n,t);let a=n.file.id,o=n.finalName,s=L(n.kind),c=`${a}|${o}|${n.importKind}|${s}`,l=i.get(c);if(!l){let e=this.project.symbols.register({exported:n.exported,external:n.external,importKind:n.importKind,kind:n.kind,name:n.finalName});e.setFile(r),this.assignTopLevelName(e,t,{scope:e.file.allNames}),l={dep:n,kinds:new Set,symbol:e},i.set(c,l),l.kinds.add(e.kind)}e[`~ref`]=l.symbol})});for(let[t,n]of e){let e=new Map;for(let[,t]of n){let n=t.dep.file,r=e.get(n);r||={from:n,imports:[],isTypeOnly:!0};let i=[...t.kinds].every(e=>L(e));t.symbol.importKind===`namespace`?(r.imports=[],r.namespaceImport=t.symbol.finalName):r.imports.push({isTypeOnly:i,kind:t.symbol.importKind,localName:t.symbol.finalName,sourceName:t.dep.finalName}),i||(r.isTypeOnly=!1),e.set(n,r)}for(let[,n]of e)t.addImport(n)}}assignTopLevelName(e,t,n){e.file&&this.assignSymbolName(e,{scope:n?.scope??e.file.topLevelNames,scopesToUpdate:[e.file.allNames,t.scopes.localNames,...n?.scopesToUpdate??[]]})}assignLocalName(e,t,n){this.assignSymbolName(e,{scope:n.scope??t.localNames(t.scope),scopesToUpdate:n.scopesToUpdate})}assignSymbolName(e,t){if(this.cacheResolvedNames.has(e.id))return;let n=e.name,r=e.nameSanitizer?.(n)??n,i=1;for(;![...t.scope.get(r)??[]].every(t=>N(e.kind,t));){let t=e.node?.language||e.file?.language,a=((t?this.project.nameConflictResolvers[t]:void 0)??this.project.defaultNameConflictResolver)({attempt:i,baseName:n});if(!a)throw Error(`Unresolvable name conflict: ${e.toString()}`);r=e.nameSanitizer?.(a)??a,i+=1}e.setFinalName(r),this.cacheResolvedNames.add(e.id);let a=[t.scope,...t.scopesToUpdate];for(let t of a)this.updateScope(e,t)}updateScope(e,t){let n=e.finalName,r=t.get(n)??new Set;r.add(e.kind),t.set(n,r)}symbolToFileIn(e){return{external:!!e.external,language:e.node?.language,logicalFilePath:e.external||e.getFilePath?.(e)||this.project.defaultFileName}}},z=class{_canonical;_exported;_exportFrom;_external;_file;_finalName;_getFilePath;_importKind;_kind;_meta;_name;_nameSanitizer;_node;"~brand"=p;id;constructor(e,t){this._exported=e.exported??!1,this._exportFrom=e.exportFrom??[],this._external=e.external,this._getFilePath=e.getFilePath,this.id=t,this._importKind=e.importKind??`named`,this._kind=e.kind??`var`,this._meta=e.meta,this._name=e.name}get canonical(){return this._canonical??this}get exported(){return this.canonical._exported}get exportFrom(){return this.canonical._exportFrom}get external(){return this.canonical._external}get file(){return this.canonical._file}get finalName(){if(!this.canonical._finalName){let e=`Symbol finalName has not been resolved yet for ${this.canonical.toString()}`;throw h(e,`symbol`),Error(e)}return this.canonical._finalName}get getFilePath(){return this.canonical._getFilePath}get importKind(){return this.canonical._importKind}get isCanonical(){return!this._canonical||this._canonical===this}get kind(){return this.canonical._kind}get meta(){return this.canonical._meta}get name(){return this.canonical._name}get nameSanitizer(){return this.canonical._nameSanitizer}get node(){return this.canonical._node}setCanonical(e){this._canonical=e}setExported(e){this.assertCanonical(),this._exported=e}setExportFrom(e){this.assertCanonical(),this._exportFrom=e}setFile(e){if(this.assertCanonical(),this._file&&this._file!==e){let e=`Symbol ${this.canonical.toString()} is already assigned to a different file.`;throw h(e,`symbol`),Error(e)}this._file=e}setFinalName(e){if(this.assertCanonical(),this._finalName&&this._finalName!==e){let e=`Symbol finalName has already been resolved for ${this.canonical.toString()}.`;throw h(e,`symbol`),Error(e)}this._finalName=e}setImportKind(e){this.assertCanonical(),this._importKind=e}setKind(e){this.assertCanonical(),this._kind=e}setName(e){this.assertCanonical(),this._name=e}setNameSanitizer(e){this.assertCanonical(),this._nameSanitizer=e}setNode(e){if(this.assertCanonical(),this._node&&this._node!==e){let e=`Symbol ${this.canonical.toString()} is already bound to a different node.`;throw h(e,`symbol`),Error(e)}this._node=e,e.symbol=this}toString(){return`[Symbol ${this.name}#${this.id}]`}assertCanonical(){if(this._canonical&&this._canonical!==this){let e=`Illegal mutation of stub symbol ${this.toString()} → canonical: ${this._canonical.toString()}`;throw h(e,`symbol`),Error(e)}}},B=class{_id=0;_indices=new Map;_queryCache=new Map;_queryCacheDependencies=new Map;_registered=new Set;_stubs=new Set;_stubCache=new Map;_values=new Map;get(e){return typeof e==`number`?this._values.get(e):this.query(e)[0]}isRegistered(e){let t=this.get(e);return t?this._registered.has(t.id):!1}get nextId(){return this._id++}query(e){let t=this.buildCacheKey(e),n=this._queryCache.get(t);if(n)return n.map(e=>this._values.get(e));let r=[],i=this.buildIndexKeySpace(e),a=new Set,o=!1;for(let e of i){a.add(this.serializeIndexEntry(e));let t=this._indices.get(e[0]);if(!t){o=!0;break}let n=t.get(e[1]);if(!n){o=!0;break}r.push(n)}if(o||!r.length)return this._queryCacheDependencies.set(t,a),this._queryCache.set(t,[]),[];let s=new Set(r[0]);for(let e of r.slice(1))s=new Set([...s].filter(t=>e.has(t)));let c=[...s];return this._queryCacheDependencies.set(t,a),this._queryCache.set(t,c),c.map(e=>this._values.get(e))}reference(e){let[t]=this.query(e);if(t)return t;let n=this.buildCacheKey(e),r=this._stubCache.get(n);if(r!==void 0)return this._values.get(r);let i=new z({meta:e,name:``},this.nextId);return this._values.set(i.id,i),this._stubs.add(i.id),this._stubCache.set(n,i.id),i}register(e){let t=new z(e,this.nextId);if(this._values.set(t.id,t),this._registered.add(t.id),t.meta){let e=this.buildIndexKeySpace(t.meta);this.indexSymbol(t.id,e),this.invalidateCache(e),this.replaceStubs(t,e)}return t}*registered(){for(let e of this._registered.values())yield this._values.get(e)}buildCacheKey(e){return this.buildIndexKeySpace(e).map(e=>this.serializeIndexEntry(e)).sort().join(`|`)}buildIndexKeySpace(e,t=``){let n=[];for(let[r,i]of Object.entries(e)){let e=t?`${t}.${r}`:r;i&&typeof i==`object`&&!Array.isArray(i)?n.push(...this.buildIndexKeySpace(i,e)):n.push([e,i])}return n}indexSymbol(e,t){for(let[n,r]of t){this._indices.has(n)||this._indices.set(n,new Map);let t=this._indices.get(n),i=t.get(r)??new Set;i.add(e),t.set(r,i)}}invalidateCache(e){let t=e.map(e=>this.serializeIndexEntry(e));for(let[e,n]of this._queryCacheDependencies.entries())for(let r of t)if(n.has(r)){this._queryCacheDependencies.delete(e),this._queryCache.delete(e);break}}isSubset(e,t){let n=new Map(t);for(let[t,r]of e)if(!n.has(t)||n.get(t)!==r)return!1;return!0}replaceStubs(e,t){for(let n of this._stubs.values()){let r=this._values.get(n);if(r?.meta&&this.isSubset(this.buildIndexKeySpace(r.meta),t)){let t=this.buildCacheKey(r.meta);this._stubCache.delete(t),this._stubs.delete(n),r.setCanonical(e)}}}serializeIndexEntry(e){return`${e[0]}:${JSON.stringify(e[1])}`}},V=class{files;nodes=new M;symbols=new B;defaultFileName;defaultNameConflictResolver;extensions;fileName;nameConflictResolvers;renderers;root;constructor(e){let t=e.fileName;this.defaultFileName=e.defaultFileName??`main`,this.defaultNameConflictResolver=e.defaultNameConflictResolver??C,this.extensions={...S,...e.extensions},this.fileName=typeof t==`string`?()=>t:t,this.files=new E(this),this.nameConflictResolvers={...T,...e.nameConflictResolvers},this.renderers=e.renderers??[],this.root=u.default.resolve(e.root).replace(/[/\\]+$/,``)}render(e){new R(this).plan(e);let t=[];for(let n of this.files.registered())if(n.finalPath&&n.renderer){let r=n.renderer.render({file:n,meta:e,project:this});t.push({content:r,path:n.finalPath})}return t}};exports.File=g,exports.Project=V,exports.Symbol=z,exports.debug=h,exports.defaultExtensions=S,exports.defaultNameConflictResolvers=T,exports.fromRef=k,exports.fromRefs=A,exports.isNode=v,exports.isNodeRef=y,exports.isRef=j,exports.isSymbol=b,exports.isSymbolRef=x,exports.nodeBrand=f,exports.ref=D,exports.refs=O,exports.simpleNameConflictResolver=C,exports.symbolBrand=p,exports.underscoreNameConflictResolver=w;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["names: Array<string>","typeNames: Array<string>","binding: IBinding & Pick<Required<IBinding>, 'aliases' | 'from'>","result","result: IFileOut | undefined","id","sets: Array<Set<SymbolId>>","stub: ISymbolOut","result: ISymbolOut","entries: Array<IndexEntry>","path","extension","path","files: Map<number, IOutput>"],"sources":["../src/bindings/utils.ts","../src/bimap/bimap.ts","../src/files/registry.ts","../src/renderer/utils.ts","../src/symbols/registry.ts","../src/project/project.ts"],"sourcesContent":["import type { IFileOut } from '../files/types';\nimport type { ISymbolOut } from '../symbols/types';\nimport type { IBinding } from './types';\n\nexport const createBinding = ({\n file,\n modulePath,\n symbol,\n symbolFile,\n}: {\n file: IFileOut;\n modulePath: string;\n symbol: ISymbolOut;\n symbolFile: IFileOut;\n}): IBinding => {\n const names: Array<string> = [];\n const typeNames: Array<string> = [];\n const binding: IBinding & Pick<Required<IBinding>, 'aliases' | 'from'> = {\n aliases: {},\n from: modulePath,\n };\n if (symbol.importKind) {\n if (symbol.importKind === 'default') {\n binding.defaultBinding = symbol.placeholder;\n if (symbol.kind === 'type') {\n binding.typeDefaultBinding = true;\n }\n } else if (symbol.importKind === 'namespace') {\n binding.namespaceBinding = symbol.placeholder;\n if (symbol.kind === 'type') {\n binding.typeNamespaceBinding = true;\n }\n }\n }\n // default to named binding\n if (\n symbol.importKind === 'named' ||\n (!names.length && !binding.defaultBinding && !binding.namespaceBinding)\n ) {\n let name = symbol.placeholder;\n const fileResolvedName = file.resolvedNames.get(symbol.id);\n if (fileResolvedName) {\n const symbolFileResolvedName = symbolFile.resolvedNames.get(symbol.id);\n if (symbolFileResolvedName) {\n if (symbolFileResolvedName !== fileResolvedName) {\n name = symbolFileResolvedName;\n binding.aliases[name] = fileResolvedName;\n }\n } else if (symbol.name && fileResolvedName !== symbol.name) {\n name = symbol.name;\n binding.aliases[name] = symbol.placeholder;\n }\n }\n names.push(name);\n if (symbol.kind === 'type') {\n typeNames.push(name);\n }\n }\n // cast type names to names to allow for cleaner API,\n // otherwise users would have to define the same values twice\n for (const typeName of typeNames) {\n if (!names.includes(typeName)) {\n names.push(typeName);\n }\n }\n binding.names = names;\n binding.typeNames = typeNames;\n return binding;\n};\n\nexport const mergeBindings = (target: IBinding, source: IBinding): void => {\n target.aliases = { ...target.aliases, ...source.aliases };\n if (source.defaultBinding !== undefined) {\n target.defaultBinding = source.defaultBinding;\n }\n target.names = [\n ...new Set([...(target.names ?? []), ...(source.names ?? [])]),\n ];\n if (source.namespaceBinding !== undefined) {\n target.namespaceBinding = source.namespaceBinding;\n }\n if (source.typeDefaultBinding !== undefined) {\n target.typeDefaultBinding = source.typeDefaultBinding;\n }\n target.typeNames = [\n ...new Set([...(target.typeNames ?? []), ...(source.typeNames ?? [])]),\n ];\n if (source.typeNamespaceBinding !== undefined) {\n target.typeNamespaceBinding = source.typeNamespaceBinding;\n }\n};\n","import type { IBiMap } from './types';\n\nexport class BiMap<Key, Value> implements IBiMap<Key, Value> {\n private map = new Map<Key, Value>();\n private reverse = new Map<Value, Key>();\n\n delete(key: Key): boolean {\n const value = this.map.get(key);\n if (value !== undefined) {\n this.reverse.delete(value);\n }\n return this.map.delete(key);\n }\n\n deleteValue(value: Value): boolean {\n const key = this.reverse.get(value);\n if (key !== undefined) {\n this.map.delete(key);\n }\n return this.reverse.delete(value);\n }\n\n entries(): IterableIterator<[Key, Value]> {\n return this.map.entries();\n }\n\n get(key: Key): Value | undefined {\n return this.map.get(key);\n }\n\n getKey(value: Value): Key | undefined {\n return this.reverse.get(value);\n }\n\n hasKey(key: Key): boolean {\n return this.map.has(key);\n }\n\n hasValue(value: Value): boolean {\n return this.reverse.has(value);\n }\n\n keys(): IterableIterator<Key> {\n return this.map.keys();\n }\n\n set(key: Key, value: Value): this {\n const oldValue = this.map.get(key);\n if (oldValue !== undefined && oldValue !== value) {\n this.reverse.delete(oldValue);\n }\n const oldKey = this.reverse.get(value);\n if (oldKey !== undefined && oldKey !== key) {\n this.map.delete(oldKey);\n }\n this.map.set(key, value);\n this.reverse.set(value, key);\n return this;\n }\n\n get size(): number {\n return this.map.size;\n }\n\n values(): IterableIterator<Value> {\n return this.map.values();\n }\n\n [Symbol.iterator](): IterableIterator<[Key, Value]> {\n return this.map[Symbol.iterator]();\n }\n}\n","import { BiMap } from '../bimap/bimap';\nimport type {\n IFileIdentifier,\n IFileIn,\n IFileOut,\n IFileRegistry,\n} from './types';\n\nexport class FileRegistry implements IFileRegistry {\n private _id: number = 0;\n private referenceOrder: Set<number> = new Set();\n private registerOrder: Set<number> = new Set();\n private selectorToId: Map<string, number> = new Map();\n private values: Map<number, IFileOut> = new Map();\n\n get(identifier: IFileIdentifier): IFileOut | undefined {\n const file = this.identifierToFile(identifier);\n\n if (file.id !== undefined) {\n return this.values.get(file.id);\n }\n\n const selector =\n file.selector !== undefined ? JSON.stringify(file.selector) : undefined;\n\n if (selector) {\n const id = this.selectorToId.get(selector);\n if (id !== undefined) {\n return this.values.get(id);\n }\n }\n\n return;\n }\n\n get id(): number {\n return this._id++;\n }\n\n private identifierToFile(\n identifier: IFileIdentifier,\n ): Pick<IFileIn, 'id' | 'selector'> {\n return typeof identifier === 'number'\n ? { id: identifier }\n : { selector: identifier };\n }\n\n isRegistered(identifier: IFileIdentifier): boolean {\n const file = this.get(identifier);\n return file ? this.registerOrder.has(file.id) : false;\n }\n\n reference(identifier: IFileIdentifier): IFileOut {\n const file = this.identifierToFile(identifier);\n return this.register(file);\n }\n\n *referenced(): IterableIterator<IFileOut> {\n for (const id of this.referenceOrder.values()) {\n yield this.values.get(id)!;\n }\n }\n\n register(file: IFileIn): IFileOut {\n if (file.id !== undefined) {\n const result = this.values.get(file.id);\n if (!result) {\n throw new Error(\n `File with ID ${file.id} not found. To register a new file, leave the ID undefined.`,\n );\n }\n return result;\n }\n\n const hasOtherKeys = Object.keys(file).some(\n (key) => !['id', 'selector'].includes(key),\n );\n\n let result: IFileOut | undefined;\n\n const selector =\n file.selector !== undefined ? JSON.stringify(file.selector) : undefined;\n if (selector) {\n const id = this.selectorToId.get(selector);\n if (id !== undefined) {\n result = this.values.get(id);\n if (!result) {\n throw new Error(\n `File with ID ${id} not found. The selector ${selector} matched an ID, but there was no result. This is likely an issue with the application logic.`,\n );\n }\n if (!hasOtherKeys) {\n return result;\n }\n }\n }\n\n const id = result?.id !== undefined ? result.id : this.id;\n result = {\n ...result,\n ...file, // clone to avoid mutation\n id,\n resolvedNames: result?.resolvedNames ?? new BiMap(),\n symbols: result?.symbols ?? {\n body: [],\n exports: [],\n imports: [],\n },\n };\n this.values.set(id, result);\n\n if (hasOtherKeys) {\n this.registerOrder.add(id);\n if (this.referenceOrder.has(id)) {\n this.referenceOrder.delete(id);\n }\n } else {\n this.referenceOrder.add(id);\n }\n\n if (selector) {\n this.selectorToId.set(selector, id);\n }\n\n return result;\n }\n\n *registered(): IterableIterator<IFileOut> {\n for (const id of this.registerOrder.values()) {\n yield this.values.get(id)!;\n }\n }\n}\n","/**\n * Wraps an ID in namespace to avoid collisions when replacing it.\n *\n * @param symbolId Stringified symbol ID to use.\n * @returns The wrapped placeholder ID.\n */\nexport const wrapId = (symbolId: string): string => `_heyapi_${symbolId}_`;\n\n/**\n * Unwraps an ID from namespace.\n *\n * @param wrappedId The wrapped placeholder ID.\n * @returns Stringified ID to use.\n */\nconst unwrapId = (wrappedId: string): string =>\n wrappedId.slice('_heyapi_'.length, -1);\n\n/**\n * Returns a RegExp instance to match ID placeholders.\n *\n * @returns RegExp instance to match ID placeholders.\n */\nconst createPlaceholderRegExp = (): RegExp => new RegExp(wrapId('\\\\d+'), 'g');\n\n/**\n *\n * @param source The source string to replace.\n * @param replacerFn Accepts a symbol ID, returns resolved symbol name.\n * @returns The replaced source string.\n */\nexport const renderIds = (\n source: string,\n replacerFn: (symbolId: number) => string | undefined,\n): string =>\n source.replace(createPlaceholderRegExp(), (match) => {\n const symbolId = Number.parseInt(unwrapId(match), 10);\n return replacerFn(symbolId) || match;\n });\n","import type { ISymbolMeta } from '../extensions/types';\nimport { wrapId } from '../renderer/utils';\nimport type {\n ISymbolIdentifier,\n ISymbolIn,\n ISymbolOut,\n ISymbolRegistry,\n} from './types';\n\ntype IndexEntry = [string, unknown];\ntype IndexKeySpace = ReadonlyArray<IndexEntry>;\ntype QueryCacheKey = string;\ntype SymbolId = number;\n\nexport class SymbolRegistry implements ISymbolRegistry {\n private _id: SymbolId = 0;\n private indices: Map<IndexEntry[0], Map<IndexEntry[1], Set<SymbolId>>> =\n new Map();\n private nodes: Map<SymbolId, unknown> = new Map();\n private queryCache: Map<QueryCacheKey, ReadonlyArray<SymbolId>> = new Map();\n private queryCacheDependencies: Map<QueryCacheKey, Set<QueryCacheKey>> =\n new Map();\n private registerOrder: Set<SymbolId> = new Set();\n private stubCache: Map<QueryCacheKey, SymbolId> = new Map();\n private stubs: Set<SymbolId> = new Set();\n private values: Map<SymbolId, ISymbolOut> = new Map();\n\n get(identifier: ISymbolIdentifier): ISymbolOut | undefined {\n return typeof identifier === 'number'\n ? this.values.get(identifier)\n : this.query(identifier)[0];\n }\n\n getValue(symbolId: SymbolId): unknown {\n return this.nodes.get(symbolId);\n }\n\n hasValue(symbolId: SymbolId): boolean {\n return this.nodes.has(symbolId);\n }\n\n get id(): SymbolId {\n return this._id++;\n }\n\n isRegistered(identifier: ISymbolIdentifier): boolean {\n const symbol = this.get(identifier);\n return symbol ? this.registerOrder.has(symbol.id) : false;\n }\n\n query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut> {\n const cacheKey = this.buildCacheKey(filter);\n const cachedIds = this.queryCache.get(cacheKey);\n if (cachedIds) {\n return cachedIds.map((symbolId) => this.values.get(symbolId)!);\n }\n const sets: Array<Set<SymbolId>> = [];\n const indexKeySpace = this.buildIndexKeySpace(filter);\n const cacheDependencies = new Set<QueryCacheKey>();\n let missed = false;\n for (const indexEntry of indexKeySpace) {\n cacheDependencies.add(this.serializeIndexEntry(indexEntry));\n const values = this.indices.get(indexEntry[0]);\n if (!values) {\n missed = true;\n break;\n }\n const set = values.get(indexEntry[1]);\n if (!set) {\n missed = true;\n break;\n }\n sets.push(set);\n }\n if (missed || !sets.length) {\n this.queryCacheDependencies.set(cacheKey, cacheDependencies);\n this.queryCache.set(cacheKey, []);\n return [];\n }\n let result = new Set(sets[0]);\n for (const set of sets.slice(1)) {\n result = new Set([...result].filter((symbolId) => set.has(symbolId)));\n }\n const resultIds = [...result];\n this.queryCacheDependencies.set(cacheKey, cacheDependencies);\n this.queryCache.set(cacheKey, resultIds);\n return resultIds.map((symbolId) => this.values.get(symbolId)!);\n }\n\n reference(meta: ISymbolMeta): ISymbolOut {\n const [registered] = this.query(meta);\n if (registered) return registered;\n const cacheKey = this.buildCacheKey(meta);\n const cachedId = this.stubCache.get(cacheKey);\n if (cachedId !== undefined) return this.values.get(cachedId)!;\n const id = this.id;\n const stub: ISymbolOut = {\n id,\n meta,\n placeholder: wrapId(String(id)),\n };\n this.values.set(stub.id, stub);\n this.stubs.add(stub.id);\n this.stubCache.set(cacheKey, stub.id);\n return stub;\n }\n\n register(symbol: ISymbolIn): ISymbolOut {\n const id = symbol.id !== undefined ? symbol.id : this.id;\n const result: ISymbolOut = {\n ...symbol, // clone to avoid mutation\n id,\n placeholder: symbol.placeholder ?? wrapId(String(id)),\n };\n this.values.set(result.id, result);\n this.registerOrder.add(result.id);\n if (result.meta) {\n const indexKeySpace = this.buildIndexKeySpace(result.meta);\n this.indexSymbol(result.id, indexKeySpace);\n this.invalidateCache(indexKeySpace);\n this.replaceStubs(result, indexKeySpace);\n }\n return result;\n }\n\n *registered(): IterableIterator<ISymbolOut> {\n for (const id of this.registerOrder.values()) {\n yield this.values.get(id)!;\n }\n }\n\n setValue(symbolId: SymbolId, value: unknown): Map<SymbolId, unknown> {\n return this.nodes.set(symbolId, value);\n }\n\n private buildCacheKey(filter: ISymbolMeta): QueryCacheKey {\n const indexKeySpace = this.buildIndexKeySpace(filter);\n return indexKeySpace\n .map((indexEntry) => this.serializeIndexEntry(indexEntry))\n .sort() // ensure order-insensitivity\n .join('|');\n }\n\n private buildIndexKeySpace(meta: ISymbolMeta, prefix = ''): IndexKeySpace {\n const entries: Array<IndexEntry> = [];\n for (const [key, value] of Object.entries(meta)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n entries.push(...this.buildIndexKeySpace(value as ISymbolMeta, path));\n } else {\n entries.push([path, value]);\n }\n }\n return entries;\n }\n\n private indexSymbol(symbolId: SymbolId, indexKeySpace: IndexKeySpace): void {\n for (const [key, value] of indexKeySpace) {\n if (!this.indices.has(key)) this.indices.set(key, new Map());\n const values = this.indices.get(key)!;\n const set = values.get(value) ?? new Set();\n set.add(symbolId);\n values.set(value, set);\n }\n }\n\n private invalidateCache(indexKeySpace: IndexKeySpace): void {\n const changed = indexKeySpace.map((indexEntry) =>\n this.serializeIndexEntry(indexEntry),\n );\n for (const [\n cacheKey,\n cacheDependencies,\n ] of this.queryCacheDependencies.entries()) {\n for (const key of changed) {\n if (cacheDependencies.has(key)) {\n this.queryCacheDependencies.delete(cacheKey);\n this.queryCache.delete(cacheKey);\n break;\n }\n }\n }\n }\n\n private isSubset(sub: IndexKeySpace, sup: IndexKeySpace): boolean {\n const supMap = new Map(sup);\n for (const [key, value] of sub) {\n if (!supMap.has(key) || supMap.get(key) !== value) {\n return false;\n }\n }\n return true;\n }\n\n private replaceStubs(symbol: ISymbolOut, indexKeySpace: IndexKeySpace): void {\n for (const stubId of this.stubs.values()) {\n const stub = this.values.get(stubId);\n if (\n stub?.meta &&\n this.isSubset(this.buildIndexKeySpace(stub.meta), indexKeySpace)\n ) {\n const cacheKey = this.buildCacheKey(stub.meta);\n this.stubCache.delete(cacheKey);\n this.values.set(stubId, Object.assign(stub, symbol));\n this.stubs.delete(stubId);\n }\n }\n }\n\n private serializeIndexEntry(indexEntry: IndexEntry): string {\n return `${indexEntry[0]}:${JSON.stringify(indexEntry[1])}`;\n }\n}\n","import path from 'node:path';\n\nimport type { IProjectRenderMeta } from '../extensions/types';\nimport { FileRegistry } from '../files/registry';\nimport type { IFileOut, IFileSelector } from '../files/types';\nimport type { IOutput } from '../output/types';\nimport type { IRenderer } from '../renderer/types';\nimport { SymbolRegistry } from '../symbols/registry';\nimport type { ISymbolOut } from '../symbols/types';\nimport type { IProject } from './types';\n\nconst externalSourceSymbol = '@';\n\nexport class Project implements IProject {\n private symbolIdToFileIds: Map<number, Set<number>> = new Map();\n\n readonly defaultFileName: string;\n readonly files = new FileRegistry();\n readonly fileName?: (name: string) => string;\n readonly renderers: Record<string, IRenderer> = {};\n readonly root: string;\n readonly symbols = new SymbolRegistry();\n\n constructor({\n defaultFileName,\n fileName,\n renderers,\n root,\n }: Pick<IProject, 'defaultFileName' | 'fileName' | 'renderers' | 'root'>) {\n this.defaultFileName = defaultFileName ?? 'main';\n this.fileName = typeof fileName === 'string' ? () => fileName : fileName;\n this.renderers = renderers;\n this.root = root;\n }\n\n private getRenderer(file: IFileOut): IRenderer | undefined {\n return file.extension ? this.renderers[file.extension] : undefined;\n }\n\n private prepareFiles(): void {\n // TODO: infer extension from symbols\n const extension = '.ts';\n for (const symbol of this.symbols.registered()) {\n const selector = this.symbolToFileSelector(symbol);\n const file = this.files.reference(selector);\n file.symbols.body.push(symbol.id);\n // update symbol->files map\n const symbolIdToFileIds =\n this.symbolIdToFileIds.get(symbol.id) ?? new Set();\n symbolIdToFileIds.add(file.id);\n this.symbolIdToFileIds.set(symbol.id, symbolIdToFileIds);\n // update re-exports\n if (symbol.exportFrom) {\n for (const exportFrom of symbol.exportFrom) {\n const exportSelector = [exportFrom];\n const exportFile = this.files.reference(exportSelector);\n if (exportFile.id !== file.id) {\n exportFile.symbols.exports.push(symbol.id);\n }\n }\n }\n }\n for (const file of this.files.referenced()) {\n if (!file.selector) continue;\n if (file.selector[0] === externalSourceSymbol) {\n const filePath = file.selector[1];\n if (!filePath) {\n this.files.register({\n external: true,\n selector: file.selector,\n });\n continue;\n }\n const extension = path.extname(filePath);\n if (!extension) {\n this.files.register({\n external: true,\n path: filePath,\n selector: file.selector,\n });\n continue;\n }\n this.files.register({\n extension,\n external: true,\n path: filePath,\n selector: file.selector,\n });\n continue;\n }\n const dirs = file.selector.slice(0, -1);\n let name = file.selector[file.selector.length - 1]!;\n name = this.fileName?.(name) || name;\n this.files.register({\n extension,\n name,\n path: path.resolve(this.root, ...dirs, `${name}${extension}`),\n selector: file.selector,\n });\n }\n\n // TODO: track symbol dependencies and inject imports into files\n // based on symbol references so the render step can just render\n }\n\n render(meta?: IProjectRenderMeta): ReadonlyArray<IOutput> {\n this.prepareFiles();\n const files: Map<number, IOutput> = new Map();\n for (const file of this.files.registered()) {\n if (file.external || !file.path) continue;\n const renderer = this.getRenderer(file);\n if (!renderer) continue;\n files.set(file.id, {\n content: renderer.renderSymbols(file, this, meta),\n path: file.path,\n });\n }\n for (const [fileId, value] of files.entries()) {\n const file = this.files.get(fileId)!;\n const renderer = this.getRenderer(file)!;\n const content = renderer.renderFile(value.content, file, this, meta);\n if (content) {\n files.set(file.id, { ...value, content });\n } else {\n files.delete(file.id);\n }\n }\n return Array.from(files.values());\n }\n\n symbolIdToFiles(symbolId: number): ReadonlyArray<IFileOut> {\n const fileIds = this.symbolIdToFileIds.get(symbolId);\n return Array.from(fileIds ?? []).map((fileId) => this.files.get(fileId)!);\n }\n\n private symbolToFileSelector(symbol: ISymbolOut): IFileSelector {\n if (symbol.external) {\n return [externalSourceSymbol, symbol.external];\n }\n const filePath = symbol.getFilePath?.(symbol);\n if (filePath) {\n return filePath.split('/');\n }\n return [this.defaultFileName];\n }\n}\n"],"mappings":"ggBAIA,MAAa,GAAiB,CAC5B,OACA,aACA,SACA,gBAMc,CACd,IAAMA,EAAuB,EAAE,CACzBC,EAA2B,EAAE,CAC7BC,EAAmE,CACvE,QAAS,EAAE,CACX,KAAM,EACP,CAeD,GAdI,EAAO,aACL,EAAO,aAAe,WACxB,EAAQ,eAAiB,EAAO,YAC5B,EAAO,OAAS,SAClB,EAAQ,mBAAqB,KAEtB,EAAO,aAAe,cAC/B,EAAQ,iBAAmB,EAAO,YAC9B,EAAO,OAAS,SAClB,EAAQ,qBAAuB,MAMnC,EAAO,aAAe,SACrB,CAAC,EAAM,QAAU,CAAC,EAAQ,gBAAkB,CAAC,EAAQ,iBACtD,CACA,IAAI,EAAO,EAAO,YAC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,GAAW,KAAK,MAAM,IAAI,EAAO,CAAE,CAG3E,qBAA6B,EAAmC,CAC9D,GAAI,EAAO,SACT,MAAO,CAAC,IAAsB,EAAO,SAAS,CAEhD,IAAM,EAAW,EAAO,cAAc,EAAO,CAI7C,OAHI,EACK,EAAS,MAAM,IAAI,CAErB,CAAC,KAAK,gBAAgB"}
1
+ {"version":3,"file":"index.cjs","names":["colors","path","defaultExtensions: Extensions","simpleNameConflictResolver: NameConflictResolver","underscoreNameConflictResolver: NameConflictResolver","defaultNameConflictResolvers: NameConflictResolvers","path","ref","names: NameScopes","file","path","ctx: RenderContext","exports","Symbol","sets: Array<Set<SymbolId>>","Symbol","entries: Array<IndexEntry>","path","path","files: Array<IOutput>"],"sources":["../src/brands.ts","../src/debug.ts","../src/files/file.ts","../src/guards.ts","../src/languages/extensions.ts","../src/planner/resolvers.ts","../src/languages/resolvers.ts","../src/files/registry.ts","../src/refs/refs.ts","../src/nodes/registry.ts","../src/project/namespace.ts","../src/planner/analyzer.ts","../src/planner/planner.ts","../src/symbols/symbol.ts","../src/symbols/registry.ts","../src/project/project.ts"],"sourcesContent":["export const fileBrand = 'heyapi.file';\nexport const nodeBrand = 'heyapi.node';\nexport const symbolBrand = 'heyapi.symbol';\n","import colors from 'ansi-colors';\n// @ts-expect-error\nimport colorSupport from 'color-support';\n\ncolors.enabled = colorSupport().hasBasic;\n\nconst DEBUG_GROUPS = {\n analyzer: colors.greenBright,\n dsl: colors.cyanBright,\n file: colors.yellowBright,\n registry: colors.blueBright,\n symbol: colors.magentaBright,\n} as const;\n\nexport function debug(message: string, group: keyof typeof DEBUG_GROUPS) {\n const value = process.env.DEBUG;\n if (!value) return;\n\n const groups = value.split(',').map((x) => x.trim().toLowerCase());\n\n if (\n !(\n groups.includes('*') ||\n groups.includes('heyapi:*') ||\n groups.includes(`heyapi:${group}`) ||\n groups.includes(group)\n )\n ) {\n return;\n }\n\n const color = DEBUG_GROUPS[group] ?? colors.whiteBright;\n const prefix = color(`heyapi:${group}`);\n\n console.debug(`${prefix} ${message}`);\n}\n","import path from 'node:path';\n\nimport type { ExportModule, ImportModule } from '../bindings';\nimport { fileBrand } from '../brands';\nimport { debug } from '../debug';\nimport type { Language } from '../languages/types';\nimport type { INode } from '../nodes/node';\nimport type { NameScopes } from '../planner/types';\nimport type { IProject } from '../project/types';\nimport type { Renderer } from '../renderer';\nimport type { IFileIn } from './types';\n\nexport class File {\n /**\n * Exports from this file.\n */\n private _exports: Array<ExportModule> = [];\n /**\n * File extension (e.g. `.ts`).\n */\n private _extension?: string;\n /**\n * Actual emitted file path, including extension and directories.\n */\n private _finalPath?: string;\n /**\n * Imports to this file.\n */\n private _imports: Array<ImportModule> = [];\n /**\n * Language of the file.\n */\n private _language?: Language;\n /**\n * Logical, extension-free path used for planning and routing.\n */\n private _logicalFilePath: string;\n /**\n * Base name of the file (without extension).\n */\n private _name?: string;\n /**\n * Syntax nodes contained in this file.\n */\n private _nodes: Array<INode> = [];\n /**\n * Renderer assigned to this file.\n */\n private _renderer?: Renderer;\n\n /** Brand used for identifying files. */\n readonly '~brand' = fileBrand;\n /** All names defined in this file, including local scopes. */\n allNames: NameScopes = new Map();\n /** Whether this file is external to the project. */\n external: boolean;\n /** Unique identifier for the file. */\n readonly id: number;\n /** The project this file belongs to. */\n readonly project: IProject;\n /** Names declared at the top level of the file. */\n topLevelNames: NameScopes = new Map();\n\n constructor(input: IFileIn, id: number, project: IProject) {\n this.external = input.external ?? false;\n this.id = id;\n if (input.language !== undefined) this._language = input.language;\n this._logicalFilePath = input.logicalFilePath.split(path.sep).join('/');\n if (input.name !== undefined) this._name = input.name;\n this.project = project;\n }\n\n /**\n * Exports from this file.\n */\n get exports(): ReadonlyArray<ExportModule> {\n return [...this._exports];\n }\n\n /**\n * Read-only accessor for the file extension.\n */\n get extension(): string | undefined {\n if (this._extension) return this._extension;\n const language = this.language;\n const extension = language ? this.project.extensions[language] : undefined;\n if (extension && extension[0]) return extension[0];\n return;\n }\n\n /**\n * Read-only accessor for the final emitted path.\n *\n * If undefined, the file has not yet been assigned a final path\n * or is external to the project and should not be emitted.\n */\n get finalPath(): string | undefined {\n if (this._finalPath) return this._finalPath;\n const dirs = this._logicalFilePath\n ? this._logicalFilePath.split('/').slice(0, -1)\n : [];\n return [...dirs, `${this.name}${this.extension ?? ''}`].join('/');\n }\n\n /**\n * Imports to this file.\n */\n get imports(): ReadonlyArray<ImportModule> {\n return [...this._imports];\n }\n\n /**\n * Language of the file; inferred from nodes or fallback if not set explicitly.\n */\n get language(): Language | undefined {\n if (this._language) return this._language;\n if (this._nodes[0]) return this._nodes[0].language;\n return;\n }\n\n /**\n * Logical, extension-free path used for planning and routing.\n */\n get logicalFilePath(): string {\n return this._logicalFilePath;\n }\n\n /**\n * Base name of the file (without extension).\n *\n * If no name was set explicitly, it is inferred from the logical file path.\n */\n get name(): string {\n if (this._name) return this._name;\n const name = this._logicalFilePath.split('/').pop();\n if (name) return name;\n const message = `File ${this.toString()} has no name`;\n debug(message, 'file');\n throw new Error(message);\n }\n\n /**\n * Syntax nodes contained in this file.\n */\n get nodes(): ReadonlyArray<INode> {\n return [...this._nodes];\n }\n\n /**\n * Renderer assigned to this file.\n */\n get renderer(): Renderer | undefined {\n return this._renderer;\n }\n\n /**\n * Add an export group to the file.\n */\n addExport(group: ExportModule): void {\n this._exports.push(group);\n }\n\n /**\n * Add an import group to the file.\n */\n addImport(group: ImportModule): void {\n this._imports.push(group);\n }\n\n /**\n * Add a syntax node to the file.\n */\n addNode(node: INode): void {\n this._nodes.push(node);\n node.file = this;\n }\n\n /**\n * Sets the file extension.\n */\n setExtension(extension: string): void {\n this._extension = extension;\n }\n\n /**\n * Sets the final emitted path of the file.\n */\n setFinalPath(path: string): void {\n this._finalPath = path;\n }\n\n /**\n * Sets the language of the file.\n */\n setLanguage(lang: Language): void {\n this._language = lang;\n }\n\n /**\n * Sets the name of the file.\n */\n setName(name: string): void {\n this._name = name;\n }\n\n /**\n * Sets the renderer assigned to this file.\n */\n setRenderer(renderer: Renderer): void {\n this._renderer = renderer;\n }\n\n /**\n * Returns a debug‑friendly string representation identifying the file.\n */\n toString(): string {\n return `[File ${this._logicalFilePath}#${this.id}]`;\n }\n}\n","import { nodeBrand, symbolBrand } from './brands';\nimport type { INode } from './nodes/node';\nimport type { Ref } from './refs/types';\nimport type { Symbol } from './symbols/symbol';\n\nexport function isBrand(value: unknown, brand: string): value is INode {\n if (!value || typeof value !== 'object') return false;\n return (value as any)['~brand'] === brand;\n}\n\nexport function isNode(value: unknown): value is INode {\n if (!value || typeof value !== 'object') return false;\n return isBrand(value, nodeBrand);\n}\n\nexport function isNodeRef(value: Ref<unknown>): value is Ref<INode> {\n return isBrand(value['~ref'], nodeBrand);\n}\n\nexport function isSymbol(value: unknown): value is Symbol {\n return isBrand(value, symbolBrand);\n}\n\nexport function isSymbolRef(value: Ref<unknown>): value is Ref<Symbol> {\n return isBrand(value['~ref'], symbolBrand);\n}\n","import type { Extensions } from './types';\n\nexport const defaultExtensions: Extensions = {\n c: ['.c'],\n 'c#': ['.cs'],\n 'c++': ['.cpp', '.hpp'],\n css: ['.css'],\n dart: ['.dart'],\n go: ['.go'],\n haskell: ['.hs'],\n html: ['.html'],\n java: ['.java'],\n javascript: ['.js', '.jsx'],\n json: ['.json'],\n kotlin: ['.kt'],\n lua: ['.lua'],\n markdown: ['.md'],\n matlab: ['.m'],\n perl: ['.pl'],\n php: ['.php'],\n python: ['.py'],\n r: ['.r'],\n ruby: ['.rb'],\n rust: ['.rs'],\n scala: ['.scala'],\n shell: ['.sh'],\n sql: ['.sql'],\n swift: ['.swift'],\n typescript: ['.ts', '.tsx'],\n yaml: ['.yaml', '.yml'],\n};\n","import type { NameConflictResolver } from './types';\n\nexport const simpleNameConflictResolver: NameConflictResolver = ({\n attempt,\n baseName,\n}) => (attempt === 0 ? baseName : `${baseName}${attempt + 1}`);\n\nexport const underscoreNameConflictResolver: NameConflictResolver = ({\n attempt,\n baseName,\n}) => (attempt === 0 ? baseName : `${baseName}_${attempt + 1}`);\n","import { underscoreNameConflictResolver } from '../planner/resolvers';\nimport type { NameConflictResolvers } from './types';\n\nexport const defaultNameConflictResolvers: NameConflictResolvers = {\n php: underscoreNameConflictResolver,\n python: underscoreNameConflictResolver,\n ruby: underscoreNameConflictResolver,\n};\n","import path from 'node:path';\n\nimport type { IProject } from '../project/types';\nimport { File } from './file';\nimport type { FileKeyArgs, IFileIn, IFileRegistry } from './types';\n\ntype FileId = number;\ntype FileKey = string;\n\nexport class FileRegistry implements IFileRegistry {\n private _id: FileId = 0;\n private _values: Map<FileKey, File> = new Map();\n private readonly project: IProject;\n\n constructor(project: IProject) {\n this.project = project;\n }\n\n get(args: FileKeyArgs): File | undefined {\n return this._values.get(this.createFileKey(args));\n }\n\n isRegistered(args: FileKeyArgs): boolean {\n return this._values.has(this.createFileKey(args));\n }\n\n get nextId(): FileId {\n return this._id++;\n }\n\n register(file: IFileIn): File {\n const key = this.createFileKey(file);\n\n let result = this._values.get(key);\n if (result) {\n if (file.name) {\n result.setName(file.name);\n }\n } else {\n result = new File(file, this.nextId, this.project);\n }\n\n this._values.set(key, result);\n\n return result;\n }\n\n *registered(): IterableIterator<File> {\n for (const file of this._values.values()) {\n yield file;\n }\n }\n\n private createFileKey(args: FileKeyArgs): string {\n const logicalPath = args.logicalFilePath.split(path.sep).join('/');\n return `${args.external ? 'ext:' : ''}${logicalPath}${args.language ? `:${args.language}` : ''}`;\n }\n}\n","import type { FromRefs, Ref, Refs } from './types';\n\n/**\n * Wraps a single value in a Ref object.\n *\n * @example\n * ```ts\n * const r = ref(123); // { '~ref': 123 }\n * console.log(r['~ref']); // 123\n * ```\n */\nexport const ref = <T>(value: T): Ref<T> => ({ '~ref': value });\n\n/**\n * Converts a plain object to an object of Refs (deep, per property).\n *\n * @example\n * ```ts\n * const obj = { a: 1, b: \"x\" };\n * const refs = refs(obj); // { a: { '~ref': 1 }, b: { '~ref': \"x\" } }\n * ```\n */\nexport const refs = <T extends Record<string, unknown>>(obj: T): Refs<T> => {\n const result = {} as Refs<T>;\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n result[key] = ref(obj[key]);\n }\n }\n return result;\n};\n\n/**\n * Unwraps a single Ref object to its value.\n *\n * @example\n * ```ts\n * const r = { '~ref': 42 };\n * const n = fromRef(r); // 42\n * console.log(n); // 42\n * ```\n */\nexport const fromRef = <T extends Ref<unknown> | undefined>(\n ref: T,\n): T extends Ref<infer U> ? U : undefined =>\n ref?.['~ref'] as T extends Ref<infer U> ? U : undefined;\n\n/**\n * Converts an object of Refs back to a plain object (unwraps all refs).\n *\n * @example\n * ```ts\n * const refs = { a: { '~ref': 1 }, b: { '~ref': \"x\" } };\n * const plain = fromRefs(refs); // { a: 1, b: \"x\" }\n * ```\n */\nexport const fromRefs = <T extends Refs<Record<string, unknown>>>(\n obj: T,\n): FromRefs<T> => {\n const result = {} as FromRefs<T>;\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n result[key] = fromRef(obj[key]!) as (typeof result)[typeof key];\n }\n }\n return result;\n};\n\n/**\n * Checks whether a value is a Ref object.\n *\n * @param value Value to check\n * @returns True if the value is a Ref object.\n */\nexport const isRef = <T>(value: unknown): value is Ref<T> =>\n typeof value === 'object' && value !== null && '~ref' in value;\n","import { fromRef, ref } from '../refs/refs';\nimport type { Ref } from '../refs/types';\nimport type { INode } from './node';\nimport type { INodeRegistry } from './types';\n\nexport class NodeRegistry implements INodeRegistry {\n private list: Array<Ref<INode | null>> = [];\n\n add(node: INode | null): number {\n const index = this.list.push(ref(node));\n return index - 1;\n }\n\n *all(): Iterable<INode> {\n for (const r of this.list) {\n const node = fromRef(r);\n if (node) yield node;\n }\n }\n\n remove(index: number): void {\n this.list[index] = ref(null);\n }\n\n update(index: number, node: INode | null): void {\n this.list[index] = ref(node);\n }\n}\n","import type { SymbolKind } from '../symbols/types';\n\n/**\n * Returns true if two declarations of given kinds\n * are allowed to share the same identifier in TypeScript.\n */\nexport function canShareName(a: SymbolKind, b: SymbolKind): boolean {\n // same-kind always valid for interfaces (merging)\n if (a === 'interface' && b === 'interface') return true;\n\n // type vs interface merges\n if (\n (a === 'interface' && b === 'type') ||\n (a === 'type' && b === 'interface')\n ) {\n return false; // TypeScript does NOT merge type-alias with interface.\n }\n\n // type vs type = conflict\n if (a === 'type' && b === 'type') return false;\n\n // interface vs class = allowed (declare-merge)\n if (\n (a === 'interface' && b === 'class') ||\n (a === 'class' && b === 'interface')\n ) {\n return true;\n }\n\n // enum vs namespace = allowed (merges into value+type)\n if (\n (a === 'enum' && b === 'namespace') ||\n (a === 'namespace' && b === 'enum')\n ) {\n return true;\n }\n\n // class vs namespace = allowed\n if (\n (a === 'class' && b === 'namespace') ||\n (a === 'namespace' && b === 'class')\n ) {\n return true;\n }\n\n // namespace vs namespace = allowed (merging)\n if (a === 'namespace' && b === 'namespace') return true;\n\n // enum vs enum = conflict IF values conflict (TypeScript flags duplicates)\n if (a === 'enum' && b === 'enum') return false;\n\n // function and namespace merge (namespace can augment function)\n if (\n (a === 'function' && b === 'namespace') ||\n (a === 'namespace' && b === 'function')\n ) {\n return true;\n }\n\n // these collide with each other in the value namespace\n const valueKinds = new Set<SymbolKind>(['class', 'enum', 'function', 'var']);\n\n const aInValue = valueKinds.has(a);\n const bInValue = valueKinds.has(b);\n\n if (aInValue && bInValue) return false;\n\n // type-only declarations do not collide with value-only declarations\n const typeKinds = new Set<SymbolKind>(['interface', 'type']);\n const aInType = typeKinds.has(a);\n const bInType = typeKinds.has(b);\n\n // if one is type-only and the other is value-only, they do NOT collide\n if (aInType !== bInType) return true;\n\n return true;\n}\n","import { isNodeRef, isSymbolRef } from '../guards';\nimport type { INode } from '../nodes/node';\nimport { fromRef, isRef, ref } from '../refs/refs';\nimport type { Ref } from '../refs/types';\nimport type { Symbol } from '../symbols/symbol';\nimport type { IAnalysisContext, Input, NameScopes, Scope } from './types';\n\nconst createScope = (parent?: Scope): Scope => ({\n children: [],\n localNames: new Map(),\n parent,\n symbols: [],\n});\n\nexport class AnalysisContext implements IAnalysisContext {\n scopes: Scope = createScope();\n symbol?: Symbol;\n scope: Scope = this.scopes;\n\n constructor(symbol?: Symbol) {\n this.symbol = symbol;\n }\n\n addDependency(symbol: Ref<Symbol>): void {\n if (this.symbol !== fromRef(symbol)) {\n this.scope.symbols.push(symbol);\n }\n }\n\n analyze(input: Input): void {\n const v = isRef(input) ? input : ref(input);\n if (isSymbolRef(v)) {\n this.addDependency(v);\n } else if (isNodeRef(v)) {\n fromRef(v).analyze(this);\n }\n }\n\n localNames(scope: Scope): NameScopes {\n const names: NameScopes = new Map();\n for (const [name, kinds] of scope.localNames) {\n names.set(name, new Set(kinds));\n }\n if (scope.parent) {\n const parentNames = this.localNames(scope.parent);\n for (const [name, kinds] of parentNames) {\n if (!names.has(name)) {\n names.set(name, kinds);\n } else {\n const existingKinds = names.get(name)!;\n for (const kind of kinds) {\n existingKinds.add(kind);\n }\n }\n }\n }\n return names;\n }\n\n popScope(): void {\n this.scope = this.scope.parent ?? this.scope;\n }\n\n pushScope(): void {\n const scope = createScope(this.scope);\n this.scope.children.push(scope);\n this.scope = scope;\n }\n\n walkScopes(\n callback: (symbol: Ref<Symbol>, scope: Scope) => void,\n scope: Scope = this.scopes,\n ): void {\n this.scope = scope;\n for (const symbol of scope.symbols) {\n callback(symbol, scope);\n }\n for (const child of scope.children) {\n scope = child;\n this.walkScopes(callback, scope);\n }\n this.scope = this.scopes;\n }\n}\n\nexport class Analyzer {\n private nodeCache = new WeakMap<INode, AnalysisContext>();\n\n analyzeNode(node: INode): AnalysisContext {\n const cached = this.nodeCache.get(node);\n if (cached) return cached;\n\n const ctx = new AnalysisContext(node.symbol);\n node.analyze(ctx);\n\n this.nodeCache.set(node, ctx);\n return ctx;\n }\n\n analyze(\n nodes: Iterable<INode>,\n callback?: (ctx: AnalysisContext, node: INode) => void,\n ): void {\n for (const node of nodes) {\n const ctx = this.analyzeNode(node);\n callback?.(ctx, node);\n }\n }\n}\n","import path from 'node:path';\n\nimport type { ExportModule, ImportModule } from '../bindings';\nimport type { IProjectRenderMeta } from '../extensions';\nimport type { File } from '../files/file';\nimport type { IFileIn } from '../files/types';\nimport { canShareName } from '../project/namespace';\nimport type { IProject } from '../project/types';\nimport { fromRef } from '../refs/refs';\nimport type { RenderContext } from '../renderer';\nimport type { Symbol } from '../symbols/symbol';\nimport type { SymbolKind } from '../symbols/types';\nimport type { AnalysisContext } from './analyzer';\nimport { Analyzer } from './analyzer';\nimport type { AssignOptions, NameScopes } from './types';\n\nconst isTypeOnlyKind = (kind: SymbolKind) =>\n kind === 'type' || kind === 'interface';\n\nexport class Planner {\n private readonly analyzer = new Analyzer();\n private readonly cacheResolvedNames = new Set<number>();\n private readonly project: IProject;\n\n constructor(project: IProject) {\n this.project = project;\n }\n\n /**\n * Executes the planning phase for the project.\n */\n plan(meta?: IProjectRenderMeta) {\n this.cacheResolvedNames.clear();\n this.allocateFiles();\n this.assignLocalNames();\n this.resolveFilePaths(meta);\n this.planExports();\n this.planImports();\n }\n\n /**\n * Creates and assigns a file to every node, re-export,\n * and external dependency.\n */\n private allocateFiles(): void {\n this.analyzer.analyze(this.project.nodes.all(), (ctx, node) => {\n const symbol = node.symbol;\n if (!symbol) return;\n\n const file = this.project.files.register(this.symbolToFileIn(symbol));\n file.addNode(node);\n symbol.setFile(file);\n for (const exportFrom of symbol.exportFrom) {\n this.project.files.register({\n external: false,\n language: file.language,\n logicalFilePath: exportFrom,\n });\n }\n ctx.walkScopes((dependency) => {\n const dep = fromRef(dependency);\n if (dep.external && dep.isCanonical && !dep.file) {\n const file = this.project.files.register(this.symbolToFileIn(dep));\n dep.setFile(file);\n }\n });\n });\n }\n\n /**\n * Assigns final names to all symbols.\n *\n * First assigns top-level (file-scoped) symbol names, then local symbols.\n */\n private assignLocalNames(): void {\n this.analyzer.analyze(this.project.nodes.all(), (ctx, node) => {\n const symbol = node.symbol;\n if (!symbol) return;\n this.assignTopLevelName(symbol, ctx);\n });\n\n this.analyzer.analyze(this.project.nodes.all(), (ctx, node) => {\n const file = node.file;\n if (!file) return;\n ctx.walkScopes((dependency) => {\n const dep = fromRef(dependency);\n // top-level or external symbol\n if (dep.file) return;\n this.assignLocalName(dep, ctx, {\n scopesToUpdate: [file.allNames],\n });\n });\n });\n }\n\n /**\n * Resolves and sets final file paths for all non-external files. Attaches renderers.\n *\n * Uses the project's fileName function if provided, otherwise uses the file's current name.\n *\n * Resolves final paths relative to the project's root directory.\n */\n private resolveFilePaths(meta?: IProjectRenderMeta): void {\n for (const file of this.project.files.registered()) {\n if (file.external) continue;\n const finalName = this.project.fileName?.(file.name) || file.name;\n file.setName(finalName);\n const finalPath = file.finalPath;\n if (finalPath) {\n file.setFinalPath(path.resolve(this.project.root, finalPath));\n }\n const ctx: RenderContext = { file, meta, project: this.project };\n const renderer = this.project.renderers.find((r) => r.supports(ctx));\n if (renderer) file.setRenderer(renderer);\n }\n }\n\n /**\n * Plans exports by analyzing all exported symbols.\n *\n * Registers re-export targets as files and creates new exported symbols for them.\n *\n * Assigns names to re-exported symbols and collects re-export metadata,\n * distinguishing type-only exports based on symbol kinds.\n */\n private planExports(): void {\n const seenByFile = new Map<\n File,\n Map<string, { kinds: Set<SymbolKind>; symbol: Symbol }>\n >();\n const sourceFile = new Map<number, File>();\n\n this.analyzer.analyze(this.project.nodes.all(), (ctx, node) => {\n if (!node.exported) return;\n\n const symbol = node.symbol;\n if (!symbol) return;\n\n const file = node.file;\n if (!file) return;\n\n for (const exportFrom of symbol.exportFrom) {\n const target = this.project.files.register({\n external: false,\n language: node.language,\n logicalFilePath: exportFrom,\n });\n if (target.id === file.id) continue;\n\n let fileMap = seenByFile.get(target);\n if (!fileMap) {\n fileMap = new Map();\n seenByFile.set(target, fileMap);\n }\n\n const exp = this.project.symbols.register({\n exported: true,\n external: symbol.external,\n importKind: symbol.importKind,\n kind: symbol.kind,\n name: symbol.finalName,\n });\n exp.setFile(target);\n sourceFile.set(exp.id, file);\n this.assignTopLevelName(exp, ctx);\n\n let entry = fileMap.get(exp.finalName);\n if (!entry) {\n entry = { kinds: new Set(), symbol: exp };\n fileMap.set(exp.finalName, entry);\n }\n entry.kinds.add(exp.kind);\n }\n });\n\n for (const [file, fileMap] of seenByFile) {\n const exports = new Map<File, ExportModule>();\n for (const [, entry] of fileMap) {\n const source = sourceFile.get(entry.symbol.id)!;\n let exp = exports.get(source);\n if (!exp) {\n exp = {\n canExportAll: true,\n exports: [],\n from: source,\n isTypeOnly: true,\n };\n }\n const isTypeOnly = [...entry.kinds].every((kind) =>\n isTypeOnlyKind(kind),\n );\n const exportedName = entry.symbol.finalName;\n exp.exports.push({\n exportedName,\n isTypeOnly,\n kind: entry.symbol.importKind,\n sourceName: entry.symbol.name,\n });\n if (entry.symbol.name !== entry.symbol.finalName) {\n exp.canExportAll = false;\n }\n if (!isTypeOnly) {\n exp.isTypeOnly = false;\n }\n exports.set(source, exp);\n }\n for (const [, exp] of exports) {\n file.addExport(exp);\n }\n }\n }\n\n /**\n * Plans imports by analyzing symbol dependencies across files.\n *\n * For external dependencies, assigns top-level names.\n *\n * Creates or reuses import symbols for dependencies from other files,\n * assigning names and updating import metadata including type-only flags.\n */\n private planImports(): void {\n const seenByFile = new Map<\n File,\n Map<\n string,\n {\n dep: Symbol;\n kinds: Set<SymbolKind>;\n symbol: Symbol;\n }\n >\n >();\n\n this.analyzer.analyze(this.project.nodes.all(), (ctx) => {\n const symbol = ctx.symbol;\n if (!symbol) return;\n\n const file = symbol.file;\n if (!file) return;\n\n let fileMap = seenByFile.get(file);\n if (!fileMap) {\n fileMap = new Map();\n seenByFile.set(file, fileMap);\n }\n\n ctx.walkScopes((dependency) => {\n const dep = fromRef(dependency);\n if (!dep.file || dep.file.id === file.id) return;\n\n if (dep.external) {\n this.assignTopLevelName(dep, ctx);\n }\n\n const fromFileId = dep.file.id;\n const importedName = dep.finalName;\n const isTypeOnly = isTypeOnlyKind(dep.kind);\n const kind = dep.importKind;\n const key = `${fromFileId}|${importedName}|${kind}|${isTypeOnly}`;\n\n let entry = fileMap.get(key);\n if (!entry) {\n const imp = this.project.symbols.register({\n exported: dep.exported,\n external: dep.external,\n importKind: dep.importKind,\n kind: dep.kind,\n name: dep.finalName,\n });\n imp.setFile(file);\n this.assignTopLevelName(imp, ctx, {\n scope: imp.file!.allNames,\n });\n entry = {\n dep,\n kinds: new Set(),\n symbol: imp,\n };\n fileMap.set(key, entry);\n entry.kinds.add(imp.kind);\n }\n\n dependency['~ref'] = entry.symbol;\n });\n });\n\n for (const [file, fileMap] of seenByFile) {\n const imports = new Map<File, ImportModule>();\n for (const [, entry] of fileMap) {\n const source = entry.dep.file!;\n let imp = imports.get(source);\n if (!imp) {\n imp = {\n from: source,\n imports: [],\n isTypeOnly: true,\n };\n }\n const isTypeOnly = [...entry.kinds].every((kind) =>\n isTypeOnlyKind(kind),\n );\n if (entry.symbol.importKind === 'namespace') {\n imp.imports = [];\n imp.namespaceImport = entry.symbol.finalName;\n } else {\n imp.imports.push({\n isTypeOnly,\n kind: entry.symbol.importKind,\n localName: entry.symbol.finalName,\n sourceName: entry.dep.finalName,\n });\n }\n if (!isTypeOnly) {\n imp.isTypeOnly = false;\n }\n imports.set(source, imp);\n }\n for (const [, imp] of imports) {\n file.addImport(imp);\n }\n }\n }\n\n /**\n * Assigns the final name to a top-level (file-scoped) symbol.\n *\n * Uses the symbol's file top-level names as the default scope,\n * and updates all relevant name scopes including the file's allNames and local scopes.\n *\n * Supports optional overrides for the naming scope and scopes to update.\n */\n private assignTopLevelName(\n symbol: Symbol,\n ctx: AnalysisContext,\n options?: Partial<AssignOptions>,\n ): void {\n if (!symbol.file) return;\n this.assignSymbolName(symbol, {\n scope: options?.scope ?? symbol.file.topLevelNames,\n scopesToUpdate: [\n symbol.file.allNames,\n ctx.scopes.localNames,\n ...(options?.scopesToUpdate ?? []),\n ],\n });\n }\n\n /**\n * Assigns the final name to a non-top-level (local) symbol.\n *\n * Uses the provided scope or derives it from the current analysis context's local names.\n *\n * Updates all provided name scopes accordingly.\n */\n private assignLocalName(\n symbol: Symbol,\n ctx: AnalysisContext,\n options: Pick<Partial<AssignOptions>, 'scope'> &\n Pick<AssignOptions, 'scopesToUpdate'>,\n ): void {\n this.assignSymbolName(symbol, {\n scope: options.scope ?? ctx.localNames(ctx.scope),\n scopesToUpdate: options.scopesToUpdate,\n });\n }\n\n /**\n * Assigns the final name to a symbol within the provided name scope.\n *\n * Resolves name conflicts until a unique name is found.\n *\n * Updates all specified name scopes with the assigned final name.\n */\n private assignSymbolName(symbol: Symbol, options: AssignOptions): void {\n if (this.cacheResolvedNames.has(symbol.id)) return;\n\n const baseName = symbol.name;\n let finalName = symbol.nameSanitizer?.(baseName) ?? baseName;\n let attempt = 1;\n\n while (true) {\n const kinds = [...(options.scope.get(finalName) ?? [])];\n\n const ok = kinds.every((kind) => canShareName(symbol.kind, kind));\n if (ok) break;\n\n const language = symbol.node?.language || symbol.file?.language;\n const resolver =\n (language ? this.project.nameConflictResolvers[language] : undefined) ??\n this.project.defaultNameConflictResolver;\n const resolvedName = resolver({ attempt, baseName });\n if (!resolvedName) {\n throw new Error(`Unresolvable name conflict: ${symbol.toString()}`);\n }\n\n finalName = symbol.nameSanitizer?.(resolvedName) ?? resolvedName;\n attempt = attempt + 1;\n }\n\n symbol.setFinalName(finalName);\n this.cacheResolvedNames.add(symbol.id);\n const updateScopes = [options.scope, ...options.scopesToUpdate];\n for (const scope of updateScopes) {\n this.updateScope(symbol, scope);\n }\n }\n\n /**\n * Updates the provided name scope with the symbol's final name and kind.\n *\n * Ensures the name scope tracks all kinds associated with a given name.\n */\n private updateScope(symbol: Symbol, scope: NameScopes): void {\n const name = symbol.finalName;\n const cache = scope.get(name) ?? new Set<SymbolKind>();\n cache.add(symbol.kind);\n scope.set(name, cache);\n }\n\n private symbolToFileIn(symbol: Symbol): IFileIn {\n return {\n external: Boolean(symbol.external),\n language: symbol.node?.language,\n logicalFilePath:\n symbol.external ||\n symbol.getFilePath?.(symbol) ||\n this.project.defaultFileName,\n } satisfies IFileIn;\n }\n}\n","import { symbolBrand } from '../brands';\nimport { debug } from '../debug';\nimport type { ISymbolMeta } from '../extensions';\nimport type { File } from '../files/file';\nimport type { INode } from '../nodes/node';\nimport type {\n BindingKind,\n ISymbolIn,\n SymbolKind,\n SymbolNameSanitizer,\n} from './types';\n\nexport class Symbol {\n /**\n * Canonical symbol this stub resolves to, if any.\n *\n * Stubs created during DSL construction may later be associated\n * with a fully registered symbol. Once set, all property lookups\n * should defer to the canonical symbol.\n */\n private _canonical?: Symbol;\n /**\n * True if this symbol is exported from its defining file.\n *\n * @default false\n */\n private _exported: boolean;\n /**\n * Names of files (without extension) from which this symbol is re-exported.\n *\n * @default []\n */\n private _exportFrom: ReadonlyArray<string>;\n /**\n * External module name if this symbol is imported from a module not managed\n * by the project (e.g. \"zod\", \"lodash\").\n *\n * @default undefined\n */\n private _external?: string;\n /**\n * The file this symbol is ultimately emitted into.\n *\n * Only top-level symbols have an assigned file.\n */\n private _file?: File;\n /**\n * The alias-resolved, conflict-free emitted name.\n */\n private _finalName?: string;\n /**\n * Custom strategy to determine file output path.\n *\n * @returns The file path to output the symbol to, or undefined to fallback to default behavior.\n */\n private _getFilePath?: (symbol: Symbol) => string | undefined;\n /**\n * How this symbol should be imported (namespace/default/named).\n *\n * @default 'named'\n */\n private _importKind: BindingKind;\n /**\n * Kind of symbol (class, type, alias, etc.).\n *\n * @default 'var'\n */\n private _kind: SymbolKind;\n /**\n * Arbitrary user metadata.\n *\n * @default undefined\n */\n private _meta?: ISymbolMeta;\n /**\n * Intended user-facing name before conflict resolution.\n *\n * @example \"UserModel\"\n */\n private _name: string;\n /**\n * Optional function to sanitize the symbol name.\n *\n * @default undefined\n */\n private _nameSanitizer?: SymbolNameSanitizer;\n /**\n * Node that defines this symbol.\n */\n private _node?: INode;\n\n /** Brand used for identifying symbols. */\n readonly '~brand' = symbolBrand;\n /** Globally unique, stable symbol ID. */\n readonly id: number;\n\n constructor(input: ISymbolIn, id: number) {\n this._exported = input.exported ?? false;\n this._exportFrom = input.exportFrom ?? [];\n this._external = input.external;\n this._getFilePath = input.getFilePath;\n this.id = id;\n this._importKind = input.importKind ?? 'named';\n this._kind = input.kind ?? 'var';\n this._meta = input.meta;\n this._name = input.name;\n }\n\n /**\n * Returns the canonical symbol for this instance.\n *\n * If this symbol was created as a stub, this getter returns\n * the fully registered canonical symbol. Otherwise, it returns\n * the symbol itself.\n */\n get canonical(): Symbol {\n return this._canonical ?? this;\n }\n\n /**\n * Indicates whether this symbol is exported from its defining file.\n */\n get exported(): boolean {\n return this.canonical._exported;\n }\n\n /**\n * Names of files (without extension) that re-export this symbol.\n */\n get exportFrom(): ReadonlyArray<string> {\n return this.canonical._exportFrom;\n }\n\n /**\n * External module from which this symbol originates, if any.\n */\n get external(): string | undefined {\n return this.canonical._external;\n }\n\n /**\n * Read‑only accessor for the assigned output file.\n *\n * Only top-level symbols have an assigned file.\n */\n get file(): File | undefined {\n return this.canonical._file;\n }\n\n /**\n * Read‑only accessor for the resolved final emitted name.\n */\n get finalName(): string {\n if (!this.canonical._finalName) {\n const message = `Symbol finalName has not been resolved yet for ${this.canonical.toString()}`;\n debug(message, 'symbol');\n throw new Error(message);\n }\n return this.canonical._finalName;\n }\n\n /**\n * Custom file path resolver, if provided.\n */\n get getFilePath(): ((symbol: Symbol) => string | undefined) | undefined {\n return this.canonical._getFilePath;\n }\n\n /**\n * How this symbol should be imported (named/default/namespace).\n */\n get importKind(): BindingKind {\n return this.canonical._importKind;\n }\n\n /**\n * Indicates whether this is a canonical symbol (not a stub).\n */\n get isCanonical(): boolean {\n return !this._canonical || this._canonical === this;\n }\n\n /**\n * The symbol's kind (class, type, alias, variable, etc.).\n */\n get kind(): SymbolKind {\n return this.canonical._kind;\n }\n\n /**\n * Arbitrary user‑provided metadata associated with this symbol.\n */\n get meta(): ISymbolMeta | undefined {\n return this.canonical._meta;\n }\n\n /**\n * User-intended name before aliasing or conflict resolution.\n */\n get name(): string {\n return this.canonical._name;\n }\n\n /**\n * Optional function to sanitize the symbol name.\n */\n get nameSanitizer(): SymbolNameSanitizer | undefined {\n return this.canonical._nameSanitizer;\n }\n\n /**\n * Read‑only accessor for the defining node.\n */\n get node(): INode | undefined {\n return this.canonical._node;\n }\n\n /**\n * Marks this symbol as a stub and assigns its canonical symbol.\n *\n * After calling this, all semantic queries (name, kind, file,\n * meta, etc.) should reflect the canonical symbol's values.\n *\n * @param symbol — The canonical symbol this stub should resolve to.\n */\n setCanonical(symbol: Symbol): void {\n this._canonical = symbol;\n }\n\n /**\n * Marks the symbol as exported from its file.\n *\n * @param exported — Whether the symbol is exported.\n */\n setExported(exported: boolean): void {\n this.assertCanonical();\n this._exported = exported;\n }\n\n /**\n * Records file names that re‑export this symbol.\n *\n * @param list — Source files re‑exporting this symbol.\n */\n setExportFrom(list: ReadonlyArray<string>): void {\n this.assertCanonical();\n this._exportFrom = list;\n }\n\n /**\n * Assigns the output file this symbol will be emitted into.\n *\n * This may only be set once.\n */\n setFile(file: File): void {\n this.assertCanonical();\n if (this._file && this._file !== file) {\n const message = `Symbol ${this.canonical.toString()} is already assigned to a different file.`;\n debug(message, 'symbol');\n throw new Error(message);\n }\n this._file = file;\n }\n\n /**\n * Assigns the conflict‑resolved final local name for this symbol.\n *\n * This may only be set once.\n */\n setFinalName(name: string): void {\n this.assertCanonical();\n if (this._finalName && this._finalName !== name) {\n const message = `Symbol finalName has already been resolved for ${this.canonical.toString()}.`;\n debug(message, 'symbol');\n throw new Error(message);\n }\n this._finalName = name;\n }\n\n /**\n * Sets how this symbol should be imported.\n *\n * @param kind — The import strategy (named/default/namespace).\n */\n setImportKind(kind: BindingKind): void {\n this.assertCanonical();\n this._importKind = kind;\n }\n\n /**\n * Sets the symbol's kind (class, type, alias, variable, etc.).\n *\n * @param kind — The new symbol kind.\n */\n setKind(kind: SymbolKind): void {\n this.assertCanonical();\n this._kind = kind;\n }\n\n /**\n * Updates the intended user‑facing name for this symbol.\n *\n * @param name — The new name.\n */\n setName(name: string): void {\n this.assertCanonical();\n this._name = name;\n }\n\n /**\n * Sets a custom function to sanitize the symbol's name.\n *\n * @param fn — The name sanitizer function to apply.\n */\n setNameSanitizer(fn: SymbolNameSanitizer): void {\n this.assertCanonical();\n this._nameSanitizer = fn;\n }\n\n /**\n * Binds the node that defines this symbol.\n *\n * This may only be set once.\n */\n setNode(node: INode): void {\n this.assertCanonical();\n if (this._node && this._node !== node) {\n const message = `Symbol ${this.canonical.toString()} is already bound to a different node.`;\n debug(message, 'symbol');\n throw new Error(message);\n }\n this._node = node;\n node.symbol = this;\n }\n\n /**\n * Returns a debug‑friendly string representation identifying the symbol.\n */\n toString(): string {\n return `[Symbol ${this.name}#${this.id}]`;\n }\n\n /**\n * Ensures this symbol is canonical before allowing mutation.\n *\n * A symbol that has been marked as a stub (i.e., its `_canonical` points\n * to a different symbol) may not be mutated. This guard throws an error\n * if any setter attempts to modify a stub, preventing accidental writes\n * to non‑canonical instances.\n *\n * @throws {Error} If the symbol is a stub and is being mutated.\n */\n private assertCanonical(): void {\n if (this._canonical && this._canonical !== this) {\n const message = `Illegal mutation of stub symbol ${this.toString()} → canonical: ${this._canonical.toString()}`;\n debug(message, 'symbol');\n throw new Error(message);\n }\n }\n}\n","import type { ISymbolMeta } from '../extensions';\nimport { Symbol } from './symbol';\nimport type { ISymbolIdentifier, ISymbolIn, ISymbolRegistry } from './types';\n\ntype IndexEntry = [string, unknown];\ntype IndexKeySpace = ReadonlyArray<IndexEntry>;\ntype QueryCacheKey = string;\ntype SymbolId = number;\n\nexport class SymbolRegistry implements ISymbolRegistry {\n private _id: SymbolId = 0;\n private _indices: Map<IndexEntry[0], Map<IndexEntry[1], Set<SymbolId>>> =\n new Map();\n private _queryCache: Map<QueryCacheKey, ReadonlyArray<SymbolId>> = new Map();\n private _queryCacheDependencies: Map<QueryCacheKey, Set<QueryCacheKey>> =\n new Map();\n private _registered: Set<SymbolId> = new Set();\n private _stubs: Set<SymbolId> = new Set();\n private _stubCache: Map<QueryCacheKey, SymbolId> = new Map();\n private _values: Map<SymbolId, Symbol> = new Map();\n\n get(identifier: ISymbolIdentifier): Symbol | undefined {\n return typeof identifier === 'number'\n ? this._values.get(identifier)\n : this.query(identifier)[0];\n }\n\n isRegistered(identifier: ISymbolIdentifier): boolean {\n const symbol = this.get(identifier);\n return symbol ? this._registered.has(symbol.id) : false;\n }\n\n get nextId(): SymbolId {\n return this._id++;\n }\n\n query(filter: ISymbolMeta): ReadonlyArray<Symbol> {\n const cacheKey = this.buildCacheKey(filter);\n const cachedIds = this._queryCache.get(cacheKey);\n if (cachedIds) {\n return cachedIds.map((symbolId) => this._values.get(symbolId)!);\n }\n const sets: Array<Set<SymbolId>> = [];\n const indexKeySpace = this.buildIndexKeySpace(filter);\n const cacheDependencies = new Set<QueryCacheKey>();\n let missed = false;\n for (const indexEntry of indexKeySpace) {\n cacheDependencies.add(this.serializeIndexEntry(indexEntry));\n const values = this._indices.get(indexEntry[0]);\n if (!values) {\n missed = true;\n break;\n }\n const set = values.get(indexEntry[1]);\n if (!set) {\n missed = true;\n break;\n }\n sets.push(set);\n }\n if (missed || !sets.length) {\n this._queryCacheDependencies.set(cacheKey, cacheDependencies);\n this._queryCache.set(cacheKey, []);\n return [];\n }\n let result = new Set(sets[0]);\n for (const set of sets.slice(1)) {\n result = new Set([...result].filter((symbolId) => set.has(symbolId)));\n }\n const resultIds = [...result];\n this._queryCacheDependencies.set(cacheKey, cacheDependencies);\n this._queryCache.set(cacheKey, resultIds);\n return resultIds.map((symbolId) => this._values.get(symbolId)!);\n }\n\n reference(meta: ISymbolMeta): Symbol {\n const [registered] = this.query(meta);\n if (registered) return registered;\n\n const cacheKey = this.buildCacheKey(meta);\n const cachedId = this._stubCache.get(cacheKey);\n if (cachedId !== undefined) return this._values.get(cachedId)!;\n\n const stub = new Symbol({ meta, name: '' }, this.nextId);\n\n this._values.set(stub.id, stub);\n this._stubs.add(stub.id);\n this._stubCache.set(cacheKey, stub.id);\n return stub;\n }\n\n register(symbol: ISymbolIn): Symbol {\n const result = new Symbol(symbol, this.nextId);\n\n this._values.set(result.id, result);\n this._registered.add(result.id);\n\n if (result.meta) {\n const indexKeySpace = this.buildIndexKeySpace(result.meta);\n this.indexSymbol(result.id, indexKeySpace);\n this.invalidateCache(indexKeySpace);\n this.replaceStubs(result, indexKeySpace);\n }\n\n return result;\n }\n\n *registered(): IterableIterator<Symbol> {\n for (const id of this._registered.values()) {\n yield this._values.get(id)!;\n }\n }\n\n private buildCacheKey(filter: ISymbolMeta): QueryCacheKey {\n const indexKeySpace = this.buildIndexKeySpace(filter);\n return indexKeySpace\n .map((indexEntry) => this.serializeIndexEntry(indexEntry))\n .sort() // ensure order-insensitivity\n .join('|');\n }\n\n private buildIndexKeySpace(meta: ISymbolMeta, prefix = ''): IndexKeySpace {\n const entries: Array<IndexEntry> = [];\n for (const [key, value] of Object.entries(meta)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n entries.push(...this.buildIndexKeySpace(value as ISymbolMeta, path));\n } else {\n entries.push([path, value]);\n }\n }\n return entries;\n }\n\n private indexSymbol(symbolId: SymbolId, indexKeySpace: IndexKeySpace): void {\n for (const [key, value] of indexKeySpace) {\n if (!this._indices.has(key)) this._indices.set(key, new Map());\n const values = this._indices.get(key)!;\n const set = values.get(value) ?? new Set();\n set.add(symbolId);\n values.set(value, set);\n }\n }\n\n private invalidateCache(indexKeySpace: IndexKeySpace): void {\n const changed = indexKeySpace.map((indexEntry) =>\n this.serializeIndexEntry(indexEntry),\n );\n for (const [\n cacheKey,\n cacheDependencies,\n ] of this._queryCacheDependencies.entries()) {\n for (const key of changed) {\n if (cacheDependencies.has(key)) {\n this._queryCacheDependencies.delete(cacheKey);\n this._queryCache.delete(cacheKey);\n break;\n }\n }\n }\n }\n\n private isSubset(sub: IndexKeySpace, sup: IndexKeySpace): boolean {\n const supMap = new Map(sup);\n for (const [key, value] of sub) {\n if (!supMap.has(key) || supMap.get(key) !== value) {\n return false;\n }\n }\n return true;\n }\n\n private replaceStubs(symbol: Symbol, indexKeySpace: IndexKeySpace): void {\n for (const stubId of this._stubs.values()) {\n const stub = this._values.get(stubId);\n if (\n stub?.meta &&\n this.isSubset(this.buildIndexKeySpace(stub.meta), indexKeySpace)\n ) {\n const cacheKey = this.buildCacheKey(stub.meta);\n this._stubCache.delete(cacheKey);\n this._stubs.delete(stubId);\n stub.setCanonical(symbol);\n }\n }\n }\n\n private serializeIndexEntry(indexEntry: IndexEntry): string {\n return `${indexEntry[0]}:${JSON.stringify(indexEntry[1])}`;\n }\n}\n","import path from 'node:path';\n\nimport type { IProjectRenderMeta } from '../extensions';\nimport { FileRegistry } from '../files/registry';\nimport { defaultExtensions } from '../languages/extensions';\nimport { defaultNameConflictResolvers } from '../languages/resolvers';\nimport type { Extensions, NameConflictResolvers } from '../languages/types';\nimport { NodeRegistry } from '../nodes/registry';\nimport type { IOutput } from '../output';\nimport { Planner } from '../planner/planner';\nimport { simpleNameConflictResolver } from '../planner/resolvers';\nimport type { NameConflictResolver } from '../planner/types';\nimport type { Renderer } from '../renderer';\nimport { SymbolRegistry } from '../symbols/registry';\nimport type { IProject } from './types';\n\nexport class Project implements IProject {\n readonly files: FileRegistry;\n readonly nodes = new NodeRegistry();\n readonly symbols = new SymbolRegistry();\n\n readonly defaultFileName: string;\n readonly defaultNameConflictResolver: NameConflictResolver;\n readonly extensions: Extensions;\n readonly fileName?: (name: string) => string;\n readonly nameConflictResolvers: NameConflictResolvers;\n readonly renderers: ReadonlyArray<Renderer>;\n readonly root: string;\n\n constructor(\n args: Pick<\n Partial<IProject>,\n | 'defaultFileName'\n | 'defaultNameConflictResolver'\n | 'extensions'\n | 'fileName'\n | 'nameConflictResolvers'\n | 'renderers'\n > &\n Pick<IProject, 'root'>,\n ) {\n const fileName = args.fileName;\n this.defaultFileName = args.defaultFileName ?? 'main';\n this.defaultNameConflictResolver =\n args.defaultNameConflictResolver ?? simpleNameConflictResolver;\n this.extensions = {\n ...defaultExtensions,\n ...args.extensions,\n };\n this.fileName = typeof fileName === 'string' ? () => fileName : fileName;\n this.files = new FileRegistry(this);\n this.nameConflictResolvers = {\n ...defaultNameConflictResolvers,\n ...args.nameConflictResolvers,\n };\n this.renderers = args.renderers ?? [];\n this.root = path.resolve(args.root).replace(/[/\\\\]+$/, '');\n }\n\n render(meta?: IProjectRenderMeta): ReadonlyArray<IOutput> {\n new Planner(this).plan(meta);\n const files: Array<IOutput> = [];\n for (const file of this.files.registered()) {\n if (file.finalPath && file.renderer) {\n const content = file.renderer.render({ file, meta, project: this });\n files.push({ content, path: file.finalPath });\n }\n }\n return files;\n }\n}\n"],"mappings":"0kBAAA,MAAa,EAAY,cACZ,EAAY,cACZ,EAAc,gBCE3B,EAAA,QAAO,SAAA,EAAA,EAAA,UAAwB,CAAC,SAEhC,MAAM,EAAe,CACnB,SAAUA,EAAAA,QAAO,YACjB,IAAKA,EAAAA,QAAO,WACZ,KAAMA,EAAAA,QAAO,aACb,SAAUA,EAAAA,QAAO,WACjB,OAAQA,EAAAA,QAAO,cAChB,CAED,SAAgB,EAAM,EAAiB,EAAkC,CACvE,IAAM,EAAQ,QAAQ,IAAI,MAC1B,GAAI,CAAC,EAAO,OAEZ,IAAM,EAAS,EAAM,MAAM,IAAI,CAAC,IAAK,GAAM,EAAE,MAAM,CAAC,aAAa,CAAC,CAElE,GACE,EACE,EAAO,SAAS,IAAI,EACpB,EAAO,SAAS,WAAW,EAC3B,EAAO,SAAS,UAAU,IAAQ,EAClC,EAAO,SAAS,EAAM,EAGxB,OAIF,IAAM,GADQ,EAAa,IAAUA,EAAAA,QAAO,aACvB,UAAU,IAAQ,CAEvC,QAAQ,MAAM,GAAG,EAAO,GAAG,IAAU,CCtBvC,IAAa,EAAb,KAAkB,CAIhB,SAAwC,EAAE,CAI1C,WAIA,WAIA,SAAwC,EAAE,CAI1C,UAIA,iBAIA,MAIA,OAA+B,EAAE,CAIjC,UAGA,SAAoB,cAEpB,SAAuB,IAAI,IAE3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