@hey-api/codegen-core
Advanced tools
+1
-1
@@ -1,2 +0,2 @@ | ||
| 'use strict';var s=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var s__default=/*#__PURE__*/_interopDefault(s);var i=class d{constructor(e,t={}){this.path=e;this.meta=t;let r=d.pathToFilePath(e);t.path&&(typeof t.path=="function"?r=t.path(r):r=t.path.replace("{{path}}",r)),this.path=r;}cache={};state={exports:new Map,imports:new Map,symbols:new Map};addExport(e){return this.addImportExport(e,"exports")}addImport(e){return this.addImportExport(e,"imports")}addImportExport(e,t){let r=typeof e.from=="string"?e.from:e.from.path,o=this.state[t].get(r);o?(this.mergeImportExportValues(o,e),this.state[t].set(r,o)):this.state[t].set(r,{...e}),this.cache[t]=void 0;}addSymbol(e){let t=e.name,r=this.state.symbols.get(t);r?(r.value=e.value,this.state.symbols.set(t,r)):this.state.symbols.set(t,{...e}),this.cache.symbols=void 0;}get exports(){return this.cache.exports||(this.cache.exports=Array.from(this.state.exports.values())),this.cache.exports}getAllSymbols(){return [...this.symbols,...this.imports.flatMap(e=>(e.names??[]).map(t=>({name:e.aliases?.[t]??t}))),...this.exports.flatMap(e=>(e.names??[]).map(t=>({name:e.aliases?.[t]??t})))]}hasContent(){return this.state.symbols.size>0||this.state.exports.size>0}hasSymbol(e){return this.state.symbols.has(e)}get imports(){return this.cache.imports||(this.cache.imports=Array.from(this.state.imports.values())),this.cache.imports}mergeImportExportValues(e,t){e.aliases={...e.aliases,...t.aliases},t.defaultImport!==void 0&&(e.defaultImport=t.defaultImport),e.names=[...new Set([...e.names??[],...t.names??[]])],t.namespaceImport!==void 0&&(e.namespaceImport=t.namespaceImport),t.typeDefaultImport!==void 0&&(e.typeDefaultImport=t.typeDefaultImport),e.typeNames=[...new Set([...e.typeNames??[],...t.typeNames??[]])],t.typeNamespaceImport!==void 0&&(e.typeNamespaceImport=t.typeNamespaceImport);}static pathToFilePath(e){return e.includes("/")?e.split("/").filter(Boolean).join(s__default.default.sep):e.includes("\\")?e.split("\\").filter(Boolean).join(s__default.default.sep):e.split(s__default.default.sep).filter(Boolean).join(s__default.default.sep)}relativePathFromFile(e){let t=s__default.default.posix.relative(s__default.default.posix.dirname(e.path),this.path);return t.startsWith(".")||(t=`./${t}`),t}relativePathToFile(e){let t=s__default.default.posix.relative(s__default.default.posix.dirname(this.path),e.path);return t.startsWith(".")||(t=`./${t}`),t}get symbols(){return this.cache.symbols||(this.cache.symbols=Array.from(this.state.symbols.values())),this.cache.symbols}};var a=class{filesMap=new Map;filesOrder=[];renderers=new Map;addExportToFile(e,t){this.ensureFile(e).addExport(t);}addImportToFile(e,t){this.ensureFile(e).addImport(t);}addSymbolToFile(e,t){this.ensureFile(e).addSymbol(t);}createFile(e,t={}){let{renderer:r,...o}=t;r&&this.ensureRenderer(r);let n=this.getFileByPath(e);if(n)return r?.id&&r.id!==n.meta.renderer&&(n.meta.renderer=r.id),n;let p=new i(e,{...o,renderer:r?.id});return this.filesOrder.push(p),this.filesMap.set(e,p),p}ensureFile(e){if(typeof e!="string")return e;let t=this.getFileByPath(e);return t||this.createFile(e)}ensureRenderer(e){return this.renderers.has(e.id)||this.renderers.set(e.id,e),this.renderers.get(e.id)}get files(){return [...this.filesOrder]}getAllSymbols(){return this.filesOrder.flatMap(e=>e.getAllSymbols())}getFileByPath(e){return this.filesMap.get(e)}render(e){let t=[];for(let r of this.filesOrder){if(!r.meta.renderer)continue;let o=this.renderers.get(r.meta.renderer);o&&t.push(o.render(r,e));}return t}};exports.CodegenFile=i;exports.CodegenProject=a;//# sourceMappingURL=index.cjs.map | ||
| 'use strict';var i=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var i__default=/*#__PURE__*/_interopDefault(i);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){return 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]()}};var a=l=>`_heyapi_${l}_`,h=l=>l.slice(8,-1),u=()=>new RegExp(a("\\d+"),"g"),y=(l,e)=>l.replace(u(),t=>{let r=Number.parseInt(h(t),10);return e(r)||t});var m=class l{constructor(e,t,r={}){this.path=e;this.project=t;this.meta=r;let o=l.pathToFilePath(e);r.path&&(typeof r.path=="function"?o=r.path(o):o=r.path.replace("{{path}}",o)),this.id=t.incrementFileId(),this.path=o;}cache={};renderSymbols=[];state={exports:new Map,imports:new Map,symbols:new Map};id;resolvedNames=new d;addExport(e){return this.addImportExport(e,"exports")}addImport(e){return this.addImportExport(e,"imports")}addImportExport(e,t){let r=this.getImportExportKey(e),o=this.state[t].get(r);e.names||(e.names=[]);for(let s of e.typeNames??[])e.names.includes(s)||(e.names=[...e.names,s]);o?(this.mergeImportExportValues(o,e),this.state[t].set(r,o)):this.state[t].set(r,{...e}),this.cache[t]=void 0;}addRenderSymbol(e){this.renderSymbols.push(e),this.cache.symbols=void 0;}addSymbol(e){let t=this.project.incrementSymbolId(),r={...e,file:this,id:t,placeholder:a(String(t)),update:o=>this.updateSymbol(t,o)};return r.value===void 0?r.headless=true:r.headless||delete r.headless,this.state.symbols.set(t,r),this.project.registerSymbol(r,this),r.headless||this.addRenderSymbol(t),r}ensureSymbol(e){return this.selectSymbolFirst(e.selector)||this.addSymbol({name:"",...e})}get exports(){return this.cache.exports||(this.cache.exports=Array.from(this.state.exports.values())),this.cache.exports}getAllSymbols(){return [...this.symbols,...this.imports.flatMap(e=>(e.names??[]).map(t=>({name:e.aliases?.[t]??t}))),...this.exports.flatMap(e=>(e.names??[]).map(t=>({name:e.aliases?.[t]??t})))]}getImportExportKey(e){return typeof e.from=="string"?e.from:e.from.path}getSymbolById(e){return this.state.symbols.get(e)}hasContent(){return this.state.exports.size>0||this.symbols.length>0}hasSymbol(e){return this.state.symbols.has(e)}get imports(){return this.cache.imports||(this.cache.imports=Array.from(this.state.imports.values())),this.cache.imports}mergeImportExportValues(e,t){e.aliases={...e.aliases,...t.aliases},t.defaultImport!==void 0&&(e.defaultImport=t.defaultImport),e.names=[...new Set([...e.names??[],...t.names??[]])],t.namespaceImport!==void 0&&(e.namespaceImport=t.namespaceImport),t.typeDefaultImport!==void 0&&(e.typeDefaultImport=t.typeDefaultImport),e.typeNames=[...new Set([...e.typeNames??[],...t.typeNames??[]])],t.typeNamespaceImport!==void 0&&(e.typeNamespaceImport=t.typeNamespaceImport);}static pathToFilePath(e){return e.includes("/")?e.split("/").filter(Boolean).join(i__default.default.sep):e.includes("\\")?e.split("\\").filter(Boolean).join(i__default.default.sep):e.split(i__default.default.sep).filter(Boolean).join(i__default.default.sep)}relativePathFromFile(e){let t=i__default.default.posix.relative(i__default.default.posix.dirname(e.path),this.path);return t.startsWith(".")||(t=`./${t}`),t}relativePathToFile(e){let t=i__default.default.posix.relative(i__default.default.posix.dirname(this.path.split(i__default.default.sep).join("/")),e.path.split(i__default.default.sep).join("/"));return !t.startsWith(".")&&t!==""&&(t=`./${t}`),t}selectSymbolAll(e){return this.project.selectSymbolAll(e,this)}selectSymbolFirst(e){return this.project.selectSymbolFirst(e,this)}selectSymbolFirstOrThrow(e){return this.project.selectSymbolFirstOrThrow(e,this)}selectSymbolLast(e){return this.project.selectSymbolLast(e,this)}get symbols(){return this.cache.symbols||(this.cache.symbols=this.renderSymbols.map(e=>this.getSymbolById(e))),this.cache.symbols}updateSymbol(e,t){let r=this.getSymbolById(e);if(!r)throw new Error(`symbol with id ${e} not found`);let o={...r,...t,id:e};return (!o.headless||o.value)&&delete o.headless,this.state.symbols.set(o.id,o),r.headless&&!o.headless&&this.addRenderSymbol(e),o}};var I=class{fileId=0;fileIdToFile=new Map;fileOrder=[];filePathToFileId=new Map;renderers=new Map;selectorToSymbolIds=new Map;symbolId=0;symbolIdToFileId=new Map;addExport(e,t){this.ensureFile(e).addExport(t);}addImport(e,t){this.ensureFile(e).addImport(t);}addSymbol(e,t){return this.ensureFile(e).addSymbol(t)}createFile(e,t={}){let{renderer:r,...o}=t;r&&this.ensureRenderer(r);let s=this.getFileByPath(e);if(s)return r?.id&&r.id!==s.meta.renderer&&(s.meta.renderer=r.id),s;let n=new m(e,this,{...o,renderer:r?.id});return this.fileOrder.push(n),this.filePathToFileId.set(e,n.id),this.fileIdToFile.set(n.id,n),n}ensureFile(e){if(typeof e!="string")return e;let t=this.getFileByPath(e);return t||this.createFile(e)}ensureRenderer(e){return this.renderers.has(e.id)||this.renderers.set(e.id,e),this.renderers.get(e.id)}get files(){return [...this.fileOrder]}getAllSymbols(){return this.fileOrder.flatMap(e=>e.getAllSymbols())}getFileByPath(e){let t=this.filePathToFileId.get(e);return t!==void 0?this.fileIdToFile.get(t):void 0}getFileBySymbolId(e){let t=this.symbolIdToFileId.get(e);return t!==void 0?this.fileIdToFile.get(t):void 0}getFileRenderer(e){return e.meta.renderer?this.renderers.get(e.meta.renderer):void 0}getSymbolById(e){return this.getFileBySymbolId(e)?.getSymbolById(e)}incrementFileId(){return this.fileId++}incrementSymbolId(){return this.symbolId++}registerSymbol(e,t){if(this.symbolIdToFileId.set(e.id,t.id),e.selector){let r=JSON.stringify(e.selector),o=this.selectorToSymbolIds.get(r)??[];o.push(e.id),this.selectorToSymbolIds.set(r,o);}}render(e){let t=[];return this.fileOrder.forEach((r,o)=>{let s=this.getFileRenderer(r);s&&(t[o]={content:s.renderSymbols(r,e),meta:r.meta,path:`${r.path}${r.meta.extension??""}`});}),this.fileOrder.forEach((r,o)=>{let s=this.getFileRenderer(r);if(!s||!t[o])return;let n=s.renderHeader(r,e),p=y(t[o].content,g=>s.replacerFn({file:r,symbolId:g}));t[o].content=`${n}${p}`;}),t.filter(Boolean)}selectSymbolAll(e,t){let r=this.selectorToSymbolIds.get(JSON.stringify(e))??[],o=[];for(let s of r){let n=this.getFileBySymbolId(s);if(!n||t&&t!==n)continue;let p=n.getSymbolById(s);p&&o.push(p);}return o}selectSymbolFirst(e,t){return this.selectSymbolAll(e,t)[0]}selectSymbolFirstOrThrow(e,t){let r=this.selectSymbolFirst(e,t);if(!r)throw new Error(`symbol for selector not found: ${JSON.stringify(e)}`);return r}selectSymbolLast(e,t){let r=this.selectSymbolAll(e,t);return r[r.length-1]}};exports.BiMap=d;exports.CodegenFile=m;exports.CodegenProject=I;exports.replaceWrappedIds=y;//# sourceMappingURL=index.cjs.map | ||
| //# sourceMappingURL=index.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/files/file.ts","../src/project/project.ts"],"names":["CodegenFile","_CodegenFile","path","meta","filePath","exp","imp","value","field","key","existing","symbol","name","target","source","file","relativePath","CodegenProject","fileOrPath","renderer","metadata","existingFile","results"],"mappings":"mJAMO,IAAMA,EAAN,MAAMC,CAAoC,CAiB/C,WAAA,CACSC,CAAAA,CACAC,EAA6B,EAAC,CACrC,CAFO,IAAA,CAAA,IAAA,CAAAD,CAAAA,CACA,UAAAC,CAAAA,CAEP,IAAIC,EAAWH,CAAAA,CAAY,cAAA,CAAeC,CAAI,CAAA,CAC1CC,EAAK,IAAA,GACH,OAAOA,EAAK,IAAA,EAAS,UAAA,CACvBC,EAAWD,CAAAA,CAAK,IAAA,CAAKC,CAAQ,CAAA,CAE7BA,CAAAA,CAAWD,EAAK,IAAA,CAAK,OAAA,CAAQ,WAAYC,CAAQ,CAAA,CAAA,CAGrD,KAAK,IAAA,CAAOA,EACd,CA7BQ,KAAA,CAIJ,EAAC,CAEG,KAAA,CAIJ,CACF,OAAA,CAAS,IAAI,IACb,OAAA,CAAS,IAAI,IACb,OAAA,CAAS,IAAI,GACf,CAAA,CAiBA,SAAA,CAAUC,EAA2B,CACnC,OAAO,KAAK,eAAA,CAAgBA,CAAAA,CAAK,SAAS,CAC5C,CAEA,SAAA,CAAUC,CAAAA,CA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QAAQ,EACjDI,CAAAA,EACLG,CAAAA,CAAQ,KAAKH,CAAAA,CAAS,MAAA,CAAOJ,EAAMZ,CAAI,CAAC,EAC1C,CACA,OAAOmB,CACT,CACF","file":"index.cjs","sourcesContent":["import path from 'node:path';\n\nimport type { ICodegenImport } from '../imports/types';\nimport type { ICodegenSymbol } from '../symbols/types';\nimport type { ICodegenFile } from './types';\n\nexport class CodegenFile implements ICodegenFile {\n private cache: {\n exports?: ReadonlyArray<ICodegenImport>;\n imports?: ReadonlyArray<ICodegenImport>;\n symbols?: ReadonlyArray<ICodegenSymbol>;\n } = {};\n\n private state: {\n exports: Map<string, ICodegenImport>;\n imports: Map<string, ICodegenImport>;\n symbols: Map<string, ICodegenSymbol>;\n } = {\n exports: new Map(),\n imports: new Map(),\n symbols: new Map(),\n };\n\n constructor(\n public path: string,\n public meta: ICodegenFile['meta'] = {},\n ) {\n let filePath = CodegenFile.pathToFilePath(path);\n if (meta.path) {\n if (typeof meta.path === 'function') {\n filePath = meta.path(filePath);\n } else {\n filePath = meta.path.replace('{{path}}', filePath);\n }\n }\n this.path = filePath;\n }\n\n addExport(exp: ICodegenImport): void {\n return this.addImportExport(exp, 'exports');\n }\n\n addImport(imp: ICodegenImport): void {\n return this.addImportExport(imp, 'imports');\n }\n\n private addImportExport(\n value: ICodegenImport,\n field: 'exports' | 'imports',\n ): void {\n const key = typeof value.from === 'string' ? value.from : value.from.path;\n const existing = this.state[field].get(key);\n if (existing) {\n this.mergeImportExportValues(existing, value);\n this.state[field].set(key, existing);\n } else {\n this.state[field].set(key, { ...value }); // clone to avoid mutation\n }\n this.cache[field] = undefined;\n }\n\n addSymbol(symbol: ICodegenSymbol): void {\n const key = symbol.name;\n const existing = this.state.symbols.get(key);\n if (existing) {\n existing.value = symbol.value;\n this.state.symbols.set(key, existing);\n } else {\n this.state.symbols.set(key, { ...symbol }); // clone to avoid mutation\n }\n this.cache.symbols = undefined;\n }\n\n get exports(): ReadonlyArray<ICodegenImport> {\n if (!this.cache.exports) {\n this.cache.exports = Array.from(this.state.exports.values());\n }\n return this.cache.exports;\n }\n\n getAllSymbols(): ReadonlyArray<ICodegenSymbol> {\n return [\n ...this.symbols,\n ...this.imports.flatMap((imp) =>\n (imp.names ?? []).map((name) => ({\n name: imp.aliases?.[name] ?? name,\n })),\n ),\n ...this.exports.flatMap((imp) =>\n (imp.names ?? []).map((name) => ({\n name: imp.aliases?.[name] ?? name,\n })),\n ),\n ];\n }\n\n hasContent(): boolean {\n return this.state.symbols.size > 0 || this.state.exports.size > 0;\n }\n\n hasSymbol(name: string): boolean {\n return this.state.symbols.has(name);\n }\n\n get imports(): ReadonlyArray<ICodegenImport> {\n if (!this.cache.imports) {\n this.cache.imports = Array.from(this.state.imports.values());\n }\n return this.cache.imports;\n }\n\n private mergeImportExportValues(\n target: ICodegenImport,\n source: ICodegenImport,\n ): void {\n target.aliases = { ...target.aliases, ...source.aliases };\n if (source.defaultImport !== undefined) {\n target.defaultImport = source.defaultImport;\n }\n target.names = [\n ...new Set([...(target.names ?? []), ...(source.names ?? [])]),\n ];\n if (source.namespaceImport !== undefined) {\n target.namespaceImport = source.namespaceImport;\n }\n if (source.typeDefaultImport !== undefined) {\n target.typeDefaultImport = source.typeDefaultImport;\n }\n target.typeNames = [\n ...new Set([...(target.typeNames ?? []), ...(source.typeNames ?? [])]),\n ];\n if (source.typeNamespaceImport !== undefined) {\n target.typeNamespaceImport = source.typeNamespaceImport;\n }\n }\n\n static pathToFilePath(source: string): string {\n if (source.includes('/')) {\n return source.split('/').filter(Boolean).join(path.sep);\n }\n if (source.includes('\\\\')) {\n return source.split('\\\\').filter(Boolean).join(path.sep);\n }\n return source.split(path.sep).filter(Boolean).join(path.sep);\n }\n\n relativePathFromFile(file: Pick<ICodegenFile, 'path'>): string {\n let relativePath = path.posix.relative(\n path.posix.dirname(file.path),\n this.path,\n );\n if (!relativePath.startsWith('.')) {\n relativePath = `./${relativePath}`;\n }\n return relativePath;\n }\n\n relativePathToFile(file: Pick<ICodegenFile, 'path'>): string {\n let relativePath = path.posix.relative(\n path.posix.dirname(this.path),\n file.path,\n );\n if (!relativePath.startsWith('.')) {\n relativePath = `./${relativePath}`;\n }\n return relativePath;\n }\n\n get symbols(): ReadonlyArray<ICodegenSymbol> {\n if (!this.cache.symbols) {\n this.cache.symbols = Array.from(this.state.symbols.values());\n }\n return this.cache.symbols;\n }\n}\n","import { CodegenFile } from '../files/file';\nimport type { ICodegenImport } from '../imports/types';\nimport type { ICodegenMeta } from '../meta/types';\nimport type { ICodegenOutput } from '../output/types';\nimport type { ICodegenRenderer } from '../renderers/types';\nimport type { ICodegenSymbol } from '../symbols/types';\nimport type { ICodegenProject } from './types';\n\nexport class CodegenProject implements ICodegenProject {\n private filesMap: Map<string, CodegenFile> = new Map();\n private filesOrder: Array<CodegenFile> = [];\n private renderers: Map<string, ICodegenRenderer> = new Map();\n\n addExportToFile(fileOrPath: CodegenFile | string, imp: ICodegenImport): void {\n const file = this.ensureFile(fileOrPath);\n file.addExport(imp);\n }\n\n addImportToFile(fileOrPath: CodegenFile | string, imp: ICodegenImport): void {\n const file = this.ensureFile(fileOrPath);\n file.addImport(imp);\n }\n\n addSymbolToFile(\n fileOrPath: CodegenFile | string,\n symbol: ICodegenSymbol,\n ): void {\n const file = this.ensureFile(fileOrPath);\n file.addSymbol(symbol);\n }\n\n createFile(\n path: string,\n meta: Omit<CodegenFile['meta'], 'renderer'> & {\n /**\n * Renderer to use to render this file.\n */\n renderer?: ICodegenRenderer;\n } = {},\n ): CodegenFile {\n const { renderer, ...metadata } = meta;\n if (renderer) {\n this.ensureRenderer(renderer);\n }\n\n const existing = this.getFileByPath(path);\n if (existing) {\n // Whoever is creating the file will override the renderer\n if (renderer?.id && renderer.id !== existing.meta.renderer) {\n existing.meta.renderer = renderer.id;\n }\n return existing;\n }\n\n const file = new CodegenFile(path, {\n ...metadata,\n renderer: renderer?.id,\n });\n this.filesOrder.push(file);\n this.filesMap.set(path, file);\n return file;\n }\n\n ensureFile(fileOrPath: CodegenFile | string): CodegenFile {\n if (typeof fileOrPath !== 'string') {\n return fileOrPath;\n }\n const existingFile = this.getFileByPath(fileOrPath);\n if (existingFile) {\n return existingFile;\n }\n return this.createFile(fileOrPath);\n }\n\n private ensureRenderer(renderer: ICodegenRenderer): ICodegenRenderer {\n if (!this.renderers.has(renderer.id)) {\n this.renderers.set(renderer.id, renderer);\n }\n return this.renderers.get(renderer.id)!;\n }\n\n get files(): ReadonlyArray<CodegenFile> {\n return [...this.filesOrder];\n }\n\n getAllSymbols(): ReadonlyArray<ICodegenSymbol> {\n return this.filesOrder.flatMap((file) => file.getAllSymbols());\n }\n\n getFileByPath(path: string): CodegenFile | undefined {\n return this.filesMap.get(path);\n }\n\n render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput> {\n const results: Array<ICodegenOutput> = [];\n for (const file of this.filesOrder) {\n if (!file.meta.renderer) continue;\n const renderer = this.renderers.get(file.meta.renderer);\n if (!renderer) continue;\n results.push(renderer.render(file, meta));\n }\n return results;\n }\n}\n"]} | ||
| {"version":3,"sources":["../src/bimap/bimap.ts","../src/renderers/renderer.ts","../src/files/file.ts","../src/project/project.ts"],"names":["BiMap","key","value","wrapId","symbolId","unwrapId","wrappedId","createPlaceholderRegExp","replaceWrappedIds","source","replacerFn","match","CodegenFile","_CodegenFile","path","project","meta","filePath","exp","imp","field","existing","typeName","id","symbol","inserted","values","name","target","file","relativePath","selector","updated","CodegenProject","fileOrPath","renderer","_meta","existingFile","fileId","ids","results","index","header","content","symbols","f"],"mappings":"mJAEO,IAAMA,EAAN,KAA6D,CAC1D,IAAM,IAAI,GAAA,CACV,QAAU,IAAI,GAAA,CAEtB,OAAOC,CAAAA,CAAmB,CACxB,IAAMC,CAAAA,CAAQ,IAAA,CAAK,IAAI,GAAA,CAAID,CAAG,EAC9B,OAAIC,CAAAA,GAAU,MAAA,EACZ,IAAA,CAAK,QAAQ,MAAA,CAAOA,CAAK,EAEpB,IAAA,CAAK,GAAA,CAAI,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,MAAA,CAAS,CAAC,CACnC,CACF","file":"index.cjs","sourcesContent":["import type { ICodegenBiMap } from './types';\n\nexport class BiMap<Key, Value> implements ICodegenBiMap<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 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","/**\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 replaceWrappedIds = (\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 path from 'node:path';\n\nimport { BiMap } from '../bimap/bimap';\nimport type { ICodegenBiMap } from '../bimap/types';\nimport type { ICodegenImport } from '../imports/types';\nimport type { ICodegenProject } from '../project/types';\nimport { wrapId } from '../renderers/renderer';\nimport type {\n ICodegenSymbolIn,\n ICodegenSymbolOut,\n ICodegenSymbolSelector,\n} from '../symbols/types';\nimport type { ICodegenFile } from './types';\n\nexport class CodegenFile implements ICodegenFile {\n private cache: {\n exports?: ReadonlyArray<ICodegenImport>;\n imports?: ReadonlyArray<ICodegenImport>;\n symbols?: ReadonlyArray<ICodegenSymbolOut>;\n } = {};\n\n private renderSymbols: Array<number> = [];\n\n private state: {\n exports: Map<string, ICodegenImport>;\n imports: Map<string, ICodegenImport>;\n symbols: Map<number, ICodegenSymbolOut>;\n } = {\n exports: new Map(),\n imports: new Map(),\n symbols: new Map(),\n };\n\n id: number;\n resolvedNames: ICodegenBiMap<number, string> = new BiMap();\n\n constructor(\n public path: string,\n public project: ICodegenProject,\n public meta: ICodegenFile['meta'] = {},\n ) {\n let filePath = CodegenFile.pathToFilePath(path);\n if (meta.path) {\n if (typeof meta.path === 'function') {\n filePath = meta.path(filePath);\n } else {\n filePath = meta.path.replace('{{path}}', filePath);\n }\n }\n this.id = project.incrementFileId();\n this.path = filePath;\n }\n\n addExport(exp: ICodegenImport): void {\n return this.addImportExport(exp, 'exports');\n }\n\n addImport(imp: ICodegenImport): void {\n return this.addImportExport(imp, 'imports');\n }\n\n private addImportExport(\n value: ICodegenImport,\n field: 'exports' | 'imports',\n ): void {\n const key = this.getImportExportKey(value);\n const existing = this.state[field].get(key);\n // cast type names to names to allow for cleaner API,\n // otherwise users would have to define the same values twice\n if (!value.names) value.names = [];\n for (const typeName of value.typeNames ?? []) {\n if (!value.names.includes(typeName)) {\n value.names = [...value.names, typeName];\n }\n }\n if (existing) {\n this.mergeImportExportValues(existing, value);\n this.state[field].set(key, existing);\n } else {\n this.state[field].set(key, { ...value }); // clone to avoid mutation\n }\n this.cache[field] = undefined; // invalidate cache\n }\n\n private addRenderSymbol(id: number): void {\n this.renderSymbols.push(id);\n this.cache.symbols = undefined; // invalidate cache\n }\n\n addSymbol(symbol: ICodegenSymbolIn): ICodegenSymbolOut {\n const id = this.project.incrementSymbolId();\n const inserted: ICodegenSymbolOut = {\n ...symbol, // clone to avoid mutation\n file: this,\n id,\n placeholder: wrapId(String(id)),\n update: (values) => this.updateSymbol(id, values),\n };\n if (inserted.value === undefined) {\n // register symbols without value as headless\n inserted.headless = true;\n } else if (!inserted.headless) {\n delete inserted.headless;\n }\n this.state.symbols.set(id, inserted);\n this.project.registerSymbol(inserted, this);\n if (!inserted.headless) {\n this.addRenderSymbol(id);\n }\n return inserted;\n }\n\n ensureSymbol(\n symbol: Partial<ICodegenSymbolIn> &\n Pick<Required<ICodegenSymbolIn>, 'selector'>,\n ): ICodegenSymbolOut {\n return (\n this.selectSymbolFirst(symbol.selector) ||\n this.addSymbol({ name: '', ...symbol })\n );\n }\n\n get exports(): ReadonlyArray<ICodegenImport> {\n if (!this.cache.exports) {\n this.cache.exports = Array.from(this.state.exports.values());\n }\n return this.cache.exports;\n }\n\n getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>> {\n return [\n ...this.symbols,\n ...this.imports.flatMap((imp) =>\n (imp.names ?? []).map((name) => ({\n name: imp.aliases?.[name] ?? name,\n })),\n ),\n ...this.exports.flatMap((imp) =>\n (imp.names ?? []).map((name) => ({\n name: imp.aliases?.[name] ?? name,\n })),\n ),\n ];\n }\n\n private getImportExportKey(value: ICodegenImport): string {\n if (typeof value.from === 'string') {\n return value.from;\n }\n return value.from.path;\n }\n\n getSymbolById(id: number): ICodegenSymbolOut | undefined {\n return this.state.symbols.get(id);\n }\n\n hasContent(): boolean {\n return this.state.exports.size > 0 || this.symbols.length > 0;\n }\n\n hasSymbol(id: number): boolean {\n return this.state.symbols.has(id);\n }\n\n get imports(): ReadonlyArray<ICodegenImport> {\n if (!this.cache.imports) {\n this.cache.imports = Array.from(this.state.imports.values());\n }\n return this.cache.imports;\n }\n\n private mergeImportExportValues(\n target: ICodegenImport,\n source: ICodegenImport,\n ): void {\n target.aliases = { ...target.aliases, ...source.aliases };\n if (source.defaultImport !== undefined) {\n target.defaultImport = source.defaultImport;\n }\n target.names = [\n ...new Set([...(target.names ?? []), ...(source.names ?? [])]),\n ];\n if (source.namespaceImport !== undefined) {\n target.namespaceImport = source.namespaceImport;\n }\n if (source.typeDefaultImport !== undefined) {\n target.typeDefaultImport = source.typeDefaultImport;\n }\n target.typeNames = [\n ...new Set([...(target.typeNames ?? []), ...(source.typeNames ?? [])]),\n ];\n if (source.typeNamespaceImport !== undefined) {\n target.typeNamespaceImport = source.typeNamespaceImport;\n }\n }\n\n static pathToFilePath(source: string): string {\n if (source.includes('/')) {\n return source.split('/').filter(Boolean).join(path.sep);\n }\n if (source.includes('\\\\')) {\n return source.split('\\\\').filter(Boolean).join(path.sep);\n }\n return source.split(path.sep).filter(Boolean).join(path.sep);\n }\n\n relativePathFromFile(file: Pick<ICodegenFile, 'path'>): string {\n let relativePath = path.posix.relative(\n path.posix.dirname(file.path),\n this.path,\n );\n if (!relativePath.startsWith('.')) {\n relativePath = `./${relativePath}`;\n }\n return relativePath;\n }\n\n relativePathToFile(file: Pick<ICodegenFile, 'path'>): string {\n let relativePath = path.posix.relative(\n path.posix.dirname(\n this.path.split(path.sep).join('/'), // normalize to posix\n ),\n file.path.split(path.sep).join('/'), // normalize to posix\n );\n if (!relativePath.startsWith('.') && relativePath !== '') {\n relativePath = `./${relativePath}`;\n }\n return relativePath;\n }\n\n selectSymbolAll(\n selector: ICodegenSymbolSelector,\n ): ReadonlyArray<ICodegenSymbolOut> {\n return this.project.selectSymbolAll(selector, this);\n }\n\n selectSymbolFirst(\n selector: ICodegenSymbolSelector,\n ): ICodegenSymbolOut | undefined {\n return this.project.selectSymbolFirst(selector, this);\n }\n\n selectSymbolFirstOrThrow(\n selector: ICodegenSymbolSelector,\n ): ICodegenSymbolOut {\n return this.project.selectSymbolFirstOrThrow(selector, this);\n }\n\n selectSymbolLast(\n selector: ICodegenSymbolSelector,\n ): ICodegenSymbolOut | undefined {\n return this.project.selectSymbolLast(selector, this);\n }\n\n get symbols(): ReadonlyArray<ICodegenSymbolOut> {\n if (!this.cache.symbols) {\n this.cache.symbols = this.renderSymbols.map(\n (id) => this.getSymbolById(id)!,\n );\n }\n return this.cache.symbols;\n }\n\n updateSymbol(\n id: number,\n symbol: Partial<ICodegenSymbolOut>,\n ): ICodegenSymbolOut {\n const existing = this.getSymbolById(id);\n if (!existing) {\n throw new Error(`symbol with id ${id} not found`);\n }\n const updated: ICodegenSymbolOut = { ...existing, ...symbol, id };\n // symbols with value can't be headless, clear redundant flag otherwise\n if (!updated.headless || updated.value) {\n delete updated.headless;\n }\n this.state.symbols.set(updated.id, updated);\n if (existing.headless && !updated.headless) {\n this.addRenderSymbol(id);\n }\n return updated;\n }\n}\n","import { CodegenFile } from '../files/file';\nimport type { ICodegenFile } from '../files/types';\nimport type { ICodegenImport } from '../imports/types';\nimport type { ICodegenMeta } from '../meta/types';\nimport type { ICodegenOutput } from '../output/types';\nimport { replaceWrappedIds } from '../renderers/renderer';\nimport type { ICodegenRenderer } from '../renderers/types';\nimport type {\n ICodegenSymbolIn,\n ICodegenSymbolOut,\n ICodegenSymbolSelector,\n} from '../symbols/types';\nimport type { ICodegenProject } from './types';\n\nexport class CodegenProject implements ICodegenProject {\n private fileId: number = 0;\n private fileIdToFile: Map<number, ICodegenFile> = new Map();\n private fileOrder: Array<ICodegenFile> = [];\n private filePathToFileId: Map<string, number> = new Map();\n private renderers: Map<string, ICodegenRenderer> = new Map();\n private selectorToSymbolIds: Map<string, Array<number>> = new Map();\n private symbolId: number = 0;\n private symbolIdToFileId: Map<number, number> = new Map();\n\n addExport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void {\n const file = this.ensureFile(fileOrPath);\n file.addExport(imp);\n }\n\n addImport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void {\n const file = this.ensureFile(fileOrPath);\n file.addImport(imp);\n }\n\n addSymbol(\n fileOrPath: ICodegenFile | string,\n symbol: ICodegenSymbolIn,\n ): ICodegenSymbolOut {\n const file = this.ensureFile(fileOrPath);\n return file.addSymbol(symbol);\n }\n\n createFile(\n path: string,\n meta: Omit<ICodegenFile['meta'], 'renderer'> & {\n /**\n * Renderer to use to render this file.\n */\n renderer?: ICodegenRenderer;\n } = {},\n ): ICodegenFile {\n const { renderer, ..._meta } = meta;\n if (renderer) {\n this.ensureRenderer(renderer);\n }\n\n const existing = this.getFileByPath(path);\n if (existing) {\n // Whoever is creating the file will override the renderer\n if (renderer?.id && renderer.id !== existing.meta.renderer) {\n existing.meta.renderer = renderer.id;\n }\n return existing;\n }\n\n const file = new CodegenFile(path, this, {\n ..._meta,\n renderer: renderer?.id,\n });\n this.fileOrder.push(file);\n this.filePathToFileId.set(path, file.id);\n this.fileIdToFile.set(file.id, file);\n return file;\n }\n\n ensureFile(fileOrPath: ICodegenFile | string): ICodegenFile {\n if (typeof fileOrPath !== 'string') {\n return fileOrPath;\n }\n const existingFile = this.getFileByPath(fileOrPath);\n if (existingFile) {\n return existingFile;\n }\n return this.createFile(fileOrPath);\n }\n\n private ensureRenderer(renderer: ICodegenRenderer): ICodegenRenderer {\n if (!this.renderers.has(renderer.id)) {\n this.renderers.set(renderer.id, renderer);\n }\n return this.renderers.get(renderer.id)!;\n }\n\n get files(): ReadonlyArray<ICodegenFile> {\n return [...this.fileOrder];\n }\n\n getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>> {\n return this.fileOrder.flatMap((file) => file.getAllSymbols());\n }\n\n getFileByPath(path: string): ICodegenFile | undefined {\n const fileId = this.filePathToFileId.get(path);\n return fileId !== undefined ? this.fileIdToFile.get(fileId) : undefined;\n }\n\n getFileBySymbolId(id: number): ICodegenFile | undefined {\n const fileId = this.symbolIdToFileId.get(id);\n return fileId !== undefined ? this.fileIdToFile.get(fileId) : undefined;\n }\n\n private getFileRenderer(file: ICodegenFile): ICodegenRenderer | undefined {\n return file.meta.renderer\n ? this.renderers.get(file.meta.renderer)\n : undefined;\n }\n\n getSymbolById(id: number): ICodegenSymbolOut | undefined {\n const file = this.getFileBySymbolId(id);\n return file?.getSymbolById(id);\n }\n\n incrementFileId(): number {\n return this.fileId++;\n }\n\n incrementSymbolId(): number {\n return this.symbolId++;\n }\n\n registerSymbol(symbol: ICodegenSymbolOut, file: ICodegenFile): void {\n this.symbolIdToFileId.set(symbol.id, file.id);\n if (symbol.selector) {\n const selector = JSON.stringify(symbol.selector);\n const ids = this.selectorToSymbolIds.get(selector) ?? [];\n ids.push(symbol.id);\n this.selectorToSymbolIds.set(selector, ids);\n }\n }\n\n render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput> {\n const results: Array<ICodegenOutput> = [];\n this.fileOrder.forEach((file, index) => {\n const renderer = this.getFileRenderer(file);\n if (!renderer) return;\n results[index] = {\n content: renderer.renderSymbols(file, meta),\n meta: file.meta,\n path: `${file.path}${file.meta.extension ?? ''}`,\n };\n });\n this.fileOrder.forEach((file, index) => {\n const renderer = this.getFileRenderer(file);\n if (!renderer || !results[index]) return;\n const header = renderer.renderHeader(file, meta);\n const content = replaceWrappedIds(results[index].content, (symbolId) =>\n renderer.replacerFn({ file, symbolId }),\n );\n results[index].content = `${header}${content}`;\n });\n return results.filter(Boolean);\n }\n\n selectSymbolAll(\n selector: ICodegenSymbolSelector,\n file?: ICodegenFile,\n ): ReadonlyArray<ICodegenSymbolOut> {\n const ids = this.selectorToSymbolIds.get(JSON.stringify(selector)) ?? [];\n const symbols: Array<ICodegenSymbolOut> = [];\n for (const id of ids) {\n const f = this.getFileBySymbolId(id);\n if (!f || (file && file !== f)) continue;\n const symbol = f.getSymbolById(id);\n if (!symbol) continue;\n symbols.push(symbol);\n }\n return symbols;\n }\n\n selectSymbolFirst(\n selector: ICodegenSymbolSelector,\n file?: ICodegenFile,\n ): ICodegenSymbolOut | undefined {\n const symbols = this.selectSymbolAll(selector, file);\n return symbols[0];\n }\n\n selectSymbolFirstOrThrow(\n selector: ICodegenSymbolSelector,\n file?: ICodegenFile,\n ): ICodegenSymbolOut {\n const symbol = this.selectSymbolFirst(selector, file);\n if (!symbol)\n throw new Error(\n `symbol for selector not found: ${JSON.stringify(selector)}`,\n );\n return symbol;\n }\n\n selectSymbolLast(\n selector: ICodegenSymbolSelector,\n file?: ICodegenFile,\n ): ICodegenSymbolOut | undefined {\n const symbols = this.selectSymbolAll(selector, file);\n return symbols[symbols.length - 1];\n }\n}\n"]} |
+468
-137
| /** | ||
| * Bi-directional map interface. | ||
| * | ||
| * Keys map to values and values map back to keys. | ||
| * | ||
| * @template Key Type of the map keys | ||
| * @template Value Type of the map values | ||
| */ | ||
| interface ICodegenBiMap<Key, Value> { | ||
| /** | ||
| * Deletes a key and its associated value from the map. | ||
| * | ||
| * @param key The key to delete. | ||
| */ | ||
| delete(key: Key): boolean; | ||
| /** | ||
| * Deletes a value and its associated key from the map. | ||
| * | ||
| * @param value The value to delete. | ||
| */ | ||
| deleteValue(value: Value): boolean; | ||
| /** | ||
| * Returns an iterator of [key, value] pairs. | ||
| */ | ||
| entries(): IterableIterator<[Key, Value]>; | ||
| /** | ||
| * Gets the value associated with a key. | ||
| * | ||
| * @param key The key to look up. | ||
| */ | ||
| get(key: Key): Value | undefined; | ||
| /** | ||
| * Gets the key associated with a value. | ||
| * | ||
| * @param value The value to look up. | ||
| */ | ||
| getKey(value: Value): Key | undefined; | ||
| /** | ||
| * Checks if a key exists in the map. | ||
| * | ||
| * @param key The key to check. | ||
| */ | ||
| hasKey(key: Key): boolean; | ||
| /** | ||
| * Checks if a value exists in the map. | ||
| * | ||
| * @param value The value to check. | ||
| */ | ||
| hasValue(value: Value): boolean; | ||
| /** | ||
| * Returns an iterator of keys. | ||
| */ | ||
| keys(): IterableIterator<Key>; | ||
| /** | ||
| * Sets a key-value pair in the map. | ||
| * | ||
| * @param key The key. | ||
| * @param value The value. | ||
| * @returns This instance for chaining. | ||
| */ | ||
| set(key: Key, value: Value): this; | ||
| /** | ||
| * Number of key-value pairs in the map. | ||
| */ | ||
| readonly size: number; | ||
| /** | ||
| * Returns an iterator of values. | ||
| */ | ||
| values(): IterableIterator<Value>; | ||
| /** | ||
| * Enables iteration with `for...of`. | ||
| */ | ||
| [Symbol.iterator](): IterableIterator<[Key, Value]>; | ||
| } | ||
| declare class BiMap<Key, Value> implements ICodegenBiMap<Key, Value> { | ||
| private map; | ||
| private reverse; | ||
| delete(key: Key): boolean; | ||
| deleteValue(value: Value): boolean; | ||
| entries(): IterableIterator<[Key, Value]>; | ||
| get(key: Key): Value | undefined; | ||
| getKey(value: Value): Key | undefined; | ||
| hasKey(key: Key): boolean; | ||
| hasValue(value: Value): boolean; | ||
| keys(): IterableIterator<Key>; | ||
| set(key: Key, value: Value): this; | ||
| get size(): number; | ||
| values(): IterableIterator<Value>; | ||
| [Symbol.iterator](): IterableIterator<[Key, Value]>; | ||
| } | ||
| /** | ||
| * Arbitrary metadata passed to render functions. | ||
@@ -46,39 +138,297 @@ * | ||
| /** | ||
| * Returns printable data. | ||
| * Returns printable data containing header and imports. | ||
| * | ||
| * @param file The file to render. | ||
| * @param meta Arbitrary metadata. | ||
| * @returns Output for file emit step | ||
| * @returns Printable string containing header and imports. | ||
| */ | ||
| render(file: CodegenFile, meta?: ICodegenMeta): ICodegenOutput; | ||
| renderHeader(file: ICodegenFile, meta?: ICodegenMeta): string; | ||
| /** | ||
| * Returns printable data containing symbols and exports. | ||
| * | ||
| * @param file The file to render. | ||
| * @param meta Arbitrary metadata. | ||
| * @returns Printable string containing symbols and exports. | ||
| */ | ||
| renderSymbols(file: ICodegenFile, meta?: ICodegenMeta): string; | ||
| /** | ||
| * Function replacing symbols with resolved names. | ||
| * | ||
| * @returns String with replaced symbols. | ||
| */ | ||
| replacerFn(args: { | ||
| file: ICodegenFile; | ||
| headless?: boolean; | ||
| scope?: 'file' | 'project'; | ||
| symbolId: number; | ||
| }): string | undefined; | ||
| } | ||
| interface ICodegenSymbol { | ||
| /** | ||
| * Selector array used to select symbols. It doesn't have to be | ||
| * unique, but in practice it might be desirable. | ||
| * | ||
| * @example ["zod", "#/components/schemas/Foo"] | ||
| */ | ||
| type ICodegenSymbolSelector = ReadonlyArray<string>; | ||
| interface ICodegenSymbolIn { | ||
| /** | ||
| * Optional description or doc comment. | ||
| * Symbols can be **headed** or **headless**. | ||
| * | ||
| * @example "Represents a user in the system" | ||
| * Headless symbols never render their `value`. Headed symbols render their | ||
| * `value` if defined. | ||
| * | ||
| * Symbols are rendered in the order they were registered as headed. | ||
| * | ||
| * Example 1: We register headless symbol `foo`, headed `bar`, and headed | ||
| * `foo`. The render order is [`bar`, `foo`]. | ||
| * | ||
| * Example 2: We register headed symbol `foo` and headed `bar`. The render | ||
| * order is [`foo`, `bar`]. | ||
| * | ||
| * Headless symbols can be used to claim a symbol or to represent imports | ||
| * or exports. | ||
| * | ||
| * @default false | ||
| */ | ||
| description?: string; | ||
| headless?: boolean; | ||
| /** | ||
| * Optional kind of symbol (e.g. "class", "function", "type", etc.). | ||
| * The desired name for the symbol within its file. If there are multiple symbols | ||
| * with the same desired name, this might not end up being the actual name. | ||
| * | ||
| * @example "class" | ||
| * @example "UserModel" | ||
| */ | ||
| kind?: string; | ||
| readonly name: string; | ||
| /** | ||
| * Unique identifier for the symbol within its file. | ||
| * Selector array used to select this symbol. It doesn't have to be | ||
| * unique, but in practice it might be desirable. | ||
| * | ||
| * @example "UserModel" | ||
| * @example ["zod", "#/components/schemas/Foo"] | ||
| */ | ||
| name: string; | ||
| readonly selector?: ICodegenSymbolSelector; | ||
| /** | ||
| * Internal representation of the symbol (e.g. AST node, IR object, raw | ||
| * code). Used to generate output. | ||
| * Internal representation of the symbol (e.g. AST node, IR object, raw code). | ||
| * Used to generate output. If left undefined, this symbol becomes `headless`. | ||
| */ | ||
| value?: unknown; | ||
| readonly value?: unknown; | ||
| } | ||
| interface ICodegenFile { | ||
| interface ICodegenSymbolOut extends ICodegenSymbolIn { | ||
| /** | ||
| * The file this symbol is located in. | ||
| */ | ||
| readonly file: ICodegenFile; | ||
| /** | ||
| * Unique symbol ID. | ||
| */ | ||
| readonly id: number; | ||
| /** | ||
| * Placeholder name for the symbol to be replaced later with the final value. | ||
| * | ||
| * @example "_heyapi_31_" | ||
| */ | ||
| readonly placeholder: string; | ||
| /** | ||
| * Updates this symbol. | ||
| * | ||
| * @param symbol The values to update. | ||
| * @returns The updated symbol. | ||
| */ | ||
| readonly update: (symbol: Partial<ICodegenSymbolOut>) => ICodegenSymbolOut; | ||
| } | ||
| interface SelectorMethods { | ||
| /** | ||
| * Retrieves symbols matching the selector. | ||
| * | ||
| * @param selector The symbol selector to find. | ||
| * @param file Find symbols only in this file. | ||
| * @returns The array of all symbols matching the selector. | ||
| * @example | ||
| * const symbols = project.selectSymbolAll(["zod", "#/components/schemas/Foo"]); | ||
| */ | ||
| selectSymbolAll( | ||
| selector: ICodegenSymbolSelector, | ||
| file?: ICodegenFile, | ||
| ): ReadonlyArray<ICodegenSymbolOut>; | ||
| /** | ||
| * Retrieves the first symbol from all symbols matching the selector. | ||
| * | ||
| * @param selector The symbol selector to find. | ||
| * @param file Find symbols only in this file. | ||
| * @returns The symbol if found, or undefined otherwise. | ||
| * @example | ||
| * const symbol = project.selectSymbolFirst(["zod", "#/components/schemas/Foo"]); | ||
| */ | ||
| selectSymbolFirst( | ||
| selector: ICodegenSymbolSelector, | ||
| file?: ICodegenFile, | ||
| ): ICodegenSymbolOut | undefined; | ||
| /** | ||
| * Retrieves the first symbol from all symbols matching the selector. | ||
| * | ||
| * @param selector The symbol selector to find. | ||
| * @param file Find symbols only in this file. | ||
| * @returns The symbol if found, or throw otherwise. | ||
| * @example | ||
| * const symbol = project.selectSymbolFirstOrThrow(["zod", "#/components/schemas/Foo"]); | ||
| */ | ||
| selectSymbolFirstOrThrow( | ||
| selector: ICodegenSymbolSelector, | ||
| file?: ICodegenFile, | ||
| ): ICodegenSymbolOut; | ||
| /** | ||
| * Retrieves the last symbol from all symbols matching the selector. | ||
| * | ||
| * @param selector The symbol selector to find. | ||
| * @param file Find symbols only in this file. | ||
| * @returns The symbol if found, or undefined otherwise. | ||
| * @example | ||
| * const symbol = project.selectSymbolLast(["zod", "#/components/schemas/Foo"]); | ||
| */ | ||
| selectSymbolLast( | ||
| selector: ICodegenSymbolSelector, | ||
| file?: ICodegenFile, | ||
| ): ICodegenSymbolOut | undefined; | ||
| } | ||
| /** | ||
| * Represents a code generation project consisting of multiple codegen files. | ||
| * Manages imports, symbols, and output generation across the project. | ||
| */ | ||
| interface ICodegenProject extends SelectorMethods { | ||
| /** | ||
| * Adds an export declaration to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the export. | ||
| * @param imp - The export declaration to add. | ||
| * @example | ||
| * project.addExport("models/user.ts", { from: "lib", names: ["User"] }); | ||
| */ | ||
| addExport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| /** | ||
| * Adds an import declaration to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the import. | ||
| * @param imp - The import declaration to add. | ||
| * @example | ||
| * project.addImport("models/user.ts", { from: "lib", names: ["User"] }); | ||
| */ | ||
| addImport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| /** | ||
| * Adds a symbol to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the symbol. | ||
| * @param symbol - The symbol to add. | ||
| * @returns The inserted symbol. | ||
| * @example | ||
| * project.addSymbol("models/user.ts", { name: "User", value: tsNode }); | ||
| */ | ||
| addSymbol( | ||
| fileOrPath: ICodegenFile | string, | ||
| symbol: ICodegenSymbolIn, | ||
| ): ICodegenSymbolOut; | ||
| /** | ||
| * Creates a new codegen file with optional metadata and adds it to the project. | ||
| * | ||
| * If a file with the same path already exists, it is returned instead. | ||
| * | ||
| * @param path - The logical output path for the file (e.g. "models/user.ts"). | ||
| * @param meta - Optional renderer and metadata to attach to the file (e.g. { isInternal: true }). | ||
| * @returns The newly created file instance. | ||
| * @example | ||
| * const file = project.createFile("models/user.ts", { isInternal: true }); | ||
| */ | ||
| createFile( | ||
| path: string, | ||
| meta?: ICodegenFile['meta'] & { renderer?: ICodegenRenderer }, | ||
| ): ICodegenFile; | ||
| /** | ||
| * Ensures a codegen file exists and returns it. | ||
| * | ||
| * If a file does not exist yet, it is created with minimal information. | ||
| * Later, it is expected `createFile()` will be called which will fill in | ||
| * the missing information such as optional metadata. | ||
| * | ||
| * @param fileOrPath - The logical output path for the file or the file itself. | ||
| * @returns The file instance. | ||
| * @example | ||
| * const file = project.ensureFile("models/user.ts"); | ||
| */ | ||
| ensureFile(fileOrPath: ICodegenFile | string): ICodegenFile; | ||
| /** | ||
| * Returns all files in the project in insertion order. | ||
| * | ||
| * @example | ||
| * project.files.forEach(file => console.log(file.path)); | ||
| */ | ||
| readonly files: ReadonlyArray<ICodegenFile>; | ||
| /** | ||
| * Returns all symbols declared or imported across all files. | ||
| * | ||
| * @returns Flattened list of all codegen symbols. | ||
| * @example | ||
| * project.getAllSymbols().filter(s => s.name === "User"); | ||
| */ | ||
| getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>; | ||
| /** | ||
| * Retrieves a file by its logical output path. | ||
| * | ||
| * @param path - The file path to find. | ||
| * @returns The file if found, or undefined otherwise. | ||
| * @example | ||
| * const file = project.getFileByPath("models/user.ts"); | ||
| */ | ||
| getFileByPath(path: string): ICodegenFile | undefined; | ||
| /** | ||
| * Retrieves a file from symbol ID included in the file. | ||
| * | ||
| * @param id The symbol ID to find. | ||
| * @returns The file if found, undefined otherwise. | ||
| * @example | ||
| * const file = project.getFileBySymbolId(31); | ||
| */ | ||
| getFileBySymbolId(id: number): ICodegenFile | undefined; | ||
| /** | ||
| * Retrieves a symbol from ID included in the project. | ||
| * | ||
| * @param id The symbol ID to find. | ||
| * @returns The symbol if found, undefined otherwise. | ||
| * @example | ||
| * const symbol = project.getSymbolById(31); | ||
| */ | ||
| getSymbolById(id: number): ICodegenSymbolOut | undefined; | ||
| /** | ||
| * Returns the current file ID and increments it. | ||
| * | ||
| * @returns File ID before being incremented | ||
| */ | ||
| incrementFileId(): number; | ||
| /** | ||
| * Returns the current symbol ID and increments it. | ||
| * | ||
| * @returns Symbol ID before being incremented | ||
| */ | ||
| incrementSymbolId(): number; | ||
| /** | ||
| * Tracks added symbol across the project. | ||
| * | ||
| * @param symbol The symbol added to file. | ||
| * @param file The file containing the added symbol. | ||
| */ | ||
| registerSymbol(symbol: ICodegenSymbolOut, file: ICodegenFile): void; | ||
| /** | ||
| * Produces output representations for all files in the project. | ||
| * | ||
| * @param meta Arbitrary metadata. | ||
| * @returns Array of outputs ready for writing or further processing. | ||
| * @example | ||
| * project.render().forEach(output => writeFile(output)); | ||
| */ | ||
| render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput>; | ||
| } | ||
| interface ICodegenFile extends SelectorMethods { | ||
| /** | ||
| * Adds an export to this file. | ||
@@ -102,4 +452,17 @@ * | ||
| */ | ||
| addSymbol(symbol: ICodegenSymbol): void; | ||
| addSymbol(symbol: ICodegenSymbolIn): ICodegenSymbolOut; | ||
| /** | ||
| * Ensures a symbol for the given selector exists, so it can be | ||
| * safely used. | ||
| * | ||
| * @param symbol The symbol to find. The required selector is used | ||
| * to match a symbol. If there's no match, we create a headless | ||
| * instance with the provided fields. | ||
| * @returns The symbol if it exists, headless instance otherwise. | ||
| */ | ||
| ensureSymbol( | ||
| symbol: Partial<ICodegenSymbolIn> & | ||
| Pick<Required<ICodegenSymbolIn>, 'selector'>, | ||
| ): ICodegenSymbolOut; | ||
| /** | ||
| * Symbols exported from other files. | ||
@@ -113,4 +476,11 @@ **/ | ||
| */ | ||
| getAllSymbols(): ReadonlyArray<ICodegenSymbol>; | ||
| getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>; | ||
| /** | ||
| * Finds a symbol by symbol ID. | ||
| * | ||
| * @param id Symbol ID | ||
| * @returns The symbol if it exists, undefined otherwise. | ||
| */ | ||
| getSymbolById(id: number): ICodegenSymbolOut | undefined; | ||
| /** | ||
| * Checks if this file contains any content. | ||
@@ -127,7 +497,11 @@ * | ||
| * | ||
| * @param name Symbol name to check | ||
| * @param id Symbol ID to check | ||
| * @returns True if the symbol is defined by this file | ||
| */ | ||
| hasSymbol(name: string): boolean; | ||
| hasSymbol(id: number): boolean; | ||
| /** | ||
| * File ID within the project. | ||
| */ | ||
| id: number; | ||
| /** | ||
| * Symbols imported from other files. | ||
@@ -172,2 +546,6 @@ **/ | ||
| /** | ||
| * Parent project this file belongs to. | ||
| */ | ||
| project: ICodegenProject; | ||
| /** | ||
| * Returns a relative path to this file from another file. | ||
@@ -187,5 +565,20 @@ * | ||
| /** | ||
| * Map holding resolved names for symbols in this file. | ||
| */ | ||
| resolvedNames: ICodegenBiMap<number, string>; | ||
| /** | ||
| * Top-level symbols declared in this file. | ||
| **/ | ||
| symbols: ReadonlyArray<ICodegenSymbol>; | ||
| symbols: ReadonlyArray<ICodegenSymbolOut>; | ||
| /** | ||
| * Updates a symbol defined by this file. | ||
| * | ||
| * @param id ID of symbol to update. | ||
| * @param symbol The values to update. | ||
| * @returns The updated symbol. | ||
| */ | ||
| updateSymbol( | ||
| id: number, | ||
| symbol: Partial<ICodegenSymbolOut>, | ||
| ): ICodegenSymbolOut; | ||
| } | ||
@@ -258,14 +651,22 @@ | ||
| path: string; | ||
| project: ICodegenProject; | ||
| meta: ICodegenFile['meta']; | ||
| private cache; | ||
| private renderSymbols; | ||
| private state; | ||
| constructor(path: string, meta?: ICodegenFile['meta']); | ||
| id: number; | ||
| resolvedNames: ICodegenBiMap<number, string>; | ||
| constructor(path: string, project: ICodegenProject, meta?: ICodegenFile['meta']); | ||
| addExport(exp: ICodegenImport): void; | ||
| addImport(imp: ICodegenImport): void; | ||
| private addImportExport; | ||
| addSymbol(symbol: ICodegenSymbol): void; | ||
| private addRenderSymbol; | ||
| addSymbol(symbol: ICodegenSymbolIn): ICodegenSymbolOut; | ||
| ensureSymbol(symbol: Partial<ICodegenSymbolIn> & Pick<Required<ICodegenSymbolIn>, 'selector'>): ICodegenSymbolOut; | ||
| get exports(): ReadonlyArray<ICodegenImport>; | ||
| getAllSymbols(): ReadonlyArray<ICodegenSymbol>; | ||
| getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>; | ||
| private getImportExportKey; | ||
| getSymbolById(id: number): ICodegenSymbolOut | undefined; | ||
| hasContent(): boolean; | ||
| hasSymbol(name: string): boolean; | ||
| hasSymbol(id: number): boolean; | ||
| get imports(): ReadonlyArray<ICodegenImport>; | ||
@@ -276,111 +677,23 @@ private mergeImportExportValues; | ||
| relativePathToFile(file: Pick<ICodegenFile, 'path'>): string; | ||
| get symbols(): ReadonlyArray<ICodegenSymbol>; | ||
| selectSymbolAll(selector: ICodegenSymbolSelector): ReadonlyArray<ICodegenSymbolOut>; | ||
| selectSymbolFirst(selector: ICodegenSymbolSelector): ICodegenSymbolOut | undefined; | ||
| selectSymbolFirstOrThrow(selector: ICodegenSymbolSelector): ICodegenSymbolOut; | ||
| selectSymbolLast(selector: ICodegenSymbolSelector): ICodegenSymbolOut | undefined; | ||
| get symbols(): ReadonlyArray<ICodegenSymbolOut>; | ||
| updateSymbol(id: number, symbol: Partial<ICodegenSymbolOut>): ICodegenSymbolOut; | ||
| } | ||
| /** | ||
| * Represents a code generation project consisting of multiple codegen files. | ||
| * Manages imports, symbols, and output generation across the project. | ||
| */ | ||
| interface ICodegenProject { | ||
| /** | ||
| * Adds an export declaration to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the export. | ||
| * @param imp - The export declaration to add. | ||
| * @example | ||
| * project.addExportToFile("models/user.ts", { from: "lib", names: ["User"] }); | ||
| */ | ||
| addExportToFile(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| /** | ||
| * Adds an import declaration to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the import. | ||
| * @param imp - The import declaration to add. | ||
| * @example | ||
| * project.addImportToFile("models/user.ts", { from: "lib", names: ["User"] }); | ||
| */ | ||
| addImportToFile(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| /** | ||
| * Adds a symbol to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the symbol. | ||
| * @param symbol - The symbol to add. | ||
| * @example | ||
| * project.addSymbolToFile("models/user.ts", { name: "User", value: tsNode }); | ||
| */ | ||
| addSymbolToFile( | ||
| fileOrPath: ICodegenFile | string, | ||
| symbol: ICodegenSymbol, | ||
| ): void; | ||
| /** | ||
| * Creates a new codegen file with optional metadata and adds it to the project. | ||
| * | ||
| * If a file with the same path already exists, it is returned instead. | ||
| * | ||
| * @param path - The logical output path for the file (e.g. "models/user.ts"). | ||
| * @param meta - Optional renderer and metadata to attach to the file (e.g. { isInternal: true }). | ||
| * @returns The newly created file instance. | ||
| * @example | ||
| * const file = project.createFile("models/user.ts", { isInternal: true }); | ||
| */ | ||
| createFile( | ||
| path: string, | ||
| meta?: ICodegenFile['meta'] & { renderer?: ICodegenRenderer }, | ||
| ): ICodegenFile; | ||
| /** | ||
| * Ensures a codegen file exists and returns it. | ||
| * | ||
| * If a file does not exist yet, it is created with minimal information. | ||
| * Later, it is expected `createFile()` will be called which will fill in | ||
| * the missing information such as optional metadata. | ||
| * | ||
| * @param fileOrPath - The logical output path for the file or the file itself. | ||
| * @returns The file instance. | ||
| * @example | ||
| * const file = project.ensureFile("models/user.ts"); | ||
| */ | ||
| ensureFile(fileOrPath: ICodegenFile | string): ICodegenFile; | ||
| /** | ||
| * Returns all files in the project in insertion order. | ||
| * | ||
| * @example | ||
| * project.files.forEach(file => console.log(file.path)); | ||
| */ | ||
| readonly files: ReadonlyArray<ICodegenFile>; | ||
| /** | ||
| * Returns all symbols declared or imported across all files. | ||
| * | ||
| * @returns Flattened list of all codegen symbols. | ||
| * @example | ||
| * project.getAllSymbols().filter(s => s.name === "User"); | ||
| */ | ||
| getAllSymbols(): ReadonlyArray<ICodegenSymbol>; | ||
| /** | ||
| * Retrieves a file by its logical output path. | ||
| * | ||
| * @param path - The file path to find. | ||
| * @returns The file if found, or undefined otherwise. | ||
| * @example | ||
| * const file = project.getFileByPath("models/user.ts"); | ||
| */ | ||
| getFileByPath(path: string): ICodegenFile | undefined; | ||
| /** | ||
| * Produces output representations for all files in the project. | ||
| * | ||
| * @param meta Arbitrary metadata. | ||
| * @returns Array of outputs ready for writing or further processing. | ||
| * @example | ||
| * project.render().forEach(output => writeFile(output)); | ||
| */ | ||
| render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput>; | ||
| } | ||
| declare class CodegenProject implements ICodegenProject { | ||
| private filesMap; | ||
| private filesOrder; | ||
| private fileId; | ||
| private fileIdToFile; | ||
| private fileOrder; | ||
| private filePathToFileId; | ||
| private renderers; | ||
| addExportToFile(fileOrPath: CodegenFile | string, imp: ICodegenImport): void; | ||
| addImportToFile(fileOrPath: CodegenFile | string, imp: ICodegenImport): void; | ||
| addSymbolToFile(fileOrPath: CodegenFile | string, symbol: ICodegenSymbol): void; | ||
| createFile(path: string, meta?: Omit<CodegenFile['meta'], 'renderer'> & { | ||
| private selectorToSymbolIds; | ||
| private symbolId; | ||
| private symbolIdToFileId; | ||
| addExport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| addImport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| addSymbol(fileOrPath: ICodegenFile | string, symbol: ICodegenSymbolIn): ICodegenSymbolOut; | ||
| createFile(path: string, meta?: Omit<ICodegenFile['meta'], 'renderer'> & { | ||
| /** | ||
@@ -390,11 +703,29 @@ * Renderer to use to render this file. | ||
| renderer?: ICodegenRenderer; | ||
| }): CodegenFile; | ||
| ensureFile(fileOrPath: CodegenFile | string): CodegenFile; | ||
| }): ICodegenFile; | ||
| ensureFile(fileOrPath: ICodegenFile | string): ICodegenFile; | ||
| private ensureRenderer; | ||
| get files(): ReadonlyArray<CodegenFile>; | ||
| getAllSymbols(): ReadonlyArray<ICodegenSymbol>; | ||
| getFileByPath(path: string): CodegenFile | undefined; | ||
| get files(): ReadonlyArray<ICodegenFile>; | ||
| getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>; | ||
| getFileByPath(path: string): ICodegenFile | undefined; | ||
| getFileBySymbolId(id: number): ICodegenFile | undefined; | ||
| private getFileRenderer; | ||
| getSymbolById(id: number): ICodegenSymbolOut | undefined; | ||
| incrementFileId(): number; | ||
| incrementSymbolId(): number; | ||
| registerSymbol(symbol: ICodegenSymbolOut, file: ICodegenFile): void; | ||
| render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput>; | ||
| selectSymbolAll(selector: ICodegenSymbolSelector, file?: ICodegenFile): ReadonlyArray<ICodegenSymbolOut>; | ||
| selectSymbolFirst(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut | undefined; | ||
| selectSymbolFirstOrThrow(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut; | ||
| selectSymbolLast(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut | undefined; | ||
| } | ||
| export { CodegenFile, CodegenProject, type ICodegenFile, type ICodegenImport, type ICodegenMeta, type ICodegenOutput, type ICodegenProject, type ICodegenRenderer, type ICodegenSymbol }; | ||
| /** | ||
| * | ||
| * @param source The source string to replace. | ||
| * @param replacerFn Accepts a symbol ID, returns resolved symbol name. | ||
| * @returns The replaced source string. | ||
| */ | ||
| declare const replaceWrappedIds: (source: string, replacerFn: (symbolId: number) => string | undefined) => string; | ||
| export { BiMap, CodegenFile, CodegenProject, type ICodegenBiMap, type ICodegenFile, type ICodegenImport, type ICodegenMeta, type ICodegenOutput, type ICodegenProject, type ICodegenRenderer, type ICodegenSymbolIn, type ICodegenSymbolOut, type ICodegenSymbolSelector, replaceWrappedIds }; |
+468
-137
| /** | ||
| * Bi-directional map interface. | ||
| * | ||
| * Keys map to values and values map back to keys. | ||
| * | ||
| * @template Key Type of the map keys | ||
| * @template Value Type of the map values | ||
| */ | ||
| interface ICodegenBiMap<Key, Value> { | ||
| /** | ||
| * Deletes a key and its associated value from the map. | ||
| * | ||
| * @param key The key to delete. | ||
| */ | ||
| delete(key: Key): boolean; | ||
| /** | ||
| * Deletes a value and its associated key from the map. | ||
| * | ||
| * @param value The value to delete. | ||
| */ | ||
| deleteValue(value: Value): boolean; | ||
| /** | ||
| * Returns an iterator of [key, value] pairs. | ||
| */ | ||
| entries(): IterableIterator<[Key, Value]>; | ||
| /** | ||
| * Gets the value associated with a key. | ||
| * | ||
| * @param key The key to look up. | ||
| */ | ||
| get(key: Key): Value | undefined; | ||
| /** | ||
| * Gets the key associated with a value. | ||
| * | ||
| * @param value The value to look up. | ||
| */ | ||
| getKey(value: Value): Key | undefined; | ||
| /** | ||
| * Checks if a key exists in the map. | ||
| * | ||
| * @param key The key to check. | ||
| */ | ||
| hasKey(key: Key): boolean; | ||
| /** | ||
| * Checks if a value exists in the map. | ||
| * | ||
| * @param value The value to check. | ||
| */ | ||
| hasValue(value: Value): boolean; | ||
| /** | ||
| * Returns an iterator of keys. | ||
| */ | ||
| keys(): IterableIterator<Key>; | ||
| /** | ||
| * Sets a key-value pair in the map. | ||
| * | ||
| * @param key The key. | ||
| * @param value The value. | ||
| * @returns This instance for chaining. | ||
| */ | ||
| set(key: Key, value: Value): this; | ||
| /** | ||
| * Number of key-value pairs in the map. | ||
| */ | ||
| readonly size: number; | ||
| /** | ||
| * Returns an iterator of values. | ||
| */ | ||
| values(): IterableIterator<Value>; | ||
| /** | ||
| * Enables iteration with `for...of`. | ||
| */ | ||
| [Symbol.iterator](): IterableIterator<[Key, Value]>; | ||
| } | ||
| declare class BiMap<Key, Value> implements ICodegenBiMap<Key, Value> { | ||
| private map; | ||
| private reverse; | ||
| delete(key: Key): boolean; | ||
| deleteValue(value: Value): boolean; | ||
| entries(): IterableIterator<[Key, Value]>; | ||
| get(key: Key): Value | undefined; | ||
| getKey(value: Value): Key | undefined; | ||
| hasKey(key: Key): boolean; | ||
| hasValue(value: Value): boolean; | ||
| keys(): IterableIterator<Key>; | ||
| set(key: Key, value: Value): this; | ||
| get size(): number; | ||
| values(): IterableIterator<Value>; | ||
| [Symbol.iterator](): IterableIterator<[Key, Value]>; | ||
| } | ||
| /** | ||
| * Arbitrary metadata passed to render functions. | ||
@@ -46,39 +138,297 @@ * | ||
| /** | ||
| * Returns printable data. | ||
| * Returns printable data containing header and imports. | ||
| * | ||
| * @param file The file to render. | ||
| * @param meta Arbitrary metadata. | ||
| * @returns Output for file emit step | ||
| * @returns Printable string containing header and imports. | ||
| */ | ||
| render(file: CodegenFile, meta?: ICodegenMeta): ICodegenOutput; | ||
| renderHeader(file: ICodegenFile, meta?: ICodegenMeta): string; | ||
| /** | ||
| * Returns printable data containing symbols and exports. | ||
| * | ||
| * @param file The file to render. | ||
| * @param meta Arbitrary metadata. | ||
| * @returns Printable string containing symbols and exports. | ||
| */ | ||
| renderSymbols(file: ICodegenFile, meta?: ICodegenMeta): string; | ||
| /** | ||
| * Function replacing symbols with resolved names. | ||
| * | ||
| * @returns String with replaced symbols. | ||
| */ | ||
| replacerFn(args: { | ||
| file: ICodegenFile; | ||
| headless?: boolean; | ||
| scope?: 'file' | 'project'; | ||
| symbolId: number; | ||
| }): string | undefined; | ||
| } | ||
| interface ICodegenSymbol { | ||
| /** | ||
| * Selector array used to select symbols. It doesn't have to be | ||
| * unique, but in practice it might be desirable. | ||
| * | ||
| * @example ["zod", "#/components/schemas/Foo"] | ||
| */ | ||
| type ICodegenSymbolSelector = ReadonlyArray<string>; | ||
| interface ICodegenSymbolIn { | ||
| /** | ||
| * Optional description or doc comment. | ||
| * Symbols can be **headed** or **headless**. | ||
| * | ||
| * @example "Represents a user in the system" | ||
| * Headless symbols never render their `value`. Headed symbols render their | ||
| * `value` if defined. | ||
| * | ||
| * Symbols are rendered in the order they were registered as headed. | ||
| * | ||
| * Example 1: We register headless symbol `foo`, headed `bar`, and headed | ||
| * `foo`. The render order is [`bar`, `foo`]. | ||
| * | ||
| * Example 2: We register headed symbol `foo` and headed `bar`. The render | ||
| * order is [`foo`, `bar`]. | ||
| * | ||
| * Headless symbols can be used to claim a symbol or to represent imports | ||
| * or exports. | ||
| * | ||
| * @default false | ||
| */ | ||
| description?: string; | ||
| headless?: boolean; | ||
| /** | ||
| * Optional kind of symbol (e.g. "class", "function", "type", etc.). | ||
| * The desired name for the symbol within its file. If there are multiple symbols | ||
| * with the same desired name, this might not end up being the actual name. | ||
| * | ||
| * @example "class" | ||
| * @example "UserModel" | ||
| */ | ||
| kind?: string; | ||
| readonly name: string; | ||
| /** | ||
| * Unique identifier for the symbol within its file. | ||
| * Selector array used to select this symbol. It doesn't have to be | ||
| * unique, but in practice it might be desirable. | ||
| * | ||
| * @example "UserModel" | ||
| * @example ["zod", "#/components/schemas/Foo"] | ||
| */ | ||
| name: string; | ||
| readonly selector?: ICodegenSymbolSelector; | ||
| /** | ||
| * Internal representation of the symbol (e.g. AST node, IR object, raw | ||
| * code). Used to generate output. | ||
| * Internal representation of the symbol (e.g. AST node, IR object, raw code). | ||
| * Used to generate output. If left undefined, this symbol becomes `headless`. | ||
| */ | ||
| value?: unknown; | ||
| readonly value?: unknown; | ||
| } | ||
| interface ICodegenFile { | ||
| interface ICodegenSymbolOut extends ICodegenSymbolIn { | ||
| /** | ||
| * The file this symbol is located in. | ||
| */ | ||
| readonly file: ICodegenFile; | ||
| /** | ||
| * Unique symbol ID. | ||
| */ | ||
| readonly id: number; | ||
| /** | ||
| * Placeholder name for the symbol to be replaced later with the final value. | ||
| * | ||
| * @example "_heyapi_31_" | ||
| */ | ||
| readonly placeholder: string; | ||
| /** | ||
| * Updates this symbol. | ||
| * | ||
| * @param symbol The values to update. | ||
| * @returns The updated symbol. | ||
| */ | ||
| readonly update: (symbol: Partial<ICodegenSymbolOut>) => ICodegenSymbolOut; | ||
| } | ||
| interface SelectorMethods { | ||
| /** | ||
| * Retrieves symbols matching the selector. | ||
| * | ||
| * @param selector The symbol selector to find. | ||
| * @param file Find symbols only in this file. | ||
| * @returns The array of all symbols matching the selector. | ||
| * @example | ||
| * const symbols = project.selectSymbolAll(["zod", "#/components/schemas/Foo"]); | ||
| */ | ||
| selectSymbolAll( | ||
| selector: ICodegenSymbolSelector, | ||
| file?: ICodegenFile, | ||
| ): ReadonlyArray<ICodegenSymbolOut>; | ||
| /** | ||
| * Retrieves the first symbol from all symbols matching the selector. | ||
| * | ||
| * @param selector The symbol selector to find. | ||
| * @param file Find symbols only in this file. | ||
| * @returns The symbol if found, or undefined otherwise. | ||
| * @example | ||
| * const symbol = project.selectSymbolFirst(["zod", "#/components/schemas/Foo"]); | ||
| */ | ||
| selectSymbolFirst( | ||
| selector: ICodegenSymbolSelector, | ||
| file?: ICodegenFile, | ||
| ): ICodegenSymbolOut | undefined; | ||
| /** | ||
| * Retrieves the first symbol from all symbols matching the selector. | ||
| * | ||
| * @param selector The symbol selector to find. | ||
| * @param file Find symbols only in this file. | ||
| * @returns The symbol if found, or throw otherwise. | ||
| * @example | ||
| * const symbol = project.selectSymbolFirstOrThrow(["zod", "#/components/schemas/Foo"]); | ||
| */ | ||
| selectSymbolFirstOrThrow( | ||
| selector: ICodegenSymbolSelector, | ||
| file?: ICodegenFile, | ||
| ): ICodegenSymbolOut; | ||
| /** | ||
| * Retrieves the last symbol from all symbols matching the selector. | ||
| * | ||
| * @param selector The symbol selector to find. | ||
| * @param file Find symbols only in this file. | ||
| * @returns The symbol if found, or undefined otherwise. | ||
| * @example | ||
| * const symbol = project.selectSymbolLast(["zod", "#/components/schemas/Foo"]); | ||
| */ | ||
| selectSymbolLast( | ||
| selector: ICodegenSymbolSelector, | ||
| file?: ICodegenFile, | ||
| ): ICodegenSymbolOut | undefined; | ||
| } | ||
| /** | ||
| * Represents a code generation project consisting of multiple codegen files. | ||
| * Manages imports, symbols, and output generation across the project. | ||
| */ | ||
| interface ICodegenProject extends SelectorMethods { | ||
| /** | ||
| * Adds an export declaration to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the export. | ||
| * @param imp - The export declaration to add. | ||
| * @example | ||
| * project.addExport("models/user.ts", { from: "lib", names: ["User"] }); | ||
| */ | ||
| addExport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| /** | ||
| * Adds an import declaration to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the import. | ||
| * @param imp - The import declaration to add. | ||
| * @example | ||
| * project.addImport("models/user.ts", { from: "lib", names: ["User"] }); | ||
| */ | ||
| addImport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| /** | ||
| * Adds a symbol to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the symbol. | ||
| * @param symbol - The symbol to add. | ||
| * @returns The inserted symbol. | ||
| * @example | ||
| * project.addSymbol("models/user.ts", { name: "User", value: tsNode }); | ||
| */ | ||
| addSymbol( | ||
| fileOrPath: ICodegenFile | string, | ||
| symbol: ICodegenSymbolIn, | ||
| ): ICodegenSymbolOut; | ||
| /** | ||
| * Creates a new codegen file with optional metadata and adds it to the project. | ||
| * | ||
| * If a file with the same path already exists, it is returned instead. | ||
| * | ||
| * @param path - The logical output path for the file (e.g. "models/user.ts"). | ||
| * @param meta - Optional renderer and metadata to attach to the file (e.g. { isInternal: true }). | ||
| * @returns The newly created file instance. | ||
| * @example | ||
| * const file = project.createFile("models/user.ts", { isInternal: true }); | ||
| */ | ||
| createFile( | ||
| path: string, | ||
| meta?: ICodegenFile['meta'] & { renderer?: ICodegenRenderer }, | ||
| ): ICodegenFile; | ||
| /** | ||
| * Ensures a codegen file exists and returns it. | ||
| * | ||
| * If a file does not exist yet, it is created with minimal information. | ||
| * Later, it is expected `createFile()` will be called which will fill in | ||
| * the missing information such as optional metadata. | ||
| * | ||
| * @param fileOrPath - The logical output path for the file or the file itself. | ||
| * @returns The file instance. | ||
| * @example | ||
| * const file = project.ensureFile("models/user.ts"); | ||
| */ | ||
| ensureFile(fileOrPath: ICodegenFile | string): ICodegenFile; | ||
| /** | ||
| * Returns all files in the project in insertion order. | ||
| * | ||
| * @example | ||
| * project.files.forEach(file => console.log(file.path)); | ||
| */ | ||
| readonly files: ReadonlyArray<ICodegenFile>; | ||
| /** | ||
| * Returns all symbols declared or imported across all files. | ||
| * | ||
| * @returns Flattened list of all codegen symbols. | ||
| * @example | ||
| * project.getAllSymbols().filter(s => s.name === "User"); | ||
| */ | ||
| getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>; | ||
| /** | ||
| * Retrieves a file by its logical output path. | ||
| * | ||
| * @param path - The file path to find. | ||
| * @returns The file if found, or undefined otherwise. | ||
| * @example | ||
| * const file = project.getFileByPath("models/user.ts"); | ||
| */ | ||
| getFileByPath(path: string): ICodegenFile | undefined; | ||
| /** | ||
| * Retrieves a file from symbol ID included in the file. | ||
| * | ||
| * @param id The symbol ID to find. | ||
| * @returns The file if found, undefined otherwise. | ||
| * @example | ||
| * const file = project.getFileBySymbolId(31); | ||
| */ | ||
| getFileBySymbolId(id: number): ICodegenFile | undefined; | ||
| /** | ||
| * Retrieves a symbol from ID included in the project. | ||
| * | ||
| * @param id The symbol ID to find. | ||
| * @returns The symbol if found, undefined otherwise. | ||
| * @example | ||
| * const symbol = project.getSymbolById(31); | ||
| */ | ||
| getSymbolById(id: number): ICodegenSymbolOut | undefined; | ||
| /** | ||
| * Returns the current file ID and increments it. | ||
| * | ||
| * @returns File ID before being incremented | ||
| */ | ||
| incrementFileId(): number; | ||
| /** | ||
| * Returns the current symbol ID and increments it. | ||
| * | ||
| * @returns Symbol ID before being incremented | ||
| */ | ||
| incrementSymbolId(): number; | ||
| /** | ||
| * Tracks added symbol across the project. | ||
| * | ||
| * @param symbol The symbol added to file. | ||
| * @param file The file containing the added symbol. | ||
| */ | ||
| registerSymbol(symbol: ICodegenSymbolOut, file: ICodegenFile): void; | ||
| /** | ||
| * Produces output representations for all files in the project. | ||
| * | ||
| * @param meta Arbitrary metadata. | ||
| * @returns Array of outputs ready for writing or further processing. | ||
| * @example | ||
| * project.render().forEach(output => writeFile(output)); | ||
| */ | ||
| render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput>; | ||
| } | ||
| interface ICodegenFile extends SelectorMethods { | ||
| /** | ||
| * Adds an export to this file. | ||
@@ -102,4 +452,17 @@ * | ||
| */ | ||
| addSymbol(symbol: ICodegenSymbol): void; | ||
| addSymbol(symbol: ICodegenSymbolIn): ICodegenSymbolOut; | ||
| /** | ||
| * Ensures a symbol for the given selector exists, so it can be | ||
| * safely used. | ||
| * | ||
| * @param symbol The symbol to find. The required selector is used | ||
| * to match a symbol. If there's no match, we create a headless | ||
| * instance with the provided fields. | ||
| * @returns The symbol if it exists, headless instance otherwise. | ||
| */ | ||
| ensureSymbol( | ||
| symbol: Partial<ICodegenSymbolIn> & | ||
| Pick<Required<ICodegenSymbolIn>, 'selector'>, | ||
| ): ICodegenSymbolOut; | ||
| /** | ||
| * Symbols exported from other files. | ||
@@ -113,4 +476,11 @@ **/ | ||
| */ | ||
| getAllSymbols(): ReadonlyArray<ICodegenSymbol>; | ||
| getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>; | ||
| /** | ||
| * Finds a symbol by symbol ID. | ||
| * | ||
| * @param id Symbol ID | ||
| * @returns The symbol if it exists, undefined otherwise. | ||
| */ | ||
| getSymbolById(id: number): ICodegenSymbolOut | undefined; | ||
| /** | ||
| * Checks if this file contains any content. | ||
@@ -127,7 +497,11 @@ * | ||
| * | ||
| * @param name Symbol name to check | ||
| * @param id Symbol ID to check | ||
| * @returns True if the symbol is defined by this file | ||
| */ | ||
| hasSymbol(name: string): boolean; | ||
| hasSymbol(id: number): boolean; | ||
| /** | ||
| * File ID within the project. | ||
| */ | ||
| id: number; | ||
| /** | ||
| * Symbols imported from other files. | ||
@@ -172,2 +546,6 @@ **/ | ||
| /** | ||
| * Parent project this file belongs to. | ||
| */ | ||
| project: ICodegenProject; | ||
| /** | ||
| * Returns a relative path to this file from another file. | ||
@@ -187,5 +565,20 @@ * | ||
| /** | ||
| * Map holding resolved names for symbols in this file. | ||
| */ | ||
| resolvedNames: ICodegenBiMap<number, string>; | ||
| /** | ||
| * Top-level symbols declared in this file. | ||
| **/ | ||
| symbols: ReadonlyArray<ICodegenSymbol>; | ||
| symbols: ReadonlyArray<ICodegenSymbolOut>; | ||
| /** | ||
| * Updates a symbol defined by this file. | ||
| * | ||
| * @param id ID of symbol to update. | ||
| * @param symbol The values to update. | ||
| * @returns The updated symbol. | ||
| */ | ||
| updateSymbol( | ||
| id: number, | ||
| symbol: Partial<ICodegenSymbolOut>, | ||
| ): ICodegenSymbolOut; | ||
| } | ||
@@ -258,14 +651,22 @@ | ||
| path: string; | ||
| project: ICodegenProject; | ||
| meta: ICodegenFile['meta']; | ||
| private cache; | ||
| private renderSymbols; | ||
| private state; | ||
| constructor(path: string, meta?: ICodegenFile['meta']); | ||
| id: number; | ||
| resolvedNames: ICodegenBiMap<number, string>; | ||
| constructor(path: string, project: ICodegenProject, meta?: ICodegenFile['meta']); | ||
| addExport(exp: ICodegenImport): void; | ||
| addImport(imp: ICodegenImport): void; | ||
| private addImportExport; | ||
| addSymbol(symbol: ICodegenSymbol): void; | ||
| private addRenderSymbol; | ||
| addSymbol(symbol: ICodegenSymbolIn): ICodegenSymbolOut; | ||
| ensureSymbol(symbol: Partial<ICodegenSymbolIn> & Pick<Required<ICodegenSymbolIn>, 'selector'>): ICodegenSymbolOut; | ||
| get exports(): ReadonlyArray<ICodegenImport>; | ||
| getAllSymbols(): ReadonlyArray<ICodegenSymbol>; | ||
| getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>; | ||
| private getImportExportKey; | ||
| getSymbolById(id: number): ICodegenSymbolOut | undefined; | ||
| hasContent(): boolean; | ||
| hasSymbol(name: string): boolean; | ||
| hasSymbol(id: number): boolean; | ||
| get imports(): ReadonlyArray<ICodegenImport>; | ||
@@ -276,111 +677,23 @@ private mergeImportExportValues; | ||
| relativePathToFile(file: Pick<ICodegenFile, 'path'>): string; | ||
| get symbols(): ReadonlyArray<ICodegenSymbol>; | ||
| selectSymbolAll(selector: ICodegenSymbolSelector): ReadonlyArray<ICodegenSymbolOut>; | ||
| selectSymbolFirst(selector: ICodegenSymbolSelector): ICodegenSymbolOut | undefined; | ||
| selectSymbolFirstOrThrow(selector: ICodegenSymbolSelector): ICodegenSymbolOut; | ||
| selectSymbolLast(selector: ICodegenSymbolSelector): ICodegenSymbolOut | undefined; | ||
| get symbols(): ReadonlyArray<ICodegenSymbolOut>; | ||
| updateSymbol(id: number, symbol: Partial<ICodegenSymbolOut>): ICodegenSymbolOut; | ||
| } | ||
| /** | ||
| * Represents a code generation project consisting of multiple codegen files. | ||
| * Manages imports, symbols, and output generation across the project. | ||
| */ | ||
| interface ICodegenProject { | ||
| /** | ||
| * Adds an export declaration to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the export. | ||
| * @param imp - The export declaration to add. | ||
| * @example | ||
| * project.addExportToFile("models/user.ts", { from: "lib", names: ["User"] }); | ||
| */ | ||
| addExportToFile(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| /** | ||
| * Adds an import declaration to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the import. | ||
| * @param imp - The import declaration to add. | ||
| * @example | ||
| * project.addImportToFile("models/user.ts", { from: "lib", names: ["User"] }); | ||
| */ | ||
| addImportToFile(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| /** | ||
| * Adds a symbol to a specific file, creating the file if it doesn't exist. | ||
| * | ||
| * @param fileOrPath - File instance or file path where to add the symbol. | ||
| * @param symbol - The symbol to add. | ||
| * @example | ||
| * project.addSymbolToFile("models/user.ts", { name: "User", value: tsNode }); | ||
| */ | ||
| addSymbolToFile( | ||
| fileOrPath: ICodegenFile | string, | ||
| symbol: ICodegenSymbol, | ||
| ): void; | ||
| /** | ||
| * Creates a new codegen file with optional metadata and adds it to the project. | ||
| * | ||
| * If a file with the same path already exists, it is returned instead. | ||
| * | ||
| * @param path - The logical output path for the file (e.g. "models/user.ts"). | ||
| * @param meta - Optional renderer and metadata to attach to the file (e.g. { isInternal: true }). | ||
| * @returns The newly created file instance. | ||
| * @example | ||
| * const file = project.createFile("models/user.ts", { isInternal: true }); | ||
| */ | ||
| createFile( | ||
| path: string, | ||
| meta?: ICodegenFile['meta'] & { renderer?: ICodegenRenderer }, | ||
| ): ICodegenFile; | ||
| /** | ||
| * Ensures a codegen file exists and returns it. | ||
| * | ||
| * If a file does not exist yet, it is created with minimal information. | ||
| * Later, it is expected `createFile()` will be called which will fill in | ||
| * the missing information such as optional metadata. | ||
| * | ||
| * @param fileOrPath - The logical output path for the file or the file itself. | ||
| * @returns The file instance. | ||
| * @example | ||
| * const file = project.ensureFile("models/user.ts"); | ||
| */ | ||
| ensureFile(fileOrPath: ICodegenFile | string): ICodegenFile; | ||
| /** | ||
| * Returns all files in the project in insertion order. | ||
| * | ||
| * @example | ||
| * project.files.forEach(file => console.log(file.path)); | ||
| */ | ||
| readonly files: ReadonlyArray<ICodegenFile>; | ||
| /** | ||
| * Returns all symbols declared or imported across all files. | ||
| * | ||
| * @returns Flattened list of all codegen symbols. | ||
| * @example | ||
| * project.getAllSymbols().filter(s => s.name === "User"); | ||
| */ | ||
| getAllSymbols(): ReadonlyArray<ICodegenSymbol>; | ||
| /** | ||
| * Retrieves a file by its logical output path. | ||
| * | ||
| * @param path - The file path to find. | ||
| * @returns The file if found, or undefined otherwise. | ||
| * @example | ||
| * const file = project.getFileByPath("models/user.ts"); | ||
| */ | ||
| getFileByPath(path: string): ICodegenFile | undefined; | ||
| /** | ||
| * Produces output representations for all files in the project. | ||
| * | ||
| * @param meta Arbitrary metadata. | ||
| * @returns Array of outputs ready for writing or further processing. | ||
| * @example | ||
| * project.render().forEach(output => writeFile(output)); | ||
| */ | ||
| render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput>; | ||
| } | ||
| declare class CodegenProject implements ICodegenProject { | ||
| private filesMap; | ||
| private filesOrder; | ||
| private fileId; | ||
| private fileIdToFile; | ||
| private fileOrder; | ||
| private filePathToFileId; | ||
| private renderers; | ||
| addExportToFile(fileOrPath: CodegenFile | string, imp: ICodegenImport): void; | ||
| addImportToFile(fileOrPath: CodegenFile | string, imp: ICodegenImport): void; | ||
| addSymbolToFile(fileOrPath: CodegenFile | string, symbol: ICodegenSymbol): void; | ||
| createFile(path: string, meta?: Omit<CodegenFile['meta'], 'renderer'> & { | ||
| private selectorToSymbolIds; | ||
| private symbolId; | ||
| private symbolIdToFileId; | ||
| addExport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| addImport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void; | ||
| addSymbol(fileOrPath: ICodegenFile | string, symbol: ICodegenSymbolIn): ICodegenSymbolOut; | ||
| createFile(path: string, meta?: Omit<ICodegenFile['meta'], 'renderer'> & { | ||
| /** | ||
@@ -390,11 +703,29 @@ * Renderer to use to render this file. | ||
| renderer?: ICodegenRenderer; | ||
| }): CodegenFile; | ||
| ensureFile(fileOrPath: CodegenFile | string): CodegenFile; | ||
| }): ICodegenFile; | ||
| ensureFile(fileOrPath: ICodegenFile | string): ICodegenFile; | ||
| private ensureRenderer; | ||
| get files(): ReadonlyArray<CodegenFile>; | ||
| getAllSymbols(): ReadonlyArray<ICodegenSymbol>; | ||
| getFileByPath(path: string): CodegenFile | undefined; | ||
| get files(): ReadonlyArray<ICodegenFile>; | ||
| getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>; | ||
| getFileByPath(path: string): ICodegenFile | undefined; | ||
| getFileBySymbolId(id: number): ICodegenFile | undefined; | ||
| private getFileRenderer; | ||
| getSymbolById(id: number): ICodegenSymbolOut | undefined; | ||
| incrementFileId(): number; | ||
| incrementSymbolId(): number; | ||
| registerSymbol(symbol: ICodegenSymbolOut, file: ICodegenFile): void; | ||
| render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput>; | ||
| selectSymbolAll(selector: ICodegenSymbolSelector, file?: ICodegenFile): ReadonlyArray<ICodegenSymbolOut>; | ||
| selectSymbolFirst(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut | undefined; | ||
| selectSymbolFirstOrThrow(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut; | ||
| selectSymbolLast(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut | undefined; | ||
| } | ||
| export { CodegenFile, CodegenProject, type ICodegenFile, type ICodegenImport, type ICodegenMeta, type ICodegenOutput, type ICodegenProject, type ICodegenRenderer, type ICodegenSymbol }; | ||
| /** | ||
| * | ||
| * @param source The source string to replace. | ||
| * @param replacerFn Accepts a symbol ID, returns resolved symbol name. | ||
| * @returns The replaced source string. | ||
| */ | ||
| declare const replaceWrappedIds: (source: string, replacerFn: (symbolId: number) => string | undefined) => string; | ||
| export { BiMap, CodegenFile, CodegenProject, type ICodegenBiMap, type ICodegenFile, type ICodegenImport, type ICodegenMeta, type ICodegenOutput, type ICodegenProject, type ICodegenRenderer, type ICodegenSymbolIn, type ICodegenSymbolOut, type ICodegenSymbolSelector, replaceWrappedIds }; |
+2
-2
@@ -1,3 +0,3 @@ | ||
| import {createRequire}from'module';import s from'node:path';createRequire(import.meta.url); | ||
| var i=class d{constructor(e,t={}){this.path=e;this.meta=t;let r=d.pathToFilePath(e);t.path&&(typeof t.path=="function"?r=t.path(r):r=t.path.replace("{{path}}",r)),this.path=r;}cache={};state={exports:new Map,imports:new Map,symbols:new Map};addExport(e){return this.addImportExport(e,"exports")}addImport(e){return this.addImportExport(e,"imports")}addImportExport(e,t){let r=typeof e.from=="string"?e.from:e.from.path,o=this.state[t].get(r);o?(this.mergeImportExportValues(o,e),this.state[t].set(r,o)):this.state[t].set(r,{...e}),this.cache[t]=void 0;}addSymbol(e){let t=e.name,r=this.state.symbols.get(t);r?(r.value=e.value,this.state.symbols.set(t,r)):this.state.symbols.set(t,{...e}),this.cache.symbols=void 0;}get exports(){return this.cache.exports||(this.cache.exports=Array.from(this.state.exports.values())),this.cache.exports}getAllSymbols(){return [...this.symbols,...this.imports.flatMap(e=>(e.names??[]).map(t=>({name:e.aliases?.[t]??t}))),...this.exports.flatMap(e=>(e.names??[]).map(t=>({name:e.aliases?.[t]??t})))]}hasContent(){return this.state.symbols.size>0||this.state.exports.size>0}hasSymbol(e){return this.state.symbols.has(e)}get imports(){return this.cache.imports||(this.cache.imports=Array.from(this.state.imports.values())),this.cache.imports}mergeImportExportValues(e,t){e.aliases={...e.aliases,...t.aliases},t.defaultImport!==void 0&&(e.defaultImport=t.defaultImport),e.names=[...new Set([...e.names??[],...t.names??[]])],t.namespaceImport!==void 0&&(e.namespaceImport=t.namespaceImport),t.typeDefaultImport!==void 0&&(e.typeDefaultImport=t.typeDefaultImport),e.typeNames=[...new Set([...e.typeNames??[],...t.typeNames??[]])],t.typeNamespaceImport!==void 0&&(e.typeNamespaceImport=t.typeNamespaceImport);}static pathToFilePath(e){return e.includes("/")?e.split("/").filter(Boolean).join(s.sep):e.includes("\\")?e.split("\\").filter(Boolean).join(s.sep):e.split(s.sep).filter(Boolean).join(s.sep)}relativePathFromFile(e){let t=s.posix.relative(s.posix.dirname(e.path),this.path);return t.startsWith(".")||(t=`./${t}`),t}relativePathToFile(e){let t=s.posix.relative(s.posix.dirname(this.path),e.path);return t.startsWith(".")||(t=`./${t}`),t}get symbols(){return this.cache.symbols||(this.cache.symbols=Array.from(this.state.symbols.values())),this.cache.symbols}};var a=class{filesMap=new Map;filesOrder=[];renderers=new Map;addExportToFile(e,t){this.ensureFile(e).addExport(t);}addImportToFile(e,t){this.ensureFile(e).addImport(t);}addSymbolToFile(e,t){this.ensureFile(e).addSymbol(t);}createFile(e,t={}){let{renderer:r,...o}=t;r&&this.ensureRenderer(r);let n=this.getFileByPath(e);if(n)return r?.id&&r.id!==n.meta.renderer&&(n.meta.renderer=r.id),n;let p=new i(e,{...o,renderer:r?.id});return this.filesOrder.push(p),this.filesMap.set(e,p),p}ensureFile(e){if(typeof e!="string")return e;let t=this.getFileByPath(e);return t||this.createFile(e)}ensureRenderer(e){return this.renderers.has(e.id)||this.renderers.set(e.id,e),this.renderers.get(e.id)}get files(){return [...this.filesOrder]}getAllSymbols(){return this.filesOrder.flatMap(e=>e.getAllSymbols())}getFileByPath(e){return this.filesMap.get(e)}render(e){let t=[];for(let r of this.filesOrder){if(!r.meta.renderer)continue;let o=this.renderers.get(r.meta.renderer);o&&t.push(o.render(r,e));}return t}};export{i as CodegenFile,a as CodegenProject};//# sourceMappingURL=index.js.map | ||
| import {createRequire}from'module';import i from'node:path';createRequire(import.meta.url); | ||
| 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){return 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]()}};var a=l=>`_heyapi_${l}_`,h=l=>l.slice(8,-1),u=()=>new RegExp(a("\\d+"),"g"),y=(l,e)=>l.replace(u(),t=>{let r=Number.parseInt(h(t),10);return e(r)||t});var m=class l{constructor(e,t,r={}){this.path=e;this.project=t;this.meta=r;let o=l.pathToFilePath(e);r.path&&(typeof r.path=="function"?o=r.path(o):o=r.path.replace("{{path}}",o)),this.id=t.incrementFileId(),this.path=o;}cache={};renderSymbols=[];state={exports:new Map,imports:new Map,symbols:new Map};id;resolvedNames=new d;addExport(e){return this.addImportExport(e,"exports")}addImport(e){return this.addImportExport(e,"imports")}addImportExport(e,t){let r=this.getImportExportKey(e),o=this.state[t].get(r);e.names||(e.names=[]);for(let s of e.typeNames??[])e.names.includes(s)||(e.names=[...e.names,s]);o?(this.mergeImportExportValues(o,e),this.state[t].set(r,o)):this.state[t].set(r,{...e}),this.cache[t]=void 0;}addRenderSymbol(e){this.renderSymbols.push(e),this.cache.symbols=void 0;}addSymbol(e){let t=this.project.incrementSymbolId(),r={...e,file:this,id:t,placeholder:a(String(t)),update:o=>this.updateSymbol(t,o)};return r.value===void 0?r.headless=true:r.headless||delete r.headless,this.state.symbols.set(t,r),this.project.registerSymbol(r,this),r.headless||this.addRenderSymbol(t),r}ensureSymbol(e){return this.selectSymbolFirst(e.selector)||this.addSymbol({name:"",...e})}get exports(){return this.cache.exports||(this.cache.exports=Array.from(this.state.exports.values())),this.cache.exports}getAllSymbols(){return [...this.symbols,...this.imports.flatMap(e=>(e.names??[]).map(t=>({name:e.aliases?.[t]??t}))),...this.exports.flatMap(e=>(e.names??[]).map(t=>({name:e.aliases?.[t]??t})))]}getImportExportKey(e){return typeof e.from=="string"?e.from:e.from.path}getSymbolById(e){return this.state.symbols.get(e)}hasContent(){return this.state.exports.size>0||this.symbols.length>0}hasSymbol(e){return this.state.symbols.has(e)}get imports(){return this.cache.imports||(this.cache.imports=Array.from(this.state.imports.values())),this.cache.imports}mergeImportExportValues(e,t){e.aliases={...e.aliases,...t.aliases},t.defaultImport!==void 0&&(e.defaultImport=t.defaultImport),e.names=[...new Set([...e.names??[],...t.names??[]])],t.namespaceImport!==void 0&&(e.namespaceImport=t.namespaceImport),t.typeDefaultImport!==void 0&&(e.typeDefaultImport=t.typeDefaultImport),e.typeNames=[...new Set([...e.typeNames??[],...t.typeNames??[]])],t.typeNamespaceImport!==void 0&&(e.typeNamespaceImport=t.typeNamespaceImport);}static pathToFilePath(e){return e.includes("/")?e.split("/").filter(Boolean).join(i.sep):e.includes("\\")?e.split("\\").filter(Boolean).join(i.sep):e.split(i.sep).filter(Boolean).join(i.sep)}relativePathFromFile(e){let t=i.posix.relative(i.posix.dirname(e.path),this.path);return t.startsWith(".")||(t=`./${t}`),t}relativePathToFile(e){let t=i.posix.relative(i.posix.dirname(this.path.split(i.sep).join("/")),e.path.split(i.sep).join("/"));return !t.startsWith(".")&&t!==""&&(t=`./${t}`),t}selectSymbolAll(e){return this.project.selectSymbolAll(e,this)}selectSymbolFirst(e){return this.project.selectSymbolFirst(e,this)}selectSymbolFirstOrThrow(e){return this.project.selectSymbolFirstOrThrow(e,this)}selectSymbolLast(e){return this.project.selectSymbolLast(e,this)}get symbols(){return this.cache.symbols||(this.cache.symbols=this.renderSymbols.map(e=>this.getSymbolById(e))),this.cache.symbols}updateSymbol(e,t){let r=this.getSymbolById(e);if(!r)throw new Error(`symbol with id ${e} not found`);let o={...r,...t,id:e};return (!o.headless||o.value)&&delete o.headless,this.state.symbols.set(o.id,o),r.headless&&!o.headless&&this.addRenderSymbol(e),o}};var I=class{fileId=0;fileIdToFile=new Map;fileOrder=[];filePathToFileId=new Map;renderers=new Map;selectorToSymbolIds=new Map;symbolId=0;symbolIdToFileId=new Map;addExport(e,t){this.ensureFile(e).addExport(t);}addImport(e,t){this.ensureFile(e).addImport(t);}addSymbol(e,t){return this.ensureFile(e).addSymbol(t)}createFile(e,t={}){let{renderer:r,...o}=t;r&&this.ensureRenderer(r);let s=this.getFileByPath(e);if(s)return r?.id&&r.id!==s.meta.renderer&&(s.meta.renderer=r.id),s;let n=new m(e,this,{...o,renderer:r?.id});return this.fileOrder.push(n),this.filePathToFileId.set(e,n.id),this.fileIdToFile.set(n.id,n),n}ensureFile(e){if(typeof e!="string")return e;let t=this.getFileByPath(e);return t||this.createFile(e)}ensureRenderer(e){return this.renderers.has(e.id)||this.renderers.set(e.id,e),this.renderers.get(e.id)}get files(){return [...this.fileOrder]}getAllSymbols(){return this.fileOrder.flatMap(e=>e.getAllSymbols())}getFileByPath(e){let t=this.filePathToFileId.get(e);return t!==void 0?this.fileIdToFile.get(t):void 0}getFileBySymbolId(e){let t=this.symbolIdToFileId.get(e);return t!==void 0?this.fileIdToFile.get(t):void 0}getFileRenderer(e){return e.meta.renderer?this.renderers.get(e.meta.renderer):void 0}getSymbolById(e){return this.getFileBySymbolId(e)?.getSymbolById(e)}incrementFileId(){return this.fileId++}incrementSymbolId(){return this.symbolId++}registerSymbol(e,t){if(this.symbolIdToFileId.set(e.id,t.id),e.selector){let r=JSON.stringify(e.selector),o=this.selectorToSymbolIds.get(r)??[];o.push(e.id),this.selectorToSymbolIds.set(r,o);}}render(e){let t=[];return this.fileOrder.forEach((r,o)=>{let s=this.getFileRenderer(r);s&&(t[o]={content:s.renderSymbols(r,e),meta:r.meta,path:`${r.path}${r.meta.extension??""}`});}),this.fileOrder.forEach((r,o)=>{let s=this.getFileRenderer(r);if(!s||!t[o])return;let n=s.renderHeader(r,e),p=y(t[o].content,g=>s.replacerFn({file:r,symbolId:g}));t[o].content=`${n}${p}`;}),t.filter(Boolean)}selectSymbolAll(e,t){let r=this.selectorToSymbolIds.get(JSON.stringify(e))??[],o=[];for(let s of r){let n=this.getFileBySymbolId(s);if(!n||t&&t!==n)continue;let p=n.getSymbolById(s);p&&o.push(p);}return o}selectSymbolFirst(e,t){return this.selectSymbolAll(e,t)[0]}selectSymbolFirstOrThrow(e,t){let r=this.selectSymbolFirst(e,t);if(!r)throw new Error(`symbol for selector not found: ${JSON.stringify(e)}`);return r}selectSymbolLast(e,t){let r=this.selectSymbolAll(e,t);return r[r.length-1]}};export{d as BiMap,m as CodegenFile,I as CodegenProject,y as replaceWrappedIds};//# sourceMappingURL=index.js.map | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/files/file.ts","../src/project/project.ts"],"names":["CodegenFile","_CodegenFile","path","meta","filePath","exp","imp","value","field","key","existing","symbol","name","target","source","file","relativePath","CodegenProject","fileOrPath","renderer","metadata","existingFile","results"],"mappings":";AAMO,IAAMA,EAAN,MAAMC,CAAoC,CAiB/C,WAAA,CACSC,CAAAA,CACAC,EAA6B,EAAC,CACrC,CAFO,IAAA,CAAA,IAAA,CAAAD,CAAAA,CACA,UAAAC,CAAAA,CAEP,IAAIC,EAAWH,CAAAA,CAAY,cAAA,CAAeC,CAAI,CAAA,CAC1CC,EAAK,IAAA,GACH,OAAOA,EAAK,IAAA,EAAS,UAAA,CACvBC,EAAWD,CAAAA,CAAK,IAAA,CAAKC,CAAQ,CAAA,CAE7BA,CAAAA,CAAWD,EAAK,IAAA,CAAK,OAAA,CAAQ,WAAYC,CAAQ,CAAA,CAAA,CAGrD,KAAK,IAAA,CAAOA,EACd,CA7BQ,KAAA,CAIJ,EAAC,CAEG,KAAA,CAIJ,CACF,OAAA,CAAS,IAAI,IACb,OAAA,CAAS,IAAI,IACb,OAAA,CAAS,IAAI,GACf,CAAA,CAiBA,SAAA,CAAUC,EAA2B,CACnC,OAAO,KAAK,eAAA,CAAgBA,CAAAA,CAAK,SAAS,CAC5C,CAEA,SAAA,CAAUC,CAAAA,CAA2B,CACnC,OAAO,IAAA,CAAK,gBAAgBA,CAAAA,CAAK,SAAS,CAC5C,CAEQ,eAAA,CACNC,EACAC,CAAAA,CACM,CACN,IAAMC,CAAAA,CAAM,OAAOF,EAAM,IAAA,EAAS,QAAA,CAAWA,CAAAA,CAAM,IAAA,CAAOA,EAAM,IAAA,CAAK,IAAA,CAC/DG,EAAW,IAAA,CAAK,KAAA,CAAMF,CAAK,CAAA,CAAE,GAAA,CAAIC,CAAG,CAAA,CACtCC,CAAAA,EACF,KAAK,uBAAA,CAAwBA,CAAAA,CAAUH,CAAK,CAAA,C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xB,OAAOA,EAET,IAAMG,CAAAA,CAAe,KAAK,aAAA,CAAcH,CAAU,EAClD,OAAIG,CAAAA,EAGG,KAAK,UAAA,CAAWH,CAAU,CACnC,CAEQ,cAAA,CAAeC,EAA8C,CACnE,OAAK,IAAA,CAAK,SAAA,CAAU,IAAIA,CAAAA,CAAS,EAAE,GACjC,IAAA,CAAK,SAAA,CAAU,IAAIA,CAAAA,CAAS,EAAA,CAAIA,CAAQ,CAAA,CAEnC,IAAA,CAAK,UAAU,GAAA,CAAIA,CAAAA,CAAS,EAAE,CACvC,CAEA,IAAI,KAAA,EAAoC,CACtC,OAAO,CAAC,GAAG,IAAA,CAAK,UAAU,CAC5B,CAEA,aAAA,EAA+C,CAC7C,OAAO,IAAA,CAAK,WAAW,OAAA,CAASJ,CAAAA,EAASA,EAAK,aAAA,EAAe,CAC/D,CAEA,aAAA,CAAcb,EAAuC,CACnD,OAAO,IAAA,CAAK,QAAA,CAAS,IAAIA,CAAI,CAC/B,CAEA,MAAA,CAAOC,CAAAA,CAAoD,CACzD,IAAMmB,CAAAA,CAAiC,EAAC,CACxC,IAAA,IAAWP,KAAQ,IAAA,CAAK,UAAA,CAAY,CAClC,GAAI,CAACA,EAAK,IAAA,CAAK,QAAA,CAAU,SACzB,IAAMI,CAAAA,CAAW,KAAK,SAAA,CAAU,GAAA,CAAIJ,EAAK,IAAA,CAAK,QAAQ,EACjDI,CAAAA,EACLG,CAAAA,CAAQ,KAAKH,CAAAA,CAAS,MAAA,CAAOJ,EAAMZ,CAAI,CAAC,EAC1C,CACA,OAAOmB,CACT,CACF","file":"index.js","sourcesContent":["import path from 'node:path';\n\nimport type { ICodegenImport } from '../imports/types';\nimport type { ICodegenSymbol } from '../symbols/types';\nimport type { ICodegenFile } from './types';\n\nexport class CodegenFile implements ICodegenFile {\n private cache: {\n exports?: ReadonlyArray<ICodegenImport>;\n imports?: ReadonlyArray<ICodegenImport>;\n symbols?: ReadonlyArray<ICodegenSymbol>;\n } = {};\n\n private state: {\n exports: Map<string, ICodegenImport>;\n imports: Map<string, ICodegenImport>;\n symbols: Map<string, ICodegenSymbol>;\n } = {\n exports: new Map(),\n imports: new Map(),\n symbols: new Map(),\n };\n\n constructor(\n public path: string,\n public meta: ICodegenFile['meta'] = {},\n ) {\n let filePath = CodegenFile.pathToFilePath(path);\n if (meta.path) {\n if (typeof meta.path === 'function') {\n filePath = meta.path(filePath);\n } else {\n filePath = meta.path.replace('{{path}}', filePath);\n }\n }\n this.path = filePath;\n }\n\n addExport(exp: ICodegenImport): void {\n return this.addImportExport(exp, 'exports');\n }\n\n addImport(imp: ICodegenImport): void {\n return this.addImportExport(imp, 'imports');\n }\n\n private addImportExport(\n value: ICodegenImport,\n field: 'exports' | 'imports',\n ): void {\n const key = typeof value.from === 'string' ? value.from : value.from.path;\n const existing = this.state[field].get(key);\n if (existing) {\n this.mergeImportExportValues(existing, value);\n this.state[field].set(key, existing);\n } else {\n this.state[field].set(key, { ...value }); // clone to avoid mutation\n }\n this.cache[field] = undefined;\n }\n\n addSymbol(symbol: ICodegenSymbol): void {\n const key = symbol.name;\n const existing = this.state.symbols.get(key);\n if (existing) {\n existing.value = symbol.value;\n this.state.symbols.set(key, existing);\n } else {\n this.state.symbols.set(key, { ...symbol }); // clone to avoid mutation\n }\n this.cache.symbols = undefined;\n }\n\n get exports(): ReadonlyArray<ICodegenImport> {\n if (!this.cache.exports) {\n this.cache.exports = Array.from(this.state.exports.values());\n }\n return this.cache.exports;\n }\n\n getAllSymbols(): ReadonlyArray<ICodegenSymbol> {\n return [\n ...this.symbols,\n ...this.imports.flatMap((imp) =>\n (imp.names ?? []).map((name) => ({\n name: imp.aliases?.[name] ?? name,\n })),\n ),\n ...this.exports.flatMap((imp) =>\n (imp.names ?? []).map((name) => ({\n name: imp.aliases?.[name] ?? name,\n })),\n ),\n ];\n }\n\n hasContent(): boolean {\n return this.state.symbols.size > 0 || this.state.exports.size > 0;\n }\n\n hasSymbol(name: string): boolean {\n return this.state.symbols.has(name);\n }\n\n get imports(): ReadonlyArray<ICodegenImport> {\n if (!this.cache.imports) {\n this.cache.imports = Array.from(this.state.imports.values());\n }\n return this.cache.imports;\n }\n\n private mergeImportExportValues(\n target: ICodegenImport,\n source: ICodegenImport,\n ): void {\n target.aliases = { ...target.aliases, ...source.aliases };\n if (source.defaultImport !== undefined) {\n target.defaultImport = source.defaultImport;\n }\n target.names = [\n ...new Set([...(target.names ?? []), ...(source.names ?? [])]),\n ];\n if (source.namespaceImport !== undefined) {\n target.namespaceImport = source.namespaceImport;\n }\n if (source.typeDefaultImport !== undefined) {\n target.typeDefaultImport = source.typeDefaultImport;\n }\n target.typeNames = [\n ...new Set([...(target.typeNames ?? []), ...(source.typeNames ?? [])]),\n ];\n if (source.typeNamespaceImport !== undefined) {\n target.typeNamespaceImport = source.typeNamespaceImport;\n }\n }\n\n static pathToFilePath(source: string): string {\n if (source.includes('/')) {\n return source.split('/').filter(Boolean).join(path.sep);\n }\n if (source.includes('\\\\')) {\n return source.split('\\\\').filter(Boolean).join(path.sep);\n }\n return source.split(path.sep).filter(Boolean).join(path.sep);\n }\n\n relativePathFromFile(file: Pick<ICodegenFile, 'path'>): string {\n let relativePath = path.posix.relative(\n path.posix.dirname(file.path),\n this.path,\n );\n if (!relativePath.startsWith('.')) {\n relativePath = `./${relativePath}`;\n }\n return relativePath;\n }\n\n relativePathToFile(file: Pick<ICodegenFile, 'path'>): string {\n let relativePath = path.posix.relative(\n path.posix.dirname(this.path),\n file.path,\n );\n if (!relativePath.startsWith('.')) {\n relativePath = `./${relativePath}`;\n }\n return relativePath;\n }\n\n get symbols(): ReadonlyArray<ICodegenSymbol> {\n if (!this.cache.symbols) {\n this.cache.symbols = Array.from(this.state.symbols.values());\n }\n return this.cache.symbols;\n }\n}\n","import { CodegenFile } from '../files/file';\nimport type { ICodegenImport } from '../imports/types';\nimport type { ICodegenMeta } from '../meta/types';\nimport type { ICodegenOutput } from '../output/types';\nimport type { ICodegenRenderer } from '../renderers/types';\nimport type { ICodegenSymbol } from '../symbols/types';\nimport type { ICodegenProject } from './types';\n\nexport class CodegenProject implements ICodegenProject {\n private filesMap: Map<string, CodegenFile> = new Map();\n private filesOrder: Array<CodegenFile> = [];\n private renderers: Map<string, ICodegenRenderer> = new Map();\n\n addExportToFile(fileOrPath: CodegenFile | string, imp: ICodegenImport): void {\n const file = this.ensureFile(fileOrPath);\n file.addExport(imp);\n }\n\n addImportToFile(fileOrPath: CodegenFile | string, imp: ICodegenImport): void {\n const file = this.ensureFile(fileOrPath);\n file.addImport(imp);\n }\n\n addSymbolToFile(\n fileOrPath: CodegenFile | string,\n symbol: ICodegenSymbol,\n ): void {\n const file = this.ensureFile(fileOrPath);\n file.addSymbol(symbol);\n }\n\n createFile(\n path: string,\n meta: Omit<CodegenFile['meta'], 'renderer'> & {\n /**\n * Renderer to use to render this file.\n */\n renderer?: ICodegenRenderer;\n } = {},\n ): CodegenFile {\n const { renderer, ...metadata } = meta;\n if (renderer) {\n this.ensureRenderer(renderer);\n }\n\n const existing = this.getFileByPath(path);\n if (existing) {\n // Whoever is creating the file will override the renderer\n if (renderer?.id && renderer.id !== existing.meta.renderer) {\n existing.meta.renderer = renderer.id;\n }\n return existing;\n }\n\n const file = new CodegenFile(path, {\n ...metadata,\n renderer: renderer?.id,\n });\n this.filesOrder.push(file);\n this.filesMap.set(path, file);\n return file;\n }\n\n ensureFile(fileOrPath: CodegenFile | string): CodegenFile {\n if (typeof fileOrPath !== 'string') {\n return fileOrPath;\n }\n const existingFile = this.getFileByPath(fileOrPath);\n if (existingFile) {\n return existingFile;\n }\n return this.createFile(fileOrPath);\n }\n\n private ensureRenderer(renderer: ICodegenRenderer): ICodegenRenderer {\n if (!this.renderers.has(renderer.id)) {\n this.renderers.set(renderer.id, renderer);\n }\n return this.renderers.get(renderer.id)!;\n }\n\n get files(): ReadonlyArray<CodegenFile> {\n return [...this.filesOrder];\n }\n\n getAllSymbols(): ReadonlyArray<ICodegenSymbol> {\n return this.filesOrder.flatMap((file) => file.getAllSymbols());\n }\n\n getFileByPath(path: string): CodegenFile | undefined {\n return this.filesMap.get(path);\n }\n\n render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput> {\n const results: Array<ICodegenOutput> = [];\n for (const file of this.filesOrder) {\n if (!file.meta.renderer) continue;\n const renderer = this.renderers.get(file.meta.renderer);\n if (!renderer) continue;\n results.push(renderer.render(file, meta));\n }\n return results;\n }\n}\n"]} | ||
| {"version":3,"sources":["../src/bimap/bimap.ts","../src/renderers/renderer.ts","../src/files/file.ts","../src/project/project.ts"],"names":["BiMap","key","value","wrapId","symbolId","unwrapId","wrappedId","createPlaceholderRegExp","replaceWrappedIds","source","replacerFn","match","CodegenFile","_CodegenFile","path","project","meta","filePath","exp","imp","field","existing","typeName","id","symbol","inserted","values","name","target","file","relativePath","selector","updated","CodegenProject","fileOrPath","renderer","_meta","existingFile","fileId","ids","results","index","header","content","symbols","f"],"mappings":";AAEO,IAAMA,EAAN,KAA6D,CAC1D,IAAM,IAAI,GAAA,CACV,QAAU,IAAI,GAAA,CAEtB,OAAOC,CAAAA,CAAmB,CACxB,IAAMC,CAAAA,CAAQ,IAAA,CAAK,IAAI,GAAA,CAAID,CAAG,EAC9B,OAAIC,CAAAA,GAAU,MAAA,EACZ,IAAA,CAAK,QAAQ,MAAA,CAAOA,CAAK,EAEpB,IAAA,CAAK,GAAA,CAAI,OAAOD,CAAG,CAC5B,CAEA,WAAA,CAAYC,CAAAA,CAAuB,CACjC,IAAMD,CAAAA,CAAM,KAAK,OAAA,CAAQ,GAAA,CAAIC,CAAK,CAAA,CAClC,OAAID,CAAAA,GAAQ,MAAA,EACV,KAAK,GAAA,CAAI,MAAA,CAAOA,CAAG,CAAA,CAEd,IAAA,CAAK,QAAQ,MAAA,CAAOC,CAAK,CAClC,CAEA,OAAA,EAA0C,CACxC,OAAO,IAAA,CAAK,IAAI,OAAA,EAClB,CAEA,GAAA,CAAID,CAAAA,CAA6B,CAC/B,OAAO,IAAA,CAAK,IAAI,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AAQ,CAAC,GAAK,EAAC,CACjEa,CAAAA,CAAoC,GAC1C,IAAA,IAAWrB,CAAAA,IAAMgB,EAAK,CACpB,IAAMM,EAAI,IAAA,CAAK,iBAAA,CAAkBtB,CAAE,CAAA,CACnC,GAAI,CAACsB,CAAAA,EAAMhB,CAAAA,EAAQA,IAASgB,CAAAA,CAAI,SAChC,IAAMrB,CAAAA,CAASqB,CAAAA,CAAE,cAActB,CAAE,CAAA,CAC5BC,GACLoB,CAAAA,CAAQ,IAAA,CAAKpB,CAAM,EACrB,CACA,OAAOoB,CACT,CAEA,kBACEb,CAAAA,CACAF,CAAAA,CAC+B,CAE/B,OADgB,IAAA,CAAK,gBAAgBE,CAAAA,CAAUF,CAAI,EACpC,CAAC,CAClB,CAEA,wBAAA,CACEE,EACAF,CAAAA,CACmB,CACnB,IAAML,CAAAA,CAAS,IAAA,CAAK,kBAAkBO,CAAAA,CAAUF,CAAI,EACpD,GAAI,CAACL,EACH,MAAM,IAAI,MACR,CAAA,+BAAA,EAAkC,IAAA,CAAK,UAAUO,CAAQ,CAAC,EAC5D,CAAA,CACF,OAAOP,CACT,CAEA,gBAAA,CACEO,EACAF,CAAAA,CAC+B,CAC/B,IAAMe,CAAAA,CAAU,IAAA,CAAK,gBAAgBb,CAAAA,CAAUF,CAAI,EACnD,OAAOe,CAAAA,CAAQA,EAAQ,MAAA,CAAS,CAAC,CACnC,CACF","file":"index.js","sourcesContent":["import type { ICodegenBiMap } from './types';\n\nexport class BiMap<Key, Value> implements ICodegenBiMap<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 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","/**\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 replaceWrappedIds = (\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 path from 'node:path';\n\nimport { BiMap } from '../bimap/bimap';\nimport type { ICodegenBiMap } from '../bimap/types';\nimport type { ICodegenImport } from '../imports/types';\nimport type { ICodegenProject } from '../project/types';\nimport { wrapId } from '../renderers/renderer';\nimport type {\n ICodegenSymbolIn,\n ICodegenSymbolOut,\n ICodegenSymbolSelector,\n} from '../symbols/types';\nimport type { ICodegenFile } from './types';\n\nexport class CodegenFile implements ICodegenFile {\n private cache: {\n exports?: ReadonlyArray<ICodegenImport>;\n imports?: ReadonlyArray<ICodegenImport>;\n symbols?: ReadonlyArray<ICodegenSymbolOut>;\n } = {};\n\n private renderSymbols: Array<number> = [];\n\n private state: {\n exports: Map<string, ICodegenImport>;\n imports: Map<string, ICodegenImport>;\n symbols: Map<number, ICodegenSymbolOut>;\n } = {\n exports: new Map(),\n imports: new Map(),\n symbols: new Map(),\n };\n\n id: number;\n resolvedNames: ICodegenBiMap<number, string> = new BiMap();\n\n constructor(\n public path: string,\n public project: ICodegenProject,\n public meta: ICodegenFile['meta'] = {},\n ) {\n let filePath = CodegenFile.pathToFilePath(path);\n if (meta.path) {\n if (typeof meta.path === 'function') {\n filePath = meta.path(filePath);\n } else {\n filePath = meta.path.replace('{{path}}', filePath);\n }\n }\n this.id = project.incrementFileId();\n this.path = filePath;\n }\n\n addExport(exp: ICodegenImport): void {\n return this.addImportExport(exp, 'exports');\n }\n\n addImport(imp: ICodegenImport): void {\n return this.addImportExport(imp, 'imports');\n }\n\n private addImportExport(\n value: ICodegenImport,\n field: 'exports' | 'imports',\n ): void {\n const key = this.getImportExportKey(value);\n const existing = this.state[field].get(key);\n // cast type names to names to allow for cleaner API,\n // otherwise users would have to define the same values twice\n if (!value.names) value.names = [];\n for (const typeName of value.typeNames ?? []) {\n if (!value.names.includes(typeName)) {\n value.names = [...value.names, typeName];\n }\n }\n if (existing) {\n this.mergeImportExportValues(existing, value);\n this.state[field].set(key, existing);\n } else {\n this.state[field].set(key, { ...value }); // clone to avoid mutation\n }\n this.cache[field] = undefined; // invalidate cache\n }\n\n private addRenderSymbol(id: number): void {\n this.renderSymbols.push(id);\n this.cache.symbols = undefined; // invalidate cache\n }\n\n addSymbol(symbol: ICodegenSymbolIn): ICodegenSymbolOut {\n const id = this.project.incrementSymbolId();\n const inserted: ICodegenSymbolOut = {\n ...symbol, // clone to avoid mutation\n file: this,\n id,\n placeholder: wrapId(String(id)),\n update: (values) => this.updateSymbol(id, values),\n };\n if (inserted.value === undefined) {\n // register symbols without value as headless\n inserted.headless = true;\n } else if (!inserted.headless) {\n delete inserted.headless;\n }\n this.state.symbols.set(id, inserted);\n this.project.registerSymbol(inserted, this);\n if (!inserted.headless) {\n this.addRenderSymbol(id);\n }\n return inserted;\n }\n\n ensureSymbol(\n symbol: Partial<ICodegenSymbolIn> &\n Pick<Required<ICodegenSymbolIn>, 'selector'>,\n ): ICodegenSymbolOut {\n return (\n this.selectSymbolFirst(symbol.selector) ||\n this.addSymbol({ name: '', ...symbol })\n );\n }\n\n get exports(): ReadonlyArray<ICodegenImport> {\n if (!this.cache.exports) {\n this.cache.exports = Array.from(this.state.exports.values());\n }\n return this.cache.exports;\n }\n\n getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>> {\n return [\n ...this.symbols,\n ...this.imports.flatMap((imp) =>\n (imp.names ?? []).map((name) => ({\n name: imp.aliases?.[name] ?? name,\n })),\n ),\n ...this.exports.flatMap((imp) =>\n (imp.names ?? []).map((name) => ({\n name: imp.aliases?.[name] ?? name,\n })),\n ),\n ];\n }\n\n private getImportExportKey(value: ICodegenImport): string {\n if (typeof value.from === 'string') {\n return value.from;\n }\n return value.from.path;\n }\n\n getSymbolById(id: number): ICodegenSymbolOut | undefined {\n return this.state.symbols.get(id);\n }\n\n hasContent(): boolean {\n return this.state.exports.size > 0 || this.symbols.length > 0;\n }\n\n hasSymbol(id: number): boolean {\n return this.state.symbols.has(id);\n }\n\n get imports(): ReadonlyArray<ICodegenImport> {\n if (!this.cache.imports) {\n this.cache.imports = Array.from(this.state.imports.values());\n }\n return this.cache.imports;\n }\n\n private mergeImportExportValues(\n target: ICodegenImport,\n source: ICodegenImport,\n ): void {\n target.aliases = { ...target.aliases, ...source.aliases };\n if (source.defaultImport !== undefined) {\n target.defaultImport = source.defaultImport;\n }\n target.names = [\n ...new Set([...(target.names ?? []), ...(source.names ?? [])]),\n ];\n if (source.namespaceImport !== undefined) {\n target.namespaceImport = source.namespaceImport;\n }\n if (source.typeDefaultImport !== undefined) {\n target.typeDefaultImport = source.typeDefaultImport;\n }\n target.typeNames = [\n ...new Set([...(target.typeNames ?? []), ...(source.typeNames ?? [])]),\n ];\n if (source.typeNamespaceImport !== undefined) {\n target.typeNamespaceImport = source.typeNamespaceImport;\n }\n }\n\n static pathToFilePath(source: string): string {\n if (source.includes('/')) {\n return source.split('/').filter(Boolean).join(path.sep);\n }\n if (source.includes('\\\\')) {\n return source.split('\\\\').filter(Boolean).join(path.sep);\n }\n return source.split(path.sep).filter(Boolean).join(path.sep);\n }\n\n relativePathFromFile(file: Pick<ICodegenFile, 'path'>): string {\n let relativePath = path.posix.relative(\n path.posix.dirname(file.path),\n this.path,\n );\n if (!relativePath.startsWith('.')) {\n relativePath = `./${relativePath}`;\n }\n return relativePath;\n }\n\n relativePathToFile(file: Pick<ICodegenFile, 'path'>): string {\n let relativePath = path.posix.relative(\n path.posix.dirname(\n this.path.split(path.sep).join('/'), // normalize to posix\n ),\n file.path.split(path.sep).join('/'), // normalize to posix\n );\n if (!relativePath.startsWith('.') && relativePath !== '') {\n relativePath = `./${relativePath}`;\n }\n return relativePath;\n }\n\n selectSymbolAll(\n selector: ICodegenSymbolSelector,\n ): ReadonlyArray<ICodegenSymbolOut> {\n return this.project.selectSymbolAll(selector, this);\n }\n\n selectSymbolFirst(\n selector: ICodegenSymbolSelector,\n ): ICodegenSymbolOut | undefined {\n return this.project.selectSymbolFirst(selector, this);\n }\n\n selectSymbolFirstOrThrow(\n selector: ICodegenSymbolSelector,\n ): ICodegenSymbolOut {\n return this.project.selectSymbolFirstOrThrow(selector, this);\n }\n\n selectSymbolLast(\n selector: ICodegenSymbolSelector,\n ): ICodegenSymbolOut | undefined {\n return this.project.selectSymbolLast(selector, this);\n }\n\n get symbols(): ReadonlyArray<ICodegenSymbolOut> {\n if (!this.cache.symbols) {\n this.cache.symbols = this.renderSymbols.map(\n (id) => this.getSymbolById(id)!,\n );\n }\n return this.cache.symbols;\n }\n\n updateSymbol(\n id: number,\n symbol: Partial<ICodegenSymbolOut>,\n ): ICodegenSymbolOut {\n const existing = this.getSymbolById(id);\n if (!existing) {\n throw new Error(`symbol with id ${id} not found`);\n }\n const updated: ICodegenSymbolOut = { ...existing, ...symbol, id };\n // symbols with value can't be headless, clear redundant flag otherwise\n if (!updated.headless || updated.value) {\n delete updated.headless;\n }\n this.state.symbols.set(updated.id, updated);\n if (existing.headless && !updated.headless) {\n this.addRenderSymbol(id);\n }\n return updated;\n }\n}\n","import { CodegenFile } from '../files/file';\nimport type { ICodegenFile } from '../files/types';\nimport type { ICodegenImport } from '../imports/types';\nimport type { ICodegenMeta } from '../meta/types';\nimport type { ICodegenOutput } from '../output/types';\nimport { replaceWrappedIds } from '../renderers/renderer';\nimport type { ICodegenRenderer } from '../renderers/types';\nimport type {\n ICodegenSymbolIn,\n ICodegenSymbolOut,\n ICodegenSymbolSelector,\n} from '../symbols/types';\nimport type { ICodegenProject } from './types';\n\nexport class CodegenProject implements ICodegenProject {\n private fileId: number = 0;\n private fileIdToFile: Map<number, ICodegenFile> = new Map();\n private fileOrder: Array<ICodegenFile> = [];\n private filePathToFileId: Map<string, number> = new Map();\n private renderers: Map<string, ICodegenRenderer> = new Map();\n private selectorToSymbolIds: Map<string, Array<number>> = new Map();\n private symbolId: number = 0;\n private symbolIdToFileId: Map<number, number> = new Map();\n\n addExport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void {\n const file = this.ensureFile(fileOrPath);\n file.addExport(imp);\n }\n\n addImport(fileOrPath: ICodegenFile | string, imp: ICodegenImport): void {\n const file = this.ensureFile(fileOrPath);\n file.addImport(imp);\n }\n\n addSymbol(\n fileOrPath: ICodegenFile | string,\n symbol: ICodegenSymbolIn,\n ): ICodegenSymbolOut {\n const file = this.ensureFile(fileOrPath);\n return file.addSymbol(symbol);\n }\n\n createFile(\n path: string,\n meta: Omit<ICodegenFile['meta'], 'renderer'> & {\n /**\n * Renderer to use to render this file.\n */\n renderer?: ICodegenRenderer;\n } = {},\n ): ICodegenFile {\n const { renderer, ..._meta } = meta;\n if (renderer) {\n this.ensureRenderer(renderer);\n }\n\n const existing = this.getFileByPath(path);\n if (existing) {\n // Whoever is creating the file will override the renderer\n if (renderer?.id && renderer.id !== existing.meta.renderer) {\n existing.meta.renderer = renderer.id;\n }\n return existing;\n }\n\n const file = new CodegenFile(path, this, {\n ..._meta,\n renderer: renderer?.id,\n });\n this.fileOrder.push(file);\n this.filePathToFileId.set(path, file.id);\n this.fileIdToFile.set(file.id, file);\n return file;\n }\n\n ensureFile(fileOrPath: ICodegenFile | string): ICodegenFile {\n if (typeof fileOrPath !== 'string') {\n return fileOrPath;\n }\n const existingFile = this.getFileByPath(fileOrPath);\n if (existingFile) {\n return existingFile;\n }\n return this.createFile(fileOrPath);\n }\n\n private ensureRenderer(renderer: ICodegenRenderer): ICodegenRenderer {\n if (!this.renderers.has(renderer.id)) {\n this.renderers.set(renderer.id, renderer);\n }\n return this.renderers.get(renderer.id)!;\n }\n\n get files(): ReadonlyArray<ICodegenFile> {\n return [...this.fileOrder];\n }\n\n getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>> {\n return this.fileOrder.flatMap((file) => file.getAllSymbols());\n }\n\n getFileByPath(path: string): ICodegenFile | undefined {\n const fileId = this.filePathToFileId.get(path);\n return fileId !== undefined ? this.fileIdToFile.get(fileId) : undefined;\n }\n\n getFileBySymbolId(id: number): ICodegenFile | undefined {\n const fileId = this.symbolIdToFileId.get(id);\n return fileId !== undefined ? this.fileIdToFile.get(fileId) : undefined;\n }\n\n private getFileRenderer(file: ICodegenFile): ICodegenRenderer | undefined {\n return file.meta.renderer\n ? this.renderers.get(file.meta.renderer)\n : undefined;\n }\n\n getSymbolById(id: number): ICodegenSymbolOut | undefined {\n const file = this.getFileBySymbolId(id);\n return file?.getSymbolById(id);\n }\n\n incrementFileId(): number {\n return this.fileId++;\n }\n\n incrementSymbolId(): number {\n return this.symbolId++;\n }\n\n registerSymbol(symbol: ICodegenSymbolOut, file: ICodegenFile): void {\n this.symbolIdToFileId.set(symbol.id, file.id);\n if (symbol.selector) {\n const selector = JSON.stringify(symbol.selector);\n const ids = this.selectorToSymbolIds.get(selector) ?? [];\n ids.push(symbol.id);\n this.selectorToSymbolIds.set(selector, ids);\n }\n }\n\n render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput> {\n const results: Array<ICodegenOutput> = [];\n this.fileOrder.forEach((file, index) => {\n const renderer = this.getFileRenderer(file);\n if (!renderer) return;\n results[index] = {\n content: renderer.renderSymbols(file, meta),\n meta: file.meta,\n path: `${file.path}${file.meta.extension ?? ''}`,\n };\n });\n this.fileOrder.forEach((file, index) => {\n const renderer = this.getFileRenderer(file);\n if (!renderer || !results[index]) return;\n const header = renderer.renderHeader(file, meta);\n const content = replaceWrappedIds(results[index].content, (symbolId) =>\n renderer.replacerFn({ file, symbolId }),\n );\n results[index].content = `${header}${content}`;\n });\n return results.filter(Boolean);\n }\n\n selectSymbolAll(\n selector: ICodegenSymbolSelector,\n file?: ICodegenFile,\n ): ReadonlyArray<ICodegenSymbolOut> {\n const ids = this.selectorToSymbolIds.get(JSON.stringify(selector)) ?? [];\n const symbols: Array<ICodegenSymbolOut> = [];\n for (const id of ids) {\n const f = this.getFileBySymbolId(id);\n if (!f || (file && file !== f)) continue;\n const symbol = f.getSymbolById(id);\n if (!symbol) continue;\n symbols.push(symbol);\n }\n return symbols;\n }\n\n selectSymbolFirst(\n selector: ICodegenSymbolSelector,\n file?: ICodegenFile,\n ): ICodegenSymbolOut | undefined {\n const symbols = this.selectSymbolAll(selector, file);\n return symbols[0];\n }\n\n selectSymbolFirstOrThrow(\n selector: ICodegenSymbolSelector,\n file?: ICodegenFile,\n ): ICodegenSymbolOut {\n const symbol = this.selectSymbolFirst(selector, file);\n if (!symbol)\n throw new Error(\n `symbol for selector not found: ${JSON.stringify(selector)}`,\n );\n return symbol;\n }\n\n selectSymbolLast(\n selector: ICodegenSymbolSelector,\n file?: ICodegenFile,\n ): ICodegenSymbolOut | undefined {\n const symbols = this.selectSymbolAll(selector, file);\n return symbols[symbols.length - 1];\n }\n}\n"]} |
+1
-1
| { | ||
| "name": "@hey-api/codegen-core", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "🧱 TypeScript framework for generating structured, multi-file source code from abstract syntax trees.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://heyapi.dev/", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
126460
89.21%764
85.89%6
200%1
Infinity%