Socket
Book a DemoSign in
Socket

@hey-api/codegen-core

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hey-api/codegen-core - npm Package Compare versions

Comparing version
0.3.1
to
0.3.2
+1
-1
dist/index.cjs

@@ -1,2 +0,2 @@

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.meta?.importKind&&(n.meta.importKind===`default`?(o.defaultBinding=n.placeholder,n.meta.kind===`type`&&(o.typeDefaultBinding=!0)):n.meta.importKind===`namespace`&&(o.namespaceBinding=n.placeholder,n.meta.kind===`type`&&(o.typeNamespaceBinding=!0))),n.meta?.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.meta?.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.idOrSelector(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++}idOrSelector(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.idOrSelector(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;nodes=new Map;registerOrder=new Set;selectorToId=new Map;values=new Map;get(e){let t=this.idOrSelector(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)}}getValue(e){return this.nodes.get(e)}hasValue(e){return this.nodes.has(e)}get id(){return this._id++}idOrSelector(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.idOrSelector(e);return this.register(t)}register(e){if(e.id!==void 0){let t=this.values.get(e.id);if(!t)throw Error(`Symbol with ID ${e.id} not found. To register a new symbol, 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(`Symbol 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,a=n?.exportFrom?[...n.exportFrom]:[];return e.exportFrom&&a.push(...e.exportFrom),n={...n,...e,exportFrom:a,id:i,placeholder:n?.placeholder??e.placeholder??p(String(i))},this.values.set(i,n),t&&this.registerOrder.add(i),r&&this.selectorToId.set(r,i),n}*registered(){for(let e of this.registerOrder.values())yield this.values.get(e)}setValue(e,t){return this.nodes.set(e,t)}};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;r.add(n.id),this.symbolIdToFileIds.set(e.id,r);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;
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={exportFrom:[],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,exportFrom:e.exportFrom??[],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;r.add(n.id),this.symbolIdToFileIds.set(e.id,r);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;
//# sourceMappingURL=index.cjs.map

@@ -1,1 +0,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","result","result: ISymbolOut | undefined","id","exportFrom: Array<string>","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.meta?.importKind) {\n if (symbol.meta.importKind === 'default') {\n binding.defaultBinding = symbol.placeholder;\n if (symbol.meta.kind === 'type') {\n binding.typeDefaultBinding = true;\n }\n } else if (symbol.meta.importKind === 'namespace') {\n binding.namespaceBinding = symbol.placeholder;\n if (symbol.meta.kind === 'type') {\n binding.typeNamespaceBinding = true;\n }\n }\n }\n // default to named binding\n if (\n symbol.meta?.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.meta?.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 { ISelector } from '../selectors/types';\nimport type { IFileIn, IFileOut, IFileRegistry } 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(fileIdOrSelector: number | ISelector): IFileOut | undefined {\n const symbol = this.idOrSelector(fileIdOrSelector);\n\n if (symbol.id !== undefined) {\n return this.values.get(symbol.id);\n }\n\n const selector =\n symbol.selector !== undefined\n ? JSON.stringify(symbol.selector)\n : 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 idOrSelector(\n symbolIdOrSelector: number | ISelector,\n ): Pick<IFileIn, 'id' | 'selector'> {\n return typeof symbolIdOrSelector === 'number'\n ? { id: symbolIdOrSelector }\n : { selector: symbolIdOrSelector };\n }\n\n isRegistered(fileIdOrSelector: number | ISelector): boolean {\n const file = this.get(fileIdOrSelector);\n return file ? this.registerOrder.has(file.id) : false;\n }\n\n reference(fileIdOrSelector: number | ISelector): IFileOut {\n const file = this.idOrSelector(fileIdOrSelector);\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 { wrapId } from '../renderer/utils';\nimport type { ISelector } from '../selectors/types';\nimport type { ISymbolIn, ISymbolOut, ISymbolRegistry } from './types';\n\nexport class SymbolRegistry implements ISymbolRegistry {\n private _id: number = 0;\n private nodes: Map<number, unknown> = new Map();\n private registerOrder: Set<number> = new Set();\n private selectorToId: Map<string, number> = new Map();\n private values: Map<number, ISymbolOut> = new Map();\n\n get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined {\n const symbol = this.idOrSelector(symbolIdOrSelector);\n\n if (symbol.id !== undefined) {\n return this.values.get(symbol.id);\n }\n\n const selector =\n symbol.selector !== undefined\n ? JSON.stringify(symbol.selector)\n : 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 getValue(symbolId: number): unknown {\n return this.nodes.get(symbolId);\n }\n\n hasValue(symbolId: number): boolean {\n return this.nodes.has(symbolId);\n }\n\n get id(): number {\n return this._id++;\n }\n\n private idOrSelector(\n symbolIdOrSelector: number | ISelector,\n ): Pick<ISymbolIn, 'id' | 'selector'> {\n return typeof symbolIdOrSelector === 'number'\n ? { id: symbolIdOrSelector }\n : { selector: symbolIdOrSelector };\n }\n\n isRegistered(symbolIdOrSelector: number | ISelector): boolean {\n const symbol = this.get(symbolIdOrSelector);\n return symbol ? this.registerOrder.has(symbol.id) : false;\n }\n\n reference(symbolIdOrSelector: number | ISelector): ISymbolOut {\n const symbol = this.idOrSelector(symbolIdOrSelector);\n return this.register(symbol);\n }\n\n register(symbol: ISymbolIn): ISymbolOut {\n if (symbol.id !== undefined) {\n const result = this.values.get(symbol.id);\n if (!result) {\n throw new Error(\n `Symbol with ID ${symbol.id} not found. To register a new symbol, leave the ID undefined.`,\n );\n }\n return result;\n }\n\n const hasOtherKeys = Object.keys(symbol).some(\n (key) => !['id', 'selector'].includes(key),\n );\n\n let result: ISymbolOut | undefined;\n\n const selector =\n symbol.selector !== undefined\n ? JSON.stringify(symbol.selector)\n : 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 `Symbol 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 const exportFrom: Array<string> = result?.exportFrom\n ? [...result.exportFrom]\n : [];\n if (symbol.exportFrom) {\n exportFrom.push(...symbol.exportFrom);\n }\n result = {\n ...result,\n ...symbol, // clone to avoid mutation\n exportFrom,\n id,\n placeholder:\n result?.placeholder ?? symbol.placeholder ?? wrapId(String(id)),\n };\n this.values.set(id, result);\n\n if (hasOtherKeys) {\n this.registerOrder.add(id);\n }\n\n if (selector) {\n this.selectorToId.set(selector, id);\n }\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: number, value: unknown): Map<number, unknown> {\n return this.nodes.set(symbolId, value);\n }\n}\n","import path from 'node:path';\n\nimport type { IProjectRenderMeta } from '../extensions/types';\nimport { FileRegistry } from '../files/registry';\nimport type { IFileOut } from '../files/types';\nimport type { IOutput } from '../output/types';\nimport type { IRenderer } from '../renderer/types';\nimport type { ISelector } from '../selectors/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 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 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): ISelector {\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,MAAM,aACX,EAAO,KAAK,aAAe,WAC7B,EAAQ,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,EAAK,GAAI,CACjB,QAAS,EAAS,cAAc,EAAM,KAAM,EAAK,CACjD,KAAM,EAAK,KACZ,CAAC,CAEJ,IAAK,GAAM,CAAC,EAAQ,KAAU,EAAM,SAAS,CAAE,CAC7C,IAAM,EAAO,KAAK,MAAM,IAAI,EAAO,CAE7B,EADW,KAAK,YAAY,EAAK,CACd,WAAW,EAAM,QAAS,EAAM,KAAM,EAAK,CAChE,EACF,EAAM,IAAI,EAAK,GAAI,CAAE,GAAG,EAAO,UAAS,CAAC,CAEzC,EAAM,OAAO,EAAK,GAAG,CAGzB,OAAO,MAAM,KAAK,EAAM,QAAQ,CAAC,CAGnC,gBAAgB,EAA2C,CACzD,IAAM,EAAU,KAAK,kBAAkB,IAAI,EAAS,CACpD,OAAO,MAAM,KAAK,GAAW,EAAE,CAAC,CAAC,IAAK,GAAW,KAAK,MAAM,IAAI,EAAO,CAAE,CAG3E,qBAA6B,EAA+B,CAC1D,GAAI,EAAO,SACT,MAAO,CAAC,IAAsB,EAAO,SAAS,CAEhD,IAAM,EAAW,EAAO,cAAc,EAAO,CAI7C,OAHI,EACK,EAAS,MAAM,IAAI,CAErB,CAAC,KAAK,gBAAgB"}
{"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 exportFrom: [],\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 exportFrom: symbol.exportFrom ?? [],\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 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 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,YACZ,EAAmB,EAAK,cAAc,IAAI,EAAO,GAAG,CAC1D,GAAI,EAAkB,CACpB,IAAM,EAAyB,EAAW,cAAc,IAAI,EAAO,GAAG,CAClE,EACE,IAA2B,IAC7B,EAAO,EACP,EAAQ,QAAQ,GAAQ,GAEjB,EAAO,MAAQ,IAAqB,EAAO,OACpD,EAAO,EAAO,KACd,EAAQ,QAAQ,GAAQ,EAAO,aAGnC,EAAM,KAAK,EAAK,CACZ,EAAO,OAAS,QAClB,EAAU,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ts
//#region src/files/types.d.ts
/**
* Selector array used to reference resources. We don't enforce
* uniqueness, but in practice it's desirable.
* Selector array used to reference files.
*
* @example ["zod", "#/components/schemas/Foo"]
* @example ["foo", "bar"]
*/
type ISelector = ReadonlyArray<string>;
//#endregion
//#region src/files/types.d.ts
type IFileSelector = ReadonlyArray<string>;
type IFileIdentifier = number | IFileSelector;
interface IFileIn {

@@ -180,8 +178,7 @@ /**

/**
* Selector array used to select this file. It doesn't have to be
* unique, but in practice it might be desirable.
* Selector array used to select this file.
*
* @example ["zod", "#/components/schemas/Foo"]
* @example ["foo", "bar"]
*/
readonly selector?: ISelector;
readonly selector?: IFileSelector;
}

@@ -217,8 +214,8 @@ interface IFileOut extends IFileIn {

/**
* Get a file by its ID.
* Get a file.
*
* @param fileIdOrSelector File ID or selector to reference.
* @param identifier File identifier to reference.
* @returns The file, or undefined if not found.
*/
get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
get(identifier: IFileIdentifier): IFileOut | undefined;
/**

@@ -233,13 +230,13 @@ * Returns the current file ID and increments it.

*
* @param fileIdOrSelector File ID or selector to check.
* @param identifier File identifier to check.
* @returns True if the file is registered, false otherwise.
*/
isRegistered(fileIdOrSelector: number | ISelector): boolean;
isRegistered(identifier: IFileIdentifier): boolean;
/**
* Returns a file by ID or selector, registering it if it doesn't exist.
* Returns a file by identifier, registering it if it doesn't exist.
*
* @param fileIdOrSelector File ID or selector to reference.
* @param identifier File identifier to reference.
* @returns The referenced or newly registered file.
*/
reference(fileIdOrSelector: number | ISelector): IFileOut;
reference(identifier: IFileIdentifier): IFileOut;
/**

@@ -287,2 +284,3 @@ * Get all unregistered files in the order they were referenced.

//#region src/symbols/types.d.ts
type ISymbolIdentifier = number | ISymbolMeta;
interface ISymbolIn {

@@ -319,2 +317,10 @@ /**

/**
* Kind of import if this symbol represents an import.
*/
readonly importKind?: 'namespace' | 'default' | 'named';
/**
* Kind of symbol.
*/
readonly kind?: 'type';
/**
* Arbitrary metadata about the symbol.

@@ -324,12 +330,3 @@ *

*/
readonly meta?: ISymbolMeta & {
/**
* Kind of import if this symbol represents an import.
*/
importKind?: 'namespace' | 'default' | 'named';
/**
* Kind of symbol.
*/
kind?: 'type';
};
readonly meta?: ISymbolMeta;
/**

@@ -348,9 +345,2 @@ * The desired name for the symbol within its file. If there are multiple symbols

readonly placeholder?: string;
/**
* Selector array used to select this symbol. It doesn't have to be
* unique, but in practice it might be desirable.
*
* @example ["zod", "#/components/schemas/Foo"]
*/
readonly selector?: ISelector;
}

@@ -375,8 +365,8 @@ interface ISymbolOut extends ISymbolIn {

/**
* Get a symbol by its ID.
* Get a symbol.
*
* @param symbolIdOrSelector Symbol ID or selector to reference.
* @param identifier Symbol identifier to reference.
* @returns The symbol, or undefined if not found.
*/
get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
get(identifier: ISymbolIdentifier): ISymbolOut | undefined;
/**

@@ -405,14 +395,21 @@ * Returns the value associated with a symbol ID.

*
* @param symbolIdOrSelector Symbol ID or selector to check.
* @param identifier Symbol identifier to check.
* @returns True if the symbol is registered, false otherwise.
*/
isRegistered(symbolIdOrSelector: number | ISelector): boolean;
isRegistered(identifier: ISymbolIdentifier): boolean;
/**
* Returns a symbol by ID or selector, registering it if it doesn't exist.
* Queries symbols by metadata filter.
*
* @param symbolIdOrSelector Symbol ID or selector to reference.
* @returns The referenced or newly registered symbol.
* @param filter Metadata filter to query symbols by.
* @returns Array of symbols matching the filter.
*/
reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut>;
/**
* References a symbol.
*
* @param meta Metadata filter to reference symbol by.
* @returns The referenced symbol.
*/
reference(meta: ISymbolMeta): ISymbolOut;
/**
* Register a symbol globally.

@@ -481,7 +478,7 @@ *

private values;
get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
get(identifier: IFileIdentifier): IFileOut | undefined;
get id(): number;
private idOrSelector;
isRegistered(fileIdOrSelector: number | ISelector): boolean;
reference(fileIdOrSelector: number | ISelector): IFileOut;
private identifierToFile;
isRegistered(identifier: IFileIdentifier): boolean;
reference(identifier: IFileIdentifier): IFileOut;
referenced(): IterableIterator<IFileOut>;

@@ -580,18 +577,30 @@ register(file: IFileIn): IFileOut;

//#region src/symbols/registry.d.ts
type SymbolId = number;
declare class SymbolRegistry implements ISymbolRegistry {
private _id;
private indices;
private nodes;
private queryCache;
private queryCacheDependencies;
private registerOrder;
private selectorToId;
private stubCache;
private stubs;
private values;
get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
getValue(symbolId: number): unknown;
hasValue(symbolId: number): boolean;
get id(): number;
private idOrSelector;
isRegistered(symbolIdOrSelector: number | ISelector): boolean;
reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
get(identifier: ISymbolIdentifier): ISymbolOut | undefined;
getValue(symbolId: SymbolId): unknown;
hasValue(symbolId: SymbolId): boolean;
get id(): SymbolId;
isRegistered(identifier: ISymbolIdentifier): boolean;
query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut>;
reference(meta: ISymbolMeta): ISymbolOut;
register(symbol: ISymbolIn): ISymbolOut;
registered(): IterableIterator<ISymbolOut>;
setValue(symbolId: number, value: unknown): Map<number, unknown>;
setValue(symbolId: SymbolId, value: unknown): Map<SymbolId, unknown>;
private buildCacheKey;
private buildIndexKeySpace;
private indexSymbol;
private invalidateCache;
private isSubset;
private replaceStubs;
private serializeIndexEntry;
}

@@ -630,3 +639,3 @@ //#endregion

//#endregion
export { type IBiMap as BiMap, type IBinding as Binding, type IFileOut as File, type IFileIn as FileIn, type IProject, type IOutput as Output, Project, type IProjectRenderMeta as ProjectRenderMeta, type IRenderer as Renderer, type ISelector as Selector, type ISymbolOut as Symbol, type ISymbolIn as SymbolIn, type ISymbolMeta as SymbolMeta, createBinding, mergeBindings, renderIds };
export { type IBiMap as BiMap, type IBinding as Binding, type IFileOut as File, type IFileIdentifier as FileIdentifier, type IFileIn as FileIn, type IProject, type IOutput as Output, Project, type IProjectRenderMeta as ProjectRenderMeta, type IRenderer as Renderer, type ISymbolOut as Symbol, type ISymbolIdentifier as SymbolIdentifier, type ISymbolIn as SymbolIn, type ISymbolMeta as SymbolMeta, createBinding, mergeBindings, renderIds };
//# sourceMappingURL=index.d.cts.map

@@ -138,12 +138,10 @@ //#region src/bimap/types.d.ts

//#endregion
//#region src/selectors/types.d.ts
//#region src/files/types.d.ts
/**
* Selector array used to reference resources. We don't enforce
* uniqueness, but in practice it's desirable.
* Selector array used to reference files.
*
* @example ["zod", "#/components/schemas/Foo"]
* @example ["foo", "bar"]
*/
type ISelector = ReadonlyArray<string>;
//#endregion
//#region src/files/types.d.ts
type IFileSelector = ReadonlyArray<string>;
type IFileIdentifier = number | IFileSelector;
interface IFileIn {

@@ -180,8 +178,7 @@ /**

/**
* Selector array used to select this file. It doesn't have to be
* unique, but in practice it might be desirable.
* Selector array used to select this file.
*
* @example ["zod", "#/components/schemas/Foo"]
* @example ["foo", "bar"]
*/
readonly selector?: ISelector;
readonly selector?: IFileSelector;
}

@@ -217,8 +214,8 @@ interface IFileOut extends IFileIn {

/**
* Get a file by its ID.
* Get a file.
*
* @param fileIdOrSelector File ID or selector to reference.
* @param identifier File identifier to reference.
* @returns The file, or undefined if not found.
*/
get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
get(identifier: IFileIdentifier): IFileOut | undefined;
/**

@@ -233,13 +230,13 @@ * Returns the current file ID and increments it.

*
* @param fileIdOrSelector File ID or selector to check.
* @param identifier File identifier to check.
* @returns True if the file is registered, false otherwise.
*/
isRegistered(fileIdOrSelector: number | ISelector): boolean;
isRegistered(identifier: IFileIdentifier): boolean;
/**
* Returns a file by ID or selector, registering it if it doesn't exist.
* Returns a file by identifier, registering it if it doesn't exist.
*
* @param fileIdOrSelector File ID or selector to reference.
* @param identifier File identifier to reference.
* @returns The referenced or newly registered file.
*/
reference(fileIdOrSelector: number | ISelector): IFileOut;
reference(identifier: IFileIdentifier): IFileOut;
/**

@@ -287,2 +284,3 @@ * Get all unregistered files in the order they were referenced.

//#region src/symbols/types.d.ts
type ISymbolIdentifier = number | ISymbolMeta;
interface ISymbolIn {

@@ -319,2 +317,10 @@ /**

/**
* Kind of import if this symbol represents an import.
*/
readonly importKind?: 'namespace' | 'default' | 'named';
/**
* Kind of symbol.
*/
readonly kind?: 'type';
/**
* Arbitrary metadata about the symbol.

@@ -324,12 +330,3 @@ *

*/
readonly meta?: ISymbolMeta & {
/**
* Kind of import if this symbol represents an import.
*/
importKind?: 'namespace' | 'default' | 'named';
/**
* Kind of symbol.
*/
kind?: 'type';
};
readonly meta?: ISymbolMeta;
/**

@@ -348,9 +345,2 @@ * The desired name for the symbol within its file. If there are multiple symbols

readonly placeholder?: string;
/**
* Selector array used to select this symbol. It doesn't have to be
* unique, but in practice it might be desirable.
*
* @example ["zod", "#/components/schemas/Foo"]
*/
readonly selector?: ISelector;
}

@@ -375,8 +365,8 @@ interface ISymbolOut extends ISymbolIn {

/**
* Get a symbol by its ID.
* Get a symbol.
*
* @param symbolIdOrSelector Symbol ID or selector to reference.
* @param identifier Symbol identifier to reference.
* @returns The symbol, or undefined if not found.
*/
get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
get(identifier: ISymbolIdentifier): ISymbolOut | undefined;
/**

@@ -405,14 +395,21 @@ * Returns the value associated with a symbol ID.

*
* @param symbolIdOrSelector Symbol ID or selector to check.
* @param identifier Symbol identifier to check.
* @returns True if the symbol is registered, false otherwise.
*/
isRegistered(symbolIdOrSelector: number | ISelector): boolean;
isRegistered(identifier: ISymbolIdentifier): boolean;
/**
* Returns a symbol by ID or selector, registering it if it doesn't exist.
* Queries symbols by metadata filter.
*
* @param symbolIdOrSelector Symbol ID or selector to reference.
* @returns The referenced or newly registered symbol.
* @param filter Metadata filter to query symbols by.
* @returns Array of symbols matching the filter.
*/
reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut>;
/**
* References a symbol.
*
* @param meta Metadata filter to reference symbol by.
* @returns The referenced symbol.
*/
reference(meta: ISymbolMeta): ISymbolOut;
/**
* Register a symbol globally.

@@ -481,7 +478,7 @@ *

private values;
get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
get(identifier: IFileIdentifier): IFileOut | undefined;
get id(): number;
private idOrSelector;
isRegistered(fileIdOrSelector: number | ISelector): boolean;
reference(fileIdOrSelector: number | ISelector): IFileOut;
private identifierToFile;
isRegistered(identifier: IFileIdentifier): boolean;
reference(identifier: IFileIdentifier): IFileOut;
referenced(): IterableIterator<IFileOut>;

@@ -580,18 +577,30 @@ register(file: IFileIn): IFileOut;

//#region src/symbols/registry.d.ts
type SymbolId = number;
declare class SymbolRegistry implements ISymbolRegistry {
private _id;
private indices;
private nodes;
private queryCache;
private queryCacheDependencies;
private registerOrder;
private selectorToId;
private stubCache;
private stubs;
private values;
get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
getValue(symbolId: number): unknown;
hasValue(symbolId: number): boolean;
get id(): number;
private idOrSelector;
isRegistered(symbolIdOrSelector: number | ISelector): boolean;
reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
get(identifier: ISymbolIdentifier): ISymbolOut | undefined;
getValue(symbolId: SymbolId): unknown;
hasValue(symbolId: SymbolId): boolean;
get id(): SymbolId;
isRegistered(identifier: ISymbolIdentifier): boolean;
query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut>;
reference(meta: ISymbolMeta): ISymbolOut;
register(symbol: ISymbolIn): ISymbolOut;
registered(): IterableIterator<ISymbolOut>;
setValue(symbolId: number, value: unknown): Map<number, unknown>;
setValue(symbolId: SymbolId, value: unknown): Map<SymbolId, unknown>;
private buildCacheKey;
private buildIndexKeySpace;
private indexSymbol;
private invalidateCache;
private isSubset;
private replaceStubs;
private serializeIndexEntry;
}

@@ -630,3 +639,3 @@ //#endregion

//#endregion
export { type IBiMap as BiMap, type IBinding as Binding, type IFileOut as File, type IFileIn as FileIn, type IProject, type IOutput as Output, Project, type IProjectRenderMeta as ProjectRenderMeta, type IRenderer as Renderer, type ISelector as Selector, type ISymbolOut as Symbol, type ISymbolIn as SymbolIn, type ISymbolMeta as SymbolMeta, createBinding, mergeBindings, renderIds };
export { type IBiMap as BiMap, type IBinding as Binding, type IFileOut as File, type IFileIdentifier as FileIdentifier, type IFileIn as FileIn, type IProject, type IOutput as Output, Project, type IProjectRenderMeta as ProjectRenderMeta, type IRenderer as Renderer, type ISymbolOut as Symbol, type ISymbolIdentifier as SymbolIdentifier, type ISymbolIn as SymbolIn, type ISymbolMeta as SymbolMeta, createBinding, mergeBindings, renderIds };
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

import e from"node:path";const t=({file:e,modulePath:t,symbol:n,symbolFile:r})=>{let i=[],a=[],o={aliases:{},from:t};if(n.meta?.importKind&&(n.meta.importKind===`default`?(o.defaultBinding=n.placeholder,n.meta.kind===`type`&&(o.typeDefaultBinding=!0)):n.meta.importKind===`namespace`&&(o.namespaceBinding=n.placeholder,n.meta.kind===`type`&&(o.typeNamespaceBinding=!0))),n.meta?.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.meta?.kind===`type`&&a.push(t)}for(let e of a)i.includes(e)||i.push(e);return o.names=i,o.typeNames=a,o},n=(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 r=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]()}},i=class{_id=0;referenceOrder=new Set;registerOrder=new Set;selectorToId=new Map;values=new Map;get(e){let t=this.idOrSelector(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++}idOrSelector(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.idOrSelector(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,i=e.selector===void 0?void 0:JSON.stringify(e.selector);if(i){let e=this.selectorToId.get(i);if(e!==void 0){if(n=this.values.get(e),!n)throw Error(`File with ID ${e} not found. The selector ${i} matched an ID, but there was no result. This is likely an issue with the application logic.`);if(!t)return n}}let a=n?.id===void 0?this.id:n.id;return n={...n,...e,id:a,resolvedNames:n?.resolvedNames??new r,symbols:n?.symbols??{body:[],exports:[],imports:[]}},this.values.set(a,n),t?(this.registerOrder.add(a),this.referenceOrder.has(a)&&this.referenceOrder.delete(a)):this.referenceOrder.add(a),i&&this.selectorToId.set(i,a),n}*registered(){for(let e of this.registerOrder.values())yield this.values.get(e)}};const a=e=>`_heyapi_${e}_`,o=e=>e.slice(8,-1),s=()=>new RegExp(a(`\\d+`),`g`),c=(e,t)=>e.replace(s(),e=>t(Number.parseInt(o(e),10))||e);var l=class{_id=0;nodes=new Map;registerOrder=new Set;selectorToId=new Map;values=new Map;get(e){let t=this.idOrSelector(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)}}getValue(e){return this.nodes.get(e)}hasValue(e){return this.nodes.has(e)}get id(){return this._id++}idOrSelector(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.idOrSelector(e);return this.register(t)}register(e){if(e.id!==void 0){let t=this.values.get(e.id);if(!t)throw Error(`Symbol with ID ${e.id} not found. To register a new symbol, 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(`Symbol 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,o=n?.exportFrom?[...n.exportFrom]:[];return e.exportFrom&&o.push(...e.exportFrom),n={...n,...e,exportFrom:o,id:i,placeholder:n?.placeholder??e.placeholder??a(String(i))},this.values.set(i,n),t&&this.registerOrder.add(i),r&&this.selectorToId.set(r,i),n}*registered(){for(let e of this.registerOrder.values())yield this.values.get(e)}setValue(e,t){return this.nodes.set(e,t)}},u=class{symbolIdToFileIds=new Map;defaultFileName;files=new i;fileName;renderers={};root;symbols=new l;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;r.add(n.id),this.symbolIdToFileIds.set(e.id,r);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 t of this.files.referenced()){if(!t.selector)continue;if(t.selector[0]===`@`){let n=t.selector[1];if(!n){this.files.register({external:!0,selector:t.selector});continue}let r=e.extname(n);if(!r){this.files.register({external:!0,path:n,selector:t.selector});continue}this.files.register({extension:r,external:!0,path:n,selector:t.selector});continue}let n=t.selector.slice(0,-1),r=t.selector[t.selector.length-1];r=this.fileName?.(r)||r,this.files.register({extension:`.ts`,name:r,path:e.resolve(this.root,...n,`${r}.ts`),selector:t.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]}};export{u as Project,t as createBinding,n as mergeBindings,c as renderIds};
import e from"node:path";const t=({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},n=(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 r=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]()}},i=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,i=e.selector===void 0?void 0:JSON.stringify(e.selector);if(i){let e=this.selectorToId.get(i);if(e!==void 0){if(n=this.values.get(e),!n)throw Error(`File with ID ${e} not found. The selector ${i} matched an ID, but there was no result. This is likely an issue with the application logic.`);if(!t)return n}}let a=n?.id===void 0?this.id:n.id;return n={...n,...e,id:a,resolvedNames:n?.resolvedNames??new r,symbols:n?.symbols??{body:[],exports:[],imports:[]}},this.values.set(a,n),t?(this.registerOrder.add(a),this.referenceOrder.has(a)&&this.referenceOrder.delete(a)):this.referenceOrder.add(a),i&&this.selectorToId.set(i,a),n}*registered(){for(let e of this.registerOrder.values())yield this.values.get(e)}};const a=e=>`_heyapi_${e}_`,o=e=>e.slice(8,-1),s=()=>new RegExp(a(`\\d+`),`g`),c=(e,t)=>e.replace(s(),e=>t(Number.parseInt(o(e),10))||e);var l=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,o={exportFrom:[],id:i,meta:e,placeholder:a(String(i))};return this.values.set(o.id,o),this.stubs.add(o.id),this.stubCache.set(n,o.id),o}register(e){let t=e.id===void 0?this.id:e.id,n={...e,exportFrom:e.exportFrom??[],id:t,placeholder:e.placeholder??a(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])}`}},u=class{symbolIdToFileIds=new Map;defaultFileName;files=new i;fileName;renderers={};root;symbols=new l;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;r.add(n.id),this.symbolIdToFileIds.set(e.id,r);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 t of this.files.referenced()){if(!t.selector)continue;if(t.selector[0]===`@`){let n=t.selector[1];if(!n){this.files.register({external:!0,selector:t.selector});continue}let r=e.extname(n);if(!r){this.files.register({external:!0,path:n,selector:t.selector});continue}this.files.register({extension:r,external:!0,path:n,selector:t.selector});continue}let n=t.selector.slice(0,-1),r=t.selector[t.selector.length-1];r=this.fileName?.(r)||r,this.files.register({extension:`.ts`,name:r,path:e.resolve(this.root,...n,`${r}.ts`),selector:t.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]}};export{u as Project,t as createBinding,n as mergeBindings,c as renderIds};
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","names":["names: Array<string>","typeNames: Array<string>","binding: IBinding & Pick<Required<IBinding>, 'aliases' | 'from'>","result","result: IFileOut | undefined","id","result","result: ISymbolOut | undefined","id","exportFrom: Array<string>","extension","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.meta?.importKind) {\n if (symbol.meta.importKind === 'default') {\n binding.defaultBinding = symbol.placeholder;\n if (symbol.meta.kind === 'type') {\n binding.typeDefaultBinding = true;\n }\n } else if (symbol.meta.importKind === 'namespace') {\n binding.namespaceBinding = symbol.placeholder;\n if (symbol.meta.kind === 'type') {\n binding.typeNamespaceBinding = true;\n }\n }\n }\n // default to named binding\n if (\n symbol.meta?.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.meta?.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 { ISelector } from '../selectors/types';\nimport type { IFileIn, IFileOut, IFileRegistry } 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(fileIdOrSelector: number | ISelector): IFileOut | undefined {\n const symbol = this.idOrSelector(fileIdOrSelector);\n\n if (symbol.id !== undefined) {\n return this.values.get(symbol.id);\n }\n\n const selector =\n symbol.selector !== undefined\n ? JSON.stringify(symbol.selector)\n : 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 idOrSelector(\n symbolIdOrSelector: number | ISelector,\n ): Pick<IFileIn, 'id' | 'selector'> {\n return typeof symbolIdOrSelector === 'number'\n ? { id: symbolIdOrSelector }\n : { selector: symbolIdOrSelector };\n }\n\n isRegistered(fileIdOrSelector: number | ISelector): boolean {\n const file = this.get(fileIdOrSelector);\n return file ? this.registerOrder.has(file.id) : false;\n }\n\n reference(fileIdOrSelector: number | ISelector): IFileOut {\n const file = this.idOrSelector(fileIdOrSelector);\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 { wrapId } from '../renderer/utils';\nimport type { ISelector } from '../selectors/types';\nimport type { ISymbolIn, ISymbolOut, ISymbolRegistry } from './types';\n\nexport class SymbolRegistry implements ISymbolRegistry {\n private _id: number = 0;\n private nodes: Map<number, unknown> = new Map();\n private registerOrder: Set<number> = new Set();\n private selectorToId: Map<string, number> = new Map();\n private values: Map<number, ISymbolOut> = new Map();\n\n get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined {\n const symbol = this.idOrSelector(symbolIdOrSelector);\n\n if (symbol.id !== undefined) {\n return this.values.get(symbol.id);\n }\n\n const selector =\n symbol.selector !== undefined\n ? JSON.stringify(symbol.selector)\n : 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 getValue(symbolId: number): unknown {\n return this.nodes.get(symbolId);\n }\n\n hasValue(symbolId: number): boolean {\n return this.nodes.has(symbolId);\n }\n\n get id(): number {\n return this._id++;\n }\n\n private idOrSelector(\n symbolIdOrSelector: number | ISelector,\n ): Pick<ISymbolIn, 'id' | 'selector'> {\n return typeof symbolIdOrSelector === 'number'\n ? { id: symbolIdOrSelector }\n : { selector: symbolIdOrSelector };\n }\n\n isRegistered(symbolIdOrSelector: number | ISelector): boolean {\n const symbol = this.get(symbolIdOrSelector);\n return symbol ? this.registerOrder.has(symbol.id) : false;\n }\n\n reference(symbolIdOrSelector: number | ISelector): ISymbolOut {\n const symbol = this.idOrSelector(symbolIdOrSelector);\n return this.register(symbol);\n }\n\n register(symbol: ISymbolIn): ISymbolOut {\n if (symbol.id !== undefined) {\n const result = this.values.get(symbol.id);\n if (!result) {\n throw new Error(\n `Symbol with ID ${symbol.id} not found. To register a new symbol, leave the ID undefined.`,\n );\n }\n return result;\n }\n\n const hasOtherKeys = Object.keys(symbol).some(\n (key) => !['id', 'selector'].includes(key),\n );\n\n let result: ISymbolOut | undefined;\n\n const selector =\n symbol.selector !== undefined\n ? JSON.stringify(symbol.selector)\n : 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 `Symbol 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 const exportFrom: Array<string> = result?.exportFrom\n ? [...result.exportFrom]\n : [];\n if (symbol.exportFrom) {\n exportFrom.push(...symbol.exportFrom);\n }\n result = {\n ...result,\n ...symbol, // clone to avoid mutation\n exportFrom,\n id,\n placeholder:\n result?.placeholder ?? symbol.placeholder ?? wrapId(String(id)),\n };\n this.values.set(id, result);\n\n if (hasOtherKeys) {\n this.registerOrder.add(id);\n }\n\n if (selector) {\n this.selectorToId.set(selector, id);\n }\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: number, value: unknown): Map<number, unknown> {\n return this.nodes.set(symbolId, value);\n }\n}\n","import path from 'node:path';\n\nimport type { IProjectRenderMeta } from '../extensions/types';\nimport { FileRegistry } from '../files/registry';\nimport type { IFileOut } from '../files/types';\nimport type { IOutput } from '../output/types';\nimport type { IRenderer } from '../renderer/types';\nimport type { ISelector } from '../selectors/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 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 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): ISelector {\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":"yBAIA,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,MAAM,aACX,EAAO,KAAK,aAAe,WAC7B,EAAQ,eAAiB,EAAO,YAC5B,EAAO,KAAK,OAAS,SACvB,EAAQ,mBAAqB,KAEtB,EAAO,KAAK,aAAe,cACpC,EAAQ,iBAAmB,EAAO,YAC9B,EAAO,KAAK,OAAS,SACvB,EAAQ,qBAAuB,MAMnC,EAAO,MAAM,aAAe,SAC3B,CAAC,EAAM,QAAU,CAAC,EAAQ,gBAAkB,CAAC,EAAQ,iBACtD,CACA,IAAI,EAAO,EAAO,YACZ,EAAmB,EAAK,cAAc,IAAI,EAAO,GAAG,CAC1D,GAAI,EAAkB,CACpB,IAAM,EAAyB,EAAW,cAAc,IAAI,EAAO,GAAG,CAClE,EACE,IAA2B,IAC7B,EAAO,EACP,EAAQ,QAAQ,GAAQ,GAEjB,EAAO,MAAQ,IAAqB,EAAO,OACpD,EAAO,EAAO,KACd,EAAQ,QAAQ,GAAQ,EAAO,aAGnC,EAAM,KAAK,EAAK,CACZ,EAAO,MAAM,OAAS,QACxB,EAAU,KAAK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IAAM,EAAW,EAAO,cAAc,EAAO,CAI7C,OAHI,EACK,EAAS,MAAM,IAAI,CAErB,CAAC,KAAK,gBAAgB"}
{"version":3,"file":"index.js","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","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 exportFrom: [],\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 exportFrom: symbol.exportFrom ?? [],\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 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 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":"yBAIA,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,E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K,CAChE,EACF,EAAM,IAAI,EAAK,GAAI,CAAE,GAAG,EAAO,UAAS,CAAC,CAEzC,EAAM,OAAO,EAAK,GAAG,CAGzB,OAAO,MAAM,KAAK,EAAM,QAAQ,CAAC,CAGnC,gBAAgB,EAA2C,CACzD,IAAM,EAAU,KAAK,kBAAkB,IAAI,EAAS,CACpD,OAAO,MAAM,KAAK,GAAW,EAAE,CAAC,CAAC,IAAK,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"}
{
"name": "@hey-api/codegen-core",
"version": "0.3.1",
"version": "0.3.2",
"description": "🧱 TypeScript framework for generating structured, multi-file source code from abstract syntax trees.",

@@ -5,0 +5,0 @@ "homepage": "https://heyapi.dev/",