moonflower 1.5.1 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/openapi/analyzerModule/analyzerModule.cjs +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.cjs.map +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.mjs +151 -124
- 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 +63 -38
- 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 q=require("crypto"),I=require("fs"),U=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"),W=require("../discoveryModule/discoverRouters/discoverRouters.cjs"),H=require("../manager/OpenApiManager.cjs"),D=require("./getSourceFileTimestamp.cjs"),w=require("./nodeParsers.cjs"),B=require("./parseEndpoint.cjs"),k=require("./parseExposedModels.cjs"),C=require("./sourceFileCache.cjs"),V=require("./workerPool.cjs");var P=typeof document<"u"?document.currentScript:null;function Y(r){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const a in r)if(a!=="default"){const l=Object.getOwnPropertyDescriptor(r,a);Object.defineProperty(n,a,l.get?l:{enumerable:!0,get:()=>r[a]})}}return n.default=r,Object.freeze(n)}const E=Y(U);function G(){const r=["./analyzerWorker.mjs","./analyzerWorker.test.mjs"];for(const n of r){const a=new URL(n,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(I.existsSync(K.fileURLToPath(a)))return a}throw new Error("analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first).")}const J=2,Q=async({logLevel:r,tsconfigPath:n,sourceFilePaths:a,sourceFileDiscovery:l,incremental:d,profiling:m="stats"})=>{const t=H.OpenApiManager.getInstance();if(t.isReady())return;r&&y.Logger.setLevel(r),y.Logger.info("Preparing OpenAPI spec");const p=new S.Project({tsConfigFilePath:E.resolve(n),skipFileDependencyResolution:!0}),{explicitRouters:f,discoveredRouterFiles:g,allSourceFiles:T}=(()=>{const u=(a??[]).map(h=>E.resolve(h)).map(h=>p.getSourceFileOrThrow(h)),M=u.flatMap(h=>({fileName:h.getFilePath(),sourceFile:h,routers:W.discoverRouters(h)})),{discoveredRouterFiles:$,discoveredSourceFiles:b}=(()=>{if(l===!1)return{discoveredRouterFiles:[],discoveredSourceFiles:[]};const h=performance.now(),x=_.discoverRouterFiles({targetPath:typeof l=="object"?l.rootPath:".",tsConfigPath:n});return m!=="off"&&y.Logger.info(`File discovery took ${Math.round(performance.now()-h)}ms`),x})(),j=u.reduce((h,x)=>h.some(z=>z.getFilePath()===x.getFilePath())?h:h.concat(x),b);return{explicitRouters:M,discoveredRouterFiles:$,allSourceFiles:j}})(),e=f.reduce((i,N)=>i.some(u=>u.fileName===N.fileName)?i:i.concat(N),g),o=T.flatMap(i=>v(i)).filter(i=>!!i);o.length>0&&o[0]&&t.setHeader(o[0]);const s=T.flatMap(i=>O(i));t.setExposedModels(s);const c=typeof d=="object"&&d.cachePath?d.cachePath:E.resolve(process.cwd(),"node_modules",".cache","moonflower"),F=await A(e,{incremental:d!==!1,cachePath:c,timestampCache:{},profiling:m,tsconfigPath:E.resolve(n)});t.setStats({discoveredRouterFiles: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}`)}))})),explicitRouterFiles:f.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}`)}))}))}),t.setEndpoints(F),t.markAsReady()},A=async(r,n,a)=>{const l=n.profiling??"stats",d=performance.now(),m=[],t=[],p=performance.now(),f=new Map;for(const e of r){const o=D.getSourceFileTimestamp(e.sourceFile,n.timestampCache,f),s=n.incremental?C.SourceFileCache.getCachedResults(e.sourceFile,o,n.cachePath):null;s?(y.Logger.debug(`[${e.fileName}] Found cached results`),m.push({endpoints:s.endpoints,fileName:e.fileName,timing:0,endpointTimings:[]})):t.push({file:e,timestamp:o})}if(l!=="off"&&y.Logger.info(`Cache freshness check took ${Math.round(performance.now()-p)}ms`),t.length===0)return l!=="off"&&y.Logger.info(`Router analysis took ${Math.round(performance.now()-d)}ms`),m.flatMap(e=>e.endpoints);const g=new Map;for(const{file:e}of t)g.set(e.fileName,{endpoints:[],fileName:e.fileName,timing:0,endpointTimings:[]});if(t.length<=J)for(const{file:e}of t){const{endpoints:o,endpointTimings:s}=L(e),c=g.get(e.fileName);c.endpoints=o,c.endpointTimings=s,c.timing=s.reduce((F,i)=>F+i.timing,0)}else{const e=t.map(({file:c})=>({fileName:c.fileName,task:{taskId:q.randomUUID(),tsconfigPath:n.tsconfigPath,sourceFilePath:c.sourceFile.getFilePath(),routerNames:c.routers.named,filterEndpointPaths:a}})),o=new V.WorkerPool(G(),e.length);let s;try{s=await o.runAll(e.map(c=>c.task))}finally{o.terminate()}for(let c=0;c<s.length;c++){const F=s[c],i=e[c].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,M)=>u+M.timing,0)}}for(const{file:e,timestamp:o}of t){const s=g.get(e.fileName);s.endpoints.length>0&&C.SourceFileCache.cacheResults(e.sourceFile,o,n.cachePath,s.endpoints)}const T=[...m,...Array.from(g.values())];return l!=="off"&&y.Logger.info(`Router analysis took ${Math.round(performance.now()-d)}ms`),l==="stats"?T.map(e=>({fileName:e.fileName,timeTaken:e.timing})).sort((e,o)=>o.timeTaken-e.timeTaken).filter(e=>e.timeTaken>500).forEach(e=>{y.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`)}):l==="debug"&&T.map(e=>({fileName:e.fileName,timeTaken:e.timing,endpointTimings:e.endpointTimings})).sort((e,o)=>o.timeTaken-e.timeTaken).forEach(e=>{y.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`),e.endpointTimings.sort((o,s)=>s.timing-o.timing).forEach(o=>{y.Logger.info(` - ${o.method} ${o.path} (${Math.round(o.timing)}ms)`),o.sectionTimings.filter(s=>s.timing>=1).sort((s,c)=>c.timing-s.timing).forEach(s=>{y.Logger.info(` - ${s.section}: ${Math.round(s.timing)}ms`)})})}),T.flatMap(e=>e.endpoints)},L=(r,n)=>{const a=[],l=[],m=["get","post","put","delete","del","patch"].join("|");return r.routers.named.forEach(t=>{const p=new RegExp(`${t}\\.(?:${m})`);r.sourceFile.forEachChild(f=>{const g=f.getText();if(p.test(g)){w.resolveEndpointPath(f);const T=performance.now(),{endpoint:e,sectionTimings:o}=B.parseEndpoint(f,r.fileName);l.push({method:e.method,path:e.path,timing:performance.now()-T,sectionTimings:o}),a.push(e)}})}),{endpoints:a,endpointTimings:l}},v=r=>{const n=R.discoverImportedName({sourceFile:r,originalName:"useApiHeader"});if(!n)return null;const a=r.forEachChildAsArray().filter(t=>t.isKind(S.SyntaxKind.ExpressionStatement)).find(t=>n&&t.getText().startsWith(n));if(!a)return null;const l=a.getFirstDescendantByKindOrThrow(S.SyntaxKind.ObjectLiteralExpression),d=w.getValuesOfObjectLiteral(l),m=t=>typeof t=="string"||Array.isArray(t)&&t.every(p=>typeof p=="string")?t:t.reduce((p,f)=>typeof f=="string"?p:{...p,[f.identifier]:m(f.value)},{});return m(d)},O=r=>{const n=[],a=R.discoverImportedName({sourceFile:r,originalName:"useExposeApiModel"}),l=R.discoverImportedName({sourceFile:r,originalName:"useExposeNamedApiModels"});return r.forEachChildAsArray().filter(d=>d.isKind(S.SyntaxKind.ExpressionStatement)).map(d=>{if(a&&d.getText().startsWith(a)){const p=(d.getFirstChild()?.getChildrenOfKind(S.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!p)return;n.push(k.parseExposedModel(p));return}if(l&&d.getText().startsWith(l)){const p=(d.getFirstChild()?.getChildrenOfKind(S.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!p)return;k.parseNamedExposedModels(p).forEach(g=>n.push(g))}}),n};exports.analyzeMultipleSourceFiles=A;exports.analyzeSourceFileApiHeader=v;exports.analyzeSourceFileEndpoints=L;exports.analyzeSourceFileExposedModels=O;exports.prepareOpenApiSpec=Q;
|
|
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 * @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\t// Build one task per uncached file. Each worker analyzes a whole file in a single pass, so it\n\t// pays the ts-morph Project cold-start (full TS program load + type-checker warmup) once and\n\t// reuses the warmed-up checker for every endpoint in that file.\n\ttype FileTask = { task: WorkerTask; fileName: string }\n\tconst allTasks: FileTask[] = uncached.map(({ file }) => ({\n\t\tfileName: file.fileName,\n\t\ttask: {\n\t\t\ttaskId: crypto.randomUUID(),\n\t\t\ttsconfigPath: config.tsconfigPath,\n\t\t\tsourceFilePath: file.sourceFile.getFilePath(),\n\t\t\trouterNames: file.routers.named,\n\t\t\tfilterEndpointPaths,\n\t\t},\n\t}))\n\n\t// Dispatch all tasks to the worker pool, capped at one worker per file.\n\tconst pool = new WorkerPool(resolveWorkerUrl(), allTasks.length)\n\n\ttype FileResult = {\n\t\tendpoints: EndpointData[]\n\t\tfileName: string\n\t\ttiming: number\n\t\tendpointTimings: EndpointTiming[]\n\t}\n\n\tlet results: WorkerResult[]\n\ttry {\n\t\tresults = await pool.runAll(allTasks.map((ft) => ft.task))\n\t} finally {\n\t\tpool.terminate()\n\t}\n\n\t// Each result maps 1:1 to a file task.\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\tfor (let i = 0; i < results.length; i++) {\n\t\tconst result = results[i]\n\t\tconst fileName = allTasks[i].fileName\n\t\tconst fileResult = byFile.get(fileName)!\n\n\t\tif ('error' in result) {\n\t\t\tLogger.error(`[${fileName}] Worker error: ${result.error}`)\n\t\t\tcontinue\n\t\t}\n\n\t\tfileResult.endpoints = result.endpoints\n\t\tfileResult.endpointTimings = result.endpointTimings\n\t\tfileResult.timing = result.endpointTimings.reduce((sum, t) => sum + t.timing, 0)\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","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","allTasks","crypto","pool","WorkerPool","results","ft","byFile","i","result","fileName","fileResult","sum","t","analyzedFiles","a","b","ep","s","sourceFile","nameOfUseApiHeader","discoverImportedName","node","SyntaxKind","targetNode","values","getValuesOfObjectLiteral","collapseObject","v","value","models","nameOfUseExposeApiModel","nameOfUseExposeNamedApiModels","firstChild","parseExposedModel","parseNamedExposedModels","model"],"mappings":"s9BAKA,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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,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}\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\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\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","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,OA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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 +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,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAE7F,OAAO,EAAiB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAK9D,KAAK,KAAK,GAAG;IACZ,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC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F,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,184 +1,211 @@
|
|
|
1
1
|
import $ from "crypto";
|
|
2
2
|
import { existsSync as v } from "fs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as k from "path";
|
|
4
4
|
import { fileURLToPath as O } from "url";
|
|
5
5
|
import { Project as L, SyntaxKind as x } from "ts-morph";
|
|
6
|
-
import { Logger as
|
|
7
|
-
import { discoverImportedName as
|
|
6
|
+
import { Logger as F } from "../../utils/logger.mjs";
|
|
7
|
+
import { discoverImportedName as P } from "../discoveryModule/discoverImports/discoverImports.mjs";
|
|
8
8
|
import { discoverRouterFiles as j } from "../discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs";
|
|
9
9
|
import { discoverRouters as z } 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 W } from "./nodeParsers.mjs";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
12
|
+
import { getValuesOfObjectLiteral as I, resolveEndpointPath as W } from "./nodeParsers.mjs";
|
|
13
|
+
import { parseEndpoint as H } from "./parseEndpoint.mjs";
|
|
14
|
+
import { parseExposedModel as K, parseNamedExposedModels as _ } from "./parseExposedModels.mjs";
|
|
15
|
+
import { SourceFileCache as R } from "./sourceFileCache.mjs";
|
|
16
|
+
import { WorkerPool as D } from "./workerPool.mjs";
|
|
16
17
|
function B() {
|
|
17
|
-
const
|
|
18
|
-
for (const
|
|
19
|
-
const
|
|
20
|
-
if (v(O(
|
|
21
|
-
return
|
|
18
|
+
const a = ["./analyzerWorker.mjs", "./analyzerWorker.test.mjs"];
|
|
19
|
+
for (const n of a) {
|
|
20
|
+
const d = new URL(n, import.meta.url);
|
|
21
|
+
if (v(O(d)))
|
|
22
|
+
return d;
|
|
22
23
|
}
|
|
23
24
|
throw new Error(
|
|
24
25
|
"analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first)."
|
|
25
26
|
);
|
|
26
27
|
}
|
|
27
|
-
const
|
|
28
|
-
logLevel:
|
|
29
|
-
tsconfigPath:
|
|
30
|
-
sourceFilePaths:
|
|
31
|
-
sourceFileDiscovery:
|
|
32
|
-
incremental:
|
|
28
|
+
const V = 2, de = async ({
|
|
29
|
+
logLevel: a,
|
|
30
|
+
tsconfigPath: n,
|
|
31
|
+
sourceFilePaths: d,
|
|
32
|
+
sourceFileDiscovery: l,
|
|
33
|
+
incremental: m,
|
|
33
34
|
profiling: f = "stats"
|
|
34
35
|
}) => {
|
|
35
36
|
const t = U.getInstance();
|
|
36
37
|
if (t.isReady())
|
|
37
38
|
return;
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
tsConfigFilePath:
|
|
39
|
+
a && F.setLevel(a), F.info("Preparing OpenAPI spec");
|
|
40
|
+
const c = new L({
|
|
41
|
+
tsConfigFilePath: k.resolve(n),
|
|
41
42
|
skipFileDependencyResolution: !0
|
|
42
|
-
}), { explicitRouters:
|
|
43
|
-
const
|
|
44
|
-
fileName:
|
|
45
|
-
sourceFile:
|
|
46
|
-
routers: z(
|
|
47
|
-
})), { discoveredRouterFiles:
|
|
48
|
-
if (
|
|
43
|
+
}), { explicitRouters: u, discoveredRouterFiles: g, allSourceFiles: T } = (() => {
|
|
44
|
+
const p = (d ?? []).map((h) => k.resolve(h)).map((h) => c.getSourceFileOrThrow(h)), M = p.flatMap((h) => ({
|
|
45
|
+
fileName: h.getFilePath(),
|
|
46
|
+
sourceFile: h,
|
|
47
|
+
routers: z(h)
|
|
48
|
+
})), { discoveredRouterFiles: C, discoveredSourceFiles: S } = (() => {
|
|
49
|
+
if (l === !1)
|
|
49
50
|
return { discoveredRouterFiles: [], discoveredSourceFiles: [] };
|
|
50
|
-
const
|
|
51
|
-
targetPath: typeof
|
|
52
|
-
tsConfigPath:
|
|
51
|
+
const h = performance.now(), E = j({
|
|
52
|
+
targetPath: typeof l == "object" ? l.rootPath : ".",
|
|
53
|
+
tsConfigPath: n
|
|
53
54
|
});
|
|
54
|
-
return f !== "off" &&
|
|
55
|
-
})(),
|
|
56
|
-
(
|
|
57
|
-
|
|
55
|
+
return f !== "off" && F.info(`File discovery took ${Math.round(performance.now() - h)}ms`), E;
|
|
56
|
+
})(), w = p.reduce(
|
|
57
|
+
(h, E) => h.some((A) => A.getFilePath() === E.getFilePath()) ? h : h.concat(E),
|
|
58
|
+
S
|
|
58
59
|
);
|
|
59
|
-
return { explicitRouters:
|
|
60
|
-
})(),
|
|
61
|
-
(s,
|
|
62
|
-
|
|
63
|
-
),
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
t.setExposedModels(
|
|
67
|
-
const r = typeof
|
|
68
|
-
incremental:
|
|
60
|
+
return { explicitRouters: M, discoveredRouterFiles: C, allSourceFiles: w };
|
|
61
|
+
})(), e = u.reduce(
|
|
62
|
+
(s, N) => s.some((p) => p.fileName === N.fileName) ? s : s.concat(N),
|
|
63
|
+
g
|
|
64
|
+
), o = T.flatMap((s) => G(s)).filter((s) => !!s);
|
|
65
|
+
o.length > 0 && o[0] && t.setHeader(o[0]);
|
|
66
|
+
const i = T.flatMap((s) => J(s));
|
|
67
|
+
t.setExposedModels(i);
|
|
68
|
+
const r = typeof m == "object" && m.cachePath ? m.cachePath : k.resolve(process.cwd(), "node_modules", ".cache", "moonflower"), y = await Y(e, {
|
|
69
|
+
incremental: m !== !1,
|
|
69
70
|
cachePath: r,
|
|
70
71
|
timestampCache: {},
|
|
71
72
|
profiling: f,
|
|
72
|
-
tsconfigPath:
|
|
73
|
+
tsconfigPath: k.resolve(n)
|
|
73
74
|
});
|
|
74
75
|
t.setStats({
|
|
75
|
-
discoveredRouterFiles:
|
|
76
|
+
discoveredRouterFiles: g.map((s) => ({
|
|
76
77
|
path: s.fileName,
|
|
77
|
-
routers: s.routers.named.map((
|
|
78
|
-
name:
|
|
79
|
-
endpoints:
|
|
78
|
+
routers: s.routers.named.map((N) => ({
|
|
79
|
+
name: N,
|
|
80
|
+
endpoints: y.filter((p) => p.sourceFilePath === s.fileName).map((p) => `${p.method.toUpperCase()} ${p.path}`)
|
|
80
81
|
}))
|
|
81
82
|
})),
|
|
82
|
-
explicitRouterFiles:
|
|
83
|
+
explicitRouterFiles: u.map((s) => ({
|
|
83
84
|
path: s.fileName,
|
|
84
|
-
routers: s.routers.named.map((
|
|
85
|
-
name:
|
|
86
|
-
endpoints:
|
|
85
|
+
routers: s.routers.named.map((N) => ({
|
|
86
|
+
name: N,
|
|
87
|
+
endpoints: y.filter((p) => p.sourceFilePath === s.fileName).map((p) => `${p.method.toUpperCase()} ${p.path}`)
|
|
87
88
|
}))
|
|
88
89
|
}))
|
|
89
|
-
}), t.setEndpoints(
|
|
90
|
-
},
|
|
91
|
-
const
|
|
92
|
-
for (const e of
|
|
93
|
-
const o = b(e.sourceFile,
|
|
94
|
-
|
|
90
|
+
}), t.setEndpoints(y), t.markAsReady();
|
|
91
|
+
}, Y = async (a, n, d) => {
|
|
92
|
+
const l = n.profiling ?? "stats", m = performance.now(), f = [], t = [], c = performance.now(), u = /* @__PURE__ */ new Map();
|
|
93
|
+
for (const e of a) {
|
|
94
|
+
const o = b(e.sourceFile, n.timestampCache, u), i = n.incremental ? R.getCachedResults(e.sourceFile, o, n.cachePath) : null;
|
|
95
|
+
i ? (F.debug(`[${e.fileName}] Found cached results`), f.push({ endpoints: i.endpoints, fileName: e.fileName, timing: 0, endpointTimings: [] })) : t.push({ file: e, timestamp: o });
|
|
95
96
|
}
|
|
96
|
-
if (t.length === 0)
|
|
97
|
-
return
|
|
98
|
-
const
|
|
99
|
-
fileName: e.fileName,
|
|
100
|
-
task: {
|
|
101
|
-
taskId: $.randomUUID(),
|
|
102
|
-
tsconfigPath: i.tsconfigPath,
|
|
103
|
-
sourceFilePath: e.sourceFile.getFilePath(),
|
|
104
|
-
routerNames: e.routers.named,
|
|
105
|
-
filterEndpointPaths: p
|
|
106
|
-
}
|
|
107
|
-
})), h = new I(B(), a.length);
|
|
108
|
-
let F;
|
|
109
|
-
try {
|
|
110
|
-
F = await h.runAll(a.map((e) => e.task));
|
|
111
|
-
} finally {
|
|
112
|
-
h.terminate();
|
|
113
|
-
}
|
|
114
|
-
const N = /* @__PURE__ */ new Map();
|
|
97
|
+
if (l !== "off" && F.info(`Cache freshness check took ${Math.round(performance.now() - c)}ms`), t.length === 0)
|
|
98
|
+
return l !== "off" && F.info(`Router analysis took ${Math.round(performance.now() - m)}ms`), f.flatMap((e) => e.endpoints);
|
|
99
|
+
const g = /* @__PURE__ */ new Map();
|
|
115
100
|
for (const { file: e } of t)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
101
|
+
g.set(e.fileName, { endpoints: [], fileName: e.fileName, timing: 0, endpointTimings: [] });
|
|
102
|
+
if (t.length <= V)
|
|
103
|
+
for (const { file: e } of t) {
|
|
104
|
+
const { endpoints: o, endpointTimings: i } = q(e), r = g.get(e.fileName);
|
|
105
|
+
r.endpoints = o, r.endpointTimings = i, r.timing = i.reduce((y, s) => y + s.timing, 0);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const e = t.map(({ file: r }) => ({
|
|
109
|
+
fileName: r.fileName,
|
|
110
|
+
task: {
|
|
111
|
+
taskId: $.randomUUID(),
|
|
112
|
+
tsconfigPath: n.tsconfigPath,
|
|
113
|
+
sourceFilePath: r.sourceFile.getFilePath(),
|
|
114
|
+
routerNames: r.routers.named,
|
|
115
|
+
filterEndpointPaths: d
|
|
116
|
+
}
|
|
117
|
+
})), o = new D(B(), e.length);
|
|
118
|
+
let i;
|
|
119
|
+
try {
|
|
120
|
+
i = await o.runAll(e.map((r) => r.task));
|
|
121
|
+
} finally {
|
|
122
|
+
o.terminate();
|
|
123
|
+
}
|
|
124
|
+
for (let r = 0; r < i.length; r++) {
|
|
125
|
+
const y = i[r], s = e[r].fileName, N = g.get(s);
|
|
126
|
+
if ("error" in y) {
|
|
127
|
+
F.error(`[${s}] Worker error: ${y.error}`);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
N.endpoints = y.endpoints, N.endpointTimings = y.endpointTimings, N.timing = y.endpointTimings.reduce((p, M) => p + M.timing, 0);
|
|
122
131
|
}
|
|
123
|
-
g.endpoints = o.endpoints, g.endpointTimings = o.endpointTimings, g.timing = o.endpointTimings.reduce((s, y) => s + y.timing, 0);
|
|
124
132
|
}
|
|
125
133
|
for (const { file: e, timestamp: o } of t) {
|
|
126
|
-
const
|
|
127
|
-
|
|
134
|
+
const i = g.get(e.fileName);
|
|
135
|
+
i.endpoints.length > 0 && R.cacheResults(e.sourceFile, o, n.cachePath, i.endpoints);
|
|
128
136
|
}
|
|
129
|
-
const T = [...f, ...Array.from(
|
|
130
|
-
return
|
|
131
|
-
|
|
132
|
-
}) :
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
const T = [...f, ...Array.from(g.values())];
|
|
138
|
+
return l !== "off" && F.info(`Router analysis took ${Math.round(performance.now() - m)}ms`), l === "stats" ? T.map((e) => ({ fileName: e.fileName, timeTaken: e.timing })).sort((e, o) => o.timeTaken - e.timeTaken).filter((e) => e.timeTaken > 500).forEach((e) => {
|
|
139
|
+
F.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`);
|
|
140
|
+
}) : l === "debug" && T.map((e) => ({ fileName: e.fileName, timeTaken: e.timing, endpointTimings: e.endpointTimings })).sort((e, o) => o.timeTaken - e.timeTaken).forEach((e) => {
|
|
141
|
+
F.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`), e.endpointTimings.sort((o, i) => i.timing - o.timing).forEach((o) => {
|
|
142
|
+
F.info(` - ${o.method} ${o.path} (${Math.round(o.timing)}ms)`), o.sectionTimings.filter((i) => i.timing >= 1).sort((i, r) => r.timing - i.timing).forEach((i) => {
|
|
143
|
+
F.info(` - ${i.section}: ${Math.round(i.timing)}ms`);
|
|
136
144
|
});
|
|
137
145
|
});
|
|
138
146
|
}), T.flatMap((e) => e.endpoints);
|
|
139
|
-
},
|
|
140
|
-
const
|
|
141
|
-
|
|
147
|
+
}, q = (a, n) => {
|
|
148
|
+
const d = [], l = [], f = ["get", "post", "put", "delete", "del", "patch"].join("|");
|
|
149
|
+
return a.routers.named.forEach((t) => {
|
|
150
|
+
const c = new RegExp(`${t}\\.(?:${f})`);
|
|
151
|
+
a.sourceFile.forEachChild((u) => {
|
|
152
|
+
const g = u.getText();
|
|
153
|
+
if (c.test(g)) {
|
|
154
|
+
W(u);
|
|
155
|
+
const T = performance.now(), { endpoint: e, sectionTimings: o } = H(u, a.fileName);
|
|
156
|
+
l.push({
|
|
157
|
+
method: e.method,
|
|
158
|
+
path: e.path,
|
|
159
|
+
timing: performance.now() - T,
|
|
160
|
+
sectionTimings: o
|
|
161
|
+
}), d.push(e);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}), { endpoints: d, endpointTimings: l };
|
|
165
|
+
}, G = (a) => {
|
|
166
|
+
const n = P({
|
|
167
|
+
sourceFile: a,
|
|
142
168
|
originalName: "useApiHeader"
|
|
143
169
|
});
|
|
144
|
-
if (!
|
|
170
|
+
if (!n)
|
|
145
171
|
return null;
|
|
146
|
-
const
|
|
147
|
-
if (!
|
|
172
|
+
const d = a.forEachChildAsArray().filter((t) => t.isKind(x.ExpressionStatement)).find((t) => n && t.getText().startsWith(n));
|
|
173
|
+
if (!d)
|
|
148
174
|
return null;
|
|
149
|
-
const
|
|
150
|
-
...
|
|
151
|
-
[
|
|
175
|
+
const l = d.getFirstDescendantByKindOrThrow(x.ObjectLiteralExpression), m = I(l), f = (t) => typeof t == "string" || Array.isArray(t) && t.every((c) => typeof c == "string") ? t : t.reduce((c, u) => typeof u == "string" ? c : {
|
|
176
|
+
...c,
|
|
177
|
+
[u.identifier]: f(u.value)
|
|
152
178
|
}, {});
|
|
153
|
-
return f(
|
|
154
|
-
},
|
|
155
|
-
const
|
|
156
|
-
sourceFile:
|
|
179
|
+
return f(m);
|
|
180
|
+
}, J = (a) => {
|
|
181
|
+
const n = [], d = P({
|
|
182
|
+
sourceFile: a,
|
|
157
183
|
originalName: "useExposeApiModel"
|
|
158
|
-
}),
|
|
159
|
-
sourceFile:
|
|
184
|
+
}), l = P({
|
|
185
|
+
sourceFile: a,
|
|
160
186
|
originalName: "useExposeNamedApiModels"
|
|
161
187
|
});
|
|
162
|
-
return
|
|
163
|
-
if (
|
|
164
|
-
const
|
|
165
|
-
if (!
|
|
188
|
+
return a.forEachChildAsArray().filter((m) => m.isKind(x.ExpressionStatement)).map((m) => {
|
|
189
|
+
if (d && m.getText().startsWith(d)) {
|
|
190
|
+
const c = (m.getFirstChild()?.getChildrenOfKind(x.SyntaxList) || [])[0].getFirstChild();
|
|
191
|
+
if (!c)
|
|
166
192
|
return;
|
|
167
|
-
|
|
193
|
+
n.push(K(c));
|
|
168
194
|
return;
|
|
169
195
|
}
|
|
170
|
-
if (
|
|
171
|
-
const
|
|
172
|
-
if (!
|
|
196
|
+
if (l && m.getText().startsWith(l)) {
|
|
197
|
+
const c = (m.getFirstChild()?.getChildrenOfKind(x.SyntaxList) || [])[0].getFirstChild();
|
|
198
|
+
if (!c)
|
|
173
199
|
return;
|
|
174
|
-
|
|
200
|
+
_(c).forEach((g) => n.push(g));
|
|
175
201
|
}
|
|
176
|
-
}),
|
|
202
|
+
}), n;
|
|
177
203
|
};
|
|
178
204
|
export {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
205
|
+
Y as analyzeMultipleSourceFiles,
|
|
206
|
+
G as analyzeSourceFileApiHeader,
|
|
207
|
+
q as analyzeSourceFileEndpoints,
|
|
208
|
+
J as analyzeSourceFileExposedModels,
|
|
209
|
+
de as prepareOpenApiSpec
|
|
183
210
|
};
|
|
184
211
|
//# 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 * @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\t// Build one task per uncached file. Each worker analyzes a whole file in a single pass, so it\n\t// pays the ts-morph Project cold-start (full TS program load + type-checker warmup) once and\n\t// reuses the warmed-up checker for every endpoint in that file.\n\ttype FileTask = { task: WorkerTask; fileName: string }\n\tconst allTasks: FileTask[] = uncached.map(({ file }) => ({\n\t\tfileName: file.fileName,\n\t\ttask: {\n\t\t\ttaskId: crypto.randomUUID(),\n\t\t\ttsconfigPath: config.tsconfigPath,\n\t\t\tsourceFilePath: file.sourceFile.getFilePath(),\n\t\t\trouterNames: file.routers.named,\n\t\t\tfilterEndpointPaths,\n\t\t},\n\t}))\n\n\t// Dispatch all tasks to the worker pool, capped at one worker per file.\n\tconst pool = new WorkerPool(resolveWorkerUrl(), allTasks.length)\n\n\ttype FileResult = {\n\t\tendpoints: EndpointData[]\n\t\tfileName: string\n\t\ttiming: number\n\t\tendpointTimings: EndpointTiming[]\n\t}\n\n\tlet results: WorkerResult[]\n\ttry {\n\t\tresults = await pool.runAll(allTasks.map((ft) => ft.task))\n\t} finally {\n\t\tpool.terminate()\n\t}\n\n\t// Each result maps 1:1 to a file task.\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\tfor (let i = 0; i < results.length; i++) {\n\t\tconst result = results[i]\n\t\tconst fileName = allTasks[i].fileName\n\t\tconst fileResult = byFile.get(fileName)!\n\n\t\tif ('error' in result) {\n\t\t\tLogger.error(`[${fileName}] Worker error: ${result.error}`)\n\t\t\tcontinue\n\t\t}\n\n\t\tfileResult.endpoints = result.endpoints\n\t\tfileResult.endpointTimings = result.endpointTimings\n\t\tfileResult.timing = result.endpointTimings.reduce((sum, t) => sum + t.timing, 0)\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","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","allTasks","crypto","pool","WorkerPool","results","ft","byFile","i","result","fileName","fileResult","sum","t","analyzedFiles","a","b","ep","s","sourceFile","nameOfUseApiHeader","discoverImportedName","node","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;AA2CO,MAAMG,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,IAAI,CAACC,MAAaR,EAAQ,qBAAqBQ,CAAQ,CAAC,GAC9FL,IAAkBG,EAAY,QAAQ,C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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}\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\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\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","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","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,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AAF;AAAA,IACA,cAAc;AAAA,EAAA,CACd;AAED,SAAAA,EACE,oBAAoB,EACpB,OAAO,CAACP,MAASA,EAAK,OAAOU,EAAW,mBAAmB,CAAC,EAC5D,IAAI,CAACV,MAAS;AACd,QAAIkB,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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AAArB,EAAeD,EAAW,YAAY,CAAC,EAAI,CAAE,aAAciB,CAAQ,EAC5DA,QACCM,EAAO,CACfT,OAAAA,EAAA,OAAO,KAAK,IAAIF,CAAQ,8CAA+CW,CAAK,EAC5EtB,EAAeD,EAAW,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","importedSourceFile","deps","error"],"mappings":";;;AAeO,SAASA,EACfC,GACAC,GACAC,IAAyB,oBAAI,OAC5B;AACK,QAAAC,IAAeC,EAAoBJ,GAAYC,CAAc,GAC7DI,IAAaF,EAAa,IAAI,CAACG,MAAQ;AACtC,UAAAC,IAAUD,EAAI,YAAY,GAC1BE,IAASN,EAAW,IAAIK,CAAO;AACrC,QAAIC,MAAW;AACP,aAAAA;AAER,UAAMC,IAAQC,EAAG,SAASH,CAAO,EAAE;AACxB,WAAAL,EAAA,IAAIK,GAASE,CAAK,GACtBA;AAAA,EAAA,CACP,GACKE,IAAkB,KAAK,IAAI,GAAGN,CAAU,GAExCO,IAAWZ,EAAW,YAAA,EAAc,MAAM,GAAG,EAAE,IAAI,GACnDa,IAAYV,EAAa;AACxB,SAAAW,EAAA;AAAA,IACN,IAAIF,CAAQ,WAAWC,CAAS,+BAA+BE,EAAgBJ,CAAe,CAAC;AAAA,EAChG,GAEOA;AACR;AAEA,SAASP,EAAoBJ,GAAwBC,GAA8C;AAClG,QAAMW,IAAWZ,EAAW,YAAA,EAAc,MAAM,GAAG,EAAE,IAAI;AACzD,MAAI,CAACY;AACJ,WAAO,CAAC;AAGT,QAAMI,IAAWf,EAAeD,EAAW,YAAA,CAAa;AACxD,MAAIgB;AACH,WAAOA,EAAS;AAIjB,EAAAf,EAAeD,EAAW,YAAY,CAAC,IAAI,EAAE,cAAc,CAAA,EAAG;AAE1D,MAAA;AACG,UAAAiB,IAAU,CAACjB,CAAU,GAErBkB,IAAqBlB,EAAW,qBAAqBmB,EAAW,iBAAiB;AAEvF,eAAWC,KAAeF,GAAoB;AACvC,YAAAG,IAAqBD,EAAY,6BAA6B;AACpE,UAAI,CAACC,GAAoB;AACxB,QAAAP,EAAO,MAAM,IAAIF,CAAQ,8BAA8BQ,EAAY,yBAAyB,GAAG;AAC/F;AAAA,MAAA;AAGK,YAAAE,IAAOlB,EAAoBiB,GAAoBpB,CAAc;AAC3D,MAAAgB,EAAA,KAAK,GAAGK,CAAI;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'
|
|
@@ -53,6 +53,13 @@ type FileDiscoveryConfig = {
|
|
|
53
53
|
|
|
54
54
|
type EndpointTiming = { method: string; path: string; timing: number; sectionTimings: SectionTiming[] }
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Number of uncached files at or below which analysis runs inline on the (already-warm) main-thread
|
|
58
|
+
* Project instead of fanning out to worker threads. Each worker pays a multi-second cold-start to
|
|
59
|
+
* build its own Project, so parallelism only wins once there are several files to share that cost.
|
|
60
|
+
*/
|
|
61
|
+
const INLINE_ANALYSIS_FILE_THRESHOLD = 2
|
|
62
|
+
|
|
56
63
|
/**
|
|
57
64
|
* @param tsconfigPath Path to tsconfig file relative to project root
|
|
58
65
|
* @param sourceFilePaths Array of router source files relative to project root
|
|
@@ -193,8 +200,10 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
193
200
|
const cached: CachedFile[] = []
|
|
194
201
|
const uncached: UncachedFile[] = []
|
|
195
202
|
|
|
203
|
+
const freshnessCheckStart = performance.now()
|
|
204
|
+
const mtimeCache: MtimeCache = new Map()
|
|
196
205
|
for (const file of files) {
|
|
197
|
-
const timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)
|
|
206
|
+
const timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache, mtimeCache)
|
|
198
207
|
const hit = config.incremental
|
|
199
208
|
? SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)
|
|
200
209
|
: null
|
|
@@ -205,6 +214,9 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
205
214
|
uncached.push({ file, timestamp })
|
|
206
215
|
}
|
|
207
216
|
}
|
|
217
|
+
if (profiling !== 'off') {
|
|
218
|
+
Logger.info(`Cache freshness check took ${Math.round(performance.now() - freshnessCheckStart)}ms`)
|
|
219
|
+
}
|
|
208
220
|
|
|
209
221
|
if (uncached.length === 0) {
|
|
210
222
|
if (profiling !== 'off') {
|
|
@@ -213,24 +225,6 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
213
225
|
return cached.flatMap((f) => f.endpoints)
|
|
214
226
|
}
|
|
215
227
|
|
|
216
|
-
// Build one task per uncached file. Each worker analyzes a whole file in a single pass, so it
|
|
217
|
-
// pays the ts-morph Project cold-start (full TS program load + type-checker warmup) once and
|
|
218
|
-
// reuses the warmed-up checker for every endpoint in that file.
|
|
219
|
-
type FileTask = { task: WorkerTask; fileName: string }
|
|
220
|
-
const allTasks: FileTask[] = uncached.map(({ file }) => ({
|
|
221
|
-
fileName: file.fileName,
|
|
222
|
-
task: {
|
|
223
|
-
taskId: crypto.randomUUID(),
|
|
224
|
-
tsconfigPath: config.tsconfigPath,
|
|
225
|
-
sourceFilePath: file.sourceFile.getFilePath(),
|
|
226
|
-
routerNames: file.routers.named,
|
|
227
|
-
filterEndpointPaths,
|
|
228
|
-
},
|
|
229
|
-
}))
|
|
230
|
-
|
|
231
|
-
// Dispatch all tasks to the worker pool, capped at one worker per file.
|
|
232
|
-
const pool = new WorkerPool(resolveWorkerUrl(), allTasks.length)
|
|
233
|
-
|
|
234
228
|
type FileResult = {
|
|
235
229
|
endpoints: EndpointData[]
|
|
236
230
|
fileName: string
|
|
@@ -238,32 +232,63 @@ export const analyzeMultipleSourceFiles = async (
|
|
|
238
232
|
endpointTimings: EndpointTiming[]
|
|
239
233
|
}
|
|
240
234
|
|
|
241
|
-
let results: WorkerResult[]
|
|
242
|
-
try {
|
|
243
|
-
results = await pool.runAll(allTasks.map((ft) => ft.task))
|
|
244
|
-
} finally {
|
|
245
|
-
pool.terminate()
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Each result maps 1:1 to a file task.
|
|
249
235
|
const byFile = new Map<string, FileResult>()
|
|
250
236
|
for (const { file } of uncached) {
|
|
251
237
|
byFile.set(file.fileName, { endpoints: [], fileName: file.fileName, timing: 0, endpointTimings: [] })
|
|
252
238
|
}
|
|
253
239
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
240
|
+
// The caller (prepareOpenApiSpec) already built and warmed a ts-morph Project on this thread, so
|
|
241
|
+
// inline analysis runs against a hot type-checker. A worker, by contrast, must spawn a thread and
|
|
242
|
+
// build its own Project from scratch — a multi-second cold-start. That cold-start only pays off
|
|
243
|
+
// when there are enough uncached files that spreading the parse work across workers beats it; below
|
|
244
|
+
// the threshold (e.g. the common single-file incremental rebuild), inline is strictly faster.
|
|
245
|
+
if (uncached.length <= INLINE_ANALYSIS_FILE_THRESHOLD) {
|
|
246
|
+
for (const { file } of uncached) {
|
|
247
|
+
const { endpoints, endpointTimings } = analyzeSourceFileEndpoints(file, filterEndpointPaths)
|
|
248
|
+
const fileResult = byFile.get(file.fileName)!
|
|
249
|
+
fileResult.endpoints = endpoints
|
|
250
|
+
fileResult.endpointTimings = endpointTimings
|
|
251
|
+
fileResult.timing = endpointTimings.reduce((sum, t) => sum + t.timing, 0)
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
// One task per file: each worker analyzes a whole file in a single pass, paying its Project
|
|
255
|
+
// cold-start once and reusing the warmed-up checker for every endpoint in that file. Cap the
|
|
256
|
+
// pool at one worker per file so we never spin up a worker with nothing to do.
|
|
257
|
+
type FileTask = { task: WorkerTask; fileName: string }
|
|
258
|
+
const allTasks: FileTask[] = uncached.map(({ file }) => ({
|
|
259
|
+
fileName: file.fileName,
|
|
260
|
+
task: {
|
|
261
|
+
taskId: crypto.randomUUID(),
|
|
262
|
+
tsconfigPath: config.tsconfigPath,
|
|
263
|
+
sourceFilePath: file.sourceFile.getFilePath(),
|
|
264
|
+
routerNames: file.routers.named,
|
|
265
|
+
filterEndpointPaths,
|
|
266
|
+
},
|
|
267
|
+
}))
|
|
258
268
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
269
|
+
const pool = new WorkerPool(resolveWorkerUrl(), allTasks.length)
|
|
270
|
+
let results: WorkerResult[]
|
|
271
|
+
try {
|
|
272
|
+
results = await pool.runAll(allTasks.map((ft) => ft.task))
|
|
273
|
+
} finally {
|
|
274
|
+
pool.terminate()
|
|
262
275
|
}
|
|
263
276
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
277
|
+
// Each result maps 1:1 to a file task.
|
|
278
|
+
for (let i = 0; i < results.length; i++) {
|
|
279
|
+
const result = results[i]
|
|
280
|
+
const fileName = allTasks[i].fileName
|
|
281
|
+
const fileResult = byFile.get(fileName)!
|
|
282
|
+
|
|
283
|
+
if ('error' in result) {
|
|
284
|
+
Logger.error(`[${fileName}] Worker error: ${result.error}`)
|
|
285
|
+
continue
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
fileResult.endpoints = result.endpoints
|
|
289
|
+
fileResult.endpointTimings = result.endpointTimings
|
|
290
|
+
fileResult.timing = result.endpointTimings.reduce((sum, t) => sum + t.timing, 0)
|
|
291
|
+
}
|
|
267
292
|
}
|
|
268
293
|
|
|
269
294
|
// Write cache for each uncached file
|
|
@@ -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
|
|