moonflower 1.4.9 → 1.5.1

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.
Files changed (41) hide show
  1. package/dist/openapi/analyzerModule/analyzerModule.cjs +1 -1
  2. package/dist/openapi/analyzerModule/analyzerModule.cjs.map +1 -1
  3. package/dist/openapi/analyzerModule/analyzerModule.d.ts +3 -2
  4. package/dist/openapi/analyzerModule/analyzerModule.d.ts.map +1 -1
  5. package/dist/openapi/analyzerModule/analyzerModule.mjs +144 -121
  6. package/dist/openapi/analyzerModule/analyzerModule.mjs.map +1 -1
  7. package/dist/openapi/analyzerModule/analyzerWorker.cjs +2 -0
  8. package/dist/openapi/analyzerModule/analyzerWorker.cjs.map +1 -0
  9. package/dist/openapi/analyzerModule/analyzerWorker.d.ts +2 -0
  10. package/dist/openapi/analyzerModule/analyzerWorker.d.ts.map +1 -0
  11. package/dist/openapi/analyzerModule/analyzerWorker.mjs +52 -0
  12. package/dist/openapi/analyzerModule/analyzerWorker.mjs.map +1 -0
  13. package/dist/openapi/analyzerModule/nodeParsers.cjs +1 -1
  14. package/dist/openapi/analyzerModule/nodeParsers.cjs.map +1 -1
  15. package/dist/openapi/analyzerModule/nodeParsers.d.ts.map +1 -1
  16. package/dist/openapi/analyzerModule/nodeParsers.mjs +199 -264
  17. package/dist/openapi/analyzerModule/nodeParsers.mjs.map +1 -1
  18. package/dist/openapi/analyzerModule/test/TestCase.d.ts +1 -0
  19. package/dist/openapi/analyzerModule/test/TestCase.d.ts.map +1 -1
  20. package/dist/openapi/analyzerModule/test/workerGlobalSetup.d.ts +3 -0
  21. package/dist/openapi/analyzerModule/test/workerGlobalSetup.d.ts.map +1 -0
  22. package/dist/openapi/analyzerModule/workerPaths.d.ts +2 -0
  23. package/dist/openapi/analyzerModule/workerPaths.d.ts.map +1 -0
  24. package/dist/openapi/analyzerModule/workerPool.cjs +2 -0
  25. package/dist/openapi/analyzerModule/workerPool.cjs.map +1 -0
  26. package/dist/openapi/analyzerModule/workerPool.d.ts +38 -0
  27. package/dist/openapi/analyzerModule/workerPool.d.ts.map +1 -0
  28. package/dist/openapi/analyzerModule/workerPool.mjs +46 -0
  29. package/dist/openapi/analyzerModule/workerPool.mjs.map +1 -0
  30. package/package.json +1 -1
  31. package/src/openapi/analyzerModule/analyzerModule.ts +116 -12
  32. package/src/openapi/analyzerModule/analyzerWorker.ts +77 -0
  33. package/src/openapi/analyzerModule/nodeParsers.ts +4 -104
  34. package/src/openapi/analyzerModule/test/TestCase.ts +1 -0
  35. package/src/openapi/analyzerModule/test/openApiAnalyzer.zod.spec.data.ts +6 -0
  36. package/src/openapi/analyzerModule/test/openApiAnalyzer.zod.spec.ts +8 -0
  37. package/src/openapi/analyzerModule/test/workerGlobalSetup.ts +25 -0
  38. package/src/openapi/analyzerModule/workerPaths.ts +4 -0
  39. package/src/openapi/analyzerModule/workerPool.ts +102 -0
  40. package/src/test/app.spec.ts +10 -1
  41. package/vite.config.ts +5 -0
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("path"),f=require("ts-morph"),u=require("../../utils/logger.cjs"),T=require("../discoveryModule/discoverImports/discoverImports.cjs"),K=require("../discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs"),H=require("../discoveryModule/discoverRouters/discoverRouters.cjs"),I=require("../manager/OpenApiManager.cjs"),U=require("./getSourceFileTimestamp.cjs"),C=require("./nodeParsers.cjs"),W=require("./parseEndpoint.cjs"),N=require("./parseExposedModels.cjs"),M=require("./sourceFileCache.cjs");function _(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const c in t)if(c!=="default"){const i=Object.getOwnPropertyDescriptor(t,c);Object.defineProperty(r,c,i.get?i:{enumerable:!0,get:()=>t[c]})}}return r.default=t,Object.freeze(r)}const E=_(q),D=({logLevel:t,tsconfigPath:r,sourceFilePaths:c,sourceFileDiscovery:i,incremental:n,profiling:l="stats"})=>{const e=I.OpenApiManager.getInstance();if(e.isReady())return;t&&u.Logger.setLevel(t),u.Logger.info("Preparing OpenAPI spec");const o=new f.Project({tsConfigFilePath:E.resolve(r),skipFileDependencyResolution:!0}),{explicitRouters:s,discoveredRouterFiles:m,allSourceFiles:y}=(()=>{const d=(c??[]).map(p=>E.resolve(p)).map(p=>o.getSourceFileOrThrow(p)),b=d.flatMap(p=>({fileName:p.getFilePath(),sourceFile:p,routers:H.discoverRouters(p)})),{discoveredRouterFiles:z,discoveredSourceFiles:k}=(()=>{if(i===!1)return{discoveredRouterFiles:[],discoveredSourceFiles:[]};const p=performance.now(),x=K.discoverRouterFiles({targetPath:typeof i=="object"?i.rootPath:".",tsConfigPath:r});return l!=="off"&&u.Logger.info(`File discovery took ${Math.round(performance.now()-p)}ms`),x})(),w=d.reduce((p,x)=>p.some(j=>j.getFilePath()===x.getFilePath())?p:p.concat(x),k);return{explicitRouters:b,discoveredRouterFiles:z,allSourceFiles:w}})(),g=s.reduce((a,h)=>a.some(d=>d.fileName===h.fileName)?a:a.concat(h),m),F=y.flatMap(a=>R(a)).filter(a=>!!a);F.length>0&&F[0]&&e.setHeader(F[0]);const $=y.flatMap(a=>v(a));e.setExposedModels($);const L=typeof n=="object"&&n.cachePath?n.cachePath:E.resolve(process.cwd(),"node_modules",".cache","moonflower"),S=P(g,{cachePath:L,timestampCache:{},profiling:l});e.setStats({discoveredRouterFiles:m.map(a=>({path:a.fileName,routers:a.routers.named.map(h=>({name:h,endpoints:S.filter(d=>d.sourceFilePath===a.fileName).map(d=>`${d.method.toUpperCase()} ${d.path}`)}))})),explicitRouterFiles:s.map(a=>({path:a.fileName,routers:a.routers.named.map(h=>({name:h,endpoints:S.filter(d=>d.sourceFilePath===a.fileName).map(d=>`${d.method.toUpperCase()} ${d.path}`)}))}))}),e.setEndpoints(S),e.markAsReady()},P=(t,r,c)=>{const i=r.profiling??"stats",n=performance.now(),l=t.map(e=>A(e,r));return i!=="off"&&u.Logger.info(`Router analysis took ${Math.round(performance.now()-n)}ms`),i==="stats"?l.map((e,o)=>({fileName:t[o].fileName,timeTaken:e.timing})).sort((e,o)=>o.timeTaken-e.timeTaken).filter(e=>e.timeTaken>500).forEach(e=>{u.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`)}):i==="debug"&&l.map((e,o)=>({fileName:t[o].fileName,timeTaken:e.timing,endpointTimings:e.endpointTimings})).sort((e,o)=>o.timeTaken-e.timeTaken).forEach(e=>{u.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`),e.endpointTimings.sort((o,s)=>s.timing-o.timing).forEach(o=>{u.Logger.info(` - ${o.method} ${o.path} (${Math.round(o.timing)}ms)`),o.sectionTimings.filter(s=>s.timing>=1).sort((s,m)=>m.timing-s.timing).forEach(s=>{u.Logger.info(` - ${s.section}: ${Math.round(s.timing)}ms`)})})}),l.flatMap(e=>e.endpoints)},A=(t,r,c)=>{const i=U.getSourceFileTimestamp(t.sourceFile,r.timestampCache),n=M.SourceFileCache.getCachedResults(t.sourceFile,i,r.cachePath);if(n)return u.Logger.debug(`[${t.fileName}] Found cached results`),{endpoints:n.endpoints,timing:0,endpointTimings:[]};u.Logger.debug(`[${t.fileName}] Analyzing...`);const l=performance.now(),{endpoints:e,endpointTimings:o}=O(t),s=performance.now();return u.Logger.debug(`[${t.fileName}] Analyzed in ${s-l}ms`),M.SourceFileCache.cacheResults(t.sourceFile,i,r.cachePath,e),{endpoints:e,timing:s-l,endpointTimings:o}},O=(t,r)=>{const c=[],i=[],l=["get","post","put","delete","del","patch"].join("|");return t.routers.named.forEach(e=>{const o=new RegExp(`${e}\\.(?:${l})`);t.sourceFile.forEachChild(s=>{const m=s.getText();if(o.test(m)){C.resolveEndpointPath(s);const y=performance.now(),{endpoint:g,sectionTimings:F}=W.parseEndpoint(s,t.fileName);i.push({method:g.method,path:g.path,timing:performance.now()-y,sectionTimings:F}),c.push(g)}})}),{endpoints:c,endpointTimings:i}},R=t=>{const r=T.discoverImportedName({sourceFile:t,originalName:"useApiHeader"});if(!r)return null;const c=t.forEachChildAsArray().filter(e=>e.isKind(f.SyntaxKind.ExpressionStatement)).find(e=>r&&e.getText().startsWith(r));if(!c)return null;const i=c.getFirstDescendantByKindOrThrow(f.SyntaxKind.ObjectLiteralExpression),n=C.getValuesOfObjectLiteral(i),l=e=>typeof e=="string"||Array.isArray(e)&&e.every(o=>typeof o=="string")?e:e.reduce((o,s)=>typeof s=="string"?o:{...o,[s.identifier]:l(s.value)},{});return l(n)},v=t=>{const r=[],c=T.discoverImportedName({sourceFile:t,originalName:"useExposeApiModel"}),i=T.discoverImportedName({sourceFile:t,originalName:"useExposeNamedApiModels"});return t.forEachChildAsArray().filter(n=>n.isKind(f.SyntaxKind.ExpressionStatement)).map(n=>{if(c&&n.getText().startsWith(c)){const o=(n.getFirstChild()?.getChildrenOfKind(f.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!o)return;r.push(N.parseExposedModel(o));return}if(i&&n.getText().startsWith(i)){const o=(n.getFirstChild()?.getChildrenOfKind(f.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!o)return;N.parseNamedExposedModels(o).forEach(m=>r.push(m))}}),r};exports.analyzeMultipleSourceFiles=P;exports.analyzeSourceFileApiHeader=R;exports.analyzeSourceFileEndpoints=O;exports.analyzeSourceFileExposedModels=v;exports.analyzeSourceFileWithCache=A;exports.prepareOpenApiSpec=D;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("crypto"),q=require("fs"),z=require("path"),U=require("url"),S=require("ts-morph"),f=require("../../utils/logger.cjs"),R=require("../discoveryModule/discoverImports/discoverImports.cjs"),I=require("../discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs"),K=require("../discoveryModule/discoverRouters/discoverRouters.cjs"),W=require("../manager/OpenApiManager.cjs"),_=require("./getSourceFileTimestamp.cjs"),H=require("./nodeParsers.cjs"),k=require("./parseExposedModels.cjs"),C=require("./sourceFileCache.cjs"),D=require("./workerPool.cjs");var P=typeof document<"u"?document.currentScript:null;function B(s){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const a in s)if(a!=="default"){const l=Object.getOwnPropertyDescriptor(s,a);Object.defineProperty(o,a,l.get?l:{enumerable:!0,get:()=>s[a]})}}return o.default=s,Object.freeze(o)}const M=B(z);function V(){const s=["./analyzerWorker.mjs","./analyzerWorker.test.mjs"];for(const o of s){const a=new URL(o,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(q.existsSync(U.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 G=async({logLevel:s,tsconfigPath:o,sourceFilePaths:a,sourceFileDiscovery:l,incremental:c,profiling:m="stats"})=>{const t=W.OpenApiManager.getInstance();if(t.isReady())return;s&&f.Logger.setLevel(s),f.Logger.info("Preparing OpenAPI spec");const d=new S.Project({tsConfigFilePath:M.resolve(o),skipFileDependencyResolution:!0}),{explicitRouters:h,discoveredRouterFiles:F,allSourceFiles:N}=(()=>{const u=(a??[]).map(p=>M.resolve(p)).map(p=>d.getSourceFileOrThrow(p)),L=u.flatMap(p=>({fileName:p.getFilePath(),sourceFile:p,routers:K.discoverRouters(p)})),{discoveredRouterFiles:w,discoveredSourceFiles:O}=(()=>{if(l===!1)return{discoveredRouterFiles:[],discoveredSourceFiles:[]};const p=performance.now(),x=I.discoverRouterFiles({targetPath:typeof l=="object"?l.rootPath:".",tsConfigPath:o});return m!=="off"&&f.Logger.info(`File discovery took ${Math.round(performance.now()-p)}ms`),x})(),$=u.reduce((p,x)=>p.some(b=>b.getFilePath()===x.getFilePath())?p:p.concat(x),O);return{explicitRouters:L,discoveredRouterFiles:w,allSourceFiles:$}})(),T=h.reduce((i,y)=>i.some(u=>u.fileName===y.fileName)?i:i.concat(y),F),e=N.flatMap(i=>E(i)).filter(i=>!!i);e.length>0&&e[0]&&t.setHeader(e[0]);const r=N.flatMap(i=>v(i));t.setExposedModels(r);const n=typeof c=="object"&&c.cachePath?c.cachePath:M.resolve(process.cwd(),"node_modules",".cache","moonflower"),g=await A(T,{incremental:c!==!1,cachePath:n,timestampCache:{},profiling:m,tsconfigPath:M.resolve(o)});t.setStats({discoveredRouterFiles:F.map(i=>({path:i.fileName,routers:i.routers.named.map(y=>({name:y,endpoints:g.filter(u=>u.sourceFilePath===i.fileName).map(u=>`${u.method.toUpperCase()} ${u.path}`)}))})),explicitRouterFiles:h.map(i=>({path:i.fileName,routers:i.routers.named.map(y=>({name:y,endpoints:g.filter(u=>u.sourceFilePath===i.fileName).map(u=>`${u.method.toUpperCase()} ${u.path}`)}))}))}),t.setEndpoints(g),t.markAsReady()},A=async(s,o,a)=>{const l=o.profiling??"stats",c=performance.now(),m=[],t=[];for(const e of s){const r=_.getSourceFileTimestamp(e.sourceFile,o.timestampCache),n=o.incremental?C.SourceFileCache.getCachedResults(e.sourceFile,r,o.cachePath):null;n?(f.Logger.debug(`[${e.fileName}] Found cached results`),m.push({endpoints:n.endpoints,fileName:e.fileName,timing:0,endpointTimings:[]})):t.push({file:e,timestamp:r})}if(t.length===0)return l!=="off"&&f.Logger.info(`Router analysis took ${Math.round(performance.now()-c)}ms`),m.flatMap(e=>e.endpoints);const d=t.map(({file:e})=>({fileName:e.fileName,task:{taskId:j.randomUUID(),tsconfigPath:o.tsconfigPath,sourceFilePath:e.sourceFile.getFilePath(),routerNames:e.routers.named,filterEndpointPaths:a}})),h=new D.WorkerPool(V(),d.length);let F;try{F=await h.runAll(d.map(e=>e.task))}finally{h.terminate()}const N=new Map;for(const{file:e}of t)N.set(e.fileName,{endpoints:[],fileName:e.fileName,timing:0,endpointTimings:[]});for(let e=0;e<F.length;e++){const r=F[e],n=d[e].fileName,g=N.get(n);if("error"in r){f.Logger.error(`[${n}] Worker error: ${r.error}`);continue}g.endpoints=r.endpoints,g.endpointTimings=r.endpointTimings,g.timing=r.endpointTimings.reduce((i,y)=>i+y.timing,0)}for(const{file:e,timestamp:r}of t){const n=N.get(e.fileName);n.endpoints.length>0&&C.SourceFileCache.cacheResults(e.sourceFile,r,o.cachePath,n.endpoints)}const T=[...m,...Array.from(N.values())];return l!=="off"&&f.Logger.info(`Router analysis took ${Math.round(performance.now()-c)}ms`),l==="stats"?T.map(e=>({fileName:e.fileName,timeTaken:e.timing})).sort((e,r)=>r.timeTaken-e.timeTaken).filter(e=>e.timeTaken>500).forEach(e=>{f.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,r)=>r.timeTaken-e.timeTaken).forEach(e=>{f.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`),e.endpointTimings.sort((r,n)=>n.timing-r.timing).forEach(r=>{f.Logger.info(` - ${r.method} ${r.path} (${Math.round(r.timing)}ms)`),r.sectionTimings.filter(n=>n.timing>=1).sort((n,g)=>g.timing-n.timing).forEach(n=>{f.Logger.info(` - ${n.section}: ${Math.round(n.timing)}ms`)})})}),T.flatMap(e=>e.endpoints)},E=s=>{const o=R.discoverImportedName({sourceFile:s,originalName:"useApiHeader"});if(!o)return null;const a=s.forEachChildAsArray().filter(t=>t.isKind(S.SyntaxKind.ExpressionStatement)).find(t=>o&&t.getText().startsWith(o));if(!a)return null;const l=a.getFirstDescendantByKindOrThrow(S.SyntaxKind.ObjectLiteralExpression),c=H.getValuesOfObjectLiteral(l),m=t=>typeof t=="string"||Array.isArray(t)&&t.every(d=>typeof d=="string")?t:t.reduce((d,h)=>typeof h=="string"?d:{...d,[h.identifier]:m(h.value)},{});return m(c)},v=s=>{const o=[],a=R.discoverImportedName({sourceFile:s,originalName:"useExposeApiModel"}),l=R.discoverImportedName({sourceFile:s,originalName:"useExposeNamedApiModels"});return s.forEachChildAsArray().filter(c=>c.isKind(S.SyntaxKind.ExpressionStatement)).map(c=>{if(a&&c.getText().startsWith(a)){const d=(c.getFirstChild()?.getChildrenOfKind(S.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!d)return;o.push(k.parseExposedModel(d));return}if(l&&c.getText().startsWith(l)){const d=(c.getFirstChild()?.getChildrenOfKind(S.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!d)return;k.parseNamedExposedModels(d).forEach(F=>o.push(F))}}),o};exports.analyzeMultipleSourceFiles=A;exports.analyzeSourceFileApiHeader=E;exports.analyzeSourceFileExposedModels=v;exports.prepareOpenApiSpec=G;
2
2
  //# sourceMappingURL=analyzerModule.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"analyzerModule.cjs","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"sourcesContent":["import * as path from 'path'\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'\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 = ({\n\tlogLevel,\n\ttsconfigPath,\n\tsourceFilePaths,\n\tsourceFileDiscovery,\n\tincremental,\n\tprofiling = 'stats',\n}: Props) => {\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 = analyzeMultipleSourceFiles(filesToAnalyze, {\n\t\tincremental: incremental !== false,\n\t\tcachePath,\n\t\ttimestampCache: {},\n\t\tprofiling,\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 = (\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},\n\tfilterEndpointPaths?: string[],\n): EndpointData[] => {\n\tconst profiling = config.profiling ?? 'stats'\n\tconst startTime = performance.now()\n\tconst analyzedFiles = files.map((file) => analyzeSourceFileWithCache(file, config, filterEndpointPaths))\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, index) => ({ fileName: files[index].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, index) => ({\n\t\t\t\tfileName: files[index].fileName,\n\t\t\t\ttimeTaken: f.timing,\n\t\t\t\tendpointTimings: f.endpointTimings,\n\t\t\t}))\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":["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","analyzedFiles","analyzeSourceFileWithCache","f","index","a","b","t","ep","timestamp","getSourceFileTimestamp","cachedResults","SourceFileCache","t1","endpointTimings","analyzeSourceFileEndpoints","t2","joinedOperations","routerName","routerPattern","node","nodeText","resolveEndpointPath","endpoint","sectionTimings","parseEndpoint","sourceFile","nameOfUseApiHeader","discoverImportedName","SyntaxKind","targetNode","values","getValuesOfObjectLiteral","collapseObject","v","value","models","nameOfUseExposeApiModel","nameOfUseExposeNamedApiModels","firstChild","parseExposedModel","parseNamedExposedModels","model"],"mappings":"82BA0CaA,EAAqB,CAAC,CAClC,SAAAC,EACA,aAAAC,EACA,gBAAAC,EACA,oBAAAC,EACA,YAAAC,EACA,UAAAC,EAAY,OACb,IAAa,CACN,MAAAC,EAAiBC,iBAAe,YAAY,EAE9C,GAAAD,EAAe,UAClB,OAGGN,GACHQ,EAAA,OAAO,SAASR,CAAQ,EAGzBQ,EAAA,OAAO,KAAK,wBAAwB,EAE9B,MAAAC,EAAU,IAAIC,UAAQ,CAC3B,iBAAkBC,EAAK,QAAQV,CAAY,EAC3C,6BAA8B,EAAA,CAC9B,EAEK,CAAE,gBAAAW,EAAiB,sBAAAC,EAAuB,eAAAC,CAAA,GAAoB,IAAM,CAGnE,MAAAC,GAFmBb,GAAmB,CAAC,GACI,IAAKc,GAAaL,EAAK,QAAQK,CAAQ,CAAC,EAC7C,IAAKC,GAAaR,EAAQ,qBAAqBQ,CAAQ,CAAC,EAC9FL,EAAkBG,EAA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ACC,kBAAkBS,EAAAA,WAAW,UAAU,GAAK,CAAC,GAEtD,CAAC,EAAE,cAAc,EACvD,GAAI,CAACU,EACJ,OAGoBE,0BAAwBF,CAAU,EAC1C,QAASG,GAAUN,EAAO,KAAKM,CAAK,CAAC,CAAA,CACnD,CACA,EACKN,CACR"}
1
+ {"version":3,"file":"analyzerModule.cjs","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { existsSync } from 'fs'\nimport * as path from 'path'\nimport { fileURLToPath } from 'url'\n\nfunction resolveWorkerUrl(): URL {\n\tconst candidates = ['./analyzerWorker.mjs', './analyzerWorker.test.mjs']\n\tfor (const candidate of candidates) {\n\t\tconst url = new URL(candidate, import.meta.url)\n\t\tif (existsSync(fileURLToPath(url))) {\n\t\t\treturn url\n\t\t}\n\t}\n\tthrow new Error(\n\t\t'analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first).',\n\t)\n}\nimport { SourceFile, SyntaxKind } from 'ts-morph'\nimport { Project } from 'ts-morph'\n\nimport { Logger } from '../../utils/logger'\nimport { discoverImportedName } from '../discoveryModule/discoverImports/discoverImports'\nimport {\n\tDiscoveredSourceFile,\n\tdiscoverRouterFiles,\n} from '../discoveryModule/discoverRouterFiles/discoverRouterFiles'\nimport { discoverRouters } from '../discoveryModule/discoverRouters/discoverRouters'\nimport { ApiDocsHeader, OpenApiManager } from '../manager/OpenApiManager'\nimport { EndpointData, ExposedModelData } from '../types'\nimport { getSourceFileTimestamp, 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,aAAWC,EAAAA,cAAcH,CAAG,CAAC,EACzB,OAAAA,CACR,CAED,MAAM,IAAI,MACT,6GACD,CACD,CA2CO,MAAMI,EAAqB,MAAO,CACxC,SAAAC,EACA,aAAAC,EACA,gBAAAC,EACA,oBAAAC,EACA,YAAAC,EACA,UAAAC,EAAY,OACb,IAA4B,CACrB,MAAAC,EAAiBC,iBAAe,YAAY,EAE9C,GAAAD,EAAe,UAClB,OAGGN,GACHQ,EAAA,OAAO,SAASR,CAAQ,EAGzBQ,EAAA,OAAO,KAAK,wBAAwB,EAE9B,MAAAC,EAAU,IAAIC,UAAQ,CAC3B,iBAAkBC,EAAK,QAAQV,CAAY,EAC3C,6BAA8B,EAAA,CAC9B,EAEK,CAAE,gBAAAW,EAAiB,sBAAAC,EAAuB,eAAAC,CAAA,GAAoB,IAAM,CAGnE,MAAAC,GAFmBb,GAAmB,CAAC,GACI,IAAKc,GAAaL,EAAK,QAAQK,CAAQ,CAAC,EAC7C,IAAKC,GAAaR,EAAQ,qBAAqBQ,CAAQ,CAAC,EAC9FL,EAAkBG,EAAY,QAASG,IAAU,CACtD,SAAUA,EAAK,YAA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AW,mBAAmB,CAAC,EAC5D,IAAKD,GAAS,CACd,GAAIS,GAA2BT,EAAK,QAAU,EAAA,WAAWS,CAAuB,EAAG,CAIlF,MAAME,GAHqBX,EAAK,cAAc,GACC,kBAAkBC,EAAAA,WAAW,UAAU,GAAK,CAAC,GAEtD,CAAC,EAAE,cAAc,EACvD,GAAI,CAACU,EACJ,OAGMH,EAAA,KAAKI,oBAAkBD,CAAU,CAAC,EACzC,MAAA,CAGD,GAAID,GAAiCV,EAAK,QAAU,EAAA,WAAWU,CAA6B,EAAG,CAI9F,MAAMC,GAHqBX,EAAK,cAAc,GACC,kBAAkBC,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"}
@@ -25,13 +25,14 @@ type EndpointTiming = {
25
25
  timing: number;
26
26
  sectionTimings: SectionTiming[];
27
27
  };
28
- export declare const prepareOpenApiSpec: ({ logLevel, tsconfigPath, sourceFilePaths, sourceFileDiscovery, incremental, profiling, }: Props) => void;
28
+ export declare const prepareOpenApiSpec: ({ logLevel, tsconfigPath, sourceFilePaths, sourceFileDiscovery, incremental, profiling, }: Props) => Promise<void>;
29
29
  export declare const analyzeMultipleSourceFiles: (files: DiscoveredSourceFile[], config: {
30
30
  incremental: boolean;
31
31
  cachePath: string;
32
32
  timestampCache: TimestampCache;
33
33
  profiling?: "stats" | "off" | "debug";
34
- }, filterEndpointPaths?: string[]) => EndpointData[];
34
+ tsconfigPath: string;
35
+ }, filterEndpointPaths?: string[]) => Promise<EndpointData[]>;
35
36
  export declare const analyzeSourceFileWithCache: (file: DiscoveredSourceFile, config: {
36
37
  incremental: boolean;
37
38
  cachePath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"analyzerModule.d.ts","sourceRoot":"","sources":["../../../src/openapi/analyzerModule/analyzerModule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C5B;IAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,cAAc,EAAE,CAAA;CAgBhF,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,wBACJ,MAAM,EAAE,KAC5B;IAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAAC,eAAe,EAAE,cAAc,EAAE,CAAA;CAgChE,CAAA;AAED,eAAO,MAAM,0BAA0B,eAAgB,UAAU,KAAG,aAAa,GAAG,IAyCnF,CAAA;AAED,eAAO,MAAM,8BAA8B,eAAgB,UAAU,KAAG,gBAAgB,EA4CvF,CAAA"}
@@ -1,161 +1,184 @@
1
- import * as T from "path";
2
- import { Project as O, SyntaxKind as F } from "ts-morph";
3
- import { Logger as m } from "../../utils/logger.mjs";
4
- import { discoverImportedName as N } from "../discoveryModule/discoverImports/discoverImports.mjs";
5
- import { discoverRouterFiles as v } from "../discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs";
6
- import { discoverRouters as w } from "../discoveryModule/discoverRouters/discoverRouters.mjs";
7
- import { OpenApiManager as z } from "../manager/OpenApiManager.mjs";
1
+ import $ from "crypto";
2
+ import { existsSync as v } from "fs";
3
+ import * as M from "path";
4
+ import { fileURLToPath as O } from "url";
5
+ import { Project as L, SyntaxKind as x } from "ts-morph";
6
+ import { Logger as u } from "../../utils/logger.mjs";
7
+ import { discoverImportedName as E } from "../discoveryModule/discoverImports/discoverImports.mjs";
8
+ import { discoverRouterFiles as j } from "../discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs";
9
+ import { discoverRouters as z } from "../discoveryModule/discoverRouters/discoverRouters.mjs";
10
+ import { OpenApiManager as U } from "../manager/OpenApiManager.mjs";
8
11
  import { getSourceFileTimestamp as b } from "./getSourceFileTimestamp.mjs";
9
- import { getValuesOfObjectLiteral as j, resolveEndpointPath as L } from "./nodeParsers.mjs";
10
- import { parseEndpoint as K } from "./parseEndpoint.mjs";
11
- import { parseExposedModel as H, parseNamedExposedModels as U } from "./parseExposedModels.mjs";
12
- import { SourceFileCache as C } from "./sourceFileCache.mjs";
13
- const se = ({
14
- logLevel: o,
12
+ import { getValuesOfObjectLiteral as W } from "./nodeParsers.mjs";
13
+ import { parseExposedModel as K, parseNamedExposedModels as H } from "./parseExposedModels.mjs";
14
+ import { SourceFileCache as P } from "./sourceFileCache.mjs";
15
+ import { WorkerPool as I } from "./workerPool.mjs";
16
+ function B() {
17
+ const m = ["./analyzerWorker.mjs", "./analyzerWorker.test.mjs"];
18
+ for (const i of m) {
19
+ const p = new URL(i, import.meta.url);
20
+ if (v(O(p)))
21
+ return p;
22
+ }
23
+ throw new Error(
24
+ "analyzerWorker.mjs not found. Run yarn build, or run tests via yarn test (which compiles the worker first)."
25
+ );
26
+ }
27
+ const ae = async ({
28
+ logLevel: m,
15
29
  tsconfigPath: i,
16
- sourceFilePaths: c,
17
- sourceFileDiscovery: n,
18
- incremental: r,
19
- profiling: l = "stats"
30
+ sourceFilePaths: p,
31
+ sourceFileDiscovery: c,
32
+ incremental: n,
33
+ profiling: f = "stats"
20
34
  }) => {
21
- const e = z.getInstance();
22
- if (e.isReady())
35
+ const t = U.getInstance();
36
+ if (t.isReady())
23
37
  return;
24
- o && m.setLevel(o), m.info("Preparing OpenAPI spec");
25
- const t = new O({
26
- tsConfigFilePath: T.resolve(i),
38
+ m && u.setLevel(m), u.info("Preparing OpenAPI spec");
39
+ const a = new L({
40
+ tsConfigFilePath: M.resolve(i),
27
41
  skipFileDependencyResolution: !0
28
- }), { explicitRouters: s, discoveredRouterFiles: u, allSourceFiles: x } = (() => {
29
- const p = (c ?? []).map((d) => T.resolve(d)).map((d) => t.getSourceFileOrThrow(d)), P = p.flatMap((d) => ({
42
+ }), { explicitRouters: h, discoveredRouterFiles: F, allSourceFiles: N } = (() => {
43
+ const l = (p ?? []).map((d) => M.resolve(d)).map((d) => a.getSourceFileOrThrow(d)), R = l.flatMap((d) => ({
30
44
  fileName: d.getFilePath(),
31
45
  sourceFile: d,
32
- routers: w(d)
33
- })), { discoveredRouterFiles: S, discoveredSourceFiles: $ } = (() => {
34
- if (n === !1)
46
+ routers: z(d)
47
+ })), { discoveredRouterFiles: A, discoveredSourceFiles: C } = (() => {
48
+ if (c === !1)
35
49
  return { discoveredRouterFiles: [], discoveredSourceFiles: [] };
36
- const d = performance.now(), y = v({
37
- targetPath: typeof n == "object" ? n.rootPath : ".",
50
+ const d = performance.now(), k = j({
51
+ targetPath: typeof c == "object" ? c.rootPath : ".",
38
52
  tsConfigPath: i
39
53
  });
40
- return l !== "off" && m.info(`File discovery took ${Math.round(performance.now() - d)}ms`), y;
41
- })(), R = p.reduce(
42
- (d, y) => d.some((k) => k.getFilePath() === y.getFilePath()) ? d : d.concat(y),
43
- $
54
+ return f !== "off" && u.info(`File discovery took ${Math.round(performance.now() - d)}ms`), k;
55
+ })(), S = l.reduce(
56
+ (d, k) => d.some((w) => w.getFilePath() === k.getFilePath()) ? d : d.concat(k),
57
+ C
44
58
  );
45
- return { explicitRouters: P, discoveredRouterFiles: S, allSourceFiles: R };
46
- })(), h = s.reduce(
47
- (a, f) => a.some((p) => p.fileName === f.fileName) ? a : a.concat(f),
48
- u
49
- ), g = x.flatMap((a) => V(a)).filter((a) => !!a);
50
- g.length > 0 && g[0] && e.setHeader(g[0]);
51
- const M = x.flatMap((a) => _(a));
52
- e.setExposedModels(M);
53
- const A = typeof r == "object" && r.cachePath ? r.cachePath : T.resolve(process.cwd(), "node_modules", ".cache", "moonflower"), E = W(h, {
54
- cachePath: A,
59
+ return { explicitRouters: R, discoveredRouterFiles: A, allSourceFiles: S };
60
+ })(), T = h.reduce(
61
+ (s, y) => s.some((l) => l.fileName === y.fileName) ? s : s.concat(y),
62
+ F
63
+ ), e = N.flatMap((s) => V(s)).filter((s) => !!s);
64
+ e.length > 0 && e[0] && t.setHeader(e[0]);
65
+ const o = N.flatMap((s) => _(s));
66
+ t.setExposedModels(o);
67
+ const r = typeof n == "object" && n.cachePath ? n.cachePath : M.resolve(process.cwd(), "node_modules", ".cache", "moonflower"), g = await D(T, {
68
+ incremental: n !== !1,
69
+ cachePath: r,
55
70
  timestampCache: {},
56
- profiling: l
71
+ profiling: f,
72
+ tsconfigPath: M.resolve(i)
57
73
  });
58
- e.setStats({
59
- discoveredRouterFiles: u.map((a) => ({
60
- path: a.fileName,
61
- routers: a.routers.named.map((f) => ({
62
- name: f,
63
- endpoints: E.filter((p) => p.sourceFilePath === a.fileName).map((p) => `${p.method.toUpperCase()} ${p.path}`)
74
+ t.setStats({
75
+ discoveredRouterFiles: F.map((s) => ({
76
+ path: s.fileName,
77
+ routers: s.routers.named.map((y) => ({
78
+ name: y,
79
+ endpoints: g.filter((l) => l.sourceFilePath === s.fileName).map((l) => `${l.method.toUpperCase()} ${l.path}`)
64
80
  }))
65
81
  })),
66
- explicitRouterFiles: s.map((a) => ({
67
- path: a.fileName,
68
- routers: a.routers.named.map((f) => ({
69
- name: f,
70
- endpoints: E.filter((p) => p.sourceFilePath === a.fileName).map((p) => `${p.method.toUpperCase()} ${p.path}`)
82
+ explicitRouterFiles: h.map((s) => ({
83
+ path: s.fileName,
84
+ routers: s.routers.named.map((y) => ({
85
+ name: y,
86
+ endpoints: g.filter((l) => l.sourceFilePath === s.fileName).map((l) => `${l.method.toUpperCase()} ${l.path}`)
71
87
  }))
72
88
  }))
73
- }), e.setEndpoints(E), e.markAsReady();
74
- }, W = (o, i, c) => {
75
- const n = i.profiling ?? "stats", r = performance.now(), l = o.map((e) => I(e, i));
76
- return n !== "off" && m.info(`Router analysis took ${Math.round(performance.now() - r)}ms`), n === "stats" ? l.map((e, t) => ({ fileName: o[t].fileName, timeTaken: e.timing })).sort((e, t) => t.timeTaken - e.timeTaken).filter((e) => e.timeTaken > 500).forEach((e) => {
77
- m.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`);
78
- }) : n === "debug" && l.map((e, t) => ({
79
- fileName: o[t].fileName,
80
- timeTaken: e.timing,
81
- endpointTimings: e.endpointTimings
82
- })).sort((e, t) => t.timeTaken - e.timeTaken).forEach((e) => {
83
- m.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`), e.endpointTimings.sort((t, s) => s.timing - t.timing).forEach((t) => {
84
- m.info(` - ${t.method} ${t.path} (${Math.round(t.timing)}ms)`), t.sectionTimings.filter((s) => s.timing >= 1).sort((s, u) => u.timing - s.timing).forEach((s) => {
85
- m.info(` - ${s.section}: ${Math.round(s.timing)}ms`);
89
+ }), t.setEndpoints(g), t.markAsReady();
90
+ }, D = async (m, i, p) => {
91
+ const c = i.profiling ?? "stats", n = performance.now(), f = [], t = [];
92
+ for (const e of m) {
93
+ const o = b(e.sourceFile, i.timestampCache), r = i.incremental ? P.getCachedResults(e.sourceFile, o, i.cachePath) : null;
94
+ r ? (u.debug(`[${e.fileName}] Found cached results`), f.push({ endpoints: r.endpoints, fileName: e.fileName, timing: 0, endpointTimings: [] })) : t.push({ file: e, timestamp: o });
95
+ }
96
+ if (t.length === 0)
97
+ return c !== "off" && u.info(`Router analysis took ${Math.round(performance.now() - n)}ms`), f.flatMap((e) => e.endpoints);
98
+ const a = t.map(({ file: e }) => ({
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();
115
+ for (const { file: e } of t)
116
+ N.set(e.fileName, { endpoints: [], fileName: e.fileName, timing: 0, endpointTimings: [] });
117
+ for (let e = 0; e < F.length; e++) {
118
+ const o = F[e], r = a[e].fileName, g = N.get(r);
119
+ if ("error" in o) {
120
+ u.error(`[${r}] Worker error: ${o.error}`);
121
+ continue;
122
+ }
123
+ g.endpoints = o.endpoints, g.endpointTimings = o.endpointTimings, g.timing = o.endpointTimings.reduce((s, y) => s + y.timing, 0);
124
+ }
125
+ for (const { file: e, timestamp: o } of t) {
126
+ const r = N.get(e.fileName);
127
+ r.endpoints.length > 0 && P.cacheResults(e.sourceFile, o, i.cachePath, r.endpoints);
128
+ }
129
+ const T = [...f, ...Array.from(N.values())];
130
+ return c !== "off" && u.info(`Router analysis took ${Math.round(performance.now() - n)}ms`), c === "stats" ? T.map((e) => ({ fileName: e.fileName, timeTaken: e.timing })).sort((e, o) => o.timeTaken - e.timeTaken).filter((e) => e.timeTaken > 500).forEach((e) => {
131
+ u.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`);
132
+ }) : c === "debug" && T.map((e) => ({ fileName: e.fileName, timeTaken: e.timing, endpointTimings: e.endpointTimings })).sort((e, o) => o.timeTaken - e.timeTaken).forEach((e) => {
133
+ u.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`), e.endpointTimings.sort((o, r) => r.timing - o.timing).forEach((o) => {
134
+ u.info(` - ${o.method} ${o.path} (${Math.round(o.timing)}ms)`), o.sectionTimings.filter((r) => r.timing >= 1).sort((r, g) => g.timing - r.timing).forEach((r) => {
135
+ u.info(` - ${r.section}: ${Math.round(r.timing)}ms`);
86
136
  });
87
137
  });
88
- }), l.flatMap((e) => e.endpoints);
89
- }, I = (o, i, c) => {
90
- const n = b(o.sourceFile, i.timestampCache), r = C.getCachedResults(o.sourceFile, n, i.cachePath);
91
- if (r)
92
- return m.debug(`[${o.fileName}] Found cached results`), { endpoints: r.endpoints, timing: 0, endpointTimings: [] };
93
- m.debug(`[${o.fileName}] Analyzing...`);
94
- const l = performance.now(), { endpoints: e, endpointTimings: t } = B(o), s = performance.now();
95
- return m.debug(`[${o.fileName}] Analyzed in ${s - l}ms`), C.cacheResults(o.sourceFile, n, i.cachePath, e), { endpoints: e, timing: s - l, endpointTimings: t };
96
- }, B = (o, i) => {
97
- const c = [], n = [], l = ["get", "post", "put", "delete", "del", "patch"].join("|");
98
- return o.routers.named.forEach((e) => {
99
- const t = new RegExp(`${e}\\.(?:${l})`);
100
- o.sourceFile.forEachChild((s) => {
101
- const u = s.getText();
102
- if (t.test(u)) {
103
- L(s);
104
- const x = performance.now(), { endpoint: h, sectionTimings: g } = K(s, o.fileName);
105
- n.push({
106
- method: h.method,
107
- path: h.path,
108
- timing: performance.now() - x,
109
- sectionTimings: g
110
- }), c.push(h);
111
- }
112
- });
113
- }), { endpoints: c, endpointTimings: n };
114
- }, V = (o) => {
115
- const i = N({
116
- sourceFile: o,
138
+ }), T.flatMap((e) => e.endpoints);
139
+ }, V = (m) => {
140
+ const i = E({
141
+ sourceFile: m,
117
142
  originalName: "useApiHeader"
118
143
  });
119
144
  if (!i)
120
145
  return null;
121
- const c = o.forEachChildAsArray().filter((e) => e.isKind(F.ExpressionStatement)).find((e) => i && e.getText().startsWith(i));
122
- if (!c)
146
+ const p = m.forEachChildAsArray().filter((t) => t.isKind(x.ExpressionStatement)).find((t) => i && t.getText().startsWith(i));
147
+ if (!p)
123
148
  return null;
124
- const n = c.getFirstDescendantByKindOrThrow(F.ObjectLiteralExpression), r = j(n), l = (e) => typeof e == "string" || Array.isArray(e) && e.every((t) => typeof t == "string") ? e : e.reduce((t, s) => typeof s == "string" ? t : {
125
- ...t,
126
- [s.identifier]: l(s.value)
149
+ const c = p.getFirstDescendantByKindOrThrow(x.ObjectLiteralExpression), n = W(c), f = (t) => typeof t == "string" || Array.isArray(t) && t.every((a) => typeof a == "string") ? t : t.reduce((a, h) => typeof h == "string" ? a : {
150
+ ...a,
151
+ [h.identifier]: f(h.value)
127
152
  }, {});
128
- return l(r);
129
- }, _ = (o) => {
130
- const i = [], c = N({
131
- sourceFile: o,
153
+ return f(n);
154
+ }, _ = (m) => {
155
+ const i = [], p = E({
156
+ sourceFile: m,
132
157
  originalName: "useExposeApiModel"
133
- }), n = N({
134
- sourceFile: o,
158
+ }), c = E({
159
+ sourceFile: m,
135
160
  originalName: "useExposeNamedApiModels"
136
161
  });
137
- return o.forEachChildAsArray().filter((r) => r.isKind(F.ExpressionStatement)).map((r) => {
138
- if (c && r.getText().startsWith(c)) {
139
- const t = (r.getFirstChild()?.getChildrenOfKind(F.SyntaxList) || [])[0].getFirstChild();
140
- if (!t)
162
+ return m.forEachChildAsArray().filter((n) => n.isKind(x.ExpressionStatement)).map((n) => {
163
+ if (p && n.getText().startsWith(p)) {
164
+ const a = (n.getFirstChild()?.getChildrenOfKind(x.SyntaxList) || [])[0].getFirstChild();
165
+ if (!a)
141
166
  return;
142
- i.push(H(t));
167
+ i.push(K(a));
143
168
  return;
144
169
  }
145
- if (n && r.getText().startsWith(n)) {
146
- const t = (r.getFirstChild()?.getChildrenOfKind(F.SyntaxList) || [])[0].getFirstChild();
147
- if (!t)
170
+ if (c && n.getText().startsWith(c)) {
171
+ const a = (n.getFirstChild()?.getChildrenOfKind(x.SyntaxList) || [])[0].getFirstChild();
172
+ if (!a)
148
173
  return;
149
- U(t).forEach((u) => i.push(u));
174
+ H(a).forEach((F) => i.push(F));
150
175
  }
151
176
  }), i;
152
177
  };
153
178
  export {
154
- W as analyzeMultipleSourceFiles,
179
+ D as analyzeMultipleSourceFiles,
155
180
  V as analyzeSourceFileApiHeader,
156
- B as analyzeSourceFileEndpoints,
157
181
  _ as analyzeSourceFileExposedModels,
158
- I as analyzeSourceFileWithCache,
159
- se as prepareOpenApiSpec
182
+ ae as prepareOpenApiSpec
160
183
  };
161
184
  //# sourceMappingURL=analyzerModule.mjs.map