moonflower 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/openapi/analyzerModule/analyzerModule.cjs +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.cjs.map +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.d.ts +3 -1
- package/dist/openapi/analyzerModule/analyzerModule.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.mjs +141 -139
- package/dist/openapi/analyzerModule/analyzerModule.mjs.map +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.cjs +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.cjs.map +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.d.ts +2 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.mjs +29 -23
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.mjs.map +1 -1
- package/package.json +1 -1
- package/src/openapi/analyzerModule/analyzerModule.ts +13 -11
- package/src/openapi/analyzerModule/getSourceFileTimestamp.ts +21 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("crypto"),U=require("fs"),W=require("path"),K=require("url"),S=require("ts-morph"),y=require("../../utils/logger.cjs"),R=require("../discoveryModule/discoverImports/discoverImports.cjs"),_=require("../discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs"),H=require("../discoveryModule/discoverRouters/discoverRouters.cjs"),D=require("../manager/OpenApiManager.cjs"),B=require("./getSourceFileTimestamp.cjs"),A=require("./nodeParsers.cjs"),V=require("./parseEndpoint.cjs"),C=require("./parseExposedModels.cjs"),w=require("./sourceFileCache.cjs"),Y=require("./workerPool.cjs");var P=typeof document<"u"?document.currentScript:null;function G(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const l in r)if(l!=="default"){const c=Object.getOwnPropertyDescriptor(r,l);Object.defineProperty(t,l,c.get?c:{enumerable:!0,get:()=>r[l]})}}return t.default=r,Object.freeze(t)}const M=G(W);function J(){const r=["./analyzerWorker.mjs","./analyzerWorker.test.mjs"];for(const t of r){const l=new URL(t,typeof document>"u"?require("url").pathToFileURL(__filename).href:P&&P.tagName.toUpperCase()==="SCRIPT"&&P.src||new URL("openapi/analyzerModule/analyzerModule.cjs",document.baseURI).href);if(U.existsSync(K.fileURLToPath(l)))return l}throw new Error("analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first).")}const Q=2,X=async({logLevel:r,tsconfigPath:t,sourceFilePaths:l,sourceFileDiscovery:c,incremental:p,profiling:m="stats",workers:o=!1})=>{const a=D.OpenApiManager.getInstance();if(a.isReady())return;r&&y.Logger.setLevel(r),y.Logger.info("Preparing OpenAPI spec");const h=new S.Project({tsConfigFilePath:M.resolve(t),skipFileDependencyResolution:!0}),{explicitRouters:g,discoveredRouterFiles:x,allSourceFiles:T}=(()=>{const u=(l??[]).map(f=>M.resolve(f)).map(f=>h.getSourceFileOrThrow(f)),k=u.flatMap(f=>({fileName:f.getFilePath(),sourceFile:f,routers:H.discoverRouters(f)})),{discoveredRouterFiles:b,discoveredSourceFiles:j}=(()=>{if(c===!1)return{discoveredRouterFiles:[],discoveredSourceFiles:[]};const f=performance.now(),E=_.discoverRouterFiles({targetPath:typeof c=="object"?c.rootPath:".",tsConfigPath:t});return m!=="off"&&y.Logger.info(`File discovery took ${Math.round(performance.now()-f)}ms`),E})(),z=u.reduce((f,E)=>f.some(q=>q.getFilePath()===E.getFilePath())?f:f.concat(E),j);return{explicitRouters:k,discoveredRouterFiles:b,allSourceFiles:z}})(),e=g.reduce((i,N)=>i.some(u=>u.fileName===N.fileName)?i:i.concat(N),x),n=T.flatMap(i=>O(i)).filter(i=>!!i);n.length>0&&n[0]&&a.setHeader(n[0]);const s=T.flatMap(i=>$(i));a.setExposedModels(s);const d=typeof p=="object"&&p.cachePath?p.cachePath:M.resolve(process.cwd(),"node_modules",".cache","moonflower"),F=await L(e,{incremental:p!==!1,cachePath:d,timestampCache:{},profiling:m,tsconfigPath:M.resolve(t),workers:o});a.setStats({discoveredRouterFiles:x.map(i=>({path:i.fileName,routers:i.routers.named.map(N=>({name:N,endpoints:F.filter(u=>u.sourceFilePath===i.fileName).map(u=>`${u.method.toUpperCase()} ${u.path}`)}))})),explicitRouterFiles:g.map(i=>({path:i.fileName,routers:i.routers.named.map(N=>({name:N,endpoints:F.filter(u=>u.sourceFilePath===i.fileName).map(u=>`${u.method.toUpperCase()} ${u.path}`)}))}))}),a.setEndpoints(F),a.markAsReady()},L=async(r,t,l)=>{const c=t.profiling??"stats",p=performance.now(),m=[],o=[],a=performance.now(),h=new Map;for(const e of r){const n=B.getSourceFileTimestamp(e.sourceFile,t.timestampCache,h),s=t.incremental?w.SourceFileCache.getCachedResults(e.sourceFile,n,t.cachePath):null;s?(y.Logger.debug(`[${e.fileName}] Found cached results`),m.push({endpoints:s.endpoints,fileName:e.fileName,timing:0,endpointTimings:[]})):o.push({file:e,timestamp:n})}if(c!=="off"&&y.Logger.info(`Cache freshness check took ${Math.round(performance.now()-a)}ms`),o.length===0)return c!=="off"&&y.Logger.info(`Router analysis took ${Math.round(performance.now()-p)}ms`),m.flatMap(e=>e.endpoints);const g=new Map;for(const{file:e}of o)g.set(e.fileName,{endpoints:[],fileName:e.fileName,timing:0,endpointTimings:[]});if(!(t.workers!==!1)||o.length<=Q)for(const{file:e}of o){const{endpoints:n,endpointTimings:s}=v(e),d=g.get(e.fileName);d.endpoints=n,d.endpointTimings=s,d.timing=s.reduce((F,i)=>F+i.timing,0)}else{const e=o.map(({file:d})=>({fileName:d.fileName,task:{taskId:I.randomUUID(),tsconfigPath:t.tsconfigPath,sourceFilePath:d.sourceFile.getFilePath(),routerNames:d.routers.named,filterEndpointPaths:l}})),n=new Y.WorkerPool(J(),e.length);let s;try{s=await n.runAll(e.map(d=>d.task))}finally{n.terminate()}for(let d=0;d<s.length;d++){const F=s[d],i=e[d].fileName,N=g.get(i);if("error"in F){y.Logger.error(`[${i}] Worker error: ${F.error}`);continue}N.endpoints=F.endpoints,N.endpointTimings=F.endpointTimings,N.timing=F.endpointTimings.reduce((u,k)=>u+k.timing,0)}}for(const{file:e,timestamp:n}of o){const s=g.get(e.fileName);s.endpoints.length>0&&w.SourceFileCache.cacheResults(e.sourceFile,n,t.cachePath,s.endpoints)}const T=[...m,...Array.from(g.values())];return c!=="off"&&y.Logger.info(`Router analysis took ${Math.round(performance.now()-p)}ms`),c==="stats"?T.map(e=>({fileName:e.fileName,timeTaken:e.timing})).sort((e,n)=>n.timeTaken-e.timeTaken).filter(e=>e.timeTaken>500).forEach(e=>{y.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`)}):c==="debug"&&T.map(e=>({fileName:e.fileName,timeTaken:e.timing,endpointTimings:e.endpointTimings})).sort((e,n)=>n.timeTaken-e.timeTaken).forEach(e=>{y.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`),e.endpointTimings.sort((n,s)=>s.timing-n.timing).forEach(n=>{y.Logger.info(` - ${n.method} ${n.path} (${Math.round(n.timing)}ms)`),n.sectionTimings.filter(s=>s.timing>=1).sort((s,d)=>d.timing-s.timing).forEach(s=>{y.Logger.info(` - ${s.section}: ${Math.round(s.timing)}ms`)})})}),T.flatMap(e=>e.endpoints)},v=(r,t)=>{const l=[],c=[],m=["get","post","put","delete","del","patch"].join("|");return r.routers.named.forEach(o=>{const a=new RegExp(`${o}\\.(?:${m})`);r.sourceFile.forEachChild(h=>{const g=h.getText();if(a.test(g)){A.resolveEndpointPath(h);const x=performance.now(),{endpoint:T,sectionTimings:e}=V.parseEndpoint(h,r.fileName);c.push({method:T.method,path:T.path,timing:performance.now()-x,sectionTimings:e}),l.push(T)}})}),{endpoints:l,endpointTimings:c}},O=r=>{const t=R.discoverImportedName({sourceFile:r,originalName:"useApiHeader"});if(!t)return null;const l=r.forEachChildAsArray().filter(o=>o.isKind(S.SyntaxKind.ExpressionStatement)).find(o=>t&&o.getText().startsWith(t));if(!l)return null;const c=l.getFirstDescendantByKindOrThrow(S.SyntaxKind.ObjectLiteralExpression),p=A.getValuesOfObjectLiteral(c),m=o=>typeof o=="string"||Array.isArray(o)&&o.every(a=>typeof a=="string")?o:o.reduce((a,h)=>typeof h=="string"?a:{...a,[h.identifier]:m(h.value)},{});return m(p)},$=r=>{const t=[],l=R.discoverImportedName({sourceFile:r,originalName:"useExposeApiModel"}),c=R.discoverImportedName({sourceFile:r,originalName:"useExposeNamedApiModels"});return r.forEachChildAsArray().filter(p=>p.isKind(S.SyntaxKind.ExpressionStatement)).map(p=>{if(l&&p.getText().startsWith(l)){const a=(p.getFirstChild()?.getChildrenOfKind(S.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!a)return;t.push(C.parseExposedModel(a));return}if(c&&p.getText().startsWith(c)){const a=(p.getFirstChild()?.getChildrenOfKind(S.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!a)return;C.parseNamedExposedModels(a).forEach(g=>t.push(g))}}),t};exports.analyzeMultipleSourceFiles=L;exports.analyzeSourceFileApiHeader=O;exports.analyzeSourceFileEndpoints=v;exports.analyzeSourceFileExposedModels=$;exports.prepareOpenApiSpec=X;
|
|
2
2
|
//# sourceMappingURL=analyzerModule.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzerModule.cjs","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { existsSync } from 'fs'\nimport * as path from 'path'\nimport { fileURLToPath } from 'url'\n\nfunction resolveWorkerUrl(): URL {\n\tconst candidates = ['./analyzerWorker.mjs', './analyzerWorker.test.mjs']\n\tfor (const candidate of candidates) {\n\t\tconst url = new URL(candidate, import.meta.url)\n\t\tif (existsSync(fileURLToPath(url))) {\n\t\t\treturn url\n\t\t}\n\t}\n\tthrow new Error(\n\t\t'analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first).',\n\t)\n}\nimport { SourceFile, SyntaxKind } from 'ts-morph'\nimport { Project } from 'ts-morph'\n\nimport { Logger } from '../../utils/logger'\nimport { discoverImportedName } from '../discoveryModule/discoverImports/discoverImports'\nimport {\n\tDiscoveredSourceFile,\n\tdiscoverRouterFiles,\n} from '../discoveryModule/discoverRouterFiles/discoverRouterFiles'\nimport { discoverRouters } from '../discoveryModule/discoverRouters/discoverRouters'\nimport { ApiDocsHeader, OpenApiManager } from '../manager/OpenApiManager'\nimport { EndpointData, ExposedModelData } from '../types'\nimport { getSourceFileTimestamp, TimestampCache } from './getSourceFileTimestamp'\nimport { getValuesOfObjectLiteral, resolveEndpointPath } from './nodeParsers'\nimport { parseEndpoint, SectionTiming } from './parseEndpoint'\nimport { parseExposedModel, parseNamedExposedModels } from './parseExposedModels'\nimport { SourceFileCache } from './sourceFileCache'\nimport { WorkerPool, WorkerResult, WorkerTask } from './workerPool'\n\ntype Props = {\n\tlogLevel?: Parameters<(typeof Logger)['setLevel']>[0]\n\ttsconfigPath: string\n\tsourceFilePaths?: string[]\n\tsourceFileDiscovery?: boolean | FileDiscoveryConfig\n\tincremental?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tcachePath: string\n\t\t }\n\tprofiling?: 'stats' | 'off' | 'debug'\n}\n\ntype FileDiscoveryConfig = {\n\trootPath: string\n}\n\ntype EndpointTiming = { method: string; path: string; timing: number; sectionTimings: SectionTiming[] }\n\n/**\n * Number of uncached files at or below which analysis runs inline on the (already-warm) main-thread\n * Project instead of fanning out to worker threads. Each worker pays a multi-second cold-start to\n * build its own Project, so parallelism only wins once there are several files to share that cost.\n */\nconst INLINE_ANALYSIS_FILE_THRESHOLD = 2\n\n/**\n * @param tsconfigPath Path to tsconfig file relative to project root\n * @param sourceFilePaths Array of router source files relative to project root\n */\nexport const prepareOpenApiSpec = async ({\n\tlogLevel,\n\ttsconfigPath,\n\tsourceFilePaths,\n\tsourceFileDiscovery,\n\tincremental,\n\tprofiling = 'stats',\n}: Props): Promise<void> => {\n\tconst openApiManager = OpenApiManager.getInstance()\n\n\tif (openApiManager.isReady()) {\n\t\treturn\n\t}\n\n\tif (logLevel) {\n\t\tLogger.setLevel(logLevel)\n\t}\n\n\tLogger.info('Preparing OpenAPI spec')\n\n\tconst project = new Project({\n\t\ttsConfigFilePath: path.resolve(tsconfigPath),\n\t\tskipFileDependencyResolution: true,\n\t})\n\n\tconst { explicitRouters, discoveredRouterFiles, allSourceFiles } = (() => {\n\t\tconst sourceFilesToAdd = sourceFilePaths ?? []\n\t\tconst resolvedSourceFilePaths = sourceFilesToAdd.map((filepath) => path.resolve(filepath))\n\t\tconst sourceFiles = resolvedSourceFilePaths.map((filePath) => project.getSourceFileOrThrow(filePath))\n\t\tconst explicitRouters = sourceFiles.flatMap((file) => ({\n\t\t\tfileName: file.getFilePath(),\n\t\t\tsourceFile: file,\n\t\t\trouters: discoverRouters(file),\n\t\t}))\n\n\t\tconst { discoveredRouterFiles, discoveredSourceFiles } = (() => {\n\t\t\tif (sourceFileDiscovery === false) {\n\t\t\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t\t\t}\n\n\t\t\tconst startTime = performance.now()\n\t\t\tconst files = discoverRouterFiles({\n\t\t\t\ttargetPath: typeof sourceFileDiscovery === 'object' ? sourceFileDiscovery.rootPath : '.',\n\t\t\t\ttsConfigPath: tsconfigPath,\n\t\t\t})\n\t\t\tif (profiling !== 'off') {\n\t\t\t\tLogger.info(`File discovery took ${Math.round(performance.now() - startTime)}ms`)\n\t\t\t}\n\t\t\treturn files\n\t\t})()\n\n\t\tconst allSourceFiles = sourceFiles.reduce(\n\t\t\t(acc, current) =>\n\t\t\t\tacc.some((r) => r.getFilePath() === current.getFilePath()) ? acc : acc.concat(current),\n\t\t\tdiscoveredSourceFiles,\n\t\t)\n\n\t\treturn { explicitRouters, discoveredRouterFiles, allSourceFiles }\n\t})()\n\n\tconst filesToAnalyze = explicitRouters.reduce(\n\t\t(acc, current) => (acc.some((r) => r.fileName === current.fileName) ? acc : acc.concat(current)),\n\t\tdiscoveredRouterFiles,\n\t)\n\n\tconst apiHeaders = allSourceFiles\n\t\t.flatMap((file) => analyzeSourceFileApiHeader(file))\n\t\t.filter((headers) => !!headers)\n\tif (apiHeaders.length > 0 && apiHeaders[0]) {\n\t\topenApiManager.setHeader(apiHeaders[0])\n\t}\n\n\tconst exposedModels = allSourceFiles.flatMap((file) => analyzeSourceFileExposedModels(file))\n\n\topenApiManager.setExposedModels(exposedModels)\n\n\tconst cachePath = (() => {\n\t\tif (typeof incremental === 'object' && incremental.cachePath) {\n\t\t\treturn incremental.cachePath\n\t\t}\n\t\treturn path.resolve(process.cwd(), 'node_modules', '.cache', 'moonflower')\n\t})()\n\tconst endpoints = await analyzeMultipleSourceFiles(filesToAnalyze, {\n\t\tincremental: incremental !== false,\n\t\tcachePath,\n\t\ttimestampCache: {},\n\t\tprofiling,\n\t\ttsconfigPath: path.resolve(tsconfigPath),\n\t})\n\n\topenApiManager.setStats({\n\t\tdiscoveredRouterFiles: discoveredRouterFiles.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t\texplicitRouterFiles: explicitRouters.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t})\n\n\topenApiManager.setEndpoints(endpoints)\n\topenApiManager.markAsReady()\n}\n\nexport const analyzeMultipleSourceFiles = async (\n\tfiles: DiscoveredSourceFile[],\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t\tprofiling?: 'stats' | 'off' | 'debug'\n\t\ttsconfigPath: string\n\t},\n\tfilterEndpointPaths?: string[],\n): Promise<EndpointData[]> => {\n\tconst profiling = config.profiling ?? 'stats'\n\tconst startTime = performance.now()\n\n\t// Separate cached files from those needing analysis\n\ttype CachedFile = { endpoints: EndpointData[]; fileName: string; timing: 0; endpointTimings: [] }\n\ttype UncachedFile = { file: DiscoveredSourceFile; timestamp: number }\n\n\tconst cached: CachedFile[] = []\n\tconst uncached: UncachedFile[] = []\n\n\tfor (const file of files) {\n\t\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)\n\t\tconst hit = config.incremental\n\t\t\t? SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\t\t\t: null\n\t\tif (hit) {\n\t\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\t\tcached.push({ endpoints: hit.endpoints, fileName: file.fileName, timing: 0, endpointTimings: [] })\n\t\t} else {\n\t\t\tuncached.push({ file, timestamp })\n\t\t}\n\t}\n\n\tif (uncached.length === 0) {\n\t\tif (profiling !== 'off') {\n\t\t\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\t\t}\n\t\treturn cached.flatMap((f) => f.endpoints)\n\t}\n\n\ttype FileResult = {\n\t\tendpoints: EndpointData[]\n\t\tfileName: string\n\t\ttiming: number\n\t\tendpointTimings: EndpointTiming[]\n\t}\n\n\tconst byFile = new Map<string, FileResult>()\n\tfor (const { file } of uncached) {\n\t\tbyFile.set(file.fileName, { endpoints: [], fileName: file.fileName, timing: 0, endpointTimings: [] })\n\t}\n\n\t// The caller (prepareOpenApiSpec) already built and warmed a ts-morph Project on this thread, so\n\t// inline analysis runs against a hot type-checker. A worker, by contrast, must spawn a thread and\n\t// build its own Project from scratch — a multi-second cold-start. That cold-start only pays off\n\t// when there are enough uncached files that spreading the parse work across workers beats it; below\n\t// the threshold (e.g. the common single-file incremental rebuild), inline is strictly faster.\n\tif (uncached.length <= INLINE_ANALYSIS_FILE_THRESHOLD) {\n\t\tfor (const { file } of uncached) {\n\t\t\tconst { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\t\t\tconst fileResult = byFile.get(file.fileName)!\n\t\t\tfileResult.endpoints = endpoints\n\t\t\tfileResult.endpointTimings = endpointTimings\n\t\t\tfileResult.timing = endpointTimings.reduce((sum, t) => sum + t.timing, 0)\n\t\t}\n\t} else {\n\t\t// One task per file: each worker analyzes a whole file in a single pass, paying its Project\n\t\t// cold-start once and reusing the warmed-up checker for every endpoint in that file. Cap the\n\t\t// pool at one worker per file so we never spin up a worker with nothing to do.\n\t\ttype FileTask = { task: WorkerTask; fileName: string }\n\t\tconst allTasks: FileTask[] = uncached.map(({ file }) => ({\n\t\t\tfileName: file.fileName,\n\t\t\ttask: {\n\t\t\t\ttaskId: crypto.randomUUID(),\n\t\t\t\ttsconfigPath: config.tsconfigPath,\n\t\t\t\tsourceFilePath: file.sourceFile.getFilePath(),\n\t\t\t\trouterNames: file.routers.named,\n\t\t\t\tfilterEndpointPaths,\n\t\t\t},\n\t\t}))\n\n\t\tconst pool = new WorkerPool(resolveWorkerUrl(), allTasks.length)\n\t\tlet results: WorkerResult[]\n\t\ttry {\n\t\t\tresults = await pool.runAll(allTasks.map((ft) => ft.task))\n\t\t} finally {\n\t\t\tpool.terminate()\n\t\t}\n\n\t\t// Each result maps 1:1 to a file task.\n\t\tfor (let i = 0; i < results.length; i++) {\n\t\t\tconst result = results[i]\n\t\t\tconst fileName = allTasks[i].fileName\n\t\t\tconst fileResult = byFile.get(fileName)!\n\n\t\t\tif ('error' in result) {\n\t\t\t\tLogger.error(`[${fileName}] Worker error: ${result.error}`)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfileResult.endpoints = result.endpoints\n\t\t\tfileResult.endpointTimings = result.endpointTimings\n\t\t\tfileResult.timing = result.endpointTimings.reduce((sum, t) => sum + t.timing, 0)\n\t\t}\n\t}\n\n\t// Write cache for each uncached file\n\tfor (const { file, timestamp } of uncached) {\n\t\tconst fileResult = byFile.get(file.fileName)!\n\t\tif (fileResult.endpoints.length > 0) {\n\t\t\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, fileResult.endpoints)\n\t\t}\n\t}\n\n\tconst analyzedFiles = [...cached, ...Array.from(byFile.values())]\n\n\tif (profiling !== 'off') {\n\t\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\t}\n\n\tif (profiling === 'stats') {\n\t\tanalyzedFiles\n\t\t\t.map((f) => ({ fileName: f.fileName, timeTaken: f.timing }))\n\t\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t\t.filter((t) => t.timeTaken > 500)\n\t\t\t.forEach((t) => {\n\t\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t\t})\n\t} else if (profiling === 'debug') {\n\t\tanalyzedFiles\n\t\t\t.map((f) => ({ fileName: f.fileName, timeTaken: f.timing, endpointTimings: f.endpointTimings }))\n\t\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t\t.forEach((t) => {\n\t\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t\t\tt.endpointTimings\n\t\t\t\t\t.sort((a, b) => b.timing - a.timing)\n\t\t\t\t\t.forEach((ep) => {\n\t\t\t\t\t\tLogger.info(` - ${ep.method} ${ep.path} (${Math.round(ep.timing)}ms)`)\n\t\t\t\t\t\tep.sectionTimings\n\t\t\t\t\t\t\t.filter((s) => s.timing >= 1)\n\t\t\t\t\t\t\t.sort((a, b) => b.timing - a.timing)\n\t\t\t\t\t\t\t.forEach((s) => {\n\t\t\t\t\t\t\t\tLogger.info(` - ${s.section}: ${Math.round(s.timing)}ms`)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t})\n\t}\n\n\treturn analyzedFiles.flatMap((f) => f.endpoints)\n}\n\nexport const analyzeSourceFileWithCache = (\n\tfile: DiscoveredSourceFile,\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t\tprofiling?: 'stats' | 'off' | 'debug'\n\t},\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; timing: number; endpointTimings: EndpointTiming[] } => {\n\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)\n\tconst cachedResults = SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\n\tif (cachedResults) {\n\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\treturn { endpoints: cachedResults.endpoints, timing: 0, endpointTimings: [] }\n\t}\n\tLogger.debug(`[${file.fileName}] Analyzing...`)\n\n\tconst t1 = performance.now()\n\tconst { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\tconst t2 = performance.now()\n\tLogger.debug(`[${file.fileName}] Analyzed in ${t2 - t1}ms`)\n\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, endpoints)\n\treturn { endpoints, timing: t2 - t1, endpointTimings }\n}\n\nexport const analyzeSourceFileEndpoints = (\n\tfile: DiscoveredSourceFile,\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; endpointTimings: EndpointTiming[] } => {\n\tconst endpoints: EndpointData[] = []\n\tconst endpointTimings: EndpointTiming[] = []\n\tconst operations = ['get', 'post', 'put', 'delete', 'del', 'patch']\n\tconst joinedOperations = operations.join('|')\n\n\tfile.routers.named.forEach((routerName) => {\n\t\tconst routerPattern = new RegExp(`${routerName}\\\\.(?:${joinedOperations})`)\n\t\tfile.sourceFile.forEachChild((node) => {\n\t\t\tconst nodeText = node.getText()\n\n\t\t\tif (routerPattern.test(nodeText)) {\n\t\t\t\tconst endpointPath = resolveEndpointPath(node) ?? ''\n\n\t\t\t\tif (filterEndpointPaths && !filterEndpointPaths.some((path) => endpointPath.includes(path))) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst t1 = performance.now()\n\t\t\t\tconst { endpoint, sectionTimings } = parseEndpoint(node, file.fileName)\n\t\t\t\tendpointTimings.push({\n\t\t\t\t\tmethod: endpoint.method,\n\t\t\t\t\tpath: endpoint.path,\n\t\t\t\t\ttiming: performance.now() - t1,\n\t\t\t\t\tsectionTimings,\n\t\t\t\t})\n\t\t\t\tendpoints.push(endpoint)\n\t\t\t}\n\t\t})\n\t})\n\n\treturn { endpoints, endpointTimings }\n}\n\nexport const analyzeSourceFileApiHeader = (sourceFile: SourceFile): ApiDocsHeader | null => {\n\tconst nameOfUseApiHeader = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useApiHeader',\n\t})\n\n\tif (!nameOfUseApiHeader) {\n\t\treturn null\n\t}\n\n\tconst node = sourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.find((node) => nameOfUseApiHeader && node.getText().startsWith(nameOfUseApiHeader))\n\n\tif (!node) {\n\t\treturn null\n\t}\n\n\tconst targetNode = node.getFirstDescendantByKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\tconst values = getValuesOfObjectLiteral(targetNode)\n\n\tconst collapseObject = (v: string | string[] | typeof values): any => {\n\t\tif (typeof v === 'string') {\n\t\t\treturn v\n\t\t}\n\t\tif (Array.isArray(v) && v.every((value) => typeof value === 'string')) {\n\t\t\treturn v\n\t\t}\n\n\t\treturn v.reduce((acc, current) => {\n\t\t\tif (typeof current === 'string') {\n\t\t\t\treturn acc\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t[current.identifier]: collapseObject(current.value as string[]),\n\t\t\t}\n\t\t}, {})\n\t}\n\treturn collapseObject(values)\n}\n\nexport const analyzeSourceFileExposedModels = (sourceFile: SourceFile): ExposedModelData[] => {\n\tconst models: ExposedModelData[] = []\n\n\tconst nameOfUseExposeApiModel = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeApiModel',\n\t})\n\n\tconst nameOfUseExposeNamedApiModels = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeNamedApiModels',\n\t})\n\n\tsourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.map((node) => {\n\t\t\tif (nameOfUseExposeApiModel && node.getText().startsWith(nameOfUseExposeApiModel)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tmodels.push(parseExposedModel(firstChild))\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (nameOfUseExposeNamedApiModels && node.getText().startsWith(nameOfUseExposeNamedApiModels)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst parsedModels = parseNamedExposedModels(firstChild)\n\t\t\t\tparsedModels.forEach((model) => models.push(model))\n\t\t\t}\n\t\t})\n\treturn models\n}\n"],"names":["resolveWorkerUrl","candidates","candidate","url","_documentCurrentScript","existsSync","fileURLToPath","INLINE_ANALYSIS_FILE_THRESHOLD","prepareOpenApiSpec","logLevel","tsconfigPath","sourceFilePaths","sourceFileDiscovery","incremental","profiling","openApiManager","OpenApiManager","Logger","project","Project","path","explicitRouters","discoveredRouterFiles","allSourceFiles","sourceFiles","filepath","filePath","file","discoverRouters","discoveredSourceFiles","startTime","files","discoverRouterFiles","acc","current","r","filesToAnalyze","apiHeaders","analyzeSourceFileApiHeader","headers","exposedModels","analyzeSourceFileExposedModels","cachePath","endpoints","analyzeMultipleSourceFiles","e","config","filterEndpointPaths","cached","uncached","timestamp","getSourceFileTimestamp","hit","SourceFileCache","f","byFile","endpointTimings","analyzeSourceFileEndpoints","fileResult","sum","t","allTasks","crypto","pool","WorkerPool","results","ft","i","result","fileName","analyzedFiles","a","b","ep","s","joinedOperations","routerName","routerPattern","node","nodeText","resolveEndpointPath","t1","endpoint","sectionTimings","parseEndpoint","sourceFile","nameOfUseApiHeader","discoverImportedName","SyntaxKind","targetNode","values","getValuesOfObjectLiteral","collapseObject","v","value","models","nameOfUseExposeApiModel","nameOfUseExposeNamedApiModels","firstChild","parseExposedModel","parseNamedExposedModels","model"],"mappings":"u/BAKA,SAASA,GAAwB,CAC1B,MAAAC,EAAa,CAAC,uBAAwB,2BAA2B,EACvE,UAAWC,KAAaD,EAAY,CACnC,MAAME,EAAM,IAAI,IAAID,EAAW,OAAA,SAAA,IAAA,QAAA,KAAA,EAAA,cAAA,UAAA,EAAA,KAAAE,GAAAA,EAAA,QAAA,YAAA,IAAA,UAAAA,EAAA,KAAA,IAAA,IAAA,4CAAA,SAAA,OAAA,EAAA,IAAe,EAC9C,GAAIC,aAAWC,EAAAA,cAAcH,CAAG,CAAC,EACzB,OAAAA,CACR,CAED,MAAM,IAAI,MACT,6GACD,CACD,CA4CA,MAAMI,EAAiC,EAM1BC,EAAqB,MAAO,CACxC,SAAAC,EACA,aAAAC,EACA,gBAAAC,EACA,oBAAAC,EACA,YAAAC,EACA,UAAAC,EAAY,OACb,IAA4B,CACrB,MAAAC,EAAiBC,iBAAe,YAAY,EAE9C,GAAAD,EAAe,UAClB,OAGGN,GACHQ,EAAA,OAAO,SAASR,CAAQ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kC4C,GAA+C,CAC7F,MAAMU,EAA6B,CAAC,EAE9BC,EAA0BT,EAAAA,qBAAqB,CACpD,WAAAF,EACA,aAAc,mBAAA,CACd,EAEKY,EAAgCV,EAAAA,qBAAqB,CAC1D,WAAAF,EACA,aAAc,yBAAA,CACd,EAED,OAAAA,EACE,oBAAoB,EACpB,OAAQP,GAASA,EAAK,OAAOU,EAAAA,WAAW,mBAAmB,CAAC,EAC5D,IAAKV,GAAS,CACd,GAAIkB,GAA2BlB,EAAK,QAAU,EAAA,WAAWkB,CAAuB,EAAG,CAIlF,MAAME,GAHqBpB,EAAK,cAAc,GACC,kBAAkBU,EAAAA,WAAW,UAAU,GAAK,CAAC,GAEtD,CAAC,EAAE,cAAc,EACvD,GAAI,CAACU,EACJ,OAGMH,EAAA,KAAKI,oBAAkBD,CAAU,CAAC,EACzC,MAAA,CAGD,GAAID,GAAiCnB,EAAK,QAAU,EAAA,WAAWmB,CAA6B,EAAG,CAI9F,MAAMC,GAHqBpB,EAAK,cAAc,GACC,kBAAkBU,EAAAA,WAAW,UAAU,GAAK,CAAC,GAEtD,CAAC,EAAE,cAAc,EACvD,GAAI,CAACU,EACJ,OAGoBE,0BAAwBF,CAAU,EAC1C,QAASG,GAAUN,EAAO,KAAKM,CAAK,CAAC,CAAA,CACnD,CACA,EACKN,CACR"}
|
|
1
|
+
{"version":3,"file":"analyzerModule.cjs","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { existsSync } from 'fs'\nimport * as path from 'path'\nimport { fileURLToPath } from 'url'\n\nfunction resolveWorkerUrl(): URL {\n\tconst candidates = ['./analyzerWorker.mjs', './analyzerWorker.test.mjs']\n\tfor (const candidate of candidates) {\n\t\tconst url = new URL(candidate, import.meta.url)\n\t\tif (existsSync(fileURLToPath(url))) {\n\t\t\treturn url\n\t\t}\n\t}\n\tthrow new Error(\n\t\t'analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first).',\n\t)\n}\nimport { SourceFile, SyntaxKind } from 'ts-morph'\nimport { Project } from 'ts-morph'\n\nimport { Logger } from '../../utils/logger'\nimport { discoverImportedName } from '../discoveryModule/discoverImports/discoverImports'\nimport {\n\tDiscoveredSourceFile,\n\tdiscoverRouterFiles,\n} from '../discoveryModule/discoverRouterFiles/discoverRouterFiles'\nimport { discoverRouters } from '../discoveryModule/discoverRouters/discoverRouters'\nimport { ApiDocsHeader, OpenApiManager } from '../manager/OpenApiManager'\nimport { EndpointData, ExposedModelData } from '../types'\nimport { getSourceFileTimestamp, MtimeCache, TimestampCache } from './getSourceFileTimestamp'\nimport { getValuesOfObjectLiteral, resolveEndpointPath } from './nodeParsers'\nimport { parseEndpoint, SectionTiming } from './parseEndpoint'\nimport { parseExposedModel, parseNamedExposedModels } from './parseExposedModels'\nimport { SourceFileCache } from './sourceFileCache'\nimport { WorkerPool, WorkerResult, WorkerTask } from './workerPool'\n\ntype Props = {\n\tlogLevel?: Parameters<(typeof Logger)['setLevel']>[0]\n\ttsconfigPath: string\n\tsourceFilePaths?: string[]\n\tsourceFileDiscovery?: boolean | FileDiscoveryConfig\n\tincremental?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tcachePath: string\n\t\t }\n\tprofiling?: 'stats' | 'off' | 'debug'\n\tworkers?: boolean\n}\n\ntype FileDiscoveryConfig = {\n\trootPath: string\n}\n\ntype EndpointTiming = { method: string; path: string; timing: number; sectionTimings: SectionTiming[] }\n\n/**\n * Number of uncached files at or below which analysis runs inline on the (already-warm) main-thread\n * Project instead of fanning out to worker threads. Each worker pays a multi-second cold-start to\n * build its own Project, so parallelism only wins once there are several files to share that cost.\n */\nconst INLINE_ANALYSIS_FILE_THRESHOLD = 2\n\n/**\n * @param tsconfigPath Path to tsconfig file relative to project root\n * @param sourceFilePaths Array of router source files relative to project root\n */\nexport const prepareOpenApiSpec = async ({\n\tlogLevel,\n\ttsconfigPath,\n\tsourceFilePaths,\n\tsourceFileDiscovery,\n\tincremental,\n\tprofiling = 'stats',\n\tworkers = false,\n}: Props): Promise<void> => {\n\tconst openApiManager = OpenApiManager.getInstance()\n\n\tif (openApiManager.isReady()) {\n\t\treturn\n\t}\n\n\tif (logLevel) {\n\t\tLogger.setLevel(logLevel)\n\t}\n\n\tLogger.info('Preparing OpenAPI spec')\n\n\tconst project = new Project({\n\t\ttsConfigFilePath: path.resolve(tsconfigPath),\n\t\tskipFileDependencyResolution: true,\n\t})\n\n\tconst { explicitRouters, discoveredRouterFiles, allSourceFiles } = (() => {\n\t\tconst sourceFilesToAdd = sourceFilePaths ?? []\n\t\tconst resolvedSourceFilePaths = sourceFilesToAdd.map((filepath) => path.resolve(filepath))\n\t\tconst sourceFiles = resolvedSourceFilePaths.map((filePath) => project.getSourceFileOrThrow(filePath))\n\t\tconst explicitRouters = sourceFiles.flatMap((file) => ({\n\t\t\tfileName: file.getFilePath(),\n\t\t\tsourceFile: file,\n\t\t\trouters: discoverRouters(file),\n\t\t}))\n\n\t\tconst { discoveredRouterFiles, discoveredSourceFiles } = (() => {\n\t\t\tif (sourceFileDiscovery === false) {\n\t\t\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t\t\t}\n\n\t\t\tconst startTime = performance.now()\n\t\t\tconst files = discoverRouterFiles({\n\t\t\t\ttargetPath: typeof sourceFileDiscovery === 'object' ? sourceFileDiscovery.rootPath : '.',\n\t\t\t\ttsConfigPath: tsconfigPath,\n\t\t\t})\n\t\t\tif (profiling !== 'off') {\n\t\t\t\tLogger.info(`File discovery took ${Math.round(performance.now() - startTime)}ms`)\n\t\t\t}\n\t\t\treturn files\n\t\t})()\n\n\t\tconst allSourceFiles = sourceFiles.reduce(\n\t\t\t(acc, current) =>\n\t\t\t\tacc.some((r) => r.getFilePath() === current.getFilePath()) ? acc : acc.concat(current),\n\t\t\tdiscoveredSourceFiles,\n\t\t)\n\n\t\treturn { explicitRouters, discoveredRouterFiles, allSourceFiles }\n\t})()\n\n\tconst filesToAnalyze = explicitRouters.reduce(\n\t\t(acc, current) => (acc.some((r) => r.fileName === current.fileName) ? acc : acc.concat(current)),\n\t\tdiscoveredRouterFiles,\n\t)\n\n\tconst apiHeaders = allSourceFiles\n\t\t.flatMap((file) => analyzeSourceFileApiHeader(file))\n\t\t.filter((headers) => !!headers)\n\tif (apiHeaders.length > 0 && apiHeaders[0]) {\n\t\topenApiManager.setHeader(apiHeaders[0])\n\t}\n\n\tconst exposedModels = allSourceFiles.flatMap((file) => analyzeSourceFileExposedModels(file))\n\n\topenApiManager.setExposedModels(exposedModels)\n\n\tconst cachePath = (() => {\n\t\tif (typeof incremental === 'object' && incremental.cachePath) {\n\t\t\treturn incremental.cachePath\n\t\t}\n\t\treturn path.resolve(process.cwd(), 'node_modules', '.cache', 'moonflower')\n\t})()\n\tconst endpoints = await analyzeMultipleSourceFiles(filesToAnalyze, {\n\t\tincremental: incremental !== false,\n\t\tcachePath,\n\t\ttimestampCache: {},\n\t\tprofiling,\n\t\ttsconfigPath: path.resolve(tsconfigPath),\n\t\tworkers,\n\t})\n\n\topenApiManager.setStats({\n\t\tdiscoveredRouterFiles: discoveredRouterFiles.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t\texplicitRouterFiles: explicitRouters.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t})\n\n\topenApiManager.setEndpoints(endpoints)\n\topenApiManager.markAsReady()\n}\n\nexport const analyzeMultipleSourceFiles = async (\n\tfiles: DiscoveredSourceFile[],\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t\tprofiling?: 'stats' | 'off' | 'debug'\n\t\ttsconfigPath: string\n\t\tworkers?: boolean\n\t},\n\tfilterEndpointPaths?: string[],\n): Promise<EndpointData[]> => {\n\tconst profiling = config.profiling ?? 'stats'\n\tconst startTime = performance.now()\n\n\t// Separate cached files from those needing analysis\n\ttype CachedFile = { endpoints: EndpointData[]; fileName: string; timing: 0; endpointTimings: [] }\n\ttype UncachedFile = { file: DiscoveredSourceFile; timestamp: number }\n\n\tconst cached: CachedFile[] = []\n\tconst uncached: UncachedFile[] = []\n\n\tconst freshnessCheckStart = performance.now()\n\tconst mtimeCache: MtimeCache = new Map()\n\tfor (const file of files) {\n\t\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache, mtimeCache)\n\t\tconst hit = config.incremental\n\t\t\t? SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\t\t\t: null\n\t\tif (hit) {\n\t\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\t\tcached.push({ endpoints: hit.endpoints, fileName: file.fileName, timing: 0, endpointTimings: [] })\n\t\t} else {\n\t\t\tuncached.push({ file, timestamp })\n\t\t}\n\t}\n\tif (profiling !== 'off') {\n\t\tLogger.info(`Cache freshness check took ${Math.round(performance.now() - freshnessCheckStart)}ms`)\n\t}\n\n\tif (uncached.length === 0) {\n\t\tif (profiling !== 'off') {\n\t\t\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\t\t}\n\t\treturn cached.flatMap((f) => f.endpoints)\n\t}\n\n\ttype FileResult = {\n\t\tendpoints: EndpointData[]\n\t\tfileName: string\n\t\ttiming: number\n\t\tendpointTimings: EndpointTiming[]\n\t}\n\n\tconst byFile = new Map<string, FileResult>()\n\tfor (const { file } of uncached) {\n\t\tbyFile.set(file.fileName, { endpoints: [], fileName: file.fileName, timing: 0, endpointTimings: [] })\n\t}\n\n\tconst useWorkers = config.workers !== false\n\tif (!useWorkers || uncached.length <= INLINE_ANALYSIS_FILE_THRESHOLD) {\n\t\tfor (const { file } of uncached) {\n\t\t\tconst { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\t\t\tconst fileResult = byFile.get(file.fileName)!\n\t\t\tfileResult.endpoints = endpoints\n\t\t\tfileResult.endpointTimings = endpointTimings\n\t\t\tfileResult.timing = endpointTimings.reduce((sum, t) => sum + t.timing, 0)\n\t\t}\n\t} else {\n\t\ttype FileTask = { task: WorkerTask; fileName: string }\n\t\tconst allTasks: FileTask[] = uncached.map(({ file }) => ({\n\t\t\tfileName: file.fileName,\n\t\t\ttask: {\n\t\t\t\ttaskId: crypto.randomUUID(),\n\t\t\t\ttsconfigPath: config.tsconfigPath,\n\t\t\t\tsourceFilePath: file.sourceFile.getFilePath(),\n\t\t\t\trouterNames: file.routers.named,\n\t\t\t\tfilterEndpointPaths,\n\t\t\t},\n\t\t}))\n\n\t\tconst pool = new WorkerPool(resolveWorkerUrl(), allTasks.length)\n\t\tlet results: WorkerResult[]\n\t\ttry {\n\t\t\tresults = await pool.runAll(allTasks.map((ft) => ft.task))\n\t\t} finally {\n\t\t\tpool.terminate()\n\t\t}\n\n\t\t// Each result maps 1:1 to a file task.\n\t\tfor (let i = 0; i < results.length; i++) {\n\t\t\tconst result = results[i]\n\t\t\tconst fileName = allTasks[i].fileName\n\t\t\tconst fileResult = byFile.get(fileName)!\n\n\t\t\tif ('error' in result) {\n\t\t\t\tLogger.error(`[${fileName}] Worker error: ${result.error}`)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfileResult.endpoints = result.endpoints\n\t\t\tfileResult.endpointTimings = result.endpointTimings\n\t\t\tfileResult.timing = result.endpointTimings.reduce((sum, t) => sum + t.timing, 0)\n\t\t}\n\t}\n\n\t// Write cache for each uncached file\n\tfor (const { file, timestamp } of uncached) {\n\t\tconst fileResult = byFile.get(file.fileName)!\n\t\tif (fileResult.endpoints.length > 0) {\n\t\t\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, fileResult.endpoints)\n\t\t}\n\t}\n\n\tconst analyzedFiles = [...cached, ...Array.from(byFile.values())]\n\n\tif (profiling !== 'off') {\n\t\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\t}\n\n\tif (profiling === 'stats') {\n\t\tanalyzedFiles\n\t\t\t.map((f) => ({ fileName: f.fileName, timeTaken: f.timing }))\n\t\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t\t.filter((t) => t.timeTaken > 500)\n\t\t\t.forEach((t) => {\n\t\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t\t})\n\t} else if (profiling === 'debug') {\n\t\tanalyzedFiles\n\t\t\t.map((f) => ({ fileName: f.fileName, timeTaken: f.timing, endpointTimings: f.endpointTimings }))\n\t\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t\t.forEach((t) => {\n\t\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t\t\tt.endpointTimings\n\t\t\t\t\t.sort((a, b) => b.timing - a.timing)\n\t\t\t\t\t.forEach((ep) => {\n\t\t\t\t\t\tLogger.info(` - ${ep.method} ${ep.path} (${Math.round(ep.timing)}ms)`)\n\t\t\t\t\t\tep.sectionTimings\n\t\t\t\t\t\t\t.filter((s) => s.timing >= 1)\n\t\t\t\t\t\t\t.sort((a, b) => b.timing - a.timing)\n\t\t\t\t\t\t\t.forEach((s) => {\n\t\t\t\t\t\t\t\tLogger.info(` - ${s.section}: ${Math.round(s.timing)}ms`)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t})\n\t}\n\n\treturn analyzedFiles.flatMap((f) => f.endpoints)\n}\n\nexport const analyzeSourceFileWithCache = (\n\tfile: DiscoveredSourceFile,\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t\tprofiling?: 'stats' | 'off' | 'debug'\n\t},\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; timing: number; endpointTimings: EndpointTiming[] } => {\n\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)\n\tconst cachedResults = SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\n\tif (cachedResults) {\n\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\treturn { endpoints: cachedResults.endpoints, timing: 0, endpointTimings: [] }\n\t}\n\tLogger.debug(`[${file.fileName}] Analyzing...`)\n\n\tconst t1 = performance.now()\n\tconst { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\tconst t2 = performance.now()\n\tLogger.debug(`[${file.fileName}] Analyzed in ${t2 - t1}ms`)\n\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, endpoints)\n\treturn { endpoints, timing: t2 - t1, endpointTimings }\n}\n\nexport const analyzeSourceFileEndpoints = (\n\tfile: DiscoveredSourceFile,\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; endpointTimings: EndpointTiming[] } => {\n\tconst endpoints: EndpointData[] = []\n\tconst endpointTimings: EndpointTiming[] = []\n\tconst operations = ['get', 'post', 'put', 'delete', 'del', 'patch']\n\tconst joinedOperations = operations.join('|')\n\n\tfile.routers.named.forEach((routerName) => {\n\t\tconst routerPattern = new RegExp(`${routerName}\\\\.(?:${joinedOperations})`)\n\t\tfile.sourceFile.forEachChild((node) => {\n\t\t\tconst nodeText = node.getText()\n\n\t\t\tif (routerPattern.test(nodeText)) {\n\t\t\t\tconst endpointPath = resolveEndpointPath(node) ?? ''\n\n\t\t\t\tif (filterEndpointPaths && !filterEndpointPaths.some((path) => endpointPath.includes(path))) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst t1 = performance.now()\n\t\t\t\tconst { endpoint, sectionTimings } = parseEndpoint(node, file.fileName)\n\t\t\t\tendpointTimings.push({\n\t\t\t\t\tmethod: endpoint.method,\n\t\t\t\t\tpath: endpoint.path,\n\t\t\t\t\ttiming: performance.now() - t1,\n\t\t\t\t\tsectionTimings,\n\t\t\t\t})\n\t\t\t\tendpoints.push(endpoint)\n\t\t\t}\n\t\t})\n\t})\n\n\treturn { endpoints, endpointTimings }\n}\n\nexport const analyzeSourceFileApiHeader = (sourceFile: SourceFile): ApiDocsHeader | null => {\n\tconst nameOfUseApiHeader = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useApiHeader',\n\t})\n\n\tif (!nameOfUseApiHeader) {\n\t\treturn null\n\t}\n\n\tconst node = sourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.find((node) => nameOfUseApiHeader && node.getText().startsWith(nameOfUseApiHeader))\n\n\tif (!node) {\n\t\treturn null\n\t}\n\n\tconst targetNode = node.getFirstDescendantByKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\tconst values = getValuesOfObjectLiteral(targetNode)\n\n\tconst collapseObject = (v: string | string[] | typeof values): any => {\n\t\tif (typeof v === 'string') {\n\t\t\treturn v\n\t\t}\n\t\tif (Array.isArray(v) && v.every((value) => typeof value === 'string')) {\n\t\t\treturn v\n\t\t}\n\n\t\treturn v.reduce((acc, current) => {\n\t\t\tif (typeof current === 'string') {\n\t\t\t\treturn acc\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t[current.identifier]: collapseObject(current.value as string[]),\n\t\t\t}\n\t\t}, {})\n\t}\n\treturn collapseObject(values)\n}\n\nexport const analyzeSourceFileExposedModels = (sourceFile: SourceFile): ExposedModelData[] => {\n\tconst models: ExposedModelData[] = []\n\n\tconst nameOfUseExposeApiModel = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeApiModel',\n\t})\n\n\tconst nameOfUseExposeNamedApiModels = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeNamedApiModels',\n\t})\n\n\tsourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.map((node) => {\n\t\t\tif (nameOfUseExposeApiModel && node.getText().startsWith(nameOfUseExposeApiModel)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tmodels.push(parseExposedModel(firstChild))\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (nameOfUseExposeNamedApiModels && node.getText().startsWith(nameOfUseExposeNamedApiModels)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst parsedModels = parseNamedExposedModels(firstChild)\n\t\t\t\tparsedModels.forEach((model) => models.push(model))\n\t\t\t}\n\t\t})\n\treturn models\n}\n"],"names":["resolveWorkerUrl","candidates","candidate","url","_documentCurrentScript","existsSync","fileURLToPath","INLINE_ANALYSIS_FILE_THRESHOLD","prepareOpenApiSpec","logLevel","tsconfigPath","sourceFilePaths","sourceFileDiscovery","incremental","profiling","workers","openApiManager","OpenApiManager","Logger","project","Project","path","explicitRouters","discoveredRouterFiles","allSourceFiles","sourceFiles","filepath","filePath","file","discoverRouters","discoveredSourceFiles","startTime","files","discoverRouterFiles","acc","current","r","filesToAnalyze","apiHeaders","analyzeSourceFileApiHeader","headers","exposedModels","analyzeSourceFileExposedModels","cachePath","endpoints","analyzeMultipleSourceFiles","e","config","filterEndpointPaths","cached","uncached","freshnessCheckStart","mtimeCache","timestamp","getSourceFileTimestamp","hit","SourceFileCache","f","byFile","endpointTimings","analyzeSourceFileEndpoints","fileResult","sum","t","allTasks","crypto","pool","WorkerPool","results","ft","i","result","fileName","analyzedFiles","a","b","ep","joinedOperations","routerName","routerPattern","node","nodeText","resolveEndpointPath","t1","endpoint","sectionTimings","parseEndpoint","sourceFile","nameOfUseApiHeader","discoverImportedName","SyntaxKind","targetNode","values","getValuesOfObjectLiteral","collapseObject","v","value","models","nameOfUseExposeApiModel","nameOfUseExposeNamedApiModels","firstChild","parseExposedModel","parseNamedExposedModels","model"],"mappings":"u/BAKA,SAASA,GAAwB,CAC1B,MAAAC,EAAa,CAAC,uBAAwB,2BAA2B,EACvE,UAAWC,KAAaD,EAAY,CACnC,MAAME,EAAM,IAAI,IAAID,EAAW,OAAA,SAAA,IAAA,QAAA,KAAA,EAAA,cAAA,UAAA,EAAA,KAAAE,GAAAA,EAAA,QAAA,YAAA,IAAA,UAAAA,EAAA,KAAA,IAAA,IAAA,4CAAA,SAAA,OAAA,EAAA,IAAe,EAC9C,GAAIC,aAAWC,EAAAA,cAAcH,CAAG,CAAC,EACzB,OAAAA,CACR,CAED,MAAM,IAAI,MACT,6GACD,CACD,CA6CA,MAAMI,EAAiC,EAM1BC,EAAqB,MAAO,CACxC,SAAAC,EACA,aAAAC,EACA,gBAAAC,EACA,oBAAAC,EACA,YAAAC,EACA,UAAAC,EAAY,QACZ,QAAAC,EAAU,EACX,IAA4B,CACrB,MAAAC,EAAiBC,iBAAe,YAAY,EAE9C,GAAAD,EAAe,UAClB,OAGGP,GACHS,EAAA,OAAO,SAAST,CAAQ,EAGzBS,EAAA,OAAO,KAAK,wBAAwB,EAE9B,MAAAC,EAAU,IAAIC,UAAQ,CAC3B,iBAAkBC,EAAK,QAAQX,CAAY,EAC3C,6BAA8B,EAAA,CAC9B,EAEK,CAAE,gBAAAY,EAAiB,sBAAAC,EAAuB,eAAAC,CAAA,GA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C,CAC7F,MAAMU,EAA6B,CAAC,EAE9BC,EAA0BT,EAAAA,qBAAqB,CACpD,WAAAF,EACA,aAAc,mBAAA,CACd,EAEKY,EAAgCV,EAAAA,qBAAqB,CAC1D,WAAAF,EACA,aAAc,yBAAA,CACd,EAED,OAAAA,EACE,oBAAoB,EACpB,OAAQP,GAASA,EAAK,OAAOU,EAAAA,WAAW,mBAAmB,CAAC,EAC5D,IAAKV,GAAS,CACd,GAAIkB,GAA2BlB,EAAK,QAAU,EAAA,WAAWkB,CAAuB,EAAG,CAIlF,MAAME,GAHqBpB,EAAK,cAAc,GACC,kBAAkBU,EAAAA,WAAW,UAAU,GAAK,CAAC,GAEtD,CAAC,EAAE,cAAc,EACvD,GAAI,CAACU,EACJ,OAGMH,EAAA,KAAKI,oBAAkBD,CAAU,CAAC,EACzC,MAAA,CAGD,GAAID,GAAiCnB,EAAK,QAAU,EAAA,WAAWmB,CAA6B,EAAG,CAI9F,MAAMC,GAHqBpB,EAAK,cAAc,GACC,kBAAkBU,EAAAA,WAAW,UAAU,GAAK,CAAC,GAEtD,CAAC,EAAE,cAAc,EACvD,GAAI,CAACU,EACJ,OAGoBE,0BAAwBF,CAAU,EAC1C,QAASG,GAAUN,EAAO,KAAKM,CAAK,CAAC,CAAA,CACnD,CACA,EACKN,CACR"}
|
|
@@ -15,6 +15,7 @@ type Props = {
|
|
|
15
15
|
cachePath: string;
|
|
16
16
|
};
|
|
17
17
|
profiling?: 'stats' | 'off' | 'debug';
|
|
18
|
+
workers?: boolean;
|
|
18
19
|
};
|
|
19
20
|
type FileDiscoveryConfig = {
|
|
20
21
|
rootPath: string;
|
|
@@ -25,13 +26,14 @@ type EndpointTiming = {
|
|
|
25
26
|
timing: number;
|
|
26
27
|
sectionTimings: SectionTiming[];
|
|
27
28
|
};
|
|
28
|
-
export declare const prepareOpenApiSpec: ({ logLevel, tsconfigPath, sourceFilePaths, sourceFileDiscovery, incremental, profiling, }: Props) => Promise<void>;
|
|
29
|
+
export declare const prepareOpenApiSpec: ({ logLevel, tsconfigPath, sourceFilePaths, sourceFileDiscovery, incremental, profiling, workers, }: Props) => Promise<void>;
|
|
29
30
|
export declare const analyzeMultipleSourceFiles: (files: DiscoveredSourceFile[], config: {
|
|
30
31
|
incremental: boolean;
|
|
31
32
|
cachePath: string;
|
|
32
33
|
timestampCache: TimestampCache;
|
|
33
34
|
profiling?: "stats" | "off" | "debug";
|
|
34
35
|
tsconfigPath: string;
|
|
36
|
+
workers?: boolean;
|
|
35
37
|
}, filterEndpointPaths?: string[]) => Promise<EndpointData[]>;
|
|
36
38
|
export declare const analyzeSourceFileWithCache: (file: DiscoveredSourceFile, config: {
|
|
37
39
|
incremental: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzerModule.d.ts","sourceRoot":"","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AAGjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3C,OAAO,EACN,oBAAoB,EAEpB,MAAM,4DAA4D,CAAA;AAEnE,OAAO,EAAE,aAAa,EAAkB,MAAM,2BAA2B,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"analyzerModule.d.ts","sourceRoot":"","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AAGjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3C,OAAO,EACN,oBAAoB,EAEpB,MAAM,4DAA4D,CAAA;AAEnE,OAAO,EAAE,aAAa,EAAkB,MAAM,2BAA2B,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EAAsC,cAA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W,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,cAAc,CAAA;IAC9B,SAAS,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO,CAAA;CACrC,wBACqB,MAAM,EAAE,KAC5B;IAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,cAAc,EAAE,CAAA;CAgBhF,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,wBACJ,MAAM,EAAE,KAC5B;IAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAAC,eAAe,EAAE,cAAc,EAAE,CAAA;CAgChE,CAAA;AAED,eAAO,MAAM,0BAA0B,eAAgB,UAAU,KAAG,aAAa,GAAG,IAyCnF,CAAA;AAED,eAAO,MAAM,8BAA8B,eAAgB,UAAU,KAAG,gBAAgB,EA4CvF,CAAA"}
|
|
@@ -1,211 +1,213 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { existsSync as
|
|
3
|
-
import * as
|
|
4
|
-
import { fileURLToPath as
|
|
5
|
-
import { Project as
|
|
6
|
-
import { Logger as
|
|
7
|
-
import { discoverImportedName as
|
|
8
|
-
import { discoverRouterFiles as
|
|
9
|
-
import { discoverRouters as
|
|
1
|
+
import v from "crypto";
|
|
2
|
+
import { existsSync as O } from "fs";
|
|
3
|
+
import * as M from "path";
|
|
4
|
+
import { fileURLToPath as L } from "url";
|
|
5
|
+
import { Project as j, SyntaxKind as E } from "ts-morph";
|
|
6
|
+
import { Logger as F } from "../../utils/logger.mjs";
|
|
7
|
+
import { discoverImportedName as R } from "../discoveryModule/discoverImports/discoverImports.mjs";
|
|
8
|
+
import { discoverRouterFiles as z } from "../discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs";
|
|
9
|
+
import { discoverRouters as W } from "../discoveryModule/discoverRouters/discoverRouters.mjs";
|
|
10
10
|
import { OpenApiManager as U } from "../manager/OpenApiManager.mjs";
|
|
11
11
|
import { getSourceFileTimestamp as b } from "./getSourceFileTimestamp.mjs";
|
|
12
|
-
import { getValuesOfObjectLiteral as I, resolveEndpointPath as
|
|
13
|
-
import { parseEndpoint as
|
|
14
|
-
import { parseExposedModel as
|
|
15
|
-
import { SourceFileCache as
|
|
16
|
-
import { WorkerPool as
|
|
17
|
-
function
|
|
12
|
+
import { getValuesOfObjectLiteral as I, resolveEndpointPath as H } from "./nodeParsers.mjs";
|
|
13
|
+
import { parseEndpoint as K } from "./parseEndpoint.mjs";
|
|
14
|
+
import { parseExposedModel as _, parseNamedExposedModels as D } from "./parseExposedModels.mjs";
|
|
15
|
+
import { SourceFileCache as w } from "./sourceFileCache.mjs";
|
|
16
|
+
import { WorkerPool as B } from "./workerPool.mjs";
|
|
17
|
+
function V() {
|
|
18
18
|
const l = ["./analyzerWorker.mjs", "./analyzerWorker.test.mjs"];
|
|
19
19
|
for (const n of l) {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
20
|
+
const d = new URL(n, import.meta.url);
|
|
21
|
+
if (O(L(d)))
|
|
22
|
+
return d;
|
|
23
23
|
}
|
|
24
24
|
throw new Error(
|
|
25
25
|
"analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first)."
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const Y = 2, fe = async ({
|
|
29
29
|
logLevel: l,
|
|
30
30
|
tsconfigPath: n,
|
|
31
|
-
sourceFilePaths:
|
|
32
|
-
sourceFileDiscovery:
|
|
33
|
-
incremental:
|
|
34
|
-
profiling:
|
|
31
|
+
sourceFilePaths: d,
|
|
32
|
+
sourceFileDiscovery: m,
|
|
33
|
+
incremental: c,
|
|
34
|
+
profiling: f = "stats",
|
|
35
|
+
workers: t = !1
|
|
35
36
|
}) => {
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
37
|
+
const r = U.getInstance();
|
|
38
|
+
if (r.isReady())
|
|
38
39
|
return;
|
|
39
|
-
l &&
|
|
40
|
-
const
|
|
41
|
-
tsConfigFilePath:
|
|
40
|
+
l && F.setLevel(l), F.info("Preparing OpenAPI spec");
|
|
41
|
+
const h = new j({
|
|
42
|
+
tsConfigFilePath: M.resolve(n),
|
|
42
43
|
skipFileDependencyResolution: !0
|
|
43
|
-
}), { explicitRouters:
|
|
44
|
-
const
|
|
45
|
-
fileName:
|
|
46
|
-
sourceFile:
|
|
47
|
-
routers:
|
|
48
|
-
})), { discoveredRouterFiles:
|
|
49
|
-
if (
|
|
44
|
+
}), { explicitRouters: g, discoveredRouterFiles: x, allSourceFiles: T } = (() => {
|
|
45
|
+
const p = (d ?? []).map((u) => M.resolve(u)).map((u) => h.getSourceFileOrThrow(u)), P = p.flatMap((u) => ({
|
|
46
|
+
fileName: u.getFilePath(),
|
|
47
|
+
sourceFile: u,
|
|
48
|
+
routers: W(u)
|
|
49
|
+
})), { discoveredRouterFiles: C, discoveredSourceFiles: S } = (() => {
|
|
50
|
+
if (m === !1)
|
|
50
51
|
return { discoveredRouterFiles: [], discoveredSourceFiles: [] };
|
|
51
|
-
const
|
|
52
|
-
targetPath: typeof
|
|
52
|
+
const u = performance.now(), k = z({
|
|
53
|
+
targetPath: typeof m == "object" ? m.rootPath : ".",
|
|
53
54
|
tsConfigPath: n
|
|
54
55
|
});
|
|
55
|
-
return
|
|
56
|
-
})(),
|
|
57
|
-
(
|
|
56
|
+
return f !== "off" && F.info(`File discovery took ${Math.round(performance.now() - u)}ms`), k;
|
|
57
|
+
})(), A = p.reduce(
|
|
58
|
+
(u, k) => u.some(($) => $.getFilePath() === k.getFilePath()) ? u : u.concat(k),
|
|
58
59
|
S
|
|
59
60
|
);
|
|
60
|
-
return { explicitRouters:
|
|
61
|
-
})(),
|
|
62
|
-
(
|
|
63
|
-
|
|
64
|
-
),
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
incremental:
|
|
70
|
-
cachePath:
|
|
61
|
+
return { explicitRouters: P, discoveredRouterFiles: C, allSourceFiles: A };
|
|
62
|
+
})(), e = g.reduce(
|
|
63
|
+
(i, N) => i.some((p) => p.fileName === N.fileName) ? i : i.concat(N),
|
|
64
|
+
x
|
|
65
|
+
), o = T.flatMap((i) => J(i)).filter((i) => !!i);
|
|
66
|
+
o.length > 0 && o[0] && r.setHeader(o[0]);
|
|
67
|
+
const s = T.flatMap((i) => Q(i));
|
|
68
|
+
r.setExposedModels(s);
|
|
69
|
+
const a = typeof c == "object" && c.cachePath ? c.cachePath : M.resolve(process.cwd(), "node_modules", ".cache", "moonflower"), y = await q(e, {
|
|
70
|
+
incremental: c !== !1,
|
|
71
|
+
cachePath: a,
|
|
71
72
|
timestampCache: {},
|
|
72
|
-
profiling:
|
|
73
|
-
tsconfigPath:
|
|
73
|
+
profiling: f,
|
|
74
|
+
tsconfigPath: M.resolve(n),
|
|
75
|
+
workers: t
|
|
74
76
|
});
|
|
75
|
-
|
|
76
|
-
discoveredRouterFiles:
|
|
77
|
-
path:
|
|
78
|
-
routers:
|
|
79
|
-
name:
|
|
80
|
-
endpoints:
|
|
77
|
+
r.setStats({
|
|
78
|
+
discoveredRouterFiles: x.map((i) => ({
|
|
79
|
+
path: i.fileName,
|
|
80
|
+
routers: i.routers.named.map((N) => ({
|
|
81
|
+
name: N,
|
|
82
|
+
endpoints: y.filter((p) => p.sourceFilePath === i.fileName).map((p) => `${p.method.toUpperCase()} ${p.path}`)
|
|
81
83
|
}))
|
|
82
84
|
})),
|
|
83
|
-
explicitRouterFiles:
|
|
84
|
-
path:
|
|
85
|
-
routers:
|
|
86
|
-
name:
|
|
87
|
-
endpoints:
|
|
85
|
+
explicitRouterFiles: g.map((i) => ({
|
|
86
|
+
path: i.fileName,
|
|
87
|
+
routers: i.routers.named.map((N) => ({
|
|
88
|
+
name: N,
|
|
89
|
+
endpoints: y.filter((p) => p.sourceFilePath === i.fileName).map((p) => `${p.method.toUpperCase()} ${p.path}`)
|
|
88
90
|
}))
|
|
89
91
|
}))
|
|
90
|
-
}),
|
|
91
|
-
},
|
|
92
|
-
const
|
|
92
|
+
}), r.setEndpoints(y), r.markAsReady();
|
|
93
|
+
}, q = async (l, n, d) => {
|
|
94
|
+
const m = n.profiling ?? "stats", c = performance.now(), f = [], t = [], r = performance.now(), h = /* @__PURE__ */ new Map();
|
|
93
95
|
for (const e of l) {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
+
const o = b(e.sourceFile, n.timestampCache, h), s = n.incremental ? w.getCachedResults(e.sourceFile, o, n.cachePath) : null;
|
|
97
|
+
s ? (F.debug(`[${e.fileName}] Found cached results`), f.push({ endpoints: s.endpoints, fileName: e.fileName, timing: 0, endpointTimings: [] })) : t.push({ file: e, timestamp: o });
|
|
96
98
|
}
|
|
97
|
-
if (t.length === 0)
|
|
98
|
-
return
|
|
99
|
-
const
|
|
99
|
+
if (m !== "off" && F.info(`Cache freshness check took ${Math.round(performance.now() - r)}ms`), t.length === 0)
|
|
100
|
+
return m !== "off" && F.info(`Router analysis took ${Math.round(performance.now() - c)}ms`), f.flatMap((e) => e.endpoints);
|
|
101
|
+
const g = /* @__PURE__ */ new Map();
|
|
100
102
|
for (const { file: e } of t)
|
|
101
|
-
|
|
102
|
-
if (t.length <=
|
|
103
|
+
g.set(e.fileName, { endpoints: [], fileName: e.fileName, timing: 0, endpointTimings: [] });
|
|
104
|
+
if (!(n.workers !== !1) || t.length <= Y)
|
|
103
105
|
for (const { file: e } of t) {
|
|
104
|
-
const { endpoints:
|
|
105
|
-
|
|
106
|
+
const { endpoints: o, endpointTimings: s } = G(e), a = g.get(e.fileName);
|
|
107
|
+
a.endpoints = o, a.endpointTimings = s, a.timing = s.reduce((y, i) => y + i.timing, 0);
|
|
106
108
|
}
|
|
107
109
|
else {
|
|
108
|
-
const e = t.map(({ file:
|
|
109
|
-
fileName:
|
|
110
|
+
const e = t.map(({ file: a }) => ({
|
|
111
|
+
fileName: a.fileName,
|
|
110
112
|
task: {
|
|
111
|
-
taskId:
|
|
113
|
+
taskId: v.randomUUID(),
|
|
112
114
|
tsconfigPath: n.tsconfigPath,
|
|
113
|
-
sourceFilePath:
|
|
114
|
-
routerNames:
|
|
115
|
-
filterEndpointPaths:
|
|
115
|
+
sourceFilePath: a.sourceFile.getFilePath(),
|
|
116
|
+
routerNames: a.routers.named,
|
|
117
|
+
filterEndpointPaths: d
|
|
116
118
|
}
|
|
117
|
-
})),
|
|
118
|
-
let
|
|
119
|
+
})), o = new B(V(), e.length);
|
|
120
|
+
let s;
|
|
119
121
|
try {
|
|
120
|
-
|
|
122
|
+
s = await o.runAll(e.map((a) => a.task));
|
|
121
123
|
} finally {
|
|
122
|
-
|
|
124
|
+
o.terminate();
|
|
123
125
|
}
|
|
124
|
-
for (let
|
|
125
|
-
const
|
|
126
|
-
if ("error" in
|
|
127
|
-
|
|
126
|
+
for (let a = 0; a < s.length; a++) {
|
|
127
|
+
const y = s[a], i = e[a].fileName, N = g.get(i);
|
|
128
|
+
if ("error" in y) {
|
|
129
|
+
F.error(`[${i}] Worker error: ${y.error}`);
|
|
128
130
|
continue;
|
|
129
131
|
}
|
|
130
|
-
N.endpoints =
|
|
132
|
+
N.endpoints = y.endpoints, N.endpointTimings = y.endpointTimings, N.timing = y.endpointTimings.reduce((p, P) => p + P.timing, 0);
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
|
-
for (const { file: e, timestamp:
|
|
134
|
-
const
|
|
135
|
-
|
|
135
|
+
for (const { file: e, timestamp: o } of t) {
|
|
136
|
+
const s = g.get(e.fileName);
|
|
137
|
+
s.endpoints.length > 0 && w.cacheResults(e.sourceFile, o, n.cachePath, s.endpoints);
|
|
136
138
|
}
|
|
137
|
-
const
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
}) :
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
const T = [...f, ...Array.from(g.values())];
|
|
140
|
+
return m !== "off" && F.info(`Router analysis took ${Math.round(performance.now() - c)}ms`), m === "stats" ? T.map((e) => ({ fileName: e.fileName, timeTaken: e.timing })).sort((e, o) => o.timeTaken - e.timeTaken).filter((e) => e.timeTaken > 500).forEach((e) => {
|
|
141
|
+
F.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`);
|
|
142
|
+
}) : m === "debug" && T.map((e) => ({ fileName: e.fileName, timeTaken: e.timing, endpointTimings: e.endpointTimings })).sort((e, o) => o.timeTaken - e.timeTaken).forEach((e) => {
|
|
143
|
+
F.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`), e.endpointTimings.sort((o, s) => s.timing - o.timing).forEach((o) => {
|
|
144
|
+
F.info(` - ${o.method} ${o.path} (${Math.round(o.timing)}ms)`), o.sectionTimings.filter((s) => s.timing >= 1).sort((s, a) => a.timing - s.timing).forEach((s) => {
|
|
145
|
+
F.info(` - ${s.section}: ${Math.round(s.timing)}ms`);
|
|
144
146
|
});
|
|
145
147
|
});
|
|
146
|
-
}),
|
|
147
|
-
},
|
|
148
|
-
const
|
|
148
|
+
}), T.flatMap((e) => e.endpoints);
|
|
149
|
+
}, G = (l, n) => {
|
|
150
|
+
const d = [], m = [], f = ["get", "post", "put", "delete", "del", "patch"].join("|");
|
|
149
151
|
return l.routers.named.forEach((t) => {
|
|
150
|
-
const r = new RegExp(`${t}\\.(?:${
|
|
151
|
-
l.sourceFile.forEachChild((
|
|
152
|
-
const
|
|
153
|
-
if (r.test(
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
method:
|
|
158
|
-
path:
|
|
159
|
-
timing: performance.now() -
|
|
160
|
-
sectionTimings:
|
|
161
|
-
}),
|
|
152
|
+
const r = new RegExp(`${t}\\.(?:${f})`);
|
|
153
|
+
l.sourceFile.forEachChild((h) => {
|
|
154
|
+
const g = h.getText();
|
|
155
|
+
if (r.test(g)) {
|
|
156
|
+
H(h);
|
|
157
|
+
const x = performance.now(), { endpoint: T, sectionTimings: e } = K(h, l.fileName);
|
|
158
|
+
m.push({
|
|
159
|
+
method: T.method,
|
|
160
|
+
path: T.path,
|
|
161
|
+
timing: performance.now() - x,
|
|
162
|
+
sectionTimings: e
|
|
163
|
+
}), d.push(T);
|
|
162
164
|
}
|
|
163
165
|
});
|
|
164
|
-
}), { endpoints:
|
|
165
|
-
},
|
|
166
|
-
const n =
|
|
166
|
+
}), { endpoints: d, endpointTimings: m };
|
|
167
|
+
}, J = (l) => {
|
|
168
|
+
const n = R({
|
|
167
169
|
sourceFile: l,
|
|
168
170
|
originalName: "useApiHeader"
|
|
169
171
|
});
|
|
170
172
|
if (!n)
|
|
171
173
|
return null;
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
174
|
+
const d = l.forEachChildAsArray().filter((t) => t.isKind(E.ExpressionStatement)).find((t) => n && t.getText().startsWith(n));
|
|
175
|
+
if (!d)
|
|
174
176
|
return null;
|
|
175
|
-
const
|
|
177
|
+
const m = d.getFirstDescendantByKindOrThrow(E.ObjectLiteralExpression), c = I(m), f = (t) => typeof t == "string" || Array.isArray(t) && t.every((r) => typeof r == "string") ? t : t.reduce((r, h) => typeof h == "string" ? r : {
|
|
176
178
|
...r,
|
|
177
|
-
[
|
|
179
|
+
[h.identifier]: f(h.value)
|
|
178
180
|
}, {});
|
|
179
|
-
return
|
|
180
|
-
},
|
|
181
|
-
const n = [],
|
|
181
|
+
return f(c);
|
|
182
|
+
}, Q = (l) => {
|
|
183
|
+
const n = [], d = R({
|
|
182
184
|
sourceFile: l,
|
|
183
185
|
originalName: "useExposeApiModel"
|
|
184
|
-
}),
|
|
186
|
+
}), m = R({
|
|
185
187
|
sourceFile: l,
|
|
186
188
|
originalName: "useExposeNamedApiModels"
|
|
187
189
|
});
|
|
188
|
-
return l.forEachChildAsArray().filter((
|
|
189
|
-
if (
|
|
190
|
-
const r = (
|
|
190
|
+
return l.forEachChildAsArray().filter((c) => c.isKind(E.ExpressionStatement)).map((c) => {
|
|
191
|
+
if (d && c.getText().startsWith(d)) {
|
|
192
|
+
const r = (c.getFirstChild()?.getChildrenOfKind(E.SyntaxList) || [])[0].getFirstChild();
|
|
191
193
|
if (!r)
|
|
192
194
|
return;
|
|
193
|
-
n.push(
|
|
195
|
+
n.push(_(r));
|
|
194
196
|
return;
|
|
195
197
|
}
|
|
196
|
-
if (
|
|
197
|
-
const r = (
|
|
198
|
+
if (m && c.getText().startsWith(m)) {
|
|
199
|
+
const r = (c.getFirstChild()?.getChildrenOfKind(E.SyntaxList) || [])[0].getFirstChild();
|
|
198
200
|
if (!r)
|
|
199
201
|
return;
|
|
200
|
-
|
|
202
|
+
D(r).forEach((g) => n.push(g));
|
|
201
203
|
}
|
|
202
204
|
}), n;
|
|
203
205
|
};
|
|
204
206
|
export {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
q as analyzeMultipleSourceFiles,
|
|
208
|
+
J as analyzeSourceFileApiHeader,
|
|
209
|
+
G as analyzeSourceFileEndpoints,
|
|
210
|
+
Q as analyzeSourceFileExposedModels,
|
|
211
|
+
fe as prepareOpenApiSpec
|
|
210
212
|
};
|
|
211
213
|
//# sourceMappingURL=analyzerModule.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzerModule.mjs","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { existsSync } from 'fs'\nimport * as path from 'path'\nimport { fileURLToPath } from 'url'\n\nfunction resolveWorkerUrl(): URL {\n\tconst candidates = ['./analyzerWorker.mjs', './analyzerWorker.test.mjs']\n\tfor (const candidate of candidates) {\n\t\tconst url = new URL(candidate, import.meta.url)\n\t\tif (existsSync(fileURLToPath(url))) {\n\t\t\treturn url\n\t\t}\n\t}\n\tthrow new Error(\n\t\t'analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first).',\n\t)\n}\nimport { SourceFile, SyntaxKind } from 'ts-morph'\nimport { Project } from 'ts-morph'\n\nimport { Logger } from '../../utils/logger'\nimport { discoverImportedName } from '../discoveryModule/discoverImports/discoverImports'\nimport {\n\tDiscoveredSourceFile,\n\tdiscoverRouterFiles,\n} from '../discoveryModule/discoverRouterFiles/discoverRouterFiles'\nimport { discoverRouters } from '../discoveryModule/discoverRouters/discoverRouters'\nimport { ApiDocsHeader, OpenApiManager } from '../manager/OpenApiManager'\nimport { EndpointData, ExposedModelData } from '../types'\nimport { getSourceFileTimestamp, TimestampCache } from './getSourceFileTimestamp'\nimport { getValuesOfObjectLiteral, resolveEndpointPath } from './nodeParsers'\nimport { parseEndpoint, SectionTiming } from './parseEndpoint'\nimport { parseExposedModel, parseNamedExposedModels } from './parseExposedModels'\nimport { SourceFileCache } from './sourceFileCache'\nimport { WorkerPool, WorkerResult, WorkerTask } from './workerPool'\n\ntype Props = {\n\tlogLevel?: Parameters<(typeof Logger)['setLevel']>[0]\n\ttsconfigPath: string\n\tsourceFilePaths?: string[]\n\tsourceFileDiscovery?: boolean | FileDiscoveryConfig\n\tincremental?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tcachePath: string\n\t\t }\n\tprofiling?: 'stats' | 'off' | 'debug'\n}\n\ntype FileDiscoveryConfig = {\n\trootPath: string\n}\n\ntype EndpointTiming = { method: string; path: string; timing: number; sectionTimings: SectionTiming[] }\n\n/**\n * Number of uncached files at or below which analysis runs inline on the (already-warm) main-thread\n * Project instead of fanning out to worker threads. Each worker pays a multi-second cold-start to\n * build its own Project, so parallelism only wins once there are several files to share that cost.\n */\nconst INLINE_ANALYSIS_FILE_THRESHOLD = 2\n\n/**\n * @param tsconfigPath Path to tsconfig file relative to project root\n * @param sourceFilePaths Array of router source files relative to project root\n */\nexport const prepareOpenApiSpec = async ({\n\tlogLevel,\n\ttsconfigPath,\n\tsourceFilePaths,\n\tsourceFileDiscovery,\n\tincremental,\n\tprofiling = 'stats',\n}: Props): Promise<void> => {\n\tconst openApiManager = OpenApiManager.getInstance()\n\n\tif (openApiManager.isReady()) {\n\t\treturn\n\t}\n\n\tif (logLevel) {\n\t\tLogger.setLevel(logLevel)\n\t}\n\n\tLogger.info('Preparing OpenAPI spec')\n\n\tconst project = new Project({\n\t\ttsConfigFilePath: path.resolve(tsconfigPath),\n\t\tskipFileDependencyResolution: true,\n\t})\n\n\tconst { explicitRouters, discoveredRouterFiles, allSourceFiles } = (() => {\n\t\tconst sourceFilesToAdd = sourceFilePaths ?? []\n\t\tconst resolvedSourceFilePaths = sourceFilesToAdd.map((filepath) => path.resolve(filepath))\n\t\tconst sourceFiles = resolvedSourceFilePaths.map((filePath) => project.getSourceFileOrThrow(filePath))\n\t\tconst explicitRouters = sourceFiles.flatMap((file) => ({\n\t\t\tfileName: file.getFilePath(),\n\t\t\tsourceFile: file,\n\t\t\trouters: discoverRouters(file),\n\t\t}))\n\n\t\tconst { discoveredRouterFiles, discoveredSourceFiles } = (() => {\n\t\t\tif (sourceFileDiscovery === false) {\n\t\t\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t\t\t}\n\n\t\t\tconst startTime = performance.now()\n\t\t\tconst files = discoverRouterFiles({\n\t\t\t\ttargetPath: typeof sourceFileDiscovery === 'object' ? sourceFileDiscovery.rootPath : '.',\n\t\t\t\ttsConfigPath: tsconfigPath,\n\t\t\t})\n\t\t\tif (profiling !== 'off') {\n\t\t\t\tLogger.info(`File discovery took ${Math.round(performance.now() - startTime)}ms`)\n\t\t\t}\n\t\t\treturn files\n\t\t})()\n\n\t\tconst allSourceFiles = sourceFiles.reduce(\n\t\t\t(acc, current) =>\n\t\t\t\tacc.some((r) => r.getFilePath() === current.getFilePath()) ? acc : acc.concat(current),\n\t\t\tdiscoveredSourceFiles,\n\t\t)\n\n\t\treturn { explicitRouters, discoveredRouterFiles, allSourceFiles }\n\t})()\n\n\tconst filesToAnalyze = explicitRouters.reduce(\n\t\t(acc, current) => (acc.some((r) => r.fileName === current.fileName) ? acc : acc.concat(current)),\n\t\tdiscoveredRouterFiles,\n\t)\n\n\tconst apiHeaders = allSourceFiles\n\t\t.flatMap((file) => analyzeSourceFileApiHeader(file))\n\t\t.filter((headers) => !!headers)\n\tif (apiHeaders.length > 0 && apiHeaders[0]) {\n\t\topenApiManager.setHeader(apiHeaders[0])\n\t}\n\n\tconst exposedModels = allSourceFiles.flatMap((file) => analyzeSourceFileExposedModels(file))\n\n\topenApiManager.setExposedModels(exposedModels)\n\n\tconst cachePath = (() => {\n\t\tif (typeof incremental === 'object' && incremental.cachePath) {\n\t\t\treturn incremental.cachePath\n\t\t}\n\t\treturn path.resolve(process.cwd(), 'node_modules', '.cache', 'moonflower')\n\t})()\n\tconst endpoints = await analyzeMultipleSourceFiles(filesToAnalyze, {\n\t\tincremental: incremental !== false,\n\t\tcachePath,\n\t\ttimestampCache: {},\n\t\tprofiling,\n\t\ttsconfigPath: path.resolve(tsconfigPath),\n\t})\n\n\topenApiManager.setStats({\n\t\tdiscoveredRouterFiles: discoveredRouterFiles.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t\texplicitRouterFiles: explicitRouters.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t})\n\n\topenApiManager.setEndpoints(endpoints)\n\topenApiManager.markAsReady()\n}\n\nexport const analyzeMultipleSourceFiles = async (\n\tfiles: DiscoveredSourceFile[],\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t\tprofiling?: 'stats' | 'off' | 'debug'\n\t\ttsconfigPath: string\n\t},\n\tfilterEndpointPaths?: string[],\n): Promise<EndpointData[]> => {\n\tconst profiling = config.profiling ?? 'stats'\n\tconst startTime = performance.now()\n\n\t// Separate cached files from those needing analysis\n\ttype CachedFile = { endpoints: EndpointData[]; fileName: string; timing: 0; endpointTimings: [] }\n\ttype UncachedFile = { file: DiscoveredSourceFile; timestamp: number }\n\n\tconst cached: CachedFile[] = []\n\tconst uncached: UncachedFile[] = []\n\n\tfor (const file of files) {\n\t\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)\n\t\tconst hit = config.incremental\n\t\t\t? SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\t\t\t: null\n\t\tif (hit) {\n\t\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\t\tcached.push({ endpoints: hit.endpoints, fileName: file.fileName, timing: 0, endpointTimings: [] })\n\t\t} else {\n\t\t\tuncached.push({ file, timestamp })\n\t\t}\n\t}\n\n\tif (uncached.length === 0) {\n\t\tif (profiling !== 'off') {\n\t\t\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\t\t}\n\t\treturn cached.flatMap((f) => f.endpoints)\n\t}\n\n\ttype FileResult = {\n\t\tendpoints: EndpointData[]\n\t\tfileName: string\n\t\ttiming: number\n\t\tendpointTimings: EndpointTiming[]\n\t}\n\n\tconst byFile = new Map<string, FileResult>()\n\tfor (const { file } of uncached) {\n\t\tbyFile.set(file.fileName, { endpoints: [], fileName: file.fileName, timing: 0, endpointTimings: [] })\n\t}\n\n\t// The caller (prepareOpenApiSpec) already built and warmed a ts-morph Project on this thread, so\n\t// inline analysis runs against a hot type-checker. A worker, by contrast, must spawn a thread and\n\t// build its own Project from scratch — a multi-second cold-start. That cold-start only pays off\n\t// when there are enough uncached files that spreading the parse work across workers beats it; below\n\t// the threshold (e.g. the common single-file incremental rebuild), inline is strictly faster.\n\tif (uncached.length <= INLINE_ANALYSIS_FILE_THRESHOLD) {\n\t\tfor (const { file } of uncached) {\n\t\t\tconst { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\t\t\tconst fileResult = byFile.get(file.fileName)!\n\t\t\tfileResult.endpoints = endpoints\n\t\t\tfileResult.endpointTimings = endpointTimings\n\t\t\tfileResult.timing = endpointTimings.reduce((sum, t) => sum + t.timing, 0)\n\t\t}\n\t} else {\n\t\t// One task per file: each worker analyzes a whole file in a single pass, paying its Project\n\t\t// cold-start once and reusing the warmed-up checker for every endpoint in that file. Cap the\n\t\t// pool at one worker per file so we never spin up a worker with nothing to do.\n\t\ttype FileTask = { task: WorkerTask; fileName: string }\n\t\tconst allTasks: FileTask[] = uncached.map(({ file }) => ({\n\t\t\tfileName: file.fileName,\n\t\t\ttask: {\n\t\t\t\ttaskId: crypto.randomUUID(),\n\t\t\t\ttsconfigPath: config.tsconfigPath,\n\t\t\t\tsourceFilePath: file.sourceFile.getFilePath(),\n\t\t\t\trouterNames: file.routers.named,\n\t\t\t\tfilterEndpointPaths,\n\t\t\t},\n\t\t}))\n\n\t\tconst pool = new WorkerPool(resolveWorkerUrl(), allTasks.length)\n\t\tlet results: WorkerResult[]\n\t\ttry {\n\t\t\tresults = await pool.runAll(allTasks.map((ft) => ft.task))\n\t\t} finally {\n\t\t\tpool.terminate()\n\t\t}\n\n\t\t// Each result maps 1:1 to a file task.\n\t\tfor (let i = 0; i < results.length; i++) {\n\t\t\tconst result = results[i]\n\t\t\tconst fileName = allTasks[i].fileName\n\t\t\tconst fileResult = byFile.get(fileName)!\n\n\t\t\tif ('error' in result) {\n\t\t\t\tLogger.error(`[${fileName}] Worker error: ${result.error}`)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfileResult.endpoints = result.endpoints\n\t\t\tfileResult.endpointTimings = result.endpointTimings\n\t\t\tfileResult.timing = result.endpointTimings.reduce((sum, t) => sum + t.timing, 0)\n\t\t}\n\t}\n\n\t// Write cache for each uncached file\n\tfor (const { file, timestamp } of uncached) {\n\t\tconst fileResult = byFile.get(file.fileName)!\n\t\tif (fileResult.endpoints.length > 0) {\n\t\t\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, fileResult.endpoints)\n\t\t}\n\t}\n\n\tconst analyzedFiles = [...cached, ...Array.from(byFile.values())]\n\n\tif (profiling !== 'off') {\n\t\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\t}\n\n\tif (profiling === 'stats') {\n\t\tanalyzedFiles\n\t\t\t.map((f) => ({ fileName: f.fileName, timeTaken: f.timing }))\n\t\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t\t.filter((t) => t.timeTaken > 500)\n\t\t\t.forEach((t) => {\n\t\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t\t})\n\t} else if (profiling === 'debug') {\n\t\tanalyzedFiles\n\t\t\t.map((f) => ({ fileName: f.fileName, timeTaken: f.timing, endpointTimings: f.endpointTimings }))\n\t\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t\t.forEach((t) => {\n\t\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t\t\tt.endpointTimings\n\t\t\t\t\t.sort((a, b) => b.timing - a.timing)\n\t\t\t\t\t.forEach((ep) => {\n\t\t\t\t\t\tLogger.info(` - ${ep.method} ${ep.path} (${Math.round(ep.timing)}ms)`)\n\t\t\t\t\t\tep.sectionTimings\n\t\t\t\t\t\t\t.filter((s) => s.timing >= 1)\n\t\t\t\t\t\t\t.sort((a, b) => b.timing - a.timing)\n\t\t\t\t\t\t\t.forEach((s) => {\n\t\t\t\t\t\t\t\tLogger.info(` - ${s.section}: ${Math.round(s.timing)}ms`)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t})\n\t}\n\n\treturn analyzedFiles.flatMap((f) => f.endpoints)\n}\n\nexport const analyzeSourceFileWithCache = (\n\tfile: DiscoveredSourceFile,\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t\tprofiling?: 'stats' | 'off' | 'debug'\n\t},\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; timing: number; endpointTimings: EndpointTiming[] } => {\n\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)\n\tconst cachedResults = SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\n\tif (cachedResults) {\n\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\treturn { endpoints: cachedResults.endpoints, timing: 0, endpointTimings: [] }\n\t}\n\tLogger.debug(`[${file.fileName}] Analyzing...`)\n\n\tconst t1 = performance.now()\n\tconst { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\tconst t2 = performance.now()\n\tLogger.debug(`[${file.fileName}] Analyzed in ${t2 - t1}ms`)\n\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, endpoints)\n\treturn { endpoints, timing: t2 - t1, endpointTimings }\n}\n\nexport const analyzeSourceFileEndpoints = (\n\tfile: DiscoveredSourceFile,\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; endpointTimings: EndpointTiming[] } => {\n\tconst endpoints: EndpointData[] = []\n\tconst endpointTimings: EndpointTiming[] = []\n\tconst operations = ['get', 'post', 'put', 'delete', 'del', 'patch']\n\tconst joinedOperations = operations.join('|')\n\n\tfile.routers.named.forEach((routerName) => {\n\t\tconst routerPattern = new RegExp(`${routerName}\\\\.(?:${joinedOperations})`)\n\t\tfile.sourceFile.forEachChild((node) => {\n\t\t\tconst nodeText = node.getText()\n\n\t\t\tif (routerPattern.test(nodeText)) {\n\t\t\t\tconst endpointPath = resolveEndpointPath(node) ?? ''\n\n\t\t\t\tif (filterEndpointPaths && !filterEndpointPaths.some((path) => endpointPath.includes(path))) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst t1 = performance.now()\n\t\t\t\tconst { endpoint, sectionTimings } = parseEndpoint(node, file.fileName)\n\t\t\t\tendpointTimings.push({\n\t\t\t\t\tmethod: endpoint.method,\n\t\t\t\t\tpath: endpoint.path,\n\t\t\t\t\ttiming: performance.now() - t1,\n\t\t\t\t\tsectionTimings,\n\t\t\t\t})\n\t\t\t\tendpoints.push(endpoint)\n\t\t\t}\n\t\t})\n\t})\n\n\treturn { endpoints, endpointTimings }\n}\n\nexport const analyzeSourceFileApiHeader = (sourceFile: SourceFile): ApiDocsHeader | null => {\n\tconst nameOfUseApiHeader = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useApiHeader',\n\t})\n\n\tif (!nameOfUseApiHeader) {\n\t\treturn null\n\t}\n\n\tconst node = sourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.find((node) => nameOfUseApiHeader && node.getText().startsWith(nameOfUseApiHeader))\n\n\tif (!node) {\n\t\treturn null\n\t}\n\n\tconst targetNode = node.getFirstDescendantByKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\tconst values = getValuesOfObjectLiteral(targetNode)\n\n\tconst collapseObject = (v: string | string[] | typeof values): any => {\n\t\tif (typeof v === 'string') {\n\t\t\treturn v\n\t\t}\n\t\tif (Array.isArray(v) && v.every((value) => typeof value === 'string')) {\n\t\t\treturn v\n\t\t}\n\n\t\treturn v.reduce((acc, current) => {\n\t\t\tif (typeof current === 'string') {\n\t\t\t\treturn acc\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t[current.identifier]: collapseObject(current.value as string[]),\n\t\t\t}\n\t\t}, {})\n\t}\n\treturn collapseObject(values)\n}\n\nexport const analyzeSourceFileExposedModels = (sourceFile: SourceFile): ExposedModelData[] => {\n\tconst models: ExposedModelData[] = []\n\n\tconst nameOfUseExposeApiModel = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeApiModel',\n\t})\n\n\tconst nameOfUseExposeNamedApiModels = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeNamedApiModels',\n\t})\n\n\tsourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.map((node) => {\n\t\t\tif (nameOfUseExposeApiModel && node.getText().startsWith(nameOfUseExposeApiModel)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tmodels.push(parseExposedModel(firstChild))\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (nameOfUseExposeNamedApiModels && node.getText().startsWith(nameOfUseExposeNamedApiModels)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst parsedModels = parseNamedExposedModels(firstChild)\n\t\t\t\tparsedModels.forEach((model) => models.push(model))\n\t\t\t}\n\t\t})\n\treturn models\n}\n"],"names":["resolveWorkerUrl","candidates","candidate","url","existsSync","fileURLToPath","INLINE_ANALYSIS_FILE_THRESHOLD","prepareOpenApiSpec","logLevel","tsconfigPath","sourceFilePaths","sourceFileDiscovery","incremental","profiling","openApiManager","OpenApiManager","Logger","project","Project","path","explicitRouters","discoveredRouterFiles","allSourceFiles","sourceFiles","filepath","filePath","file","discoverRouters","discoveredSourceFiles","startTime","files","discoverRouterFiles","acc","current","r","filesToAnalyze","apiHeaders","analyzeSourceFileApiHeader","headers","exposedModels","analyzeSourceFileExposedModels","cachePath","endpoints","analyzeMultipleSourceFiles","e","config","filterEndpointPaths","cached","uncached","timestamp","getSourceFileTimestamp","hit","SourceFileCache","f","byFile","endpointTimings","analyzeSourceFileEndpoints","fileResult","sum","t","allTasks","crypto","pool","WorkerPool","results","ft","i","result","fileName","analyzedFiles","a","b","ep","s","joinedOperations","routerName","routerPattern","node","nodeText","resolveEndpointPath","t1","endpoint","sectionTimings","parseEndpoint","sourceFile","nameOfUseApiHeader","discoverImportedName","SyntaxKind","targetNode","values","getValuesOfObjectLiteral","collapseObject","v","value","models","nameOfUseExposeApiModel","nameOfUseExposeNamedApiModels","firstChild","parseExposedModel","parseNamedExposedModels","model"],"mappings":";;;;;;;;;;;;;;;;AAKA,SAASA,IAAwB;AAC1B,QAAAC,IAAa,CAAC,wBAAwB,2BAA2B;AACvE,aAAWC,KAAaD,GAAY;AACnC,UAAME,IAAM,IAAI,IAAID,GAAW,YAAY,GAAG;AAC9C,QAAIE,EAAWC,EAAcF,CAAG,CAAC;AACzB,aAAAA;AAAA,EACR;AAED,QAAM,IAAI;AAAA,IACT;AAAA,EACD;AACD;AA4CA,MAAMG,IAAiC,GAM1BC,KAAqB,OAAO;AAAA,EACxC,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC,IAAY;AACb,MAA4B;AACrB,QAAAC,IAAiBC,EAAe,YAAY;AAE9C,MAAAD,EAAe;AAClB;AAGD,EAAIN,KACHQ,EAAO,SAASR,CAAQ,GAGzBQ,EAAO,KAAK,wBAAwB;AAE9B,QAAAC,IAAU,IAAIC,EAAQ;AAAA,IAC3B,kBAAkBC,EAAK,QAAQV,CAAY;AAAA,IAC3C,8BAA8B;AAAA,EAAA,CAC9B,GAEK,EAAE,iBAAAW,GAAiB,uBAAAC,GAAuB,gBAAAC,EAAA,KAAoB,MAAM;AAGnE,UAAAC,KAFmBb,KAAmB,CAAC,GACI,IAAI,CAACc,MAAaL,EAAK,QAAQK,CAAQ,CAAC,EAC7C,IA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../../src/openapi/analyzerModule/analyzerModule.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { existsSync } from 'fs'\nimport * as path from 'path'\nimport { fileURLToPath } from 'url'\n\nfunction resolveWorkerUrl(): URL {\n\tconst candidates = ['./analyzerWorker.mjs', './analyzerWorker.test.mjs']\n\tfor (const candidate of candidates) {\n\t\tconst url = new URL(candidate, import.meta.url)\n\t\tif (existsSync(fileURLToPath(url))) {\n\t\t\treturn url\n\t\t}\n\t}\n\tthrow new Error(\n\t\t'analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first).',\n\t)\n}\nimport { SourceFile, SyntaxKind } from 'ts-morph'\nimport { Project } from 'ts-morph'\n\nimport { Logger } from '../../utils/logger'\nimport { discoverImportedName } from '../discoveryModule/discoverImports/discoverImports'\nimport {\n\tDiscoveredSourceFile,\n\tdiscoverRouterFiles,\n} from '../discoveryModule/discoverRouterFiles/discoverRouterFiles'\nimport { discoverRouters } from '../discoveryModule/discoverRouters/discoverRouters'\nimport { ApiDocsHeader, OpenApiManager } from '../manager/OpenApiManager'\nimport { EndpointData, ExposedModelData } from '../types'\nimport { getSourceFileTimestamp, MtimeCache, TimestampCache } from './getSourceFileTimestamp'\nimport { getValuesOfObjectLiteral, resolveEndpointPath } from './nodeParsers'\nimport { parseEndpoint, SectionTiming } from './parseEndpoint'\nimport { parseExposedModel, parseNamedExposedModels } from './parseExposedModels'\nimport { SourceFileCache } from './sourceFileCache'\nimport { WorkerPool, WorkerResult, WorkerTask } from './workerPool'\n\ntype Props = {\n\tlogLevel?: Parameters<(typeof Logger)['setLevel']>[0]\n\ttsconfigPath: string\n\tsourceFilePaths?: string[]\n\tsourceFileDiscovery?: boolean | FileDiscoveryConfig\n\tincremental?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tcachePath: string\n\t\t }\n\tprofiling?: 'stats' | 'off' | 'debug'\n\tworkers?: boolean\n}\n\ntype FileDiscoveryConfig = {\n\trootPath: string\n}\n\ntype EndpointTiming = { method: string; path: string; timing: number; sectionTimings: SectionTiming[] }\n\n/**\n * Number of uncached files at or below which analysis runs inline on the (already-warm) main-thread\n * Project instead of fanning out to worker threads. Each worker pays a multi-second cold-start to\n * build its own Project, so parallelism only wins once there are several files to share that cost.\n */\nconst INLINE_ANALYSIS_FILE_THRESHOLD = 2\n\n/**\n * @param tsconfigPath Path to tsconfig file relative to project root\n * @param sourceFilePaths Array of router source files relative to project root\n */\nexport const prepareOpenApiSpec = async ({\n\tlogLevel,\n\ttsconfigPath,\n\tsourceFilePaths,\n\tsourceFileDiscovery,\n\tincremental,\n\tprofiling = 'stats',\n\tworkers = false,\n}: Props): Promise<void> => {\n\tconst openApiManager = OpenApiManager.getInstance()\n\n\tif (openApiManager.isReady()) {\n\t\treturn\n\t}\n\n\tif (logLevel) {\n\t\tLogger.setLevel(logLevel)\n\t}\n\n\tLogger.info('Preparing OpenAPI spec')\n\n\tconst project = new Project({\n\t\ttsConfigFilePath: path.resolve(tsconfigPath),\n\t\tskipFileDependencyResolution: true,\n\t})\n\n\tconst { explicitRouters, discoveredRouterFiles, allSourceFiles } = (() => {\n\t\tconst sourceFilesToAdd = sourceFilePaths ?? []\n\t\tconst resolvedSourceFilePaths = sourceFilesToAdd.map((filepath) => path.resolve(filepath))\n\t\tconst sourceFiles = resolvedSourceFilePaths.map((filePath) => project.getSourceFileOrThrow(filePath))\n\t\tconst explicitRouters = sourceFiles.flatMap((file) => ({\n\t\t\tfileName: file.getFilePath(),\n\t\t\tsourceFile: file,\n\t\t\trouters: discoverRouters(file),\n\t\t}))\n\n\t\tconst { discoveredRouterFiles, discoveredSourceFiles } = (() => {\n\t\t\tif (sourceFileDiscovery === false) {\n\t\t\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t\t\t}\n\n\t\t\tconst startTime = performance.now()\n\t\t\tconst files = discoverRouterFiles({\n\t\t\t\ttargetPath: typeof sourceFileDiscovery === 'object' ? sourceFileDiscovery.rootPath : '.',\n\t\t\t\ttsConfigPath: tsconfigPath,\n\t\t\t})\n\t\t\tif (profiling !== 'off') {\n\t\t\t\tLogger.info(`File discovery took ${Math.round(performance.now() - startTime)}ms`)\n\t\t\t}\n\t\t\treturn files\n\t\t})()\n\n\t\tconst allSourceFiles = sourceFiles.reduce(\n\t\t\t(acc, current) =>\n\t\t\t\tacc.some((r) => r.getFilePath() === current.getFilePath()) ? acc : acc.concat(current),\n\t\t\tdiscoveredSourceFiles,\n\t\t)\n\n\t\treturn { explicitRouters, discoveredRouterFiles, allSourceFiles }\n\t})()\n\n\tconst filesToAnalyze = explicitRouters.reduce(\n\t\t(acc, current) => (acc.some((r) => r.fileName === current.fileName) ? acc : acc.concat(current)),\n\t\tdiscoveredRouterFiles,\n\t)\n\n\tconst apiHeaders = allSourceFiles\n\t\t.flatMap((file) => analyzeSourceFileApiHeader(file))\n\t\t.filter((headers) => !!headers)\n\tif (apiHeaders.length > 0 && apiHeaders[0]) {\n\t\topenApiManager.setHeader(apiHeaders[0])\n\t}\n\n\tconst exposedModels = allSourceFiles.flatMap((file) => analyzeSourceFileExposedModels(file))\n\n\topenApiManager.setExposedModels(exposedModels)\n\n\tconst cachePath = (() => {\n\t\tif (typeof incremental === 'object' && incremental.cachePath) {\n\t\t\treturn incremental.cachePath\n\t\t}\n\t\treturn path.resolve(process.cwd(), 'node_modules', '.cache', 'moonflower')\n\t})()\n\tconst endpoints = await analyzeMultipleSourceFiles(filesToAnalyze, {\n\t\tincremental: incremental !== false,\n\t\tcachePath,\n\t\ttimestampCache: {},\n\t\tprofiling,\n\t\ttsconfigPath: path.resolve(tsconfigPath),\n\t\tworkers,\n\t})\n\n\topenApiManager.setStats({\n\t\tdiscoveredRouterFiles: discoveredRouterFiles.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t\texplicitRouterFiles: explicitRouters.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t})\n\n\topenApiManager.setEndpoints(endpoints)\n\topenApiManager.markAsReady()\n}\n\nexport const analyzeMultipleSourceFiles = async (\n\tfiles: DiscoveredSourceFile[],\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t\tprofiling?: 'stats' | 'off' | 'debug'\n\t\ttsconfigPath: string\n\t\tworkers?: boolean\n\t},\n\tfilterEndpointPaths?: string[],\n): Promise<EndpointData[]> => {\n\tconst profiling = config.profiling ?? 'stats'\n\tconst startTime = performance.now()\n\n\t// Separate cached files from those needing analysis\n\ttype CachedFile = { endpoints: EndpointData[]; fileName: string; timing: 0; endpointTimings: [] }\n\ttype UncachedFile = { file: DiscoveredSourceFile; timestamp: number }\n\n\tconst cached: CachedFile[] = []\n\tconst uncached: UncachedFile[] = []\n\n\tconst freshnessCheckStart = performance.now()\n\tconst mtimeCache: MtimeCache = new Map()\n\tfor (const file of files) {\n\t\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache, mtimeCache)\n\t\tconst hit = config.incremental\n\t\t\t? SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\t\t\t: null\n\t\tif (hit) {\n\t\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\t\tcached.push({ endpoints: hit.endpoints, fileName: file.fileName, timing: 0, endpointTimings: [] })\n\t\t} else {\n\t\t\tuncached.push({ file, timestamp })\n\t\t}\n\t}\n\tif (profiling !== 'off') {\n\t\tLogger.info(`Cache freshness check took ${Math.round(performance.now() - freshnessCheckStart)}ms`)\n\t}\n\n\tif (uncached.length === 0) {\n\t\tif (profiling !== 'off') {\n\t\t\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\t\t}\n\t\treturn cached.flatMap((f) => f.endpoints)\n\t}\n\n\ttype FileResult = {\n\t\tendpoints: EndpointData[]\n\t\tfileName: string\n\t\ttiming: number\n\t\tendpointTimings: EndpointTiming[]\n\t}\n\n\tconst byFile = new Map<string, FileResult>()\n\tfor (const { file } of uncached) {\n\t\tbyFile.set(file.fileName, { endpoints: [], fileName: file.fileName, timing: 0, endpointTimings: [] })\n\t}\n\n\tconst useWorkers = config.workers !== false\n\tif (!useWorkers || uncached.length <= INLINE_ANALYSIS_FILE_THRESHOLD) {\n\t\tfor (const { file } of uncached) {\n\t\t\tconst { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\t\t\tconst fileResult = byFile.get(file.fileName)!\n\t\t\tfileResult.endpoints = endpoints\n\t\t\tfileResult.endpointTimings = endpointTimings\n\t\t\tfileResult.timing = endpointTimings.reduce((sum, t) => sum + t.timing, 0)\n\t\t}\n\t} else {\n\t\ttype FileTask = { task: WorkerTask; fileName: string }\n\t\tconst allTasks: FileTask[] = uncached.map(({ file }) => ({\n\t\t\tfileName: file.fileName,\n\t\t\ttask: {\n\t\t\t\ttaskId: crypto.randomUUID(),\n\t\t\t\ttsconfigPath: config.tsconfigPath,\n\t\t\t\tsourceFilePath: file.sourceFile.getFilePath(),\n\t\t\t\trouterNames: file.routers.named,\n\t\t\t\tfilterEndpointPaths,\n\t\t\t},\n\t\t}))\n\n\t\tconst pool = new WorkerPool(resolveWorkerUrl(), allTasks.length)\n\t\tlet results: WorkerResult[]\n\t\ttry {\n\t\t\tresults = await pool.runAll(allTasks.map((ft) => ft.task))\n\t\t} finally {\n\t\t\tpool.terminate()\n\t\t}\n\n\t\t// Each result maps 1:1 to a file task.\n\t\tfor (let i = 0; i < results.length; i++) {\n\t\t\tconst result = results[i]\n\t\t\tconst fileName = allTasks[i].fileName\n\t\t\tconst fileResult = byFile.get(fileName)!\n\n\t\t\tif ('error' in result) {\n\t\t\t\tLogger.error(`[${fileName}] Worker error: ${result.error}`)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfileResult.endpoints = result.endpoints\n\t\t\tfileResult.endpointTimings = result.endpointTimings\n\t\t\tfileResult.timing = result.endpointTimings.reduce((sum, t) => sum + t.timing, 0)\n\t\t}\n\t}\n\n\t// Write cache for each uncached file\n\tfor (const { file, timestamp } of uncached) {\n\t\tconst fileResult = byFile.get(file.fileName)!\n\t\tif (fileResult.endpoints.length > 0) {\n\t\t\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, fileResult.endpoints)\n\t\t}\n\t}\n\n\tconst analyzedFiles = [...cached, ...Array.from(byFile.values())]\n\n\tif (profiling !== 'off') {\n\t\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\t}\n\n\tif (profiling === 'stats') {\n\t\tanalyzedFiles\n\t\t\t.map((f) => ({ fileName: f.fileName, timeTaken: f.timing }))\n\t\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t\t.filter((t) => t.timeTaken > 500)\n\t\t\t.forEach((t) => {\n\t\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t\t})\n\t} else if (profiling === 'debug') {\n\t\tanalyzedFiles\n\t\t\t.map((f) => ({ fileName: f.fileName, timeTaken: f.timing, endpointTimings: f.endpointTimings }))\n\t\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t\t.forEach((t) => {\n\t\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t\t\tt.endpointTimings\n\t\t\t\t\t.sort((a, b) => b.timing - a.timing)\n\t\t\t\t\t.forEach((ep) => {\n\t\t\t\t\t\tLogger.info(` - ${ep.method} ${ep.path} (${Math.round(ep.timing)}ms)`)\n\t\t\t\t\t\tep.sectionTimings\n\t\t\t\t\t\t\t.filter((s) => s.timing >= 1)\n\t\t\t\t\t\t\t.sort((a, b) => b.timing - a.timing)\n\t\t\t\t\t\t\t.forEach((s) => {\n\t\t\t\t\t\t\t\tLogger.info(` - ${s.section}: ${Math.round(s.timing)}ms`)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t})\n\t}\n\n\treturn analyzedFiles.flatMap((f) => f.endpoints)\n}\n\nexport const analyzeSourceFileWithCache = (\n\tfile: DiscoveredSourceFile,\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t\tprofiling?: 'stats' | 'off' | 'debug'\n\t},\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; timing: number; endpointTimings: EndpointTiming[] } => {\n\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)\n\tconst cachedResults = SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\n\tif (cachedResults) {\n\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\treturn { endpoints: cachedResults.endpoints, timing: 0, endpointTimings: [] }\n\t}\n\tLogger.debug(`[${file.fileName}] Analyzing...`)\n\n\tconst t1 = performance.now()\n\tconst { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\tconst t2 = performance.now()\n\tLogger.debug(`[${file.fileName}] Analyzed in ${t2 - t1}ms`)\n\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, endpoints)\n\treturn { endpoints, timing: t2 - t1, endpointTimings }\n}\n\nexport const analyzeSourceFileEndpoints = (\n\tfile: DiscoveredSourceFile,\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; endpointTimings: EndpointTiming[] } => {\n\tconst endpoints: EndpointData[] = []\n\tconst endpointTimings: EndpointTiming[] = []\n\tconst operations = ['get', 'post', 'put', 'delete', 'del', 'patch']\n\tconst joinedOperations = operations.join('|')\n\n\tfile.routers.named.forEach((routerName) => {\n\t\tconst routerPattern = new RegExp(`${routerName}\\\\.(?:${joinedOperations})`)\n\t\tfile.sourceFile.forEachChild((node) => {\n\t\t\tconst nodeText = node.getText()\n\n\t\t\tif (routerPattern.test(nodeText)) {\n\t\t\t\tconst endpointPath = resolveEndpointPath(node) ?? ''\n\n\t\t\t\tif (filterEndpointPaths && !filterEndpointPaths.some((path) => endpointPath.includes(path))) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst t1 = performance.now()\n\t\t\t\tconst { endpoint, sectionTimings } = parseEndpoint(node, file.fileName)\n\t\t\t\tendpointTimings.push({\n\t\t\t\t\tmethod: endpoint.method,\n\t\t\t\t\tpath: endpoint.path,\n\t\t\t\t\ttiming: performance.now() - t1,\n\t\t\t\t\tsectionTimings,\n\t\t\t\t})\n\t\t\t\tendpoints.push(endpoint)\n\t\t\t}\n\t\t})\n\t})\n\n\treturn { endpoints, endpointTimings }\n}\n\nexport const analyzeSourceFileApiHeader = (sourceFile: SourceFile): ApiDocsHeader | null => {\n\tconst nameOfUseApiHeader = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useApiHeader',\n\t})\n\n\tif (!nameOfUseApiHeader) {\n\t\treturn null\n\t}\n\n\tconst node = sourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.find((node) => nameOfUseApiHeader && node.getText().startsWith(nameOfUseApiHeader))\n\n\tif (!node) {\n\t\treturn null\n\t}\n\n\tconst targetNode = node.getFirstDescendantByKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\tconst values = getValuesOfObjectLiteral(targetNode)\n\n\tconst collapseObject = (v: string | string[] | typeof values): any => {\n\t\tif (typeof v === 'string') {\n\t\t\treturn v\n\t\t}\n\t\tif (Array.isArray(v) && v.every((value) => typeof value === 'string')) {\n\t\t\treturn v\n\t\t}\n\n\t\treturn v.reduce((acc, current) => {\n\t\t\tif (typeof current === 'string') {\n\t\t\t\treturn acc\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t[current.identifier]: collapseObject(current.value as string[]),\n\t\t\t}\n\t\t}, {})\n\t}\n\treturn collapseObject(values)\n}\n\nexport const analyzeSourceFileExposedModels = (sourceFile: SourceFile): ExposedModelData[] => {\n\tconst models: ExposedModelData[] = []\n\n\tconst nameOfUseExposeApiModel = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeApiModel',\n\t})\n\n\tconst nameOfUseExposeNamedApiModels = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeNamedApiModels',\n\t})\n\n\tsourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.map((node) => {\n\t\t\tif (nameOfUseExposeApiModel && node.getText().startsWith(nameOfUseExposeApiModel)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tmodels.push(parseExposedModel(firstChild))\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (nameOfUseExposeNamedApiModels && node.getText().startsWith(nameOfUseExposeNamedApiModels)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst parsedModels = parseNamedExposedModels(firstChild)\n\t\t\t\tparsedModels.forEach((model) => models.push(model))\n\t\t\t}\n\t\t})\n\treturn models\n}\n"],"names":["resolveWorkerUrl","candidates","candidate","url","existsSync","fileURLToPath","INLINE_ANALYSIS_FILE_THRESHOLD","prepareOpenApiSpec","logLevel","tsconfigPath","sourceFilePaths","sourceFileDiscovery","incremental","profiling","workers","openApiManager","OpenApiManager","Logger","project","Project","path","explicitRouters","discoveredRouterFiles","allSourceFiles","sourceFiles","filepath","filePath","file","discoverRouters","discoveredSourceFiles","startTime","files","discoverRouterFiles","acc","current","r","filesToAnalyze","apiHeaders","analyzeSourceFileApiHeader","headers","exposedModels","analyzeSourceFileExposedModels","cachePath","endpoints","analyzeMultipleSourceFiles","e","config","filterEndpointPaths","cached","uncached","freshnessCheckStart","mtimeCache","timestamp","getSourceFileTimestamp","hit","SourceFileCache","f","byFile","endpointTimings","analyzeSourceFileEndpoints","fileResult","sum","t","allTasks","crypto","pool","WorkerPool","results","ft","i","result","fileName","analyzedFiles","a","b","ep","joinedOperations","routerName","routerPattern","node","nodeText","resolveEndpointPath","t1","endpoint","sectionTimings","parseEndpoint","sourceFile","nameOfUseApiHeader","discoverImportedName","SyntaxKind","targetNode","values","getValuesOfObjectLiteral","collapseObject","v","value","models","nameOfUseExposeApiModel","nameOfUseExposeNamedApiModels","firstChild","parseExposedModel","parseNamedExposedModels","model"],"mappings":";;;;;;;;;;;;;;;;AAKA,SAASA,IAAwB;AAC1B,QAAAC,IAAa,CAAC,wBAAwB,2BAA2B;AACvE,aAAWC,KAAaD,GAAY;AACnC,UAAME,IAAM,IAAI,IAAID,GAAW,YAAY,GAAG;AAC9C,QAAIE,EAAWC,EAAcF,CAAG,CAAC;AACzB,aAAAA;AAAA,EACR;AAED,QAAM,IAAI;AAAA,IACT;AAAA,EACD;AACD;AA6CA,MAAMG,IAAiC,GAM1BC,KAAqB,OAAO;AAAA,EACxC,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,SAAAC,IAAU;AACX,MAA4B;AACrB,QAAAC,IA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KAA2BlB,EAAK,QAAU,EAAA,WAAWkB,CAAuB,GAAG;AAIlF,YAAME,KAHqBpB,EAAK,cAAc,GACC,kBAAkBU,EAAW,UAAU,KAAK,CAAC,GAEtD,CAAC,EAAE,cAAc;AACvD,UAAI,CAACU;AACJ;AAGM,MAAAH,EAAA,KAAKI,EAAkBD,CAAU,CAAC;AACzC;AAAA,IAAA;AAGD,QAAID,KAAiCnB,EAAK,QAAU,EAAA,WAAWmB,CAA6B,GAAG;AAI9F,YAAMC,KAHqBpB,EAAK,cAAc,GACC,kBAAkBU,EAAW,UAAU,KAAK,CAAC,GAEtD,CAAC,EAAE,cAAc;AACvD,UAAI,CAACU;AACJ;AAID,MADqBE,EAAwBF,CAAU,EAC1C,QAAQ,CAACG,MAAUN,EAAO,KAAKM,CAAK,CAAC;AAAA,IAAA;AAAA,EACnD,CACA,GACKN;AACR;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("fs"),m=require("ts-morph"),a=require("../../utils/logger.cjs");function h(e,t,o=new Map){const r=u(e,t),n=r.map(d=>{const p=d.getFilePath(),g=o.get(p);if(g!==void 0)return g;const l=f.statSync(p).mtimeMs;return o.set(p,l),l}),i=Math.max(...n),s=e.getFilePath().split("/").pop(),c=r.length;return a.Logger.debug(`[${s}] Found ${c} imports, latest touched at ${a.formatTimestamp(i)}.`),i}function u(e,t){const o=e.getFilePath().split("/").pop();if(!o)return[];const r=t[e.getFilePath()];if(r)return r.dependencies;t[e.getFilePath()]={dependencies:[]};try{const n=[e],i=e.getDescendantsOfKind(m.SyntaxKind.ImportDeclaration);for(const s of i){const c=s.getModuleSpecifierSourceFile();if(!c){a.Logger.debug(`[${o}] Could not resolve import ${s.getModuleSpecifierValue()}.`);continue}const d=u(c,t);n.push(...d)}return t[e.getFilePath()]={dependencies:n},n}catch(n){return a.Logger.warn(`[${o}] Caught an error while processing imports:`,n),t[e.getFilePath()]={dependencies:[]},[]}}exports.getSourceFileTimestamp=h;
|
|
2
2
|
//# sourceMappingURL=getSourceFileTimestamp.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceFileTimestamp.cjs","sources":["../../../src/openapi/analyzerModule/getSourceFileTimestamp.ts"],"sourcesContent":["import fs from 'fs'\nimport { SourceFile, SyntaxKind } from 'ts-morph'\n\nimport { formatTimestamp, Logger } from '../../utils/logger'\n\nexport type TimestampCache = Record<string, { dependencies: SourceFile[] }>\n\nexport function getSourceFileTimestamp(
|
|
1
|
+
{"version":3,"file":"getSourceFileTimestamp.cjs","sources":["../../../src/openapi/analyzerModule/getSourceFileTimestamp.ts"],"sourcesContent":["import fs from 'fs'\nimport { SourceFile, SyntaxKind } from 'ts-morph'\n\nimport { formatTimestamp, Logger } from '../../utils/logger'\n\nexport type TimestampCache = Record<string, { dependencies: SourceFile[] }>\n\n/**\n * Per-run cache of file mtimes keyed by absolute path. Router files share large parts of their\n * transitive import graphs (common types, utils, models), so without this the same dependency gets\n * `statSync`-ed once per importing router — tens of thousands of redundant syscalls across a project\n * with dozens of routers. mtimes don't change mid-run, so memoizing is safe.\n */\nexport type MtimeCache = Map<string, number>\n\nexport function getSourceFileTimestamp(\n\tsourceFile: SourceFile,\n\ttimestampCache: TimestampCache,\n\tmtimeCache: MtimeCache = new Map(),\n) {\n\tconst dependencies = getFileDependencies(sourceFile, timestampCache)\n\tconst timestamps = dependencies.map((dep) => {\n\t\tconst depPath = dep.getFilePath()\n\t\tconst cached = mtimeCache.get(depPath)\n\t\tif (cached !== undefined) {\n\t\t\treturn cached\n\t\t}\n\t\tconst mtime = fs.statSync(depPath).mtimeMs\n\t\tmtimeCache.set(depPath, mtime)\n\t\treturn mtime\n\t})\n\tconst latestTimestamp = Math.max(...timestamps)\n\n\tconst fileName = sourceFile.getFilePath().split('/').pop()\n\tconst depsCount = dependencies.length\n\tLogger.debug(\n\t\t`[${fileName}] Found ${depsCount} imports, latest touched at ${formatTimestamp(latestTimestamp)}.`,\n\t)\n\n\treturn latestTimestamp\n}\n\nfunction getFileDependencies(sourceFile: SourceFile, timestampCache: TimestampCache): SourceFile[] {\n\tconst fileName = sourceFile.getFilePath().split('/').pop()\n\tif (!fileName) {\n\t\treturn []\n\t}\n\n\tconst cacheHit = timestampCache[sourceFile.getFilePath()]\n\tif (cacheHit) {\n\t\treturn cacheHit.dependencies\n\t}\n\n\t// Initialize cache entry early to prevent circular dependencies\n\ttimestampCache[sourceFile.getFilePath()] = { dependencies: [] }\n\n\ttry {\n\t\tconst results = [sourceFile]\n\n\t\tconst importDeclarations = sourceFile.getDescendantsOfKind(SyntaxKind.ImportDeclaration)\n\n\t\tfor (const declaration of importDeclarations) {\n\t\t\tconst importedSourceFile = declaration.getModuleSpecifierSourceFile()\n\t\t\tif (!importedSourceFile) {\n\t\t\t\tLogger.debug(`[${fileName}] Could not resolve import ${declaration.getModuleSpecifierValue()}.`)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst deps = getFileDependencies(importedSourceFile, timestampCache)\n\t\t\tresults.push(...deps)\n\t\t}\n\n\t\ttimestampCache[sourceFile.getFilePath()] = { dependencies: results }\n\t\treturn results\n\t} catch (error) {\n\t\tLogger.warn(`[${fileName}] Caught an error while processing imports:`, error)\n\t\ttimestampCache[sourceFile.getFilePath()] = { dependencies: [] }\n\t\treturn []\n\t}\n}\n"],"names":["getSourceFileTimestamp","sourceFile","timestampCache","mtimeCache","dependencies","getFileDependencies","timestamps","dep","depPath","cached","mtime","fs","latestTimestamp","fileName","depsCount","Logger","formatTimestamp","cacheHit","results","importDeclarations","SyntaxKind","declaration","importedSourceFile","deps","error"],"mappings":"gKAeO,SAASA,EACfC,EACAC,EACAC,EAAyB,IAAI,IAC5B,CACK,MAAAC,EAAeC,EAAoBJ,EAAYC,CAAc,EAC7DI,EAAaF,EAAa,IAAKG,GAAQ,CACtC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W,YAAY,CAAC,EAAI,CAAE,aAAc,CAAA,CAAG,EACvD,CAAC,CAAA,CAEV"}
|
|
@@ -3,5 +3,6 @@ import { SourceFile } from 'ts-morph';
|
|
|
3
3
|
export type TimestampCache = Record<string, {
|
|
4
4
|
dependencies: SourceFile[];
|
|
5
5
|
}>;
|
|
6
|
-
export
|
|
6
|
+
export type MtimeCache = Map<string, number>;
|
|
7
|
+
export declare function getSourceFileTimestamp(sourceFile: SourceFile, timestampCache: TimestampCache, mtimeCache?: MtimeCache): number;
|
|
7
8
|
//# sourceMappingURL=getSourceFileTimestamp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceFileTimestamp.d.ts","sourceRoot":"","sources":["../../../src/openapi/analyzerModule/getSourceFileTimestamp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AAIjD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,YAAY,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"getSourceFileTimestamp.d.ts","sourceRoot":"","sources":["../../../src/openapi/analyzerModule/getSourceFileTimestamp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AAIjD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,YAAY,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC,CAAA;AAQ3E,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE5C,wBAAgB,sBAAsB,CACrC,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,UAAU,GAAE,UAAsB,UAsBlC"}
|
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { SyntaxKind as
|
|
3
|
-
import { Logger as
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import m from "fs";
|
|
2
|
+
import { SyntaxKind as u } from "ts-morph";
|
|
3
|
+
import { Logger as d, formatTimestamp as h } from "../../utils/logger.mjs";
|
|
4
|
+
function F(e, t, o = /* @__PURE__ */ new Map()) {
|
|
5
|
+
const i = f(e, t), n = i.map((a) => {
|
|
6
|
+
const c = a.getFilePath(), l = o.get(c);
|
|
7
|
+
if (l !== void 0)
|
|
8
|
+
return l;
|
|
9
|
+
const g = m.statSync(c).mtimeMs;
|
|
10
|
+
return o.set(c, g), g;
|
|
11
|
+
}), r = Math.max(...n), s = e.getFilePath().split("/").pop(), p = i.length;
|
|
12
|
+
return d.debug(
|
|
13
|
+
`[${s}] Found ${p} imports, latest touched at ${h(r)}.`
|
|
14
|
+
), r;
|
|
9
15
|
}
|
|
10
|
-
function
|
|
11
|
-
const o =
|
|
16
|
+
function f(e, t) {
|
|
17
|
+
const o = e.getFilePath().split("/").pop();
|
|
12
18
|
if (!o)
|
|
13
19
|
return [];
|
|
14
|
-
const i =
|
|
20
|
+
const i = t[e.getFilePath()];
|
|
15
21
|
if (i)
|
|
16
22
|
return i.dependencies;
|
|
17
|
-
|
|
23
|
+
t[e.getFilePath()] = { dependencies: [] };
|
|
18
24
|
try {
|
|
19
|
-
const
|
|
20
|
-
for (const
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
|
|
25
|
+
const n = [e], r = e.getDescendantsOfKind(u.ImportDeclaration);
|
|
26
|
+
for (const s of r) {
|
|
27
|
+
const p = s.getModuleSpecifierSourceFile();
|
|
28
|
+
if (!p) {
|
|
29
|
+
d.debug(`[${o}] Could not resolve import ${s.getModuleSpecifierValue()}.`);
|
|
24
30
|
continue;
|
|
25
31
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
32
|
+
const a = f(p, t);
|
|
33
|
+
n.push(...a);
|
|
28
34
|
}
|
|
29
|
-
return
|
|
30
|
-
} catch (
|
|
31
|
-
return
|
|
35
|
+
return t[e.getFilePath()] = { dependencies: n }, n;
|
|
36
|
+
} catch (n) {
|
|
37
|
+
return d.warn(`[${o}] Caught an error while processing imports:`, n), t[e.getFilePath()] = { dependencies: [] }, [];
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
export {
|
|
35
|
-
|
|
41
|
+
F as getSourceFileTimestamp
|
|
36
42
|
};
|
|
37
43
|
//# sourceMappingURL=getSourceFileTimestamp.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceFileTimestamp.mjs","sources":["../../../src/openapi/analyzerModule/getSourceFileTimestamp.ts"],"sourcesContent":["import fs from 'fs'\nimport { SourceFile, SyntaxKind } from 'ts-morph'\n\nimport { formatTimestamp, Logger } from '../../utils/logger'\n\nexport type TimestampCache = Record<string, { dependencies: SourceFile[] }>\n\nexport function getSourceFileTimestamp(
|
|
1
|
+
{"version":3,"file":"getSourceFileTimestamp.mjs","sources":["../../../src/openapi/analyzerModule/getSourceFileTimestamp.ts"],"sourcesContent":["import fs from 'fs'\nimport { SourceFile, SyntaxKind } from 'ts-morph'\n\nimport { formatTimestamp, Logger } from '../../utils/logger'\n\nexport type TimestampCache = Record<string, { dependencies: SourceFile[] }>\n\n/**\n * Per-run cache of file mtimes keyed by absolute path. Router files share large parts of their\n * transitive import graphs (common types, utils, models), so without this the same dependency gets\n * `statSync`-ed once per importing router — tens of thousands of redundant syscalls across a project\n * with dozens of routers. mtimes don't change mid-run, so memoizing is safe.\n */\nexport type MtimeCache = Map<string, number>\n\nexport function getSourceFileTimestamp(\n\tsourceFile: SourceFile,\n\ttimestampCache: TimestampCache,\n\tmtimeCache: MtimeCache = new Map(),\n) {\n\tconst dependencies = getFileDependencies(sourceFile, timestampCache)\n\tconst timestamps = dependencies.map((dep) => {\n\t\tconst depPath = dep.getFilePath()\n\t\tconst cached = mtimeCache.get(depPath)\n\t\tif (cached !== undefined) {\n\t\t\treturn cached\n\t\t}\n\t\tconst mtime = fs.statSync(depPath).mtimeMs\n\t\tmtimeCache.set(depPath, mtime)\n\t\treturn mtime\n\t})\n\tconst latestTimestamp = Math.max(...timestamps)\n\n\tconst fileName = sourceFile.getFilePath().split('/').pop()\n\tconst depsCount = dependencies.length\n\tLogger.debug(\n\t\t`[${fileName}] Found ${depsCount} imports, latest touched at ${formatTimestamp(latestTimestamp)}.`,\n\t)\n\n\treturn latestTimestamp\n}\n\nfunction getFileDependencies(sourceFile: SourceFile, timestampCache: TimestampCache): SourceFile[] {\n\tconst fileName = sourceFile.getFilePath().split('/').pop()\n\tif (!fileName) {\n\t\treturn []\n\t}\n\n\tconst cacheHit = timestampCache[sourceFile.getFilePath()]\n\tif (cacheHit) {\n\t\treturn cacheHit.dependencies\n\t}\n\n\t// Initialize cache entry early to prevent circular dependencies\n\ttimestampCache[sourceFile.getFilePath()] = { dependencies: [] }\n\n\ttry {\n\t\tconst results = [sourceFile]\n\n\t\tconst importDeclarations = sourceFile.getDescendantsOfKind(SyntaxKind.ImportDeclaration)\n\n\t\tfor (const declaration of importDeclarations) {\n\t\t\tconst importedSourceFile = declaration.getModuleSpecifierSourceFile()\n\t\t\tif (!importedSourceFile) {\n\t\t\t\tLogger.debug(`[${fileName}] Could not resolve import ${declaration.getModuleSpecifierValue()}.`)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst deps = getFileDependencies(importedSourceFile, timestampCache)\n\t\t\tresults.push(...deps)\n\t\t}\n\n\t\ttimestampCache[sourceFile.getFilePath()] = { dependencies: results }\n\t\treturn results\n\t} catch (error) {\n\t\tLogger.warn(`[${fileName}] Caught an error while processing imports:`, error)\n\t\ttimestampCache[sourceFile.getFilePath()] = { dependencies: [] }\n\t\treturn []\n\t}\n}\n"],"names":["getSourceFileTimestamp","sourceFile","timestampCache","mtimeCache","dependencies","getFileDependencies","timestamps","dep","depPath","cached","mtime","fs","latestTimestamp","fileName","depsCount","Logger","formatTimestamp","cacheHit","results","importDeclarations","SyntaxKind","declaration","importedSourceF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AI;AAAA,IAAA;AAGrB,WAAArB,EAAeD,EAAW,YAAY,CAAC,IAAI,EAAE,cAAciB,EAAQ,GAC5DA;AAAA,WACCM,GAAO;AACf,WAAAT,EAAO,KAAK,IAAIF,CAAQ,+CAA+CW,CAAK,GAC5EtB,EAAeD,EAAW,YAAY,CAAC,IAAI,EAAE,cAAc,CAAA,EAAG,GACvD,CAAC;AAAA,EAAA;AAEV;"}
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
import { discoverRouters } from '../discoveryModule/discoverRouters/discoverRouters'
|
|
28
28
|
import { ApiDocsHeader, OpenApiManager } from '../manager/OpenApiManager'
|
|
29
29
|
import { EndpointData, ExposedModelData } from '../types'
|
|
30
|
-
import { getSourceFileTimestamp, TimestampCache } from './getSourceFileTimestamp'
|
|
30
|
+
import { getSourceFileTimestamp, MtimeCache, TimestampCache } from './getSourceFileTimestamp'
|
|
31
31
|
import { getValuesOfObjectLiteral, resolveEndpointPath } from './nodeParsers'
|
|
32
32
|
import { parseEndpoint, SectionTiming } from './parseEndpoint'
|
|
33
33
|
import { parseExposedModel, parseNamedExposedModels } from './parseExposedModels'
|
|
@@ -45,6 +45,7 @@ type Props = {
|
|
|
45
45
|
cachePath: string
|
|
46
46
|
}
|
|
47
47
|
profiling?: 'stats' | 'off' | 'debug'
|
|
48
|
+
workers?: boolean
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
type FileDiscoveryConfig = {
|
|
@@ -71,6 +72,7 @@ export const prepareOpenApiSpec = async ({
|
|
|
71
72
|
sourceFileDiscovery,
|
|
72
73
|
incremental,
|
|
73
74
|
profiling = 'stats',
|
|
75
|
+
workers = false,
|
|
74
76
|
}: Props): Promise<void> => {
|
|
75
77
|
const openApiManager = OpenApiManager.getInstance()
|
|
76
78
|
|
|
@@ -152,6 +154,7 @@ export const prepareOpenApiSpec = async ({
|
|
|
152
154
|
timestampCache: {},
|
|
153
155
|
profiling,
|
|
154
156
|
tsconfigPath: path.resolve(tsconfigPath),
|
|
157
|
+
workers,
|
|
155
158
|
})
|
|
156
159
|
|
|
157
160
|
openApiManager.setStats({
|
|
@@ -187,6 +190,7 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
187
190
|
timestampCache: TimestampCache
|
|
188
191
|
profiling?: 'stats' | 'off' | 'debug'
|
|
189
192
|
tsconfigPath: string
|
|
193
|
+
workers?: boolean
|
|
190
194
|
},
|
|
191
195
|
filterEndpointPaths?: string[],
|
|
192
196
|
): Promise<EndpointData[]> => {
|
|
@@ -200,8 +204,10 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
200
204
|
const cached: CachedFile[] = []
|
|
201
205
|
const uncached: UncachedFile[] = []
|
|
202
206
|
|
|
207
|
+
const freshnessCheckStart = performance.now()
|
|
208
|
+
const mtimeCache: MtimeCache = new Map()
|
|
203
209
|
for (const file of files) {
|
|
204
|
-
const timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)
|
|
210
|
+
const timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache, mtimeCache)
|
|
205
211
|
const hit = config.incremental
|
|
206
212
|
? SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)
|
|
207
213
|
: null
|
|
@@ -212,6 +218,9 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
212
218
|
uncached.push({ file, timestamp })
|
|
213
219
|
}
|
|
214
220
|
}
|
|
221
|
+
if (profiling !== 'off') {
|
|
222
|
+
Logger.info(`Cache freshness check took ${Math.round(performance.now() - freshnessCheckStart)}ms`)
|
|
223
|
+
}
|
|
215
224
|
|
|
216
225
|
if (uncached.length === 0) {
|
|
217
226
|
if (profiling !== 'off') {
|
|
@@ -232,12 +241,8 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
232
241
|
byFile.set(file.fileName, { endpoints: [], fileName: file.fileName, timing: 0, endpointTimings: [] })
|
|
233
242
|
}
|
|
234
243
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
// build its own Project from scratch — a multi-second cold-start. That cold-start only pays off
|
|
238
|
-
// when there are enough uncached files that spreading the parse work across workers beats it; below
|
|
239
|
-
// the threshold (e.g. the common single-file incremental rebuild), inline is strictly faster.
|
|
240
|
-
if (uncached.length <= INLINE_ANALYSIS_FILE_THRESHOLD) {
|
|
244
|
+
const useWorkers = config.workers !== false
|
|
245
|
+
if (!useWorkers || uncached.length <= INLINE_ANALYSIS_FILE_THRESHOLD) {
|
|
241
246
|
for (const { file } of uncached) {
|
|
242
247
|
const { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)
|
|
243
248
|
const fileResult = byFile.get(file.fileName)!
|
|
@@ -246,9 +251,6 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
246
251
|
fileResult.timing = endpointTimings.reduce((sum, t) => sum + t.timing, 0)
|
|
247
252
|
}
|
|
248
253
|
} else {
|
|
249
|
-
// One task per file: each worker analyzes a whole file in a single pass, paying its Project
|
|
250
|
-
// cold-start once and reusing the warmed-up checker for every endpoint in that file. Cap the
|
|
251
|
-
// pool at one worker per file so we never spin up a worker with nothing to do.
|
|
252
254
|
type FileTask = { task: WorkerTask; fileName: string }
|
|
253
255
|
const allTasks: FileTask[] = uncached.map(({ file }) => ({
|
|
254
256
|
fileName: file.fileName,
|
|
@@ -5,11 +5,29 @@ import { formatTimestamp, Logger } from '../../utils/logger'
|
|
|
5
5
|
|
|
6
6
|
export type TimestampCache = Record<string, { dependencies: SourceFile[] }>
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Per-run cache of file mtimes keyed by absolute path. Router files share large parts of their
|
|
10
|
+
* transitive import graphs (common types, utils, models), so without this the same dependency gets
|
|
11
|
+
* `statSync`-ed once per importing router — tens of thousands of redundant syscalls across a project
|
|
12
|
+
* with dozens of routers. mtimes don't change mid-run, so memoizing is safe.
|
|
13
|
+
*/
|
|
14
|
+
export type MtimeCache = Map<string, number>
|
|
15
|
+
|
|
16
|
+
export function getSourceFileTimestamp(
|
|
17
|
+
sourceFile: SourceFile,
|
|
18
|
+
timestampCache: TimestampCache,
|
|
19
|
+
mtimeCache: MtimeCache = new Map(),
|
|
20
|
+
) {
|
|
9
21
|
const dependencies = getFileDependencies(sourceFile, timestampCache)
|
|
10
22
|
const timestamps = dependencies.map((dep) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
23
|
+
const depPath = dep.getFilePath()
|
|
24
|
+
const cached = mtimeCache.get(depPath)
|
|
25
|
+
if (cached !== undefined) {
|
|
26
|
+
return cached
|
|
27
|
+
}
|
|
28
|
+
const mtime = fs.statSync(depPath).mtimeMs
|
|
29
|
+
mtimeCache.set(depPath, mtime)
|
|
30
|
+
return mtime
|
|
13
31
|
})
|
|
14
32
|
const latestTimestamp = Math.max(...timestamps)
|
|
15
33
|
|