@hey-api/codegen-core 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:path`);c=s(c);const l=({file:e,modulePath:t,symbol:n,symbolFile:r})=>{let i=[],a=[],o={aliases:{},from:t};if(n.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;
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:path`);c=s(c);const l=({file:e,modulePath:t,symbol:n,symbolFile:r})=>{let i=[],a=[],o={aliases:{},from:t};if(n.importKind&&(n.importKind===`default`?(o.defaultBinding=n.placeholder,n.kind===`type`&&(o.typeDefaultBinding=!0)):n.importKind===`namespace`&&(o.namespaceBinding=n.placeholder,n.kind===`type`&&(o.typeNamespaceBinding=!0))),n.importKind===`named`||!i.length&&!o.defaultBinding&&!o.namespaceBinding){let t=n.placeholder,s=e.resolvedNames.get(n.id);if(s){let e=r.resolvedNames.get(n.id);e?e!==s&&(t=e,o.aliases[t]=s):n.name&&s!==n.name&&(t=n.name,o.aliases[t]=n.placeholder)}i.push(t),n.kind===`type`&&a.push(t)}for(let e of a)i.includes(e)||i.push(e);return o.names=i,o.typeNames=a,o},u=(e,t)=>{e.aliases={...e.aliases,...t.aliases},t.defaultBinding!==void 0&&(e.defaultBinding=t.defaultBinding),e.names=[...new Set([...e.names??[],...t.names??[]])],t.namespaceBinding!==void 0&&(e.namespaceBinding=t.namespaceBinding),t.typeDefaultBinding!==void 0&&(e.typeDefaultBinding=t.typeDefaultBinding),e.typeNames=[...new Set([...e.typeNames??[],...t.typeNames??[]])],t.typeNamespaceBinding!==void 0&&(e.typeNamespaceBinding=t.typeNamespaceBinding)};var d=class{map=new Map;reverse=new Map;delete(e){let t=this.map.get(e);return t!==void 0&&this.reverse.delete(t),this.map.delete(e)}deleteValue(e){let t=this.reverse.get(e);return t!==void 0&&this.map.delete(t),this.reverse.delete(e)}entries(){return this.map.entries()}get(e){return this.map.get(e)}getKey(e){return this.reverse.get(e)}hasKey(e){return this.map.has(e)}hasValue(e){return this.reverse.has(e)}keys(){return this.map.keys()}set(e,t){let n=this.map.get(e);n!==void 0&&n!==t&&this.reverse.delete(n);let r=this.reverse.get(t);return r!==void 0&&r!==e&&this.map.delete(r),this.map.set(e,t),this.reverse.set(t,e),this}get size(){return this.map.size}values(){return this.map.values()}[Symbol.iterator](){return this.map[Symbol.iterator]()}},f=class{_id=0;referenceOrder=new Set;registerOrder=new Set;selectorToId=new Map;values=new Map;get(e){let t=this.identifierToFile(e);if(t.id!==void 0)return this.values.get(t.id);let n=t.selector===void 0?void 0:JSON.stringify(t.selector);if(n){let e=this.selectorToId.get(n);if(e!==void 0)return this.values.get(e)}}get id(){return this._id++}identifierToFile(e){return typeof e==`number`?{id:e}:{selector:e}}isRegistered(e){let t=this.get(e);return t?this.registerOrder.has(t.id):!1}reference(e){let t=this.identifierToFile(e);return this.register(t)}*referenced(){for(let e of this.referenceOrder.values())yield this.values.get(e)}register(e){if(e.id!==void 0){let t=this.values.get(e.id);if(!t)throw Error(`File with ID ${e.id} not found. To register a new file, leave the ID undefined.`);return t}let t=Object.keys(e).some(e=>![`id`,`selector`].includes(e)),n,r=e.selector===void 0?void 0:JSON.stringify(e.selector);if(r){let e=this.selectorToId.get(r);if(e!==void 0){if(n=this.values.get(e),!n)throw Error(`File with ID ${e} not found. The selector ${r} matched an ID, but there was no result. This is likely an issue with the application logic.`);if(!t)return n}}let i=n?.id===void 0?this.id:n.id;return n={...n,...e,id:i,resolvedNames:n?.resolvedNames??new d,symbols:n?.symbols??{body:[],exports:[],imports:[]}},this.values.set(i,n),t?(this.registerOrder.add(i),this.referenceOrder.has(i)&&this.referenceOrder.delete(i)):this.referenceOrder.add(i),r&&this.selectorToId.set(r,i),n}*registered(){for(let e of this.registerOrder.values())yield this.values.get(e)}};const p=e=>`_heyapi_${e}_`,m=e=>e.slice(8,-1),h=()=>new RegExp(p(`\\d+`),`g`),g=(e,t)=>e.replace(h(),e=>t(Number.parseInt(m(e),10))||e);var _=class{_id=0;indices=new Map;nodes=new Map;queryCache=new Map;queryCacheDependencies=new Map;registerOrder=new Set;stubCache=new Map;stubs=new Set;values=new Map;get(e){return typeof e==`number`?this.values.get(e):this.query(e)[0]}getValue(e){return this.nodes.get(e)}hasValue(e){return this.nodes.has(e)}get id(){return this._id++}isRegistered(e){let t=this.get(e);return t?this.registerOrder.has(t.id):!1}query(e){let t=this.buildCacheKey(e),n=this.queryCache.get(t);if(n)return n.map(e=>this.values.get(e));let r=[],i=this.buildIndexKeySpace(e),a=new Set,o=!1;for(let e of i){a.add(this.serializeIndexEntry(e));let t=this.indices.get(e[0]);if(!t){o=!0;break}let n=t.get(e[1]);if(!n){o=!0;break}r.push(n)}if(o||!r.length)return this.queryCacheDependencies.set(t,a),this.queryCache.set(t,[]),[];let s=new Set(r[0]);for(let e of r.slice(1))s=new Set([...s].filter(t=>e.has(t)));let c=[...s];return this.queryCacheDependencies.set(t,a),this.queryCache.set(t,c),c.map(e=>this.values.get(e))}reference(e){let[t]=this.query(e);if(t)return t;let n=this.buildCacheKey(e),r=this.stubCache.get(n);if(r!==void 0)return this.values.get(r);let i=this.id,a={id:i,meta:e,placeholder:p(String(i))};return this.values.set(a.id,a),this.stubs.add(a.id),this.stubCache.set(n,a.id),a}register(e){let t=e.id===void 0?this.id:e.id,n={...e,id:t,placeholder:e.placeholder??p(String(t))};if(this.values.set(n.id,n),this.registerOrder.add(n.id),n.meta){let e=this.buildIndexKeySpace(n.meta);this.indexSymbol(n.id,e),this.invalidateCache(e),this.replaceStubs(n,e)}return n}*registered(){for(let e of this.registerOrder.values())yield this.values.get(e)}setValue(e,t){return this.nodes.set(e,t)}buildCacheKey(e){return this.buildIndexKeySpace(e).map(e=>this.serializeIndexEntry(e)).sort().join(`|`)}buildIndexKeySpace(e,t=``){let n=[];for(let[r,i]of Object.entries(e)){let e=t?`${t}.${r}`:r;i&&typeof i==`object`&&!Array.isArray(i)?n.push(...this.buildIndexKeySpace(i,e)):n.push([e,i])}return n}indexSymbol(e,t){for(let[n,r]of t){this.indices.has(n)||this.indices.set(n,new Map);let t=this.indices.get(n),i=t.get(r)??new Set;i.add(e),t.set(r,i)}}invalidateCache(e){let t=e.map(e=>this.serializeIndexEntry(e));for(let[e,n]of this.queryCacheDependencies.entries())for(let r of t)if(n.has(r)){this.queryCacheDependencies.delete(e),this.queryCache.delete(e);break}}isSubset(e,t){let n=new Map(t);for(let[t,r]of e)if(!n.has(t)||n.get(t)!==r)return!1;return!0}replaceStubs(e,t){for(let n of this.stubs.values()){let r=this.values.get(n);if(r?.meta&&this.isSubset(this.buildIndexKeySpace(r.meta),t)){let t=this.buildCacheKey(r.meta);this.stubCache.delete(t),this.values.set(n,Object.assign(r,e)),this.stubs.delete(n)}}}serializeIndexEntry(e){return`${e[0]}:${JSON.stringify(e[1])}`}};const v=`@`;var y=class{symbolIdToFileIds=new Map;defaultFileName;files=new f;fileName;renderers={};root;symbols=new _;constructor({defaultFileName:e,fileName:t,renderers:n,root:r}){this.defaultFileName=e??`main`,this.fileName=typeof t==`string`?()=>t:t,this.renderers=n,this.root=r}getRenderer(e){return e.extension?this.renderers[e.extension]:void 0}prepareFiles(){for(let e of this.symbols.registered()){let t=this.symbolToFileSelector(e),n=this.files.reference(t);n.symbols.body.push(e.id);let r=this.symbolIdToFileIds.get(e.id)??new Set;if(r.add(n.id),this.symbolIdToFileIds.set(e.id,r),e.exportFrom)for(let t of e.exportFrom){let r=[t],i=this.files.reference(r);i.id!==n.id&&i.symbols.exports.push(e.id)}}for(let e of this.files.referenced()){if(!e.selector)continue;if(e.selector[0]===`@`){let t=e.selector[1];if(!t){this.files.register({external:!0,selector:e.selector});continue}let n=c.default.extname(t);if(!n){this.files.register({external:!0,path:t,selector:e.selector});continue}this.files.register({extension:n,external:!0,path:t,selector:e.selector});continue}let t=e.selector.slice(0,-1),n=e.selector[e.selector.length-1];n=this.fileName?.(n)||n,this.files.register({extension:`.ts`,name:n,path:c.default.resolve(this.root,...t,`${n}.ts`),selector:e.selector})}}render(e){this.prepareFiles();let t=new Map;for(let n of this.files.registered()){if(n.external||!n.path)continue;let r=this.getRenderer(n);r&&t.set(n.id,{content:r.renderSymbols(n,this,e),path:n.path})}for(let[n,r]of t.entries()){let i=this.files.get(n),a=this.getRenderer(i).renderFile(r.content,i,this,e);a?t.set(i.id,{...r,content:a}):t.delete(i.id)}return Array.from(t.values())}symbolIdToFiles(e){let t=this.symbolIdToFileIds.get(e);return Array.from(t??[]).map(e=>this.files.get(e))}symbolToFileSelector(e){if(e.external)return[`@`,e.external];let t=e.getFilePath?.(e);return t?t.split(`/`):[this.defaultFileName]}};exports.Project=y,exports.createBinding=l,exports.mergeBindings=u,exports.renderIds=g;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["names: Array<string>","typeNames: Array<string>","binding: IBinding & Pick<Required<IBinding>, 'aliases' | 'from'>","result","result: IFileOut | undefined","id","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,eAAiB,EAAO,YAC5B,EAAO,KAAK,OAAS,SACvB,EAAQ,mBAAqB,KAEtB,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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"}
1
+ {"version":3,"file":"index.cjs","names":["names: Array<string>","typeNames: Array<string>","binding: IBinding & Pick<Required<IBinding>, 'aliases' | 'from'>","result","result: IFileOut | undefined","id","sets: Array<Set<SymbolId>>","stub: ISymbolOut","result: ISymbolOut","entries: Array<IndexEntry>","path","extension","path","files: Map<number, IOutput>"],"sources":["../src/bindings/utils.ts","../src/bimap/bimap.ts","../src/files/registry.ts","../src/renderer/utils.ts","../src/symbols/registry.ts","../src/project/project.ts"],"sourcesContent":["import type { IFileOut } from '../files/types';\nimport type { ISymbolOut } from '../symbols/types';\nimport type { IBinding } from './types';\n\nexport const createBinding = ({\n file,\n modulePath,\n symbol,\n symbolFile,\n}: {\n file: IFileOut;\n modulePath: string;\n symbol: ISymbolOut;\n symbolFile: IFileOut;\n}): IBinding => {\n const names: Array<string> = [];\n const typeNames: Array<string> = [];\n const binding: IBinding & Pick<Required<IBinding>, 'aliases' | 'from'> = {\n aliases: {},\n from: modulePath,\n };\n if (symbol.importKind) {\n if (symbol.importKind === 'default') {\n binding.defaultBinding = symbol.placeholder;\n if (symbol.kind === 'type') {\n binding.typeDefaultBinding = true;\n }\n } else if (symbol.importKind === 'namespace') {\n binding.namespaceBinding = symbol.placeholder;\n if (symbol.kind === 'type') {\n binding.typeNamespaceBinding = true;\n }\n }\n }\n // default to named binding\n if (\n symbol.importKind === 'named' ||\n (!names.length && !binding.defaultBinding && !binding.namespaceBinding)\n ) {\n let name = symbol.placeholder;\n const fileResolvedName = file.resolvedNames.get(symbol.id);\n if (fileResolvedName) {\n const symbolFileResolvedName = symbolFile.resolvedNames.get(symbol.id);\n if (symbolFileResolvedName) {\n if (symbolFileResolvedName !== fileResolvedName) {\n name = symbolFileResolvedName;\n binding.aliases[name] = fileResolvedName;\n }\n } else if (symbol.name && fileResolvedName !== symbol.name) {\n name = symbol.name;\n binding.aliases[name] = symbol.placeholder;\n }\n }\n names.push(name);\n if (symbol.kind === 'type') {\n typeNames.push(name);\n }\n }\n // cast type names to names to allow for cleaner API,\n // otherwise users would have to define the same values twice\n for (const typeName of typeNames) {\n if (!names.includes(typeName)) {\n names.push(typeName);\n }\n }\n binding.names = names;\n binding.typeNames = typeNames;\n return binding;\n};\n\nexport const mergeBindings = (target: IBinding, source: IBinding): void => {\n target.aliases = { ...target.aliases, ...source.aliases };\n if (source.defaultBinding !== undefined) {\n target.defaultBinding = source.defaultBinding;\n }\n target.names = [\n ...new Set([...(target.names ?? []), ...(source.names ?? [])]),\n ];\n if (source.namespaceBinding !== undefined) {\n target.namespaceBinding = source.namespaceBinding;\n }\n if (source.typeDefaultBinding !== undefined) {\n target.typeDefaultBinding = source.typeDefaultBinding;\n }\n target.typeNames = [\n ...new Set([...(target.typeNames ?? []), ...(source.typeNames ?? [])]),\n ];\n if (source.typeNamespaceBinding !== undefined) {\n target.typeNamespaceBinding = source.typeNamespaceBinding;\n }\n};\n","import type { IBiMap } from './types';\n\nexport class BiMap<Key, Value> implements IBiMap<Key, Value> {\n private map = new Map<Key, Value>();\n private reverse = new Map<Value, Key>();\n\n delete(key: Key): boolean {\n const value = this.map.get(key);\n if (value !== undefined) {\n this.reverse.delete(value);\n }\n return this.map.delete(key);\n }\n\n deleteValue(value: Value): boolean {\n const key = this.reverse.get(value);\n if (key !== undefined) {\n this.map.delete(key);\n }\n return this.reverse.delete(value);\n }\n\n entries(): IterableIterator<[Key, Value]> {\n return this.map.entries();\n }\n\n get(key: Key): Value | undefined {\n return this.map.get(key);\n }\n\n getKey(value: Value): Key | undefined {\n return this.reverse.get(value);\n }\n\n hasKey(key: Key): boolean {\n return this.map.has(key);\n }\n\n hasValue(value: Value): boolean {\n return this.reverse.has(value);\n }\n\n keys(): IterableIterator<Key> {\n return this.map.keys();\n }\n\n set(key: Key, value: Value): this {\n const oldValue = this.map.get(key);\n if (oldValue !== undefined && oldValue !== value) {\n this.reverse.delete(oldValue);\n }\n const oldKey = this.reverse.get(value);\n if (oldKey !== undefined && oldKey !== key) {\n this.map.delete(oldKey);\n }\n this.map.set(key, value);\n this.reverse.set(value, key);\n return this;\n }\n\n get size(): number {\n return this.map.size;\n }\n\n values(): IterableIterator<Value> {\n return this.map.values();\n }\n\n [Symbol.iterator](): IterableIterator<[Key, Value]> {\n return this.map[Symbol.iterator]();\n }\n}\n","import { BiMap } from '../bimap/bimap';\nimport type {\n IFileIdentifier,\n IFileIn,\n IFileOut,\n IFileRegistry,\n} from './types';\n\nexport class FileRegistry implements IFileRegistry {\n private _id: number = 0;\n private referenceOrder: Set<number> = new Set();\n private registerOrder: Set<number> = new Set();\n private selectorToId: Map<string, number> = new Map();\n private values: Map<number, IFileOut> = new Map();\n\n get(identifier: IFileIdentifier): IFileOut | undefined {\n const file = this.identifierToFile(identifier);\n\n if (file.id !== undefined) {\n return this.values.get(file.id);\n }\n\n const selector =\n file.selector !== undefined ? JSON.stringify(file.selector) : undefined;\n\n if (selector) {\n const id = this.selectorToId.get(selector);\n if (id !== undefined) {\n return this.values.get(id);\n }\n }\n\n return;\n }\n\n get id(): number {\n return this._id++;\n }\n\n private identifierToFile(\n identifier: IFileIdentifier,\n ): Pick<IFileIn, 'id' | 'selector'> {\n return typeof identifier === 'number'\n ? { id: identifier }\n : { selector: identifier };\n }\n\n isRegistered(identifier: IFileIdentifier): boolean {\n const file = this.get(identifier);\n return file ? this.registerOrder.has(file.id) : false;\n }\n\n reference(identifier: IFileIdentifier): IFileOut {\n const file = this.identifierToFile(identifier);\n return this.register(file);\n }\n\n *referenced(): IterableIterator<IFileOut> {\n for (const id of this.referenceOrder.values()) {\n yield this.values.get(id)!;\n }\n }\n\n register(file: IFileIn): IFileOut {\n if (file.id !== undefined) {\n const result = this.values.get(file.id);\n if (!result) {\n throw new Error(\n `File with ID ${file.id} not found. To register a new file, leave the ID undefined.`,\n );\n }\n return result;\n }\n\n const hasOtherKeys = Object.keys(file).some(\n (key) => !['id', 'selector'].includes(key),\n );\n\n let result: IFileOut | undefined;\n\n const selector =\n file.selector !== undefined ? JSON.stringify(file.selector) : undefined;\n if (selector) {\n const id = this.selectorToId.get(selector);\n if (id !== undefined) {\n result = this.values.get(id);\n if (!result) {\n throw new Error(\n `File with ID ${id} not found. The selector ${selector} matched an ID, but there was no result. This is likely an issue with the application logic.`,\n );\n }\n if (!hasOtherKeys) {\n return result;\n }\n }\n }\n\n const id = result?.id !== undefined ? result.id : this.id;\n result = {\n ...result,\n ...file, // clone to avoid mutation\n id,\n resolvedNames: result?.resolvedNames ?? new BiMap(),\n symbols: result?.symbols ?? {\n body: [],\n exports: [],\n imports: [],\n },\n };\n this.values.set(id, result);\n\n if (hasOtherKeys) {\n this.registerOrder.add(id);\n if (this.referenceOrder.has(id)) {\n this.referenceOrder.delete(id);\n }\n } else {\n this.referenceOrder.add(id);\n }\n\n if (selector) {\n this.selectorToId.set(selector, id);\n }\n\n return result;\n }\n\n *registered(): IterableIterator<IFileOut> {\n for (const id of this.registerOrder.values()) {\n yield this.values.get(id)!;\n }\n }\n}\n","/**\n * Wraps an ID in namespace to avoid collisions when replacing it.\n *\n * @param symbolId Stringified symbol ID to use.\n * @returns The wrapped placeholder ID.\n */\nexport const wrapId = (symbolId: string): string => `_heyapi_${symbolId}_`;\n\n/**\n * Unwraps an ID from namespace.\n *\n * @param wrappedId The wrapped placeholder ID.\n * @returns Stringified ID to use.\n */\nconst unwrapId = (wrappedId: string): string =>\n wrappedId.slice('_heyapi_'.length, -1);\n\n/**\n * Returns a RegExp instance to match ID placeholders.\n *\n * @returns RegExp instance to match ID placeholders.\n */\nconst createPlaceholderRegExp = (): RegExp => new RegExp(wrapId('\\\\d+'), 'g');\n\n/**\n *\n * @param source The source string to replace.\n * @param replacerFn Accepts a symbol ID, returns resolved symbol name.\n * @returns The replaced source string.\n */\nexport const renderIds = (\n source: string,\n replacerFn: (symbolId: number) => string | undefined,\n): string =>\n source.replace(createPlaceholderRegExp(), (match) => {\n const symbolId = Number.parseInt(unwrapId(match), 10);\n return replacerFn(symbolId) || match;\n });\n","import type { ISymbolMeta } from '../extensions/types';\nimport { wrapId } from '../renderer/utils';\nimport type {\n ISymbolIdentifier,\n ISymbolIn,\n ISymbolOut,\n ISymbolRegistry,\n} from './types';\n\ntype IndexEntry = [string, unknown];\ntype IndexKeySpace = ReadonlyArray<IndexEntry>;\ntype QueryCacheKey = string;\ntype SymbolId = number;\n\nexport class SymbolRegistry implements ISymbolRegistry {\n private _id: SymbolId = 0;\n private indices: Map<IndexEntry[0], Map<IndexEntry[1], Set<SymbolId>>> =\n new Map();\n private nodes: Map<SymbolId, unknown> = new Map();\n private queryCache: Map<QueryCacheKey, ReadonlyArray<SymbolId>> = new Map();\n private queryCacheDependencies: Map<QueryCacheKey, Set<QueryCacheKey>> =\n new Map();\n private registerOrder: Set<SymbolId> = new Set();\n private stubCache: Map<QueryCacheKey, SymbolId> = new Map();\n private stubs: Set<SymbolId> = new Set();\n private values: Map<SymbolId, ISymbolOut> = new Map();\n\n get(identifier: ISymbolIdentifier): ISymbolOut | undefined {\n return typeof identifier === 'number'\n ? this.values.get(identifier)\n : this.query(identifier)[0];\n }\n\n getValue(symbolId: SymbolId): unknown {\n return this.nodes.get(symbolId);\n }\n\n hasValue(symbolId: SymbolId): boolean {\n return this.nodes.has(symbolId);\n }\n\n get id(): SymbolId {\n return this._id++;\n }\n\n isRegistered(identifier: ISymbolIdentifier): boolean {\n const symbol = this.get(identifier);\n return symbol ? this.registerOrder.has(symbol.id) : false;\n }\n\n query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut> {\n const cacheKey = this.buildCacheKey(filter);\n const cachedIds = this.queryCache.get(cacheKey);\n if (cachedIds) {\n return cachedIds.map((symbolId) => this.values.get(symbolId)!);\n }\n const sets: Array<Set<SymbolId>> = [];\n const indexKeySpace = this.buildIndexKeySpace(filter);\n const cacheDependencies = new Set<QueryCacheKey>();\n let missed = false;\n for (const indexEntry of indexKeySpace) {\n cacheDependencies.add(this.serializeIndexEntry(indexEntry));\n const values = this.indices.get(indexEntry[0]);\n if (!values) {\n missed = true;\n break;\n }\n const set = values.get(indexEntry[1]);\n if (!set) {\n missed = true;\n break;\n }\n sets.push(set);\n }\n if (missed || !sets.length) {\n this.queryCacheDependencies.set(cacheKey, cacheDependencies);\n this.queryCache.set(cacheKey, []);\n return [];\n }\n let result = new Set(sets[0]);\n for (const set of sets.slice(1)) {\n result = new Set([...result].filter((symbolId) => set.has(symbolId)));\n }\n const resultIds = [...result];\n this.queryCacheDependencies.set(cacheKey, cacheDependencies);\n this.queryCache.set(cacheKey, resultIds);\n return resultIds.map((symbolId) => this.values.get(symbolId)!);\n }\n\n reference(meta: ISymbolMeta): ISymbolOut {\n const [registered] = this.query(meta);\n if (registered) return registered;\n const cacheKey = this.buildCacheKey(meta);\n const cachedId = this.stubCache.get(cacheKey);\n if (cachedId !== undefined) return this.values.get(cachedId)!;\n const id = this.id;\n const stub: ISymbolOut = {\n id,\n meta,\n placeholder: wrapId(String(id)),\n };\n this.values.set(stub.id, stub);\n this.stubs.add(stub.id);\n this.stubCache.set(cacheKey, stub.id);\n return stub;\n }\n\n register(symbol: ISymbolIn): ISymbolOut {\n const id = symbol.id !== undefined ? symbol.id : this.id;\n const result: ISymbolOut = {\n ...symbol, // clone to avoid mutation\n id,\n placeholder: symbol.placeholder ?? wrapId(String(id)),\n };\n this.values.set(result.id, result);\n this.registerOrder.add(result.id);\n if (result.meta) {\n const indexKeySpace = this.buildIndexKeySpace(result.meta);\n this.indexSymbol(result.id, indexKeySpace);\n this.invalidateCache(indexKeySpace);\n this.replaceStubs(result, indexKeySpace);\n }\n return result;\n }\n\n *registered(): IterableIterator<ISymbolOut> {\n for (const id of this.registerOrder.values()) {\n yield this.values.get(id)!;\n }\n }\n\n setValue(symbolId: SymbolId, value: unknown): Map<SymbolId, unknown> {\n return this.nodes.set(symbolId, value);\n }\n\n private buildCacheKey(filter: ISymbolMeta): QueryCacheKey {\n const indexKeySpace = this.buildIndexKeySpace(filter);\n return indexKeySpace\n .map((indexEntry) => this.serializeIndexEntry(indexEntry))\n .sort() // ensure order-insensitivity\n .join('|');\n }\n\n private buildIndexKeySpace(meta: ISymbolMeta, prefix = ''): IndexKeySpace {\n const entries: Array<IndexEntry> = [];\n for (const [key, value] of Object.entries(meta)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n entries.push(...this.buildIndexKeySpace(value as ISymbolMeta, path));\n } else {\n entries.push([path, value]);\n }\n }\n return entries;\n }\n\n private indexSymbol(symbolId: SymbolId, indexKeySpace: IndexKeySpace): void {\n for (const [key, value] of indexKeySpace) {\n if (!this.indices.has(key)) this.indices.set(key, new Map());\n const values = this.indices.get(key)!;\n const set = values.get(value) ?? new Set();\n set.add(symbolId);\n values.set(value, set);\n }\n }\n\n private invalidateCache(indexKeySpace: IndexKeySpace): void {\n const changed = indexKeySpace.map((indexEntry) =>\n this.serializeIndexEntry(indexEntry),\n );\n for (const [\n cacheKey,\n cacheDependencies,\n ] of this.queryCacheDependencies.entries()) {\n for (const key of changed) {\n if (cacheDependencies.has(key)) {\n this.queryCacheDependencies.delete(cacheKey);\n this.queryCache.delete(cacheKey);\n break;\n }\n }\n }\n }\n\n private isSubset(sub: IndexKeySpace, sup: IndexKeySpace): boolean {\n const supMap = new Map(sup);\n for (const [key, value] of sub) {\n if (!supMap.has(key) || supMap.get(key) !== value) {\n return false;\n }\n }\n return true;\n }\n\n private replaceStubs(symbol: ISymbolOut, indexKeySpace: IndexKeySpace): void {\n for (const stubId of this.stubs.values()) {\n const stub = this.values.get(stubId);\n if (\n stub?.meta &&\n this.isSubset(this.buildIndexKeySpace(stub.meta), indexKeySpace)\n ) {\n const cacheKey = this.buildCacheKey(stub.meta);\n this.stubCache.delete(cacheKey);\n this.values.set(stubId, Object.assign(stub, symbol));\n this.stubs.delete(stubId);\n }\n }\n }\n\n private serializeIndexEntry(indexEntry: IndexEntry): string {\n return `${indexEntry[0]}:${JSON.stringify(indexEntry[1])}`;\n }\n}\n","import path from 'node:path';\n\nimport type { IProjectRenderMeta } from '../extensions/types';\nimport { FileRegistry } from '../files/registry';\nimport type { IFileOut, IFileSelector } from '../files/types';\nimport type { IOutput } from '../output/types';\nimport type { IRenderer } from '../renderer/types';\nimport { SymbolRegistry } from '../symbols/registry';\nimport type { ISymbolOut } from '../symbols/types';\nimport type { IProject } from './types';\n\nconst externalSourceSymbol = '@';\n\nexport class Project implements IProject {\n private symbolIdToFileIds: Map<number, Set<number>> = new Map();\n\n readonly defaultFileName: string;\n readonly files = new FileRegistry();\n readonly fileName?: (name: string) => string;\n readonly renderers: Record<string, IRenderer> = {};\n readonly root: string;\n readonly symbols = new SymbolRegistry();\n\n constructor({\n defaultFileName,\n fileName,\n renderers,\n root,\n }: Pick<IProject, 'defaultFileName' | 'fileName' | 'renderers' | 'root'>) {\n this.defaultFileName = defaultFileName ?? 'main';\n this.fileName = typeof fileName === 'string' ? () => fileName : fileName;\n this.renderers = renderers;\n this.root = root;\n }\n\n private getRenderer(file: IFileOut): IRenderer | undefined {\n return file.extension ? this.renderers[file.extension] : undefined;\n }\n\n private prepareFiles(): void {\n // TODO: infer extension from symbols\n const extension = '.ts';\n for (const symbol of this.symbols.registered()) {\n const selector = this.symbolToFileSelector(symbol);\n const file = this.files.reference(selector);\n file.symbols.body.push(symbol.id);\n // update symbol->files map\n const symbolIdToFileIds =\n this.symbolIdToFileIds.get(symbol.id) ?? new Set();\n symbolIdToFileIds.add(file.id);\n this.symbolIdToFileIds.set(symbol.id, symbolIdToFileIds);\n // update re-exports\n if (symbol.exportFrom) {\n for (const exportFrom of symbol.exportFrom) {\n const exportSelector = [exportFrom];\n const exportFile = this.files.reference(exportSelector);\n if (exportFile.id !== file.id) {\n exportFile.symbols.exports.push(symbol.id);\n }\n }\n }\n }\n for (const file of this.files.referenced()) {\n if (!file.selector) continue;\n if (file.selector[0] === externalSourceSymbol) {\n const filePath = file.selector[1];\n if (!filePath) {\n this.files.register({\n external: true,\n selector: file.selector,\n });\n continue;\n }\n const extension = path.extname(filePath);\n if (!extension) {\n this.files.register({\n external: true,\n path: filePath,\n selector: file.selector,\n });\n continue;\n }\n this.files.register({\n extension,\n external: true,\n path: filePath,\n selector: file.selector,\n });\n continue;\n }\n const dirs = file.selector.slice(0, -1);\n let name = file.selector[file.selector.length - 1]!;\n name = this.fileName?.(name) || name;\n this.files.register({\n extension,\n name,\n path: path.resolve(this.root, ...dirs, `${name}${extension}`),\n selector: file.selector,\n });\n }\n\n // TODO: track symbol dependencies and inject imports into files\n // based on symbol references so the render step can just render\n }\n\n render(meta?: IProjectRenderMeta): ReadonlyArray<IOutput> {\n this.prepareFiles();\n const files: Map<number, IOutput> = new Map();\n for (const file of this.files.registered()) {\n if (file.external || !file.path) continue;\n const renderer = this.getRenderer(file);\n if (!renderer) continue;\n files.set(file.id, {\n content: renderer.renderSymbols(file, this, meta),\n path: file.path,\n });\n }\n for (const [fileId, value] of files.entries()) {\n const file = this.files.get(fileId)!;\n const renderer = this.getRenderer(file)!;\n const content = renderer.renderFile(value.content, file, this, meta);\n if (content) {\n files.set(file.id, { ...value, content });\n } else {\n files.delete(file.id);\n }\n }\n return Array.from(files.values());\n }\n\n symbolIdToFiles(symbolId: number): ReadonlyArray<IFileOut> {\n const fileIds = this.symbolIdToFileIds.get(symbolId);\n return Array.from(fileIds ?? []).map((fileId) => this.files.get(fileId)!);\n }\n\n private symbolToFileSelector(symbol: ISymbolOut): IFileSelector {\n if (symbol.external) {\n return [externalSourceSymbol, symbol.external];\n }\n const filePath = symbol.getFilePath?.(symbol);\n if (filePath) {\n return filePath.split('/');\n }\n return [this.defaultFileName];\n }\n}\n"],"mappings":"ggBAIA,MAAa,GAAiB,CAC5B,OACA,aACA,SACA,gBAMc,CACd,IAAMA,EAAuB,EAAE,CACzBC,EAA2B,EAAE,CAC7BC,EAAmE,CACvE,QAAS,EAAE,CACX,KAAM,EACP,CAeD,GAdI,EAAO,aACL,EAAO,aAAe,WACxB,EAAQ,eAAiB,EAAO,YAC5B,EAAO,OAAS,SAClB,EAAQ,mBAAqB,KAEtB,EAAO,aAAe,cAC/B,EAAQ,iBAAmB,EAAO,YAC9B,EAAO,OAAS,SAClB,EAAQ,qBAAuB,MAMnC,EAAO,aAAe,SACrB,CAAC,EAAM,QAAU,CAAC,EAAQ,gBAAkB,CAAC,EAAQ,iBACtD,CACA,IAAI,EAAO,EAAO,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,KAAK,EAAK,CAKxB,IAAK,IAAM,KAAY,EAChB,EAAM,SAAS,EAAS,EAC3B,EAAM,KAAK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,CAClB,gBACA,OACA,KAAMC,EAAAA,QAAK,QAAQ,KAAK,KAAM,GAAG,EAAM,GAAG,OAAmB,CAC7D,SAAU,EAAK,SAChB,CAAC,EAON,OAAO,EAAmD,CACxD,KAAK,cAAc,CACnB,IAAMC,EAA8B,IAAI,IACxC,IAAK,IAAM,KAAQ,KAAK,MAAM,YAAY,CAAE,CAC1C,GAAI,EAAK,UAAY,CAAC,EAAK,KAAM,SACjC,IAAM,EAAW,KAAK,YAAY,EAAK,CAClC,GACL,EAAM,IAAI,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,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"}
package/dist/index.d.cts CHANGED
@@ -135,21 +135,19 @@ interface IBinding {
135
135
  typeNamespaceBinding?: boolean;
136
136
  }
