moonflower 1.4.9 → 1.5.0

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 +163 -125
  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 +44 -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 +33 -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 +142 -12
  32. package/src/openapi/analyzerModule/analyzerWorker.ts +73 -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 +92 -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"),F=require("ts-morph"),f=require("../../utils/logger.cjs"),E=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"),A=require("./sourceFileCache.cjs"),D=require("./workerPool.cjs");var R=typeof document<"u"?document.currentScript:null;function B(s){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(i,n,a.get?a:{enumerable:!0,get:()=>s[n]})}}return i.default=s,Object.freeze(i)}const M=B(z);function V(){const s=["./analyzerWorker.mjs","./analyzerWorker.test.mjs"];for(const i of s){const n=new URL(i,typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("openapi/analyzerModule/analyzerModule.cjs",document.baseURI).href);if(q.existsSync(U.fileURLToPath(n)))return n}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:i,sourceFilePaths:n,sourceFileDiscovery:a,incremental:l,profiling:m="stats"})=>{const r=W.OpenApiManager.getInstance();if(r.isReady())return;s&&f.Logger.setLevel(s),f.Logger.info("Preparing OpenAPI spec");const p=new F.Project({tsConfigFilePath:M.resolve(i),skipFileDependencyResolution:!0}),{explicitRouters:h,discoveredRouterFiles:g,allSourceFiles:N}=(()=>{const d=(n??[]).map(u=>M.resolve(u)).map(u=>p.getSourceFileOrThrow(u)),P=d.flatMap(u=>({fileName:u.getFilePath(),sourceFile:u,routers:K.discoverRouters(u)})),{discoveredRouterFiles:w,discoveredSourceFiles:L}=(()=>{if(a===!1)return{discoveredRouterFiles:[],discoveredSourceFiles:[]};const u=performance.now(),S=I.discoverRouterFiles({targetPath:typeof a=="object"?a.rootPath:".",tsConfigPath:i});return m!=="off"&&f.Logger.info(`File discovery took ${Math.round(performance.now()-u)}ms`),S})(),$=d.reduce((u,S)=>u.some(b=>b.getFilePath()===S.getFilePath())?u:u.concat(S),L);return{explicitRouters:P,discoveredRouterFiles:w,allSourceFiles:$}})(),T=h.reduce((t,c)=>t.some(d=>d.fileName===c.fileName)?t:t.concat(c),g),y=N.flatMap(t=>O(t)).filter(t=>!!t);y.length>0&&y[0]&&r.setHeader(y[0]);const x=N.flatMap(t=>v(t));r.setExposedModels(x);const e=typeof l=="object"&&l.cachePath?l.cachePath:M.resolve(process.cwd(),"node_modules",".cache","moonflower"),o=await C(T,{incremental:l!==!1,cachePath:e,timestampCache:{},profiling:m,tsconfigPath:M.resolve(i)});r.setStats({discoveredRouterFiles:g.map(t=>({path:t.fileName,routers:t.routers.named.map(c=>({name:c,endpoints:o.filter(d=>d.sourceFilePath===t.fileName).map(d=>`${d.method.toUpperCase()} ${d.path}`)}))})),explicitRouterFiles:h.map(t=>({path:t.fileName,routers:t.routers.named.map(c=>({name:c,endpoints:o.filter(d=>d.sourceFilePath===t.fileName).map(d=>`${d.method.toUpperCase()} ${d.path}`)}))}))}),r.setEndpoints(o),r.markAsReady()},C=async(s,i,n)=>{const a=i.profiling??"stats",l=performance.now(),m=[],r=[];for(const e of s){const o=_.getSourceFileTimestamp(e.sourceFile,i.timestampCache),t=i.incremental?A.SourceFileCache.getCachedResults(e.sourceFile,o,i.cachePath):null;t?(f.Logger.debug(`[${e.fileName}] Found cached results`),m.push({endpoints:t.endpoints,fileName:e.fileName,timing:0,endpointTimings:[]})):r.push({file:e,timestamp:o})}if(r.length===0)return a!=="off"&&f.Logger.info(`Router analysis took ${Math.round(performance.now()-l)}ms`),m.flatMap(e=>e.endpoints);const h=["get","post","put","delete","del","patch"].join("|"),g=[];for(const{file:e}of r)for(const o of e.routers.named){const t=new RegExp(`${o}\\.(?:${h})`);let c=0;e.sourceFile.forEachChild(d=>{const P=d.getText();t.test(P)&&(g.push({fileName:e.fileName,task:{taskId:j.randomUUID(),tsconfigPath:i.tsconfigPath,sourceFilePath:e.sourceFile.getFilePath(),routerName:o,endpointIndex:c}}),c++)})}const N=new D.WorkerPool(V());let T;try{T=await N.runAll(g.map(e=>e.task))}finally{N.terminate()}const y=new Map;for(const{file:e}of r)y.set(e.fileName,{endpoints:[],fileName:e.fileName,timing:0,endpointTimings:[]});for(let e=0;e<T.length;e++){const o=T[e],t=g[e].fileName,c=y.get(t);if("error"in o){f.Logger.error(`[${t}] Worker error: ${o.error}`);continue}c.endpoints.push(o.endpoint),c.timing+=o.timing,c.endpointTimings.push({method:o.endpoint.method,path:o.endpoint.path,timing:o.timing,sectionTimings:o.sectionTimings})}for(const{file:e,timestamp:o}of r){const t=y.get(e.fileName);t.endpoints.length>0&&A.SourceFileCache.cacheResults(e.sourceFile,o,i.cachePath,t.endpoints)}const x=[...m,...Array.from(y.values())];return a!=="off"&&f.Logger.info(`Router analysis took ${Math.round(performance.now()-l)}ms`),a==="stats"?x.map(e=>({fileName:e.fileName,timeTaken:e.timing})).sort((e,o)=>o.timeTaken-e.timeTaken).filter(e=>e.timeTaken>500).forEach(e=>{f.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`)}):a==="debug"&&x.map(e=>({fileName:e.fileName,timeTaken:e.timing,endpointTimings:e.endpointTimings})).sort((e,o)=>o.timeTaken-e.timeTaken).forEach(e=>{f.Logger.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`),e.endpointTimings.sort((o,t)=>t.timing-o.timing).forEach(o=>{f.Logger.info(` - ${o.method} ${o.path} (${Math.round(o.timing)}ms)`),o.sectionTimings.filter(t=>t.timing>=1).sort((t,c)=>c.timing-t.timing).forEach(t=>{f.Logger.info(` - ${t.section}: ${Math.round(t.timing)}ms`)})})}),x.flatMap(e=>e.endpoints)},O=s=>{const i=E.discoverImportedName({sourceFile:s,originalName:"useApiHeader"});if(!i)return null;const n=s.forEachChildAsArray().filter(r=>r.isKind(F.SyntaxKind.ExpressionStatement)).find(r=>i&&r.getText().startsWith(i));if(!n)return null;const a=n.getFirstDescendantByKindOrThrow(F.SyntaxKind.ObjectLiteralExpression),l=H.getValuesOfObjectLiteral(a),m=r=>typeof r=="string"||Array.isArray(r)&&r.every(p=>typeof p=="string")?r:r.reduce((p,h)=>typeof h=="string"?p:{...p,[h.identifier]:m(h.value)},{});return m(l)},v=s=>{const i=[],n=E.discoverImportedName({sourceFile:s,originalName:"useExposeApiModel"}),a=E.discoverImportedName({sourceFile:s,originalName:"useExposeNamedApiModels"});return s.forEachChildAsArray().filter(l=>l.isKind(F.SyntaxKind.ExpressionStatement)).map(l=>{if(n&&l.getText().startsWith(n)){const p=(l.getFirstChild()?.getChildrenOfKind(F.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!p)return;i.push(k.parseExposedModel(p));return}if(a&&l.getText().startsWith(a)){const p=(l.getFirstChild()?.getChildrenOfKind(F.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!p)return;k.parseNamedExposedModels(p).forEach(g=>i.push(g))}}),i};exports.analyzeMultipleSourceFiles=C;exports.analyzeSourceFileApiHeader=O;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,GA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KAAKI,oBAAkBD,CAAU,CAAC,EACzC,MAAA,CAGD,GAAID,GAAiClB,EAAK,QAAU,EAAA,WAAWkB,CAA6B,EAAG,CAI9F,MAAMC,GAHqBnB,EAAK,cAAc,GACC,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 endpoint across all uncached files\n\tconst OPERATIONS = ['get', 'post', 'put', 'delete', 'del', 'patch']\n\tconst operationsPattern = OPERATIONS.join('|')\n\n\ttype FileTask = { task: WorkerTask; fileName: string }\n\tconst allTasks: FileTask[] = []\n\n\tfor (const { file } of uncached) {\n\t\tfor (const routerName of file.routers.named) {\n\t\t\tconst routerPattern = new RegExp(`${routerName}\\\\.(?:${operationsPattern})`)\n\t\t\tlet endpointIndex = 0\n\t\t\tfile.sourceFile.forEachChild((node) => {\n\t\t\t\tconst nodeText = node.getText()\n\t\t\t\tif (routerPattern.test(nodeText)) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!filterEndpointPaths ||\n\t\t\t\t\t\tfilterEndpointPaths.some((p) => resolveEndpointPath(node)?.includes(p))\n\t\t\t\t\t) {\n\t\t\t\t\t\tallTasks.push({\n\t\t\t\t\t\t\tfileName: file.fileName,\n\t\t\t\t\t\t\ttask: {\n\t\t\t\t\t\t\t\ttaskId: crypto.randomUUID(),\n\t\t\t\t\t\t\t\ttsconfigPath: config.tsconfigPath,\n\t\t\t\t\t\t\t\tsourceFilePath: file.sourceFile.getFilePath(),\n\t\t\t\t\t\t\t\trouterName,\n\t\t\t\t\t\t\t\tendpointIndex,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tendpointIndex++\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n\n\t// Dispatch all tasks to the worker pool\n\tconst pool = new WorkerPool(resolveWorkerUrl())\n\n\ttype EndpointTiming = { method: string; path: string; timing: number; sectionTimings: SectionTiming[] }\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// Group results by file\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.push(result.endpoint)\n\t\tfileResult.timing += result.timing\n\t\tfileResult.endpointTimings.push({\n\t\t\tmethod: result.endpoint.method,\n\t\t\tpath: result.endpoint.path,\n\t\t\ttiming: result.timing,\n\t\t\tsectionTimings: result.sectionTimings,\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","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","operationsPattern","allTasks","routerName","routerPattern","endpointIndex","node","nodeText","crypto","pool","WorkerPool","results","ft","byFile","i","result","fileName","fileResult","analyzedFiles","a","b","t","ep","s","sourceFile","nameOfUseApiHeader","discoverImportedName","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,EAA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QAAU,EAAA,WAAW6B,CAAuB,EAAG,CAIlF,MAAME,GAHqB/B,EAAK,cAAc,GACC,kBAAkBqB,EAAAA,WAAW,UAAU,GAAK,CAAC,GAEtD,CAAC,EAAE,cAAc,EACvD,GAAI,CAACU,EACJ,OAGMH,EAAA,KAAKI,oBAAkBD,CAAU,CAAC,EACzC,MAAA,CAGD,GAAID,GAAiC9B,EAAK,QAAU,EAAA,WAAW8B,CAA6B,EAAG,CAI9F,MAAMC,GAHqB/B,EAAK,cAAc,GACC,kBAAkBqB,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.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UA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E,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,199 @@
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 w from "crypto";
2
+ import { existsSync as O } from "fs";
3
+ import * as P from "path";
4
+ import { fileURLToPath as v } from "url";
5
+ import { Project as j, SyntaxKind as x } from "ts-morph";
6
+ import { Logger as u } from "../../utils/logger.mjs";
7
+ import { discoverImportedName as M } from "../discoveryModule/discoverImports/discoverImports.mjs";
8
+ import { discoverRouterFiles as L } 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,
15
- tsconfigPath: i,
16
- sourceFilePaths: c,
17
- sourceFileDiscovery: n,
12
+ import { getValuesOfObjectLiteral as W } from "./nodeParsers.mjs";
13
+ import { parseExposedModel as I, parseNamedExposedModels as K } from "./parseExposedModels.mjs";
14
+ import { SourceFileCache as R } from "./sourceFileCache.mjs";
15
+ import { WorkerPool as H } from "./workerPool.mjs";
16
+ function B() {
17
+ const l = ["./analyzerWorker.mjs", "./analyzerWorker.test.mjs"];
18
+ for (const s of l) {
19
+ const d = new URL(s, import.meta.url);
20
+ if (O(v(d)))
21
+ return d;
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: l,
29
+ tsconfigPath: s,
30
+ sourceFilePaths: d,
31
+ sourceFileDiscovery: m,
18
32
  incremental: r,
19
- profiling: l = "stats"
33
+ profiling: f = "stats"
20
34
  }) => {
21
- const e = z.getInstance();
22
- if (e.isReady())
35
+ const i = U.getInstance();
36
+ if (i.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
+ l && u.setLevel(l), u.info("Preparing OpenAPI spec");
39
+ const c = new j({
40
+ tsConfigFilePath: P.resolve(s),
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) => ({
30
- fileName: d.getFilePath(),
31
- sourceFile: d,
32
- routers: w(d)
33
- })), { discoveredRouterFiles: S, discoveredSourceFiles: $ } = (() => {
34
- if (n === !1)
42
+ }), { explicitRouters: h, discoveredRouterFiles: g, allSourceFiles: y } = (() => {
43
+ const a = (d ?? []).map((p) => P.resolve(p)).map((p) => c.getSourceFileOrThrow(p)), k = a.flatMap((p) => ({
44
+ fileName: p.getFilePath(),
45
+ sourceFile: p,
46
+ routers: z(p)
47
+ })), { discoveredRouterFiles: A, discoveredSourceFiles: C } = (() => {
48
+ if (m === !1)
35
49
  return { discoveredRouterFiles: [], discoveredSourceFiles: [] };
36
- const d = performance.now(), y = v({
37
- targetPath: typeof n == "object" ? n.rootPath : ".",
38
- tsConfigPath: i
50
+ const p = performance.now(), E = L({
51
+ targetPath: typeof m == "object" ? m.rootPath : ".",
52
+ tsConfigPath: s
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() - p)}ms`), E;
55
+ })(), S = a.reduce(
56
+ (p, E) => p.some(($) => $.getFilePath() === E.getFilePath()) ? p : p.concat(E),
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: k, discoveredRouterFiles: A, allSourceFiles: S };
60
+ })(), N = h.reduce(
61
+ (t, n) => t.some((a) => a.fileName === n.fileName) ? t : t.concat(n),
62
+ g
63
+ ), F = y.flatMap((t) => V(t)).filter((t) => !!t);
64
+ F.length > 0 && F[0] && i.setHeader(F[0]);
65
+ const T = y.flatMap((t) => _(t));
66
+ i.setExposedModels(T);
67
+ const e = typeof r == "object" && r.cachePath ? r.cachePath : P.resolve(process.cwd(), "node_modules", ".cache", "moonflower"), o = await D(N, {
68
+ incremental: r !== !1,
69
+ cachePath: e,
55
70
  timestampCache: {},
56
- profiling: l
71
+ profiling: f,
72
+ tsconfigPath: P.resolve(s)
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
+ i.setStats({
75
+ discoveredRouterFiles: g.map((t) => ({
76
+ path: t.fileName,
77
+ routers: t.routers.named.map((n) => ({
78
+ name: n,
79
+ endpoints: o.filter((a) => a.sourceFilePath === t.fileName).map((a) => `${a.method.toUpperCase()} ${a.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((t) => ({
83
+ path: t.fileName,
84
+ routers: t.routers.named.map((n) => ({
85
+ name: n,
86
+ endpoints: o.filter((a) => a.sourceFilePath === t.fileName).map((a) => `${a.method.toUpperCase()} ${a.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
+ }), i.setEndpoints(o), i.markAsReady();
90
+ }, D = async (l, s, d) => {
91
+ const m = s.profiling ?? "stats", r = performance.now(), f = [], i = [];
92
+ for (const e of l) {
93
+ const o = b(e.sourceFile, s.timestampCache), t = s.incremental ? R.getCachedResults(e.sourceFile, o, s.cachePath) : null;
94
+ t ? (u.debug(`[${e.fileName}] Found cached results`), f.push({ endpoints: t.endpoints, fileName: e.fileName, timing: 0, endpointTimings: [] })) : i.push({ file: e, timestamp: o });
95
+ }
96
+ if (i.length === 0)
97
+ return m !== "off" && u.info(`Router analysis took ${Math.round(performance.now() - r)}ms`), f.flatMap((e) => e.endpoints);
98
+ const h = ["get", "post", "put", "delete", "del", "patch"].join("|"), g = [];
99
+ for (const { file: e } of i)
100
+ for (const o of e.routers.named) {
101
+ const t = new RegExp(`${o}\\.(?:${h})`);
102
+ let n = 0;
103
+ e.sourceFile.forEachChild((a) => {
104
+ const k = a.getText();
105
+ t.test(k) && (g.push({
106
+ fileName: e.fileName,
107
+ task: {
108
+ taskId: w.randomUUID(),
109
+ tsconfigPath: s.tsconfigPath,
110
+ sourceFilePath: e.sourceFile.getFilePath(),
111
+ routerName: o,
112
+ endpointIndex: n
113
+ }
114
+ }), n++);
86
115
  });
116
+ }
117
+ const y = new H(B());
118
+ let N;
119
+ try {
120
+ N = await y.runAll(g.map((e) => e.task));
121
+ } finally {
122
+ y.terminate();
123
+ }
124
+ const F = /* @__PURE__ */ new Map();
125
+ for (const { file: e } of i)
126
+ F.set(e.fileName, { endpoints: [], fileName: e.fileName, timing: 0, endpointTimings: [] });
127
+ for (let e = 0; e < N.length; e++) {
128
+ const o = N[e], t = g[e].fileName, n = F.get(t);
129
+ if ("error" in o) {
130
+ u.error(`[${t}] Worker error: ${o.error}`);
131
+ continue;
132
+ }
133
+ n.endpoints.push(o.endpoint), n.timing += o.timing, n.endpointTimings.push({
134
+ method: o.endpoint.method,
135
+ path: o.endpoint.path,
136
+ timing: o.timing,
137
+ sectionTimings: o.sectionTimings
87
138
  });
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
- }
139
+ }
140
+ for (const { file: e, timestamp: o } of i) {
141
+ const t = F.get(e.fileName);
142
+ t.endpoints.length > 0 && R.cacheResults(e.sourceFile, o, s.cachePath, t.endpoints);
143
+ }
144
+ const T = [...f, ...Array.from(F.values())];
145
+ return m !== "off" && u.info(`Router analysis took ${Math.round(performance.now() - r)}ms`), m === "stats" ? T.map((e) => ({ fileName: e.fileName, timeTaken: e.timing })).sort((e, o) => o.timeTaken - e.timeTaken).filter((e) => e.timeTaken > 500).forEach((e) => {
146
+ u.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`);
147
+ }) : m === "debug" && T.map((e) => ({ fileName: e.fileName, timeTaken: e.timing, endpointTimings: e.endpointTimings })).sort((e, o) => o.timeTaken - e.timeTaken).forEach((e) => {
148
+ u.info(`- [${e.fileName}] Took ${Math.round(e.timeTaken)}ms to analyze`), e.endpointTimings.sort((o, t) => t.timing - o.timing).forEach((o) => {
149
+ u.info(` - ${o.method} ${o.path} (${Math.round(o.timing)}ms)`), o.sectionTimings.filter((t) => t.timing >= 1).sort((t, n) => n.timing - t.timing).forEach((t) => {
150
+ u.info(` - ${t.section}: ${Math.round(t.timing)}ms`);
151
+ });
112
152
  });
113
- }), { endpoints: c, endpointTimings: n };
114
- }, V = (o) => {
115
- const i = N({
116
- sourceFile: o,
153
+ }), T.flatMap((e) => e.endpoints);
154
+ }, V = (l) => {
155
+ const s = M({
156
+ sourceFile: l,
117
157
  originalName: "useApiHeader"
118
158
  });
119
- if (!i)
159
+ if (!s)
120
160
  return null;
121
- const c = o.forEachChildAsArray().filter((e) => e.isKind(F.ExpressionStatement)).find((e) => i && e.getText().startsWith(i));
122
- if (!c)
161
+ const d = l.forEachChildAsArray().filter((i) => i.isKind(x.ExpressionStatement)).find((i) => s && i.getText().startsWith(s));
162
+ if (!d)
123
163
  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)
164
+ const m = d.getFirstDescendantByKindOrThrow(x.ObjectLiteralExpression), r = W(m), f = (i) => typeof i == "string" || Array.isArray(i) && i.every((c) => typeof c == "string") ? i : i.reduce((c, h) => typeof h == "string" ? c : {
165
+ ...c,
166
+ [h.identifier]: f(h.value)
127
167
  }, {});
128
- return l(r);
129
- }, _ = (o) => {
130
- const i = [], c = N({
131
- sourceFile: o,
168
+ return f(r);
169
+ }, _ = (l) => {
170
+ const s = [], d = M({
171
+ sourceFile: l,
132
172
  originalName: "useExposeApiModel"
133
- }), n = N({
134
- sourceFile: o,
173
+ }), m = M({
174
+ sourceFile: l,
135
175
  originalName: "useExposeNamedApiModels"
136
176
  });
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)
177
+ return l.forEachChildAsArray().filter((r) => r.isKind(x.ExpressionStatement)).map((r) => {
178
+ if (d && r.getText().startsWith(d)) {
179
+ const c = (r.getFirstChild()?.getChildrenOfKind(x.SyntaxList) || [])[0].getFirstChild();
180
+ if (!c)
141
181
  return;
142
- i.push(H(t));
182
+ s.push(I(c));
143
183
  return;
144
184
  }
145
- if (n && r.getText().startsWith(n)) {
146
- const t = (r.getFirstChild()?.getChildrenOfKind(F.SyntaxList) || [])[0].getFirstChild();
147
- if (!t)
185
+ if (m && r.getText().startsWith(m)) {
186
+ const c = (r.getFirstChild()?.getChildrenOfKind(x.SyntaxList) || [])[0].getFirstChild();
187
+ if (!c)
148
188
  return;
149
- U(t).forEach((u) => i.push(u));
189
+ K(c).forEach((g) => s.push(g));
150
190
  }
151
- }), i;
191
+ }), s;
152
192
  };
153
193
  export {
154
- W as analyzeMultipleSourceFiles,
194
+ D as analyzeMultipleSourceFiles,
155
195
  V as analyzeSourceFileApiHeader,
156
- B as analyzeSourceFileEndpoints,
157
196
  _ as analyzeSourceFileExposedModels,
158
- I as analyzeSourceFileWithCache,
159
- se as prepareOpenApiSpec
197
+ ae as prepareOpenApiSpec
160
198
  };
161
199
  //# sourceMappingURL=analyzerModule.mjs.map