moonflower 1.4.8 → 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.
- package/dist/openapi/analyzerModule/analyzerModule.cjs +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.cjs.map +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.d.ts +18 -3
- package/dist/openapi/analyzerModule/analyzerModule.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.mjs +168 -112
- package/dist/openapi/analyzerModule/analyzerModule.mjs.map +1 -1
- package/dist/openapi/analyzerModule/analyzerWorker.cjs +2 -0
- package/dist/openapi/analyzerModule/analyzerWorker.cjs.map +1 -0
- package/dist/openapi/analyzerModule/analyzerWorker.d.ts +2 -0
- package/dist/openapi/analyzerModule/analyzerWorker.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/analyzerWorker.mjs +44 -0
- package/dist/openapi/analyzerModule/analyzerWorker.mjs.map +1 -0
- package/dist/openapi/analyzerModule/nodeParsers.cjs +1 -1
- package/dist/openapi/analyzerModule/nodeParsers.cjs.map +1 -1
- package/dist/openapi/analyzerModule/nodeParsers.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/nodeParsers.mjs +199 -264
- package/dist/openapi/analyzerModule/nodeParsers.mjs.map +1 -1
- package/dist/openapi/analyzerModule/parseEndpoint.cjs +1 -1
- package/dist/openapi/analyzerModule/parseEndpoint.cjs.map +1 -1
- package/dist/openapi/analyzerModule/parseEndpoint.d.ts +8 -1
- package/dist/openapi/analyzerModule/parseEndpoint.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/parseEndpoint.mjs +121 -106
- package/dist/openapi/analyzerModule/parseEndpoint.mjs.map +1 -1
- package/dist/openapi/analyzerModule/test/TestCase.d.ts +1 -0
- package/dist/openapi/analyzerModule/test/TestCase.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/test/workerGlobalSetup.d.ts +3 -0
- package/dist/openapi/analyzerModule/test/workerGlobalSetup.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/workerPaths.d.ts +2 -0
- package/dist/openapi/analyzerModule/workerPaths.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/workerPool.cjs +2 -0
- package/dist/openapi/analyzerModule/workerPool.cjs.map +1 -0
- package/dist/openapi/analyzerModule/workerPool.d.ts +33 -0
- package/dist/openapi/analyzerModule/workerPool.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/workerPool.mjs +46 -0
- package/dist/openapi/analyzerModule/workerPool.mjs.map +1 -0
- package/package.json +1 -1
- package/src/openapi/analyzerModule/analyzerModule.ts +198 -25
- package/src/openapi/analyzerModule/analyzerWorker.ts +73 -0
- package/src/openapi/analyzerModule/nodeParsers.ts +4 -104
- package/src/openapi/analyzerModule/parseEndpoint.ts +31 -9
- package/src/openapi/analyzerModule/test/TestCase.ts +1 -0
- package/src/openapi/analyzerModule/test/openApiAnalyzer.spec.ts +2 -2
- package/src/openapi/analyzerModule/test/openApiAnalyzer.zod.spec.data.ts +6 -0
- package/src/openapi/analyzerModule/test/openApiAnalyzer.zod.spec.ts +9 -1
- package/src/openapi/analyzerModule/test/workerGlobalSetup.ts +25 -0
- package/src/openapi/analyzerModule/workerPaths.ts +4 -0
- package/src/openapi/analyzerModule/workerPool.ts +92 -0
- package/src/test/app.spec.ts +10 -1
- package/vite.config.ts +5 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("path"),
|
|
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 } 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}\n\ntype FileDiscoveryConfig = {\n\trootPath: string\n}\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}: 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\tLogger.info(`File discovery took ${Math.round(performance.now() - startTime)}ms`)\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})\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},\n\tfilterEndpointPaths?: string[],\n): EndpointData[] => {\n\tconst startTime = performance.now()\n\tconst analyzedFiles = files.map((file) => analyzeSourceFileWithCache(file, config, filterEndpointPaths))\n\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\n\tanalyzedFiles\n\t\t.map((f, index) => ({\n\t\t\tfileName: files[index].fileName,\n\t\t\ttimeTaken: f.timing,\n\t\t}))\n\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t.filter((t) => t.timeTaken > 500)\n\t\t.forEach((t) => {\n\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\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},\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; timing: number } => {\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 }\n\t}\n\tLogger.debug(`[${file.fileName}] Analyzing...`)\n\n\tconst t1 = performance.now()\n\tconst endpoints = 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 }\n}\n\nexport const analyzeSourceFileEndpoints = (\n\tfile: DiscoveredSourceFile,\n\tfilterEndpointPaths?: string[],\n): EndpointData[] => {\n\tconst endpoints: EndpointData[] = []\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\tendpoints.push(parseEndpoint(node, file.fileName))\n\t\t\t}\n\t\t})\n\t})\n\n\treturn endpoints\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","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","timestamp","getSourceFileTimestamp","cachedResults","SourceFileCache","t1","analyzeSourceFileEndpoints","t2","joinedOperations","routerName","routerPattern","node","nodeText","resolveEndpointPath","parseEndpoint","sourceFile","nameOfUseApiHeader","discoverImportedName","SyntaxKind","targetNode","values","getValuesOfObjectLiteral","collapseObject","v","value","models","nameOfUseExposeApiModel","nameOfUseExposeNamedApiModels","firstChild","parseExposedModel","parseNamedExposedModels","model"],"mappings":"82BAuCaA,EAAqB,CAAC,CAClC,SAAAC,EACA,aAAAC,EACA,gBAAAC,EACA,oBAAAC,EACA,YAAAC,CACD,IAAa,CACN,MAAAC,EAAiBC,iBAAe,YAAY,EAE9C,GAAAD,EAAe,UAClB,OAGGL,GACHO,EAAA,OAAO,SAASP,CAAQ,EAGzBO,EAAA,OAAO,KAAK,wBAAwB,EAE9B,MAAAC,EAAU,IAAIC,UAAQ,CAC3B,iBAAkBC,EAAK,QAAQT,CAAY,EAC3C,6BAA8B,EAAA,CAC9B,EAEK,CAAE,gBAAAU,EAAiB,sBAAAC,EAAuB,eAAAC,CAAA,GAAoB,IAAM,CAGnE,MAAAC,GAFmBZ,GAAmB,CAAC,GACI,IAAKa,GAAaL,E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Ac,EACvD,GAAI,CAACU,EACJ,OAGMH,EAAA,KAAKI,oBAAkBD,CAAU,CAAC,EACzC,MAAA,CAGD,GAAID,GAAiChB,EAAK,QAAU,EAAA,WAAWgB,CAA6B,EAAG,CAI9F,MAAMC,GAHqBjB,EAAK,cAAc,GACC,kBAAkBO,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,K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C5D,IAAKrB,GAAS,CACd,GAAI6B,GAA2B7B,EAAK,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"}
|
|
@@ -4,6 +4,7 @@ import { DiscoveredSourceFile } from '../discoveryModule/discoverRouterFiles/dis
|
|
|
4
4
|
import { ApiDocsHeader } from '../manager/OpenApiManager';
|
|
5
5
|
import { EndpointData, ExposedModelData } from '../types';
|
|
6
6
|
import { TimestampCache } from './getSourceFileTimestamp';
|
|
7
|
+
import { SectionTiming } from './parseEndpoint';
|
|
7
8
|
|
|
8
9
|
type Props = {
|
|
9
10
|
logLevel?: Parameters<(typeof Logger)['setLevel']>[0];
|
|
@@ -13,25 +14,39 @@ type Props = {
|
|
|
13
14
|
incremental?: boolean | {
|
|
14
15
|
cachePath: string;
|
|
15
16
|
};
|
|
17
|
+
profiling?: 'stats' | 'off' | 'debug';
|
|
16
18
|
};
|
|
17
19
|
type FileDiscoveryConfig = {
|
|
18
20
|
rootPath: string;
|
|
19
21
|
};
|
|
20
|
-
|
|
22
|
+
type EndpointTiming = {
|
|
23
|
+
method: string;
|
|
24
|
+
path: string;
|
|
25
|
+
timing: number;
|
|
26
|
+
sectionTimings: SectionTiming[];
|
|
27
|
+
};
|
|
28
|
+
export declare const prepareOpenApiSpec: ({ logLevel, tsconfigPath, sourceFilePaths, sourceFileDiscovery, incremental, profiling, }: Props) => Promise<void>;
|
|
21
29
|
export declare const analyzeMultipleSourceFiles: (files: DiscoveredSourceFile[], config: {
|
|
22
30
|
incremental: boolean;
|
|
23
31
|
cachePath: string;
|
|
24
32
|
timestampCache: TimestampCache;
|
|
25
|
-
|
|
33
|
+
profiling?: "stats" | "off" | "debug";
|
|
34
|
+
tsconfigPath: string;
|
|
35
|
+
}, filterEndpointPaths?: string[]) => Promise<EndpointData[]>;
|
|
26
36
|
export declare const analyzeSourceFileWithCache: (file: DiscoveredSourceFile, config: {
|
|
27
37
|
incremental: boolean;
|
|
28
38
|
cachePath: string;
|
|
29
39
|
timestampCache: TimestampCache;
|
|
40
|
+
profiling?: "stats" | "off" | "debug";
|
|
30
41
|
}, filterEndpointPaths?: string[]) => {
|
|
31
42
|
endpoints: EndpointData[];
|
|
32
43
|
timing: number;
|
|
44
|
+
endpointTimings: EndpointTiming[];
|
|
45
|
+
};
|
|
46
|
+
export declare const analyzeSourceFileEndpoints: (file: DiscoveredSourceFile, filterEndpointPaths?: string[]) => {
|
|
47
|
+
endpoints: EndpointData[];
|
|
48
|
+
endpointTimings: EndpointTiming[];
|
|
33
49
|
};
|
|
34
|
-
export declare const analyzeSourceFileEndpoints: (file: DiscoveredSourceFile, filterEndpointPaths?: string[]) => EndpointData[];
|
|
35
50
|
export declare const analyzeSourceFileApiHeader: (sourceFile: SourceFile) => ApiDocsHeader | null;
|
|
36
51
|
export declare const analyzeSourceFileExposedModels: (sourceFile: SourceFile) => ExposedModelData[];
|
|
37
52
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzerModule.d.ts","sourceRoot":"","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"analyzerModule.d.ts","sourceRoot":"","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"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AAE,cAAc,CAAA;IAC9B,SAAS,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO,CAAA;IACrC,YAAY,EAAE,MAAM,CAAA;CACpB,wBACqB,MAAM,EAAE,KAC5B,OAAO,CAAC,YAAY,EAAE,CAyJxB,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,UAClB;IACP,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,cAAc,CAAA;IAC9B,SAAS,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO,CAAA;CACrC,wBACqB,MAAM,EAAE,KAC5B;IAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,cAAc,EAAE,CAAA;CAgBhF,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,wBACJ,MAAM,EAAE,KAC5B;IAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAAC,eAAe,EAAE,cAAc,EAAE,CAAA;CAgChE,CAAA;AAED,eAAO,MAAM,0BAA0B,eAAgB,UAAU,KAAG,aAAa,GAAG,IAyCnF,CAAA;AAED,eAAO,MAAM,8BAA8B,eAAgB,UAAU,KAAG,gBAAgB,EA4CvF,CAAA"}
|
|
@@ -1,143 +1,199 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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";
|
|
11
|
+
import { getSourceFileTimestamp as b } from "./getSourceFileTimestamp.mjs";
|
|
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,
|
|
32
|
+
incremental: r,
|
|
33
|
+
profiling: f = "stats"
|
|
19
34
|
}) => {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
35
|
+
const i = U.getInstance();
|
|
36
|
+
if (i.isReady())
|
|
22
37
|
return;
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
tsConfigFilePath:
|
|
38
|
+
l && u.setLevel(l), u.info("Preparing OpenAPI spec");
|
|
39
|
+
const c = new j({
|
|
40
|
+
tsConfigFilePath: P.resolve(s),
|
|
26
41
|
skipFileDependencyResolution: !0
|
|
27
|
-
}), { explicitRouters:
|
|
28
|
-
const
|
|
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) => ({
|
|
29
44
|
fileName: p.getFilePath(),
|
|
30
45
|
sourceFile: p,
|
|
31
|
-
routers:
|
|
32
|
-
})), { discoveredRouterFiles:
|
|
33
|
-
if (
|
|
46
|
+
routers: z(p)
|
|
47
|
+
})), { discoveredRouterFiles: A, discoveredSourceFiles: C } = (() => {
|
|
48
|
+
if (m === !1)
|
|
34
49
|
return { discoveredRouterFiles: [], discoveredSourceFiles: [] };
|
|
35
|
-
const p = performance.now(),
|
|
36
|
-
targetPath: typeof
|
|
37
|
-
tsConfigPath:
|
|
50
|
+
const p = performance.now(), E = L({
|
|
51
|
+
targetPath: typeof m == "object" ? m.rootPath : ".",
|
|
52
|
+
tsConfigPath: s
|
|
38
53
|
});
|
|
39
|
-
return
|
|
40
|
-
})(),
|
|
41
|
-
(p,
|
|
42
|
-
|
|
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
|
|
43
58
|
);
|
|
44
|
-
return { explicitRouters:
|
|
45
|
-
})(),
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
),
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
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,
|
|
70
|
+
timestampCache: {},
|
|
71
|
+
profiling: f,
|
|
72
|
+
tsconfigPath: P.resolve(s)
|
|
55
73
|
});
|
|
56
|
-
|
|
57
|
-
discoveredRouterFiles:
|
|
58
|
-
path:
|
|
59
|
-
routers:
|
|
60
|
-
name:
|
|
61
|
-
endpoints:
|
|
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}`)
|
|
62
80
|
}))
|
|
63
81
|
})),
|
|
64
|
-
explicitRouterFiles:
|
|
65
|
-
path:
|
|
66
|
-
routers:
|
|
67
|
-
name:
|
|
68
|
-
endpoints:
|
|
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}`)
|
|
69
87
|
}))
|
|
70
88
|
}))
|
|
71
|
-
}),
|
|
72
|
-
},
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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++);
|
|
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
|
|
138
|
+
});
|
|
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
|
+
});
|
|
94
152
|
});
|
|
95
|
-
}),
|
|
96
|
-
},
|
|
97
|
-
const
|
|
98
|
-
sourceFile:
|
|
153
|
+
}), T.flatMap((e) => e.endpoints);
|
|
154
|
+
}, V = (l) => {
|
|
155
|
+
const s = M({
|
|
156
|
+
sourceFile: l,
|
|
99
157
|
originalName: "useApiHeader"
|
|
100
158
|
});
|
|
101
|
-
if (!
|
|
159
|
+
if (!s)
|
|
102
160
|
return null;
|
|
103
|
-
const
|
|
104
|
-
if (!
|
|
161
|
+
const d = l.forEachChildAsArray().filter((i) => i.isKind(x.ExpressionStatement)).find((i) => s && i.getText().startsWith(s));
|
|
162
|
+
if (!d)
|
|
105
163
|
return null;
|
|
106
|
-
const
|
|
107
|
-
...
|
|
108
|
-
[
|
|
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)
|
|
109
167
|
}, {});
|
|
110
|
-
return
|
|
111
|
-
},
|
|
112
|
-
const
|
|
113
|
-
sourceFile:
|
|
168
|
+
return f(r);
|
|
169
|
+
}, _ = (l) => {
|
|
170
|
+
const s = [], d = M({
|
|
171
|
+
sourceFile: l,
|
|
114
172
|
originalName: "useExposeApiModel"
|
|
115
|
-
}),
|
|
116
|
-
sourceFile:
|
|
173
|
+
}), m = M({
|
|
174
|
+
sourceFile: l,
|
|
117
175
|
originalName: "useExposeNamedApiModels"
|
|
118
176
|
});
|
|
119
|
-
return
|
|
120
|
-
if (
|
|
121
|
-
const
|
|
122
|
-
if (!
|
|
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)
|
|
123
181
|
return;
|
|
124
|
-
|
|
182
|
+
s.push(I(c));
|
|
125
183
|
return;
|
|
126
184
|
}
|
|
127
|
-
if (
|
|
128
|
-
const
|
|
129
|
-
if (!
|
|
185
|
+
if (m && r.getText().startsWith(m)) {
|
|
186
|
+
const c = (r.getFirstChild()?.getChildrenOfKind(x.SyntaxList) || [])[0].getFirstChild();
|
|
187
|
+
if (!c)
|
|
130
188
|
return;
|
|
131
|
-
|
|
189
|
+
K(c).forEach((g) => s.push(g));
|
|
132
190
|
}
|
|
133
|
-
}),
|
|
191
|
+
}), s;
|
|
134
192
|
};
|
|
135
193
|
export {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
W as analyzeSourceFileWithCache,
|
|
141
|
-
oe as prepareOpenApiSpec
|
|
194
|
+
D as analyzeMultipleSourceFiles,
|
|
195
|
+
V as analyzeSourceFileApiHeader,
|
|
196
|
+
_ as analyzeSourceFileExposedModels,
|
|
197
|
+
ae as prepareOpenApiSpec
|
|
142
198
|
};
|
|
143
199
|
//# sourceMappingURL=analyzerModule.mjs.map
|