137
137
  //#endregion
138
- //#region src/selectors/types.d.ts
138
+ //#region src/files/types.d.ts
139
139
  /**
140
- * Selector array used to reference resources. We don't enforce
141
- * uniqueness, but in practice it's desirable.
140
+ * Selector array used to reference files.
142
141
  *
143
- * @example ["zod", "#/components/schemas/Foo"]
142
+ * @example ["foo", "bar"]
144
143
  */
145
- type ISelector = ReadonlyArray<string>;
146
- //#endregion
147
- //#region src/files/types.d.ts
148
- interface IFileIn {
144
+ type IFileSelector = ReadonlyArray<string>;
145
+ type IFileIdentifier = number | IFileSelector;
146
+ type IFileIn = {
149
147
  /**
150
148
  * File extension, if any.
151
149
  */
152
- readonly extension?: string;
150
+ extension?: string;
153
151
  /**
154
152
  * Indicates whether the file is external, meaning it is not generated
155
153
  * as part of the project but is referenced (e.g., a module from
@@ -157,7 +155,7 @@ interface IFileIn {
157
155
  *
158
156
  * @example true
159
157
  */
160
- readonly external?: boolean;
158
+ external?: boolean;
161
159
  /**
162
160
  * Unique file ID. If one is not provided, it will be auto-generated.
163
161
  */
@@ -168,22 +166,21 @@ interface IFileIn {
168
166
  *
169
167
  * @example "UserModel"
170
168
  */
171
- readonly name?: string;
169
+ name?: string;
172
170
  /**
173
171
  * Absolute logical output path for the file.
174
172
  *
175
173
  * @example "/src/models/user.ts"
176
174
  */
177
- readonly path?: string;
175
+ path?: string;
178
176
  /**
179
- * Selector array used to select this file. It doesn't have to be
180
- * unique, but in practice it might be desirable.
177
+ * Selector array used to select this file.
181
178
  *
182
- * @example ["zod", "#/components/schemas/Foo"]
179
+ * @example ["foo", "bar"]
183
180
  */
184
- readonly selector?: ISelector;
185
- }
186
- interface IFileOut extends IFileIn {
181
+ readonly selector?: IFileSelector;
182
+ };
183
+ type IFileOut = IFileIn & {
187
184
  /**
188
185
  * Unique file ID.
189
186
  */
@@ -209,15 +206,15 @@ interface IFileOut extends IFileIn {
209
206
  */
210
207
  imports: Array<number>;
211
208
  };
212
- }
209
+ };
213
210
  interface IFileRegistry {
214
211
  /**
215
- * Get a file by its ID.
212
+ * Get a file.
216
213
  *
217
- * @param fileIdOrSelector File ID or selector to reference.
214
+ * @param identifier File identifier to reference.
218
215
  * @returns The file, or undefined if not found.
219
216
  */
220
- get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
217
+ get(identifier: IFileIdentifier): IFileOut | undefined;
221
218
  /**
222
219
  * Returns the current file ID and increments it.
223
220
  *
@@ -227,17 +224,17 @@ interface IFileRegistry {
227
224
  /**
228
225
  * Returns whether a file is registered in the registry.
229
226
  *
230
- * @param fileIdOrSelector File ID or selector to check.
227
+ * @param identifier File identifier to check.
231
228
  * @returns True if the file is registered, false otherwise.
232
229
  */
233
- isRegistered(fileIdOrSelector: number | ISelector): boolean;
230
+ isRegistered(identifier: IFileIdentifier): boolean;
234
231
  /**
235
- * Returns a file by ID or selector, registering it if it doesn't exist.
232
+ * Returns a file by identifier, registering it if it doesn't exist.
236
233
  *
237
- * @param fileIdOrSelector File ID or selector to reference.
234
+ * @param identifier File identifier to reference.
238
235
  * @returns The referenced or newly registered file.
239
236
  */
240
- reference(fileIdOrSelector: number | ISelector): IFileOut;
237
+ reference(identifier: IFileIdentifier): IFileOut;
241
238
  /**
242
239
  * Get all unregistered files in the order they were referenced.
243
240
  *
@@ -280,96 +277,74 @@ interface ISymbolMeta {
280
277
  }
281
278
  //#endregion
282
279
  //#region src/symbols/types.d.ts
283
- interface ISymbolIn {
280
+ type ISymbolIdentifier = number | ISymbolMeta;
281
+ type ISymbolIn = {
284
282
  /**
285
283
  * Array of file names (without extensions) from which this symbol is re-exported.
286
284
  *
287
285
  * @default undefined
288
286
  */
289
- readonly exportFrom?: ReadonlyArray<string>;
287
+ exportFrom?: ReadonlyArray<string>;
290
288
  /**
291
289
  * Whether this symbol is exported from its own file.
292
290
  *
293
291
  * @default false
294
292
  */
295
- readonly exported?: boolean;
293
+ exported?: boolean;
296
294
  /**
297
295
  * External module name if this symbol is imported from a module not managed
298
296
  * by the project (e.g. "zod", "lodash").
299
297
  *
300
298
  * @default undefined
301
299
  */
302
- readonly external?: string;
300
+ external?: string;
303
301
  /**
304
302
  * Optional output strategy to override default behavior.
305
303
  *
306
304
  * @returns The file path to output the symbol to, or undefined to fallback to default behavior.
307
305
  */
308
- readonly getFilePath?: (symbol: ISymbolOut) => string | undefined;
306
+ getFilePath?: (symbol: ISymbolOut) => string | undefined;
309
307
  /**
310
308
  * Unique symbol ID. If one is not provided, it will be auto-generated.
311
309
  */
312
310
  readonly id?: number;
311
+ /**
312
+ * Kind of import if this symbol represents an import.
313
+ */
314
+ importKind?: 'namespace' | 'default' | 'named';
315
+ /**
316
+ * Kind of symbol.
317
+ */
318
+ kind?: 'class' | 'function' | 'type';
313
319
  /**
314
320
  * Arbitrary metadata about the symbol.
315
321
  *
316
322
  * @default undefined
317
323
  */
318
- readonly meta?: ISymbolMeta & {
319
- /**
320
- * Kind of import if this symbol represents an import.
321
- */
322
- importKind?: 'namespace' | 'default' | 'named';
323
- /**
324
- * Kind of symbol.
325
- */
326
- kind?: 'type';
327
- };
324
+ meta?: ISymbolMeta;
328
325
  /**
329
326
  * The desired name for the symbol within its file. If there are multiple symbols
330
327
  * with the same desired name, this might not end up being the actual name.
331
328
  *
332
329
  * @example "UserModel"
333
330
  */
334
- readonly name?: string;
331
+ name?: string;
335
332
  /**
336
333
  * Placeholder name for the symbol to be replaced later with the final value.
337
334
  *
338
335
  * @example "_heyapi_31_"
339
336
  */
340
337
  readonly placeholder?: string;
341
- /**
342
- * Selector array used to select this symbol. It doesn't have to be
343
- * unique, but in practice it might be desirable.
344
- *
345
- * @example ["zod", "#/components/schemas/Foo"]
346
- */
347
- readonly selector?: ISelector;
348
- }
349
- interface ISymbolOut extends ISymbolIn {
350
- /**
351
- * Array of file names (without extensions) from which this symbol is re-exported.
352
- */
353
- readonly exportFrom: ReadonlyArray<string>;
354
- /**
355
- * Unique symbol ID.
356
- */
357
- readonly id: number;
358
- /**
359
- * Placeholder name for the symbol to be replaced later with the final value.
360
- *
361
- * @example "_heyapi_31_"
362
- */
363
- readonly placeholder: string;
364
- }
338
+ };
339
+ type ISymbolOut = Omit<ISymbolIn, 'id' | 'placeholder'> & Pick<Required<ISymbolIn>, 'id' | 'placeholder'>;
365
340
  interface ISymbolRegistry {
366
341
  /**
367
- * Get a symbol by its ID.
342
+ * Get a symbol.
368
343
  *
369
- * @param symbolIdOrSelector Symbol ID or selector to reference.
344
+ * @param identifier Symbol identifier to reference.
370
345
  * @returns The symbol, or undefined if not found.
371
346
  */
372
- get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
347
+ get(identifier: ISymbolIdentifier): ISymbolOut | undefined;
373
348
  /**
374
349
  * Returns the value associated with a symbol ID.
375
350
  *
@@ -393,17 +368,24 @@ interface ISymbolRegistry {
393
368
  /**
394
369
  * Returns whether a symbol is registered in the registry.
395
370
  *
396
- * @param symbolIdOrSelector Symbol ID or selector to check.
371
+ * @param identifier Symbol identifier to check.
397
372
  * @returns True if the symbol is registered, false otherwise.
398
373
  */
399
- isRegistered(symbolIdOrSelector: number | ISelector): boolean;
374
+ isRegistered(identifier: ISymbolIdentifier): boolean;
400
375
  /**
401
- * Returns a symbol by ID or selector, registering it if it doesn't exist.
376
+ * Queries symbols by metadata filter.
402
377
  *
403
- * @param symbolIdOrSelector Symbol ID or selector to reference.
404
- * @returns The referenced or newly registered symbol.
378
+ * @param filter Metadata filter to query symbols by.
379
+ * @returns Array of symbols matching the filter.
405
380
  */
406
- reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
381
+ query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut>;
382
+ /**
383
+ * References a symbol.
384
+ *
385
+ * @param meta Metadata filter to reference symbol by.
386
+ * @returns The referenced symbol.
387
+ */
388
+ reference(meta: ISymbolMeta): ISymbolOut;
407
389
  /**
408
390
  * Register a symbol globally.
409
391
  *
@@ -468,11 +450,11 @@ declare class FileRegistry implements IFileRegistry {
468
450
  private registerOrder;
469
451
  private selectorToId;
470
452
  private values;
471
- get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
453
+ get(identifier: IFileIdentifier): IFileOut | undefined;
472
454
  get id(): number;
473
- private idOrSelector;
474
- isRegistered(fileIdOrSelector: number | ISelector): boolean;
475
- reference(fileIdOrSelector: number | ISelector): IFileOut;
455
+ private identifierToFile;
456
+ isRegistered(identifier: IFileIdentifier): boolean;
457
+ reference(identifier: IFileIdentifier): IFileOut;
476
458
  referenced(): IterableIterator<IFileOut>;
477
459
  register(file: IFileIn): IFileOut;
478
460
  registered(): IterableIterator<IFileOut>;
@@ -566,22 +548,34 @@ interface IRenderer {
566
548
  }
567
549
  //#endregion
568
550
  //#region src/symbols/registry.d.ts
551
+ type SymbolId = number;
569
552
  declare class SymbolRegistry implements ISymbolRegistry {
570
553
  private _id;
554
+ private indices;
571
555
  private nodes;
556
+ private queryCache;
557
+ private queryCacheDependencies;
572
558
  private registerOrder;
573
- private selectorToId;
559
+ private stubCache;
560
+ private stubs;
574
561
  private values;
575
- get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
576
- getValue(symbolId: number): unknown;
577
- hasValue(symbolId: number): boolean;
578
- get id(): number;
579
- private idOrSelector;
580
- isRegistered(symbolIdOrSelector: number | ISelector): boolean;
581
- reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
562
+ get(identifier: ISymbolIdentifier): ISymbolOut | undefined;
563
+ getValue(symbolId: SymbolId): unknown;
564
+ hasValue(symbolId: SymbolId): boolean;
565
+ get id(): SymbolId;
566
+ isRegistered(identifier: ISymbolIdentifier): boolean;
567
+ query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut>;
568
+ reference(meta: ISymbolMeta): ISymbolOut;
582
569
  register(symbol: ISymbolIn): ISymbolOut;
583
570
  registered(): IterableIterator<ISymbolOut>;
584
- setValue(symbolId: number, value: unknown): Map<number, unknown>;
571
+ setValue(symbolId: SymbolId, value: unknown): Map<SymbolId, unknown>;
572
+ private buildCacheKey;
573
+ private buildIndexKeySpace;
574
+ private indexSymbol;
575
+ private invalidateCache;
576
+ private isSubset;
577
+ private replaceStubs;
578
+ private serializeIndexEntry;
585
579
  }
586
580
  //#endregion
587
581
  //#region src/project/project.d.ts
@@ -615,5 +609,5 @@ declare class Project implements IProject {
615
609
  */
616
610
  declare const renderIds: (source: string, replacerFn: (symbolId: number) => string | undefined) => string;
617
611
  //#endregion
618
- 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 };
612
+ 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 };
619
613
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -135,21 +135,19 @@ interface IBinding {
135
135
  typeNamespaceBinding?: boolean;
136
136
  }
137
137
  //#endregion
138
- //#region src/selectors/types.d.ts
138
+ //#region src/files/types.d.ts
139
139
  /**
140
- * Selector array used to reference resources. We don't enforce
141
- * uniqueness, but in practice it's desirable.
140
+ * Selector array used to reference files.
142
141
  *
143
- * @example ["zod", "#/components/schemas/Foo"]
142
+ * @example ["foo", "bar"]
144
143
  */
145
- type ISelector = ReadonlyArray<string>;
146
- //#endregion
147
- //#region src/files/types.d.ts
148
- interface IFileIn {
144
+ type IFileSelector = ReadonlyArray<string>;
145
+ type IFileIdentifier = number | IFileSelector;
146
+ type IFileIn = {
149
147
  /**
150
148
  * File extension, if any.
151
149
  */
152
- readonly extension?: string;
150
+ extension?: string;
153
151
  /**
154
152
  * Indicates whether the file is external, meaning it is not generated
155
153
  * as part of the project but is referenced (e.g., a module from
@@ -157,7 +155,7 @@ interface IFileIn {
157
155
  *
158
156
  * @example true
159
157
  */
160
- readonly external?: boolean;
158
+ external?: boolean;
161
159
  /**
162
160
  * Unique file ID. If one is not provided, it will be auto-generated.
163
161
  */
@@ -168,22 +166,21 @@ interface IFileIn {
168
166
  *
169
167
  * @example "UserModel"
170
168
  */
171
- readonly name?: string;
169
+ name?: string;
172
170
  /**
173
171
  * Absolute logical output path for the file.
174
172
  *
175
173
  * @example "/src/models/user.ts"
176
174
  */
177
- readonly path?: string;
175
+ path?: string;
178
176
  /**
179
- * Selector array used to select this file. It doesn't have to be
180
- * unique, but in practice it might be desirable.
177
+ * Selector array used to select this file.
181
178
  *
182
- * @example ["zod", "#/components/schemas/Foo"]
179
+ * @example ["foo", "bar"]
183
180
  */
184
- readonly selector?: ISelector;
185
- }
186
- interface IFileOut extends IFileIn {
181
+ readonly selector?: IFileSelector;
182
+ };
183
+ type IFileOut = IFileIn & {
187
184
  /**
188
185
  * Unique file ID.
189
186
  */
@@ -209,15 +206,15 @@ interface IFileOut extends IFileIn {
209
206
  */
210
207
  imports: Array<number>;
211
208
  };
212
- }
209
+ };
213
210
  interface IFileRegistry {
214
211
  /**
215
- * Get a file by its ID.
212
+ * Get a file.
216
213
  *
217
- * @param fileIdOrSelector File ID or selector to reference.
214
+ * @param identifier File identifier to reference.
218
215
  * @returns The file, or undefined if not found.
219
216
  */
220
- get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
217
+ get(identifier: IFileIdentifier): IFileOut | undefined;
221
218
  /**
222
219
  * Returns the current file ID and increments it.
223
220
  *
@@ -227,17 +224,17 @@ interface IFileRegistry {
227
224
  /**
228
225
  * Returns whether a file is registered in the registry.
229
226
  *
230
- * @param fileIdOrSelector File ID or selector to check.
227
+ * @param identifier File identifier to check.
231
228
  * @returns True if the file is registered, false otherwise.
232
229
  */
233
- isRegistered(fileIdOrSelector: number | ISelector): boolean;
230
+ isRegistered(identifier: IFileIdentifier): boolean;
234
231
  /**
235
- * Returns a file by ID or selector, registering it if it doesn't exist.
232
+ * Returns a file by identifier, registering it if it doesn't exist.
236
233
  *
237
- * @param fileIdOrSelector File ID or selector to reference.
234
+ * @param identifier File identifier to reference.
238
235
  * @returns The referenced or newly registered file.
239
236
  */
240
- reference(fileIdOrSelector: number | ISelector): IFileOut;
237
+ reference(identifier: IFileIdentifier): IFileOut;
241
238
  /**
242
239
  * Get all unregistered files in the order they were referenced.
243
240
  *
@@ -280,96 +277,74 @@ interface ISymbolMeta {
280
277
  }
281
278
  //#endregion
282
279
  //#region src/symbols/types.d.ts
283
- interface ISymbolIn {
280
+ type ISymbolIdentifier = number | ISymbolMeta;
281
+ type ISymbolIn = {
284
282
  /**
285
283
  * Array of file names (without extensions) from which this symbol is re-exported.
286
284
  *
287
285
  * @default undefined
288
286
  */
289
- readonly exportFrom?: ReadonlyArray<string>;
287
+ exportFrom?: ReadonlyArray<string>;
290
288
  /**
291
289
  * Whether this symbol is exported from its own file.
292
290
  *
293
291
  * @default false
294
292
  */
295
- readonly exported?: boolean;
293
+ exported?: boolean;
296
294
  /**
297
295
  * External module name if this symbol is imported from a module not managed
298
296
  * by the project (e.g. "zod", "lodash").
299
297
  *
300
298
  * @default undefined
301
299
  */
302
- readonly external?: string;
300
+ external?: string;
303
301
  /**
304
302
  * Optional output strategy to override default behavior.
305
303
  *
306
304
  * @returns The file path to output the symbol to, or undefined to fallback to default behavior.
307
305
  */
308
- readonly getFilePath?: (symbol: ISymbolOut) => string | undefined;
306
+ getFilePath?: (symbol: ISymbolOut) => string | undefined;
309
307
  /**
310
308
  * Unique symbol ID. If one is not provided, it will be auto-generated.
311
309
  */
312
310
  readonly id?: number;
311
+ /**
312
+ * Kind of import if this symbol represents an import.
313
+ */
314
+ importKind?: 'namespace' | 'default' | 'named';
315
+ /**
316
+ * Kind of symbol.
317
+ */
318
+ kind?: 'class' | 'function' | 'type';
313
319
  /**
314
320
  * Arbitrary metadata about the symbol.
315
321
  *
316
322
  * @default undefined
317
323
  */
318
- readonly meta?: ISymbolMeta & {
319
- /**
320
- * Kind of import if this symbol represents an import.
321
- */
322
- importKind?: 'namespace' | 'default' | 'named';
323
- /**
324
- * Kind of symbol.
325
- */
326
- kind?: 'type';
327
- };
324
+ meta?: ISymbolMeta;
328
325
  /**
329
326
  * The desired name for the symbol within its file. If there are multiple symbols
330
327
  * with the same desired name, this might not end up being the actual name.
331
328
  *
332
329
  * @example "UserModel"
333
330
  */
334
- readonly name?: string;
331
+ name?: string;
335
332
  /**
336
333
  * Placeholder name for the symbol to be replaced later with the final value.
337
334
  *
338
335
  * @example "_heyapi_31_"
339
336
  */
340
337
  readonly placeholder?: string;
341
- /**
342
- * Selector array used to select this symbol. It doesn't have to be
343
- * unique, but in practice it might be desirable.
344
- *
345
- * @example ["zod", "#/components/schemas/Foo"]
346
- */
347
- readonly selector?: ISelector;
348
- }
349
- interface ISymbolOut extends ISymbolIn {
350
- /**
351
- * Array of file names (without extensions) from which this symbol is re-exported.
352
- */
353
- readonly exportFrom: ReadonlyArray<string>;
354
- /**
355
- * Unique symbol ID.
356
- */
357
- readonly id: number;
358
- /**
359
- * Placeholder name for the symbol to be replaced later with the final value.
360
- *
361
- * @example "_heyapi_31_"
362
- */
363
- readonly placeholder: string;
364
- }
338
+ };
339
+ type ISymbolOut = Omit<ISymbolIn, 'id' | 'placeholder'> & Pick<Required<ISymbolIn>, 'id' | 'placeholder'>;
365
340
  interface ISymbolRegistry {
366
341
  /**
367
- * Get a symbol by its ID.
342
+ * Get a symbol.
368
343
  *
369
- * @param symbolIdOrSelector Symbol ID or selector to reference.
344
+ * @param identifier Symbol identifier to reference.
370
345
  * @returns The symbol, or undefined if not found.
371
346
  */
372
- get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
347
+ get(identifier: ISymbolIdentifier): ISymbolOut | undefined;
373
348
  /**
374
349
  * Returns the value associated with a symbol ID.
375
350
  *
@@ -393,17 +368,24 @@ interface ISymbolRegistry {
393
368
  /**
394
369
  * Returns whether a symbol is registered in the registry.
395
370
  *
396
- * @param symbolIdOrSelector Symbol ID or selector to check.
371
+ * @param identifier Symbol identifier to check.
397
372
  * @returns True if the symbol is registered, false otherwise.
398
373
  */
399
- isRegistered(symbolIdOrSelector: number | ISelector): boolean;
374
+ isRegistered(identifier: ISymbolIdentifier): boolean;
400
375
  /**
401
- * Returns a symbol by ID or selector, registering it if it doesn't exist.
376
+ * Queries symbols by metadata filter.
402
377
  *
403
- * @param symbolIdOrSelector Symbol ID or selector to reference.
404
- * @returns The referenced or newly registered symbol.
378
+ * @param filter Metadata filter to query symbols by.
379
+ * @returns Array of symbols matching the filter.
405
380
  */
406
- reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
381
+ query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut>;
382
+ /**
383
+ * References a symbol.
384
+ *
385
+ * @param meta Metadata filter to reference symbol by.
386
+ * @returns The referenced symbol.
387
+ */
388
+ reference(meta: ISymbolMeta): ISymbolOut;
407
389
  /**
408
390
  * Register a symbol globally.
409
391
  *
@@ -468,11 +450,11 @@ declare class FileRegistry implements IFileRegistry {
468
450
  private registerOrder;
469
451
  private selectorToId;
470
452
  private values;
471
- get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
453
+ get(identifier: IFileIdentifier): IFileOut | undefined;
472
454
  get id(): number;
473
- private idOrSelector;
474
- isRegistered(fileIdOrSelector: number | ISelector): boolean;
475
- reference(fileIdOrSelector: number | ISelector): IFileOut;
455
+ private identifierToFile;
456
+ isRegistered(identifier: IFileIdentifier): boolean;
457
+ reference(identifier: IFileIdentifier): IFileOut;
476
458
  referenced(): IterableIterator<IFileOut>;
477
459
  register(file: IFileIn): IFileOut;
478
460
  registered(): IterableIterator<IFileOut>;
@@ -566,22 +548,34 @@ interface IRenderer {
566
548
  }
567
549
  //#endregion
568
550
  //#region src/symbols/registry.d.ts
551
+ type SymbolId = number;
569
552
  declare class SymbolRegistry implements ISymbolRegistry {
570
553
  private _id;
554
+ private indices;
571
555
  private nodes;
556
+ private queryCache;
557
+ private queryCacheDependencies;
572
558
  private registerOrder;
573
- private selectorToId;
559
+ private stubCache;
560
+ private stubs;
574
561
  private values;
575
- get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
576
- getValue(symbolId: number): unknown;
577
- hasValue(symbolId: number): boolean;
578
- get id(): number;
579
- private idOrSelector;
580
- isRegistered(symbolIdOrSelector: number | ISelector): boolean;
581
- reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
562
+ get(identifier: ISymbolIdentifier): ISymbolOut | undefined;
563
+ getValue(symbolId: SymbolId): unknown;
564
+ hasValue(symbolId: SymbolId): boolean;
565
+ get id(): SymbolId;
566
+ isRegistered(identifier: ISymbolIdentifier): boolean;
567
+ query(filter: ISymbolMeta): ReadonlyArray<ISymbolOut>;
568
+ reference(meta: ISymbolMeta): ISymbolOut;
582
569
  register(symbol: ISymbolIn): ISymbolOut;
583
570
  registered(): IterableIterator<ISymbolOut>;
584
- setValue(symbolId: number, value: unknown): Map<number, unknown>;
571
+ setValue(symbolId: SymbolId, value: unknown): Map<SymbolId, unknown>;
572
+ private buildCacheKey;
573
+ private buildIndexKeySpace;
574
+ private indexSymbol;
575
+ private invalidateCache;
576
+ private isSubset;
577
+ private replaceStubs;
578
+ private serializeIndexEntry;
585
579
  }
586
580
  //#endregion
587
581
  //#region src/project/project.d.ts
@@ -615,5 +609,5 @@ declare class Project implements IProject {
615
609
  */
616
610
  declare const renderIds: (source: string, replacerFn: (symbolId: number) => string | undefined) => string;
617
611
  //#endregion
618
- 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 };
612
+ 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 };
619
613
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 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};
1
+ 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={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,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;if(r.add(n.id),this.symbolIdToFileIds.set(e.id,r),e.exportFrom)for(let t of e.exportFrom){let r=[t],i=this.files.reference(r);i.id!==n.id&&i.symbols.exports.push(e.id)}}for(let 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};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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,EAAK,CAKxB,IAAK,IAAM,KAAY,EAChB,EAAM,SAAS,EAAS,EAC3B,EAAM,KAAK,EAAS,CAKxB,MAFA,GAAQ,MAAQ,EAChB,EAAQ,UAAY,EACb,GAGI,GAAiB,EAAkB,IAA2B,CACzE,EAAO,QAAU,CAAE,GAAG,EAAO,QAAS,GA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S,OAAS,GAChD,EAAO,KAAK,WAAW,EAAK,EAAI,EAChC,KAAK,MAAM,SAAS,CAClB,gBACA,OACA,KAAM,EAAK,QAAQ,KAAK,KAAM,GAAG,EAAM,GAAG,OAAmB,CAC7D,SAAU,EAAK,SAChB,CAAC,EAON,OAAO,EAAmD,CACxD,KAAK,cAAc,CACnB,IAAMC,EAA8B,IAAI,IACxC,IAAK,IAAM,KAAQ,KAAK,MAAM,YAAY,CAAE,CAC1C,GAAI,EAAK,UAAY,CAAC,EAAK,KAAM,SACjC,IAAM,EAAW,KAAK,YAAY,EAAK,CAClC,GACL,EAAM,IAAI,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"}
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","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 id,\n meta,\n placeholder: wrapId(String(id)),\n };\n this.values.set(stub.id, stub);\n this.stubs.add(stub.id);\n this.stubCache.set(cacheKey, stub.id);\n return stub;\n }\n\n register(symbol: ISymbolIn): ISymbolOut {\n const id = symbol.id !== undefined ? symbol.id : this.id;\n const result: ISymbolOut = {\n ...symbol, // clone to avoid mutation\n id,\n placeholder: symbol.placeholder ?? wrapId(String(id)),\n };\n this.values.set(result.id, result);\n this.registerOrder.add(result.id);\n if (result.meta) {\n const indexKeySpace = this.buildIndexKeySpace(result.meta);\n this.indexSymbol(result.id, indexKeySpace);\n this.invalidateCache(indexKeySpace);\n this.replaceStubs(result, indexKeySpace);\n }\n return result;\n }\n\n *registered(): IterableIterator<ISymbolOut> {\n for (const id of this.registerOrder.values()) {\n yield this.values.get(id)!;\n }\n }\n\n setValue(symbolId: SymbolId, value: unknown): Map<SymbolId, unknown> {\n return this.nodes.set(symbolId, value);\n }\n\n private buildCacheKey(filter: ISymbolMeta): QueryCacheKey {\n const indexKeySpace = this.buildIndexKeySpace(filter);\n return indexKeySpace\n .map((indexEntry) => this.serializeIndexEntry(indexEntry))\n .sort() // ensure order-insensitivity\n .join('|');\n }\n\n private buildIndexKeySpace(meta: ISymbolMeta, prefix = ''): IndexKeySpace {\n const entries: Array<IndexEntry> = [];\n for (const [key, value] of Object.entries(meta)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n entries.push(...this.buildIndexKeySpace(value as ISymbolMeta, path));\n } else {\n entries.push([path, value]);\n }\n }\n return entries;\n }\n\n private indexSymbol(symbolId: SymbolId, indexKeySpace: IndexKeySpace): void {\n for (const [key, value] of indexKeySpace) {\n if (!this.indices.has(key)) this.indices.set(key, new Map());\n const values = this.indices.get(key)!;\n const set = values.get(value) ?? new Set();\n set.add(symbolId);\n values.set(value, set);\n }\n }\n\n private invalidateCache(indexKeySpace: IndexKeySpace): void {\n const changed = indexKeySpace.map((indexEntry) =>\n this.serializeIndexEntry(indexEntry),\n );\n for (const [\n cacheKey,\n cacheDependencies,\n ] of this.queryCacheDependencies.entries()) {\n for (const key of changed) {\n if (cacheDependencies.has(key)) {\n this.queryCacheDependencies.delete(cacheKey);\n this.queryCache.delete(cacheKey);\n break;\n }\n }\n }\n }\n\n private isSubset(sub: IndexKeySpace, sup: IndexKeySpace): boolean {\n const supMap = new Map(sup);\n for (const [key, value] of sub) {\n if (!supMap.has(key) || supMap.get(key) !== value) {\n return false;\n }\n }\n return true;\n }\n\n private replaceStubs(symbol: ISymbolOut, indexKeySpace: IndexKeySpace): void {\n for (const stubId of this.stubs.values()) {\n const stub = this.values.get(stubId);\n if (\n stub?.meta &&\n this.isSubset(this.buildIndexKeySpace(stub.meta), indexKeySpace)\n ) {\n const cacheKey = this.buildCacheKey(stub.meta);\n this.stubCache.delete(cacheKey);\n this.values.set(stubId, Object.assign(stub, symbol));\n this.stubs.delete(stubId);\n }\n }\n }\n\n private serializeIndexEntry(indexEntry: IndexEntry): string {\n return `${indexEntry[0]}:${JSON.stringify(indexEntry[1])}`;\n }\n}\n","import path from 'node:path';\n\nimport type { IProjectRenderMeta } from '../extensions/types';\nimport { FileRegistry } from '../files/registry';\nimport type { IFileOut, IFileSelector } from '../files/types';\nimport type { IOutput } from '../output/types';\nimport type { IRenderer } from '../renderer/types';\nimport { SymbolRegistry } from '../symbols/registry';\nimport type { ISymbolOut } from '../symbols/types';\nimport type { IProject } from './types';\n\nconst externalSourceSymbol = '@';\n\nexport class Project implements IProject {\n private symbolIdToFileIds: Map<number, Set<number>> = new Map();\n\n readonly defaultFileName: string;\n readonly files = new FileRegistry();\n readonly fileName?: (name: string) => string;\n readonly renderers: Record<string, IRenderer> = {};\n readonly root: string;\n readonly symbols = new SymbolRegistry();\n\n constructor({\n defaultFileName,\n fileName,\n renderers,\n root,\n }: Pick<IProject, 'defaultFileName' | 'fileName' | 'renderers' | 'root'>) {\n this.defaultFileName = defaultFileName ?? 'main';\n this.fileName = typeof fileName === 'string' ? () => fileName : fileName;\n this.renderers = renderers;\n this.root = root;\n }\n\n private getRenderer(file: IFileOut): IRenderer | undefined {\n return file.extension ? this.renderers[file.extension] : undefined;\n }\n\n private prepareFiles(): void {\n // TODO: infer extension from symbols\n const extension = '.ts';\n for (const symbol of this.symbols.registered()) {\n const selector = this.symbolToFileSelector(symbol);\n const file = this.files.reference(selector);\n file.symbols.body.push(symbol.id);\n // update symbol->files map\n const symbolIdToFileIds =\n this.symbolIdToFileIds.get(symbol.id) ?? new Set();\n symbolIdToFileIds.add(file.id);\n this.symbolIdToFileIds.set(symbol.id, symbolIdToFileIds);\n // update re-exports\n if (symbol.exportFrom) {\n for (const exportFrom of symbol.exportFrom) {\n const exportSelector = [exportFrom];\n const exportFile = this.files.reference(exportSelector);\n if (exportFile.id !== file.id) {\n exportFile.symbols.exports.push(symbol.id);\n }\n }\n }\n }\n for (const file of this.files.referenced()) {\n if (!file.selector) continue;\n if (file.selector[0] === externalSourceSymbol) {\n const filePath = file.selector[1];\n if (!filePath) {\n this.files.register({\n external: true,\n selector: file.selector,\n });\n continue;\n }\n const extension = path.extname(filePath);\n if (!extension) {\n this.files.register({\n external: true,\n path: filePath,\n selector: file.selector,\n });\n continue;\n }\n this.files.register({\n extension,\n external: true,\n path: filePath,\n selector: file.selector,\n });\n continue;\n }\n const dirs = file.selector.slice(0, -1);\n let name = file.selector[file.selector.length - 1]!;\n name = this.fileName?.(name) || name;\n this.files.register({\n extension,\n name,\n path: path.resolve(this.root, ...dirs, `${name}${extension}`),\n selector: file.selector,\n });\n }\n\n // TODO: track symbol dependencies and inject imports into files\n // based on symbol references so the render step can just render\n }\n\n render(meta?: IProjectRenderMeta): ReadonlyArray<IOutput> {\n this.prepareFiles();\n const files: Map<number, IOutput> = new Map();\n for (const file of this.files.registered()) {\n if (file.external || !file.path) continue;\n const renderer = this.getRenderer(file);\n if (!renderer) continue;\n files.set(file.id, {\n content: renderer.renderSymbols(file, this, meta),\n path: file.path,\n });\n }\n for (const [fileId, value] of files.entries()) {\n const file = this.files.get(fileId)!;\n const renderer = this.getRenderer(file)!;\n const content = renderer.renderFile(value.content, file, this, meta);\n if (content) {\n files.set(file.id, { ...value, content });\n } else {\n files.delete(file.id);\n }\n }\n return Array.from(files.values());\n }\n\n symbolIdToFiles(symbolId: number): ReadonlyArray<IFileOut> {\n const fileIds = this.symbolIdToFileIds.get(symbolId);\n return Array.from(fileIds ?? []).map((fileId) => this.files.get(fileId)!);\n }\n\n private symbolToFileSelector(symbol: ISymbolOut): IFileSelector {\n if (symbol.external) {\n return [externalSourceSymbol, symbol.external];\n }\n const filePath = symbol.getFilePath?.(symbol);\n if (filePath) {\n return filePath.split('/');\n }\n return [this.defaultFileName];\n }\n}\n"],"mappings":"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,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,E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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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hey-api/codegen-core",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "🧱 TypeScript framework for generating structured, multi-file source code from abstract syntax trees.",
5
5
  "homepage": "https://heyapi.dev/",
6
6
  "repository": {