moonflower 0.10.6 → 0.11.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 (77) hide show
  1. package/cli/prettyprint.ts +4 -3
  2. package/dist/cli/prettyprint.d.ts.map +1 -1
  3. package/dist/cli/prettyprint.js +4 -3
  4. package/dist/src/errors/BaseHttpError.d.ts.map +1 -1
  5. package/dist/src/hooks/useCookieParams.js +1 -1
  6. package/dist/src/hooks/useHeaderParams.js +1 -1
  7. package/dist/src/hooks/usePathParams.js +1 -1
  8. package/dist/src/hooks/useQueryParams.js +1 -1
  9. package/dist/src/hooks/useRequestBody.js +1 -1
  10. package/dist/src/hooks/useRequestRawBody.js +1 -1
  11. package/dist/src/openapi/analyzerModule/analyzerModule.d.ts +20 -1
  12. package/dist/src/openapi/analyzerModule/analyzerModule.d.ts.map +1 -1
  13. package/dist/src/openapi/analyzerModule/analyzerModule.js +53 -9
  14. package/dist/src/openapi/analyzerModule/getSourceFileTimestamp.d.ts +6 -0
  15. package/dist/src/openapi/analyzerModule/getSourceFileTimestamp.d.ts.map +1 -0
  16. package/dist/src/openapi/analyzerModule/getSourceFileTimestamp.js +49 -0
  17. package/dist/src/openapi/analyzerModule/nodeParsers.d.ts.map +1 -1
  18. package/dist/src/openapi/analyzerModule/nodeParsers.js +15 -0
  19. package/dist/src/openapi/analyzerModule/parseEndpoint.d.ts.map +1 -1
  20. package/dist/src/openapi/analyzerModule/parseEndpoint.js +9 -8
  21. package/dist/src/openapi/analyzerModule/parseExposedModels.d.ts.map +1 -1
  22. package/dist/src/openapi/analyzerModule/sourceFileCache.d.ts +10 -0
  23. package/dist/src/openapi/analyzerModule/sourceFileCache.d.ts.map +1 -0
  24. package/dist/src/openapi/analyzerModule/sourceFileCache.js +67 -0
  25. package/dist/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.js +1 -1
  26. package/dist/src/openapi/generatorModule/generateComponentSchemas.d.ts.map +1 -1
  27. package/dist/src/openapi/generatorModule/generatePaths.d.ts.map +1 -1
  28. package/dist/src/openapi/generatorModule/generatePaths.js +4 -1
  29. package/dist/src/openapi/generatorModule/getSchema.d.ts.map +1 -1
  30. package/dist/src/openapi/generatorModule/getSchema.js +3 -0
  31. package/dist/src/utils/TypeUtils.d.ts.map +1 -1
  32. package/dist/src/utils/logger.d.ts +10 -0
  33. package/dist/src/utils/logger.d.ts.map +1 -0
  34. package/dist/src/utils/logger.js +73 -0
  35. package/dist/src/validators/types.d.ts.map +1 -1
  36. package/dist/tsconfig.build.tsbuildinfo +1 -1
  37. package/eslint.config.mjs +42 -0
  38. package/package.json +1 -1
  39. package/src/errors/BaseHttpError.ts +4 -1
  40. package/src/hooks/authentication/useAuth.ts +1 -1
  41. package/src/hooks/authentication/useOptionalAuth.ts +1 -1
  42. package/src/hooks/useCookieParams.ts +4 -4
  43. package/src/hooks/useExposeApiModel/useExposeApiModel.spec.data.ts +2 -0
  44. package/src/hooks/useHeaderParams.ts +4 -4
  45. package/src/hooks/usePathParams.ts +5 -5
  46. package/src/hooks/useQueryParams.ts +4 -4
  47. package/src/hooks/useRequestBody.spec.ts +4 -0
  48. package/src/hooks/useRequestBody.ts +5 -5
  49. package/src/hooks/useRequestRawBody.spec.ts +7 -7
  50. package/src/hooks/useRequestRawBody.ts +2 -2
  51. package/src/hooks/useReturnValue.ts +1 -1
  52. package/src/openapi/analyzerModule/analyzerModule.ts +91 -11
  53. package/src/openapi/analyzerModule/getSourceFileTimestamp.ts +59 -0
  54. package/src/openapi/analyzerModule/nodeParsers.ts +26 -9
  55. package/src/openapi/analyzerModule/parseEndpoint.ts +17 -15
  56. package/src/openapi/analyzerModule/parseExposedModels.ts +0 -1
  57. package/src/openapi/analyzerModule/sourceFileCache.ts +84 -0
  58. package/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.ts +6 -6
  59. package/src/openapi/analyzerModule/test/openApiAnalyzer.spec.ts +3 -4
  60. package/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts +4 -4
  61. package/src/openapi/discoveryModule/discoverRouters/discoverRouters.ts +3 -3
  62. package/src/openapi/generatorModule/generateComponentSchemas.ts +0 -1
  63. package/src/openapi/generatorModule/generatePaths.ts +4 -2
  64. package/src/openapi/generatorModule/getSchema.ts +3 -0
  65. package/src/openapi/generatorModule/test/openApiGenerator.spec.ts +5 -5
  66. package/src/openapi/manager/OpenApiManager.ts +2 -2
  67. package/src/router/Router.ts +8 -8
  68. package/src/test/app.ts +2 -2
  69. package/src/utils/TypeUtils.ts +15 -15
  70. package/src/utils/logger.ts +71 -0
  71. package/src/utils/mockContext.ts +6 -6
  72. package/src/utils/printers.spec.ts +5 -5
  73. package/src/utils/validationMessages.ts +2 -2
  74. package/src/validators/InternalParamWrappers.ts +1 -1
  75. package/src/validators/ParamWrappers.ts +3 -3
  76. package/src/validators/types.ts +2 -2
  77. package/.eslintrc.js +0 -26
@@ -1,4 +1,5 @@
1
1
  import { ApiAnalysisStats } from '../src/openapi/manager/OpenApiManager'
2
+ import { Logger } from '../src/utils/logger'
2
3
 
3
4
  export const printAnalysisStats = (stats: ApiAnalysisStats) => {
4
5
  stats.explicitRouterFiles.forEach((file) => printRouterFile(file))
@@ -6,11 +7,11 @@ export const printAnalysisStats = (stats: ApiAnalysisStats) => {
6
7
  }
7
8
 
8
9
  export const printRouterFile = (file: ApiAnalysisStats['discoveredRouterFiles'][number]) => {
9
- console.info(`${file.path}`)
10
+ Logger.info(`${file.path}`)
10
11
  file.routers.forEach((r) => {
11
- console.info(`└ ${r.name}`)
12
+ Logger.info(`└ ${r.name}`)
12
13
  r.endpoints.forEach((e) => {
13
- console.info(` └ ${e}`)
14
+ Logger.info(` └ ${e}`)
14
15
  })
15
16
  })
16
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prettyprint.d.ts","sourceRoot":"","sources":["../../cli/prettyprint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAA;AAExE,eAAO,MAAM,kBAAkB,UAAW,gBAAgB,SAGzD,CAAA;AAED,eAAO,MAAM,eAAe,SAAU,gBAAgB,CAAC,uBAAuB,CAAC,CAAC,MAAM,CAAC,SAQtF,CAAA"}
1
+ {"version":3,"file":"prettyprint.d.ts","sourceRoot":"","sources":["../../cli/prettyprint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAA;AAGxE,eAAO,MAAM,kBAAkB,UAAW,gBAAgB,SAGzD,CAAA;AAED,eAAO,MAAM,eAAe,SAAU,gBAAgB,CAAC,uBAAuB,CAAC,CAAC,MAAM,CAAC,SAQtF,CAAA"}
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printRouterFile = exports.printAnalysisStats = void 0;
4
+ const logger_1 = require("../src/utils/logger");
4
5
  const printAnalysisStats = (stats) => {
5
6
  stats.explicitRouterFiles.forEach((file) => (0, exports.printRouterFile)(file));
6
7
  stats.discoveredRouterFiles.forEach((file) => (0, exports.printRouterFile)(file));
7
8
  };
8
9
  exports.printAnalysisStats = printAnalysisStats;
9
10
  const printRouterFile = (file) => {
10
- console.info(`${file.path}`);
11
+ logger_1.Logger.info(`${file.path}`);
11
12
  file.routers.forEach((r) => {
12
- console.info(`└ ${r.name}`);
13
+ logger_1.Logger.info(`└ ${r.name}`);
13
14
  r.endpoints.forEach((e) => {
14
- console.info(` └ ${e}`);
15
+ logger_1.Logger.info(` └ ${e}`);
15
16
  });
16
17
  });
17
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"BaseHttpError.d.ts","sourceRoot":"","sources":["../../../src/errors/BaseHttpError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEhE,MAAM,WAAW,SAAS;IACzB,MAAM,EAAE,WAAW,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,aAAc,SAAQ,KAAM,YAAW,SAAS;IAGzC,MAAM,EAAE,WAAW;IAAS,OAAO,EAAE,MAAM;IAFvD,MAAM,EAAE,MAAM,CAAA;gBAEF,MAAM,EAAE,WAAW,EAAS,OAAO,EAAE,MAAM;CAI9D"}
1
+ {"version":3,"file":"BaseHttpError.d.ts","sourceRoot":"","sources":["../../../src/errors/BaseHttpError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEhE,MAAM,WAAW,SAAS;IACzB,MAAM,EAAE,WAAW,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,aAAc,SAAQ,KAAM,YAAW,SAAS;IAIpD,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,MAAM;IAJhB,MAAM,EAAE,MAAM,CAAA;gBAGb,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM;CAKvB"}
@@ -30,7 +30,7 @@ const useCookieParams = (ctx, validators) => {
30
30
  parsedValue,
31
31
  };
32
32
  }
33
- catch (error) {
33
+ catch (_a) {
34
34
  return { param, validated: false };
35
35
  }
36
36
  });
@@ -31,7 +31,7 @@ const useHeaderParams = (ctx, validators) => {
31
31
  parsedValue,
32
32
  };
33
33
  }
34
- catch (error) {
34
+ catch (_a) {
35
35
  return { param, validated: false };
36
36
  }
37
37
  });
@@ -26,7 +26,7 @@ const usePathParams = (ctx, validators) => {
26
26
  parsedValue,
27
27
  };
28
28
  }
29
- catch (error) {
29
+ catch (_a) {
30
30
  return { param, validated: false };
31
31
  }
32
32
  });
@@ -30,7 +30,7 @@ const useQueryParams = (ctx, validators) => {
30
30
  parsedValue,
31
31
  };
32
32
  }
33
- catch (error) {
33
+ catch (_a) {
34
34
  return { param, validated: false };
35
35
  }
36
36
  });
@@ -39,7 +39,7 @@ const useRequestBody = (ctx, validators) => {
39
39
  parsedValue,
40
40
  };
41
41
  }
42
- catch (error) {
42
+ catch (_a) {
43
43
  return { param, validated: false };
44
44
  }
45
45
  });
@@ -22,7 +22,7 @@ const useRequestRawBody = (ctx, validator) => {
22
22
  parsedValue,
23
23
  };
24
24
  }
25
- catch (error) {
25
+ catch (_a) {
26
26
  return { validated: false };
27
27
  }
28
28
  })();
@@ -1,16 +1,35 @@
1
1
  import { SourceFile } from 'ts-morph';
2
+ import { Project } from 'ts-morph';
3
+ import { Logger } from '../../utils/logger';
2
4
  import { DiscoveredSourceFile } from '../discoveryModule/discoverRouterFiles/discoverRouterFiles';
3
5
  import { ApiDocsHeader } from '../manager/OpenApiManager';
4
6
  import { EndpointData, ExposedModelData } from '../types';
7
+ import { TimestampCache } from './getSourceFileTimestamp';
5
8
  type Props = {
9
+ logLevel?: Parameters<(typeof Logger)['setLevel']>[0];
6
10
  tsconfigPath: string;
7
11
  sourceFilePaths?: string[];
8
12
  sourceFileDiscovery?: boolean | FileDiscoveryConfig;
13
+ incremental?: boolean | {
14
+ cachePath: string;
15
+ };
9
16
  };
10
17
  type FileDiscoveryConfig = {
11
18
  rootPath: string;
12
19
  };
13
- export declare const prepareOpenApiSpec: ({ tsconfigPath, sourceFilePaths, sourceFileDiscovery }: Props) => void;
20
+ export declare const prepareOpenApiSpec: ({ logLevel, tsconfigPath, sourceFilePaths, sourceFileDiscovery, incremental, }: Props) => void;
21
+ export declare const analyzeMultipleSourceFiles: (files: DiscoveredSourceFile[], config: {
22
+ incremental: boolean;
23
+ cachePath: string;
24
+ project: Project;
25
+ timestampCache: TimestampCache;
26
+ }, filterEndpointPaths?: string[]) => EndpointData[];
27
+ export declare const analyzeSourceFileWithCache: (file: DiscoveredSourceFile, config: {
28
+ incremental: boolean;
29
+ cachePath: string;
30
+ project: Project;
31
+ timestampCache: TimestampCache;
32
+ }, filterEndpointPaths?: string[]) => EndpointData[];
14
33
  export declare const analyzeSourceFileEndpoints: (file: DiscoveredSourceFile, filterEndpointPaths?: string[]) => EndpointData[];
15
34
  export declare const analyzeSourceFileApiHeader: (sourceFile: SourceFile) => ApiDocsHeader | null;
16
35
  export declare const analyzeSourceFileExposedModels: (sourceFile: SourceFile) => ExposedModelData[];
@@ -1 +1 @@
1
- {"version":3,"file":"analyzerModule.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/analyzerModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AAIjD,OAAO,EACN,oBAAoB,EAEpB,MAAM,4DAA4D,CAAA;AAEnE,OAAO,EAAE,aAAa,EAAkB,MAAM,2BAA2B,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAKzD,KAAK,KAAK,GAAG;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,mBAAmB,CAAC,EAAE,OAAO,GAAG,mBAAmB,CAAA;CACnD,CAAA;AAED,KAAK,mBAAmB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AAMD,eAAO,MAAM,kBAAkB,2DAA4D,KAAK,SAkF/F,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,wBACJ,MAAM,EAAE,KAC5B,YAAY,EAqBd,CAAA;AAED,eAAO,MAAM,0BAA0B,eAAgB,UAAU,KAAG,aAAa,GAAG,IAyCnF,CAAA;AAED,eAAO,MAAM,8BAA8B,eAAgB,UAAU,KAAG,gBAAgB,EA4CvF,CAAA"}
1
+ {"version":3,"file":"analyzerModule.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/analyzerModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3C,OAAO,EACN,oBAAoB,EAEpB,MAAM,4DAA4D,CAAA;AAEnE,OAAO,EAAE,aAAa,EAAkB,MAAM,2BAA2B,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EAA0B,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAMjF,KAAK,KAAK,GAAG;IACZ,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACrD,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,mBAAmB,CAAC,EAAE,OAAO,GAAG,mBAAmB,CAAA;IACnD,WAAW,CAAC,EACT,OAAO,GACP;QACA,SAAS,EAAE,MAAM,CAAA;KAChB,CAAA;CACJ,CAAA;AAED,KAAK,mBAAmB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AAMD,eAAO,MAAM,kBAAkB,mFAM5B,KAAK,SAwGP,CAAA;AAED,eAAO,MAAM,0BAA0B,UAC/B,oBAAoB,EAAE,UACrB;IACP,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,cAAc,EAAE,cAAc,CAAA;CAC9B,wBACqB,MAAM,EAAE,mBAG9B,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,UAClB;IACP,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,cAAc,EAAE,cAAc,CAAA;CAC9B,wBACqB,MAAM,EAAE,KAC5B,YAAY,EAgBd,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,wBACJ,MAAM,EAAE,KAC5B,YAAY,EAwBd,CAAA;AAED,eAAO,MAAM,0BAA0B,eAAgB,UAAU,KAAG,aAAa,GAAG,IAyCnF,CAAA;AAED,eAAO,MAAM,8BAA8B,eAAgB,UAAU,KAAG,gBAAgB,EA4CvF,CAAA"}
@@ -33,22 +33,29 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.analyzeSourceFileExposedModels = exports.analyzeSourceFileApiHeader = exports.analyzeSourceFileEndpoints = exports.prepareOpenApiSpec = void 0;
36
+ exports.analyzeSourceFileExposedModels = exports.analyzeSourceFileApiHeader = exports.analyzeSourceFileEndpoints = exports.analyzeSourceFileWithCache = exports.analyzeMultipleSourceFiles = exports.prepareOpenApiSpec = void 0;
37
37
  const path = __importStar(require("path"));
38
38
  const ts_morph_1 = require("ts-morph");
39
39
  const ts_morph_2 = require("ts-morph");
40
+ const logger_1 = require("../../utils/logger");
40
41
  const discoverImports_1 = require("../discoveryModule/discoverImports/discoverImports");
41
42
  const discoverRouterFiles_1 = require("../discoveryModule/discoverRouterFiles/discoverRouterFiles");
42
43
  const discoverRouters_1 = require("../discoveryModule/discoverRouters/discoverRouters");
43
44
  const OpenApiManager_1 = require("../manager/OpenApiManager");
45
+ const getSourceFileTimestamp_1 = require("./getSourceFileTimestamp");
44
46
  const nodeParsers_1 = require("./nodeParsers");
45
47
  const parseEndpoint_1 = require("./parseEndpoint");
46
48
  const parseExposedModels_1 = require("./parseExposedModels");
47
- const prepareOpenApiSpec = ({ tsconfigPath, sourceFilePaths, sourceFileDiscovery }) => {
49
+ const sourceFileCache_1 = require("./sourceFileCache");
50
+ const prepareOpenApiSpec = ({ logLevel, tsconfigPath, sourceFilePaths, sourceFileDiscovery, incremental, }) => {
48
51
  const openApiManager = OpenApiManager_1.OpenApiManager.getInstance();
49
52
  if (openApiManager.isReady()) {
50
53
  return;
51
54
  }
55
+ if (logLevel) {
56
+ logger_1.Logger.setLevel(logLevel);
57
+ }
58
+ logger_1.Logger.info('Preparing OpenAPI spec');
52
59
  const project = new ts_morph_2.Project({
53
60
  tsConfigFilePath: path.resolve(tsconfigPath),
54
61
  });
@@ -65,10 +72,13 @@ const prepareOpenApiSpec = ({ tsconfigPath, sourceFilePaths, sourceFileDiscovery
65
72
  if (sourceFileDiscovery === false) {
66
73
  return { discoveredRouterFiles: [], discoveredSourceFiles: [] };
67
74
  }
68
- return (0, discoverRouterFiles_1.discoverRouterFiles)({
75
+ const startTime = performance.now();
76
+ const files = (0, discoverRouterFiles_1.discoverRouterFiles)({
69
77
  targetPath: typeof sourceFileDiscovery === 'object' ? sourceFileDiscovery.rootPath : '.',
70
78
  tsConfigPath: tsconfigPath,
71
79
  });
80
+ logger_1.Logger.info(`File discovery took ${Math.round(performance.now() - startTime)}ms`);
81
+ return files;
72
82
  })();
73
83
  const allSourceFiles = sourceFiles.reduce((acc, current) => acc.some((r) => r.getFilePath() === current.getFilePath()) ? acc : acc.concat(current), discoveredSourceFiles);
74
84
  return { explicitRouters, discoveredRouterFiles, allSourceFiles };
@@ -82,7 +92,20 @@ const prepareOpenApiSpec = ({ tsconfigPath, sourceFilePaths, sourceFileDiscovery
82
92
  }
83
93
  const exposedModels = allSourceFiles.flatMap((file) => (0, exports.analyzeSourceFileExposedModels)(file));
84
94
  openApiManager.setExposedModels(exposedModels);
85
- const endpoints = filesToAnalyze.flatMap((file) => (0, exports.analyzeSourceFileEndpoints)(file));
95
+ const startTime = performance.now();
96
+ const cachePath = (() => {
97
+ if (typeof incremental === 'object' && incremental.cachePath) {
98
+ return incremental.cachePath;
99
+ }
100
+ return path.resolve(process.cwd(), 'node_modules', '.cache', 'moonflower');
101
+ })();
102
+ const endpoints = (0, exports.analyzeMultipleSourceFiles)(filesToAnalyze, {
103
+ incremental: incremental !== false,
104
+ cachePath,
105
+ project,
106
+ timestampCache: {},
107
+ });
108
+ logger_1.Logger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`);
86
109
  openApiManager.setStats({
87
110
  discoveredRouterFiles: discoveredRouterFiles.map((file) => ({
88
111
  path: file.fileName,
@@ -107,18 +130,39 @@ const prepareOpenApiSpec = ({ tsconfigPath, sourceFilePaths, sourceFileDiscovery
107
130
  openApiManager.markAsReady();
108
131
  };
109
132
  exports.prepareOpenApiSpec = prepareOpenApiSpec;
133
+ const analyzeMultipleSourceFiles = (files, config, filterEndpointPaths) => {
134
+ return files.flatMap((file) => (0, exports.analyzeSourceFileWithCache)(file, config, filterEndpointPaths));
135
+ };
136
+ exports.analyzeMultipleSourceFiles = analyzeMultipleSourceFiles;
137
+ const analyzeSourceFileWithCache = (file, config, filterEndpointPaths) => {
138
+ const timestamp = (0, getSourceFileTimestamp_1.getSourceFileTimestamp)(file.sourceFile, config.timestampCache);
139
+ const cachedResults = sourceFileCache_1.SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath);
140
+ if (cachedResults) {
141
+ logger_1.Logger.debug(`[${file.fileName}] Found cached results`);
142
+ return cachedResults.endpoints;
143
+ }
144
+ logger_1.Logger.debug(`[${file.fileName}] Analyzing...`);
145
+ const t1 = performance.now();
146
+ const endpoints = (0, exports.analyzeSourceFileEndpoints)(file, filterEndpointPaths);
147
+ const t2 = performance.now();
148
+ logger_1.Logger.info(`[${file.fileName}] Analyzed in ${t2 - t1}ms`);
149
+ sourceFileCache_1.SourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, endpoints);
150
+ return endpoints;
151
+ };
152
+ exports.analyzeSourceFileWithCache = analyzeSourceFileWithCache;
110
153
  const analyzeSourceFileEndpoints = (file, filterEndpointPaths) => {
111
154
  const endpoints = [];
155
+ const operations = ['get', 'post', 'put', 'delete', 'del', 'patch'];
156
+ const joinedOperations = operations.join('|');
112
157
  file.routers.named.forEach((routerName) => {
113
158
  file.sourceFile.forEachChild((node) => {
114
159
  var _a, _b;
115
160
  const nodeText = node.getText();
116
- const operations = ['get', 'post', 'put', 'delete', 'del', 'patch'];
117
- const targetNodes = operations.map((op) => `${routerName}.${op}`);
118
- if (targetNodes.some((targetNode) => nodeText.includes(targetNode))) {
161
+ const routerPattern = new RegExp(`${routerName}\\.(?:${joinedOperations})`);
162
+ if (routerPattern.test(nodeText)) {
119
163
  const endpointText = (_b = (_a = node.getFirstDescendantByKind(ts_morph_1.SyntaxKind.StringLiteral)) === null || _a === void 0 ? void 0 : _a.getText()) !== null && _b !== void 0 ? _b : '';
120
- const endpointPath = endpointText.substring(1, endpointText.length - 1);
121
- if (!!filterEndpointPaths && !filterEndpointPaths.some((path) => endpointPath.includes(path))) {
164
+ const endpointPath = endpointText.slice(1, -1);
165
+ if (filterEndpointPaths && !filterEndpointPaths.some((path) => endpointPath.includes(path))) {
122
166
  return;
123
167
  }
124
168
  endpoints.push((0, parseEndpoint_1.parseEndpoint)(node, file.fileName));
@@ -0,0 +1,6 @@
1
+ import { SourceFile } from 'ts-morph';
2
+ export type TimestampCache = Record<string, {
3
+ dependencies: SourceFile[];
4
+ }>;
5
+ export declare function getSourceFileTimestamp(sourceFile: SourceFile, timestampCache: TimestampCache): number;
6
+ //# sourceMappingURL=getSourceFileTimestamp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSourceFileTimestamp.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/getSourceFileTimestamp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AAIjD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,YAAY,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC,CAAA;AAE3E,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,UAe5F"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSourceFileTimestamp = getSourceFileTimestamp;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const ts_morph_1 = require("ts-morph");
9
+ const logger_1 = require("../../utils/logger");
10
+ function getSourceFileTimestamp(sourceFile, timestampCache) {
11
+ const dependencies = getFileDependencies(sourceFile, timestampCache);
12
+ const timestamps = dependencies.map((dep) => {
13
+ const stat = fs_1.default.statSync(dep.getFilePath());
14
+ return stat.mtimeMs;
15
+ });
16
+ const latestTimestamp = Math.max(...timestamps);
17
+ const fileName = sourceFile.getFilePath().split('/').pop();
18
+ const depsCount = dependencies.length;
19
+ logger_1.Logger.debug(`[${fileName}] Found ${depsCount} imports, latest touched at ${(0, logger_1.formatTimestamp)(latestTimestamp)}.`);
20
+ return latestTimestamp;
21
+ }
22
+ function getFileDependencies(sourceFile, timestampCache) {
23
+ const cacheHit = timestampCache[sourceFile.getFilePath()];
24
+ if (cacheHit) {
25
+ return cacheHit.dependencies;
26
+ }
27
+ const fileName = sourceFile.getFilePath().split('/').pop();
28
+ timestampCache[sourceFile.getFilePath()] = { dependencies: [] };
29
+ try {
30
+ const results = [sourceFile];
31
+ const importDeclarations = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ImportDeclaration);
32
+ for (const declaration of importDeclarations) {
33
+ const importedSourceFile = declaration.getModuleSpecifierSourceFile();
34
+ if (!importedSourceFile) {
35
+ logger_1.Logger.debug(`[${fileName}] Could not resolve import ${declaration.getModuleSpecifierValue()}.`);
36
+ continue;
37
+ }
38
+ const deps = getFileDependencies(importedSourceFile, timestampCache);
39
+ results.push(...deps);
40
+ }
41
+ timestampCache[sourceFile.getFilePath()] = { dependencies: results };
42
+ return results;
43
+ }
44
+ catch (error) {
45
+ logger_1.Logger.warn(`[${fileName}] Caught an error while processing imports:`, error);
46
+ timestampCache[sourceFile.getFilePath()] = { dependencies: [] };
47
+ return [];
48
+ }
49
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"nodeParsers.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/nodeParsers.ts"],"names":[],"mappings":"AACA,OAAO,EACN,IAAI,EACJ,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAE3B,EAAE,EACF,IAAI,EACJ,iBAAiB,EACjB,MAAM,UAAU,CAAA;AAGjB,OAAO,EAAE,eAAe,EAAE,WAAW,EAAqB,MAAM,SAAS,CAAA;AAEzE,eAAO,MAAM,sBAAsB,SAAU,IAAI,KAAG,IAyBnD,CAAA;AAED,eAAO,MAAM,+BAA+B,SAExC,kBAAkB,GAClB,iBAAiB,GACjB,iBAAiB,GACjB,wBAAwB,GACxB,2BAA2B,KAC5B,IAYF,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,iBAAiB,KAAG,WAAW,CAAC,OAAO,CAOlF,CAAA;AAED,eAAO,MAAM,qBAAqB,oBAAqB,IAAI,KAAG,WAAW,CAAC,OAAO,CAkIhF,CAAA;AAED,eAAO,MAAM,0BAA0B,sBACnB,IAAI,CAAC,EAAE,CAAC,uBAAuB,CAAC,KACjD,CAAC,eAAe,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,EA8BnE,CAAA;AAED,eAAO,MAAM,yBAAyB,qBAAsB,IAAI,KAAG,WAAW,CAAC,OAAO,CAoFrF,CAAA;AAED,eAAO,MAAM,+BAA+B,SAAU,IAAI,KAAG,OA4B5D,CAAA;AAED,eAAO,MAAM,+BAA+B,oBAC1B,IAAI,QACf,aAAa,GAAG,cAAc,KAClC,MAuDF,CAAA;AAWD,eAAO,MAAM,kBAAkB,kBACf,IAAI,cACP,IAAI,UACT,IAAI,EAAE,KACX,WAAW,CAAC,OAAO,CAiMrB,CAAA;AAiBD,eAAO,MAAM,wBAAwB,sBAAuB,IAAI,CAAC,EAAE,CAAC,uBAAuB,CAAC;;;GAmB3F,CAAA"}
1
+ {"version":3,"file":"nodeParsers.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/nodeParsers.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,IAAI,EACJ,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAE3B,EAAE,EACF,IAAI,EACJ,iBAAiB,EACjB,MAAM,UAAU,CAAA;AAKjB,OAAO,EAAE,eAAe,EAAE,WAAW,EAAqB,MAAM,SAAS,CAAA;AAEzE,eAAO,MAAM,sBAAsB,SAAU,IAAI,KAAG,IAyBnD,CAAA;AAED,eAAO,MAAM,+BAA+B,SAExC,kBAAkB,GAClB,iBAAiB,GACjB,iBAAiB,GACjB,wBAAwB,GACxB,2BAA2B,KAC5B,IAYF,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,iBAAiB,KAAG,WAAW,CAAC,OAAO,CAOlF,CAAA;AAED,eAAO,MAAM,qBAAqB,oBAAqB,IAAI,KAAG,WAAW,CAAC,OAAO,CAoIhF,CAAA;AAED,eAAO,MAAM,0BAA0B,sBACnB,IAAI,CAAC,EAAE,CAAC,uBAAuB,CAAC,KACjD,CAAC,eAAe,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,EAgCnE,CAAA;AAED,eAAO,MAAM,yBAAyB,qBAAsB,IAAI,KAAG,WAAW,CAAC,OAAO,CAyFrF,CAAA;AAED,eAAO,MAAM,+BAA+B,SAAU,IAAI,KAAG,OA4B5D,CAAA;AAED,eAAO,MAAM,+BAA+B,oBAC1B,IAAI,QACf,aAAa,GAAG,cAAc,KAClC,MAyDF,CAAA;AAWD,eAAO,MAAM,kBAAkB,kBACf,IAAI,cACP,IAAI,UACT,IAAI,EAAE,KACX,WAAW,CAAC,OAAO,CAmMrB,CAAA;AAoBD,eAAO,MAAM,wBAAwB,sBAAuB,IAAI,CAAC,EAAE,CAAC,uBAAuB,CAAC;;;GAmB3F,CAAA"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getValuesOfObjectLiteral = exports.getProperTypeShape = exports.getValidatorPropertyStringValue = exports.getValidatorPropertyOptionality = exports.getValidatorPropertyShape = exports.getShapeOfValidatorLiteral = exports.getRecursiveNodeShape = exports.getTypeReferenceShape = exports.findPropertyAssignmentValueNode = exports.findNodeImplementation = void 0;
4
4
  const ts_morph_1 = require("ts-morph");
5
+ const logger_1 = require("../../utils/logger");
5
6
  const OpenApiManager_1 = require("../manager/OpenApiManager");
6
7
  const findNodeImplementation = (node) => {
7
8
  var _a, _b;
@@ -145,6 +146,8 @@ const getRecursiveNodeShape = (nodeOrReference) => {
145
146
  if (asExpressionNode) {
146
147
  return (0, exports.getRecursiveNodeShape)(asExpressionNode.getChildAtIndex(2));
147
148
  }
149
+ const fileName = node.getSourceFile().getFilePath().split('/').pop();
150
+ logger_1.Logger.warn(`[${fileName}] Unknown node type: ${node.getKindName()}`);
148
151
  return 'unknown_1';
149
152
  };
150
153
  exports.getRecursiveNodeShape = getRecursiveNodeShape;
@@ -160,6 +163,8 @@ const getShapeOfValidatorLiteral = (objectLiteralNode) => {
160
163
  if (identifierNode.isKind(ts_morph_1.SyntaxKind.StringLiteral)) {
161
164
  return identifierNode.getLiteralText();
162
165
  }
166
+ const fileName = node.getSourceFile().getFilePath().split('/').pop();
167
+ logger_1.Logger.warn(`[${fileName}] Unknown identifier name: ${identifierNode.getText()}`);
163
168
  return 'unknown_30';
164
169
  })();
165
170
  const assignmentValueNode = node.getLastChild();
@@ -217,6 +222,8 @@ const getValidatorPropertyShape = (innerLiteralNode) => {
217
222
  if (callExpressionArgument.getKind() === ts_morph_1.SyntaxKind.IntersectionType) {
218
223
  return (0, exports.getValidatorPropertyShape)(callExpressionArgument);
219
224
  }
225
+ const fileName = innerLiteralNode.getSourceFile().getFilePath().split('/').pop();
226
+ logger_1.Logger.warn(`[${fileName}] Unknown call expression argument: ${callExpressionArgument.getKindName()}`);
220
227
  return 'unknown_3';
221
228
  }
222
229
  const innerNodePropertyAssignments = innerLiteralNode
@@ -241,6 +248,8 @@ const getValidatorPropertyShape = (innerLiteralNode) => {
241
248
  const targetSyntaxList = importTypeNode.getChildAtIndex(indexOfGreaterThanToken - 1);
242
249
  return (0, exports.getRecursiveNodeShape)(targetSyntaxList.getFirstChild());
243
250
  }
251
+ const fileName = innerLiteralNode.getSourceFile().getFilePath().split('/').pop();
252
+ logger_1.Logger.warn(`[${fileName}] Unknown import type node`);
244
253
  return 'unknown_2';
245
254
  };
246
255
  exports.getValidatorPropertyShape = getValidatorPropertyShape;
@@ -314,6 +323,8 @@ const getValidatorPropertyStringValue = (nodeOrReference, name) => {
314
323
  return targetNode.getLiteralText();
315
324
  }
316
325
  }
326
+ const fileName = node.getSourceFile().getFilePath().split('/').pop();
327
+ logger_1.Logger.warn(`[${fileName}] Unknown property string value node ${node.getKindName()}`);
317
328
  return 'unknown_25';
318
329
  };
319
330
  exports.getValidatorPropertyStringValue = getValidatorPropertyStringValue;
@@ -490,6 +501,8 @@ const getProperTypeShape = (typeOrPromise, atLocation, stack = []) => {
490
501
  .filter((shape) => typeof shape !== 'string');
491
502
  return shapesOfChildren.reduce((total, current) => [...total, ...current], []);
492
503
  }
504
+ const fileName = atLocation.getSourceFile().getFilePath().split('/').pop();
505
+ logger_1.Logger.warn(`[${fileName}] Unknown type shape node ${typeOrPromise.getText()}`);
493
506
  return 'unknown_5';
494
507
  };
495
508
  exports.getProperTypeShape = getProperTypeShape;
@@ -509,6 +522,8 @@ const getLiteralValueOfNode = (node) => {
509
522
  else if (node.isKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)) {
510
523
  return (0, exports.getValuesOfObjectLiteral)(node);
511
524
  }
525
+ const fileName = node.getSourceFile().getFilePath().split('/').pop();
526
+ logger_1.Logger.warn(`[${fileName}] Unknown literal value node ${node.getKindName()}`);
512
527
  return 'unknown_6';
513
528
  };
514
529
  const getValuesOfObjectLiteral = (objectLiteralNode) => {
@@ -1 +1 @@
1
- {"version":3,"file":"parseEndpoint.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/parseEndpoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAc,EAAE,EAAE,MAAM,UAAU,CAAA;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAWvC,eAAO,MAAM,aAAa,SAAU,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,kBAAkB,MAAM,iBAqHxE,CAAA"}
1
+ {"version":3,"file":"parseEndpoint.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/parseEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,EAAE,EAAE,MAAM,UAAU,CAAA;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAYvC,eAAO,MAAM,aAAa,SAAU,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,kBAAkB,MAAM,iBAqHxE,CAAA"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseEndpoint = void 0;
4
4
  const ts_morph_1 = require("ts-morph");
5
5
  const nodeParsers_1 = require("./nodeParsers");
6
+ const logger_1 = require("../../utils/logger");
6
7
  const parseEndpoint = (node, sourceFilePath) => {
7
8
  var _a;
8
9
  const parsedEndpointMethod = node
@@ -40,7 +41,7 @@ const parseEndpoint = (node, sourceFilePath) => {
40
41
  segment: 'api',
41
42
  error: err,
42
43
  });
43
- console.error('Error', err);
44
+ logger_1.Logger.error('Error', err);
44
45
  }
45
46
  try {
46
47
  endpointData.requestPathParams = parseRequestParams(node, endpointPath);
@@ -50,7 +51,7 @@ const parseEndpoint = (node, sourceFilePath) => {
50
51
  segment: 'path',
51
52
  error: err,
52
53
  });
53
- console.error('Error', err);
54
+ logger_1.Logger.error('Error', err);
54
55
  }
55
56
  try {
56
57
  endpointData.requestQuery = parseRequestObjectInput(node, 'useQueryParams');
@@ -60,7 +61,7 @@ const parseEndpoint = (node, sourceFilePath) => {
60
61
  segment: 'query',
61
62
  error: err,
62
63
  });
63
- console.error('Error', err);
64
+ logger_1.Logger.error('Error', err);
64
65
  }
65
66
  try {
66
67
  endpointData.requestHeaders = parseRequestObjectInput(node, 'useHeaderParams');
@@ -70,7 +71,7 @@ const parseEndpoint = (node, sourceFilePath) => {
70
71
  segment: 'headers',
71
72
  error: err,
72
73
  });
73
- console.error('Error', err);
74
+ logger_1.Logger.error('Error', err);
74
75
  }
75
76
  try {
76
77
  const parsedBody = parseRequestRawBody(node);
@@ -83,7 +84,7 @@ const parseEndpoint = (node, sourceFilePath) => {
83
84
  segment: 'rawBody',
84
85
  error: err,
85
86
  });
86
- console.error('Error', err);
87
+ logger_1.Logger.error('Error', err);
87
88
  }
88
89
  try {
89
90
  endpointData.objectBody = parseRequestObjectInput(node, 'useRequestBody');
@@ -93,7 +94,7 @@ const parseEndpoint = (node, sourceFilePath) => {
93
94
  segment: 'objectBody',
94
95
  error: err,
95
96
  });
96
- console.error('Error', err);
97
+ logger_1.Logger.error('Error', err);
97
98
  }
98
99
  try {
99
100
  endpointData.responses = parseRequestResponse(node);
@@ -103,7 +104,7 @@ const parseEndpoint = (node, sourceFilePath) => {
103
104
  segment: 'response',
104
105
  error: err,
105
106
  });
106
- console.error('Error', err);
107
+ logger_1.Logger.error('Error', err);
107
108
  }
108
109
  return endpointData;
109
110
  };
@@ -165,7 +166,7 @@ const parseRequestRawBody = (node) => {
165
166
  return null;
166
167
  }
167
168
  const paramNode = hookNode.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList);
168
- const valueNode = (0, nodeParsers_1.findNodeImplementation)(paramNode.getLastChild());
169
+ const valueNode = (0, nodeParsers_1.findNodeImplementation)(paramNode.getLastChild((node) => !node.isKind(ts_morph_1.SyntaxKind.CommaToken)));
169
170
  return {
170
171
  signature: (0, nodeParsers_1.getValidatorPropertyShape)(valueNode),
171
172
  optional: (0, nodeParsers_1.getValidatorPropertyOptionality)(valueNode),
@@ -1 +1 @@
1
- {"version":3,"file":"parseExposedModels.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/parseExposedModels.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAc,EAAE,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAI3C,eAAO,MAAM,iBAAiB,SAAU,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAG,gBAevD,CAAA;AAED,eAAO,MAAM,uBAAuB,SAAU,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAG,gBAAgB,EAS7E,CAAA"}
1
+ {"version":3,"file":"parseExposedModels.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/parseExposedModels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,EAAE,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAI3C,eAAO,MAAM,iBAAiB,SAAU,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAG,gBAevD,CAAA;AAED,eAAO,MAAM,uBAAuB,SAAU,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAG,gBAAgB,EAS7E,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { SourceFile } from 'ts-morph';
2
+ import { EndpointData } from '../types';
3
+ export declare const SourceFileCache: {
4
+ getCachedResults: (file: SourceFile, timestamp: number, cachePath: string) => {
5
+ endpoints: EndpointData[];
6
+ } | undefined;
7
+ cacheResults: (file: SourceFile, timestamp: number, cachePath: string, endpoints: EndpointData[]) => void;
8
+ purgeCache: (cacheFilePath: string) => void;
9
+ };
10
+ //# sourceMappingURL=sourceFileCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceFileCache.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/sourceFileCache.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAGrC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAKvC,eAAO,MAAM,eAAe;6BACF,UAAU,aAAa,MAAM,aAAa,MAAM;;;yBAsDpD,UAAU,aAAa,MAAM,aAAa,MAAM,aAAa,YAAY,EAAE;gCASpE,MAAM;CAOlC,CAAA"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SourceFileCache = void 0;
7
+ const assert_1 = __importDefault(require("assert"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const logger_1 = require("../../utils/logger");
12
+ const CACHE_VERSION = 1;
13
+ exports.SourceFileCache = {
14
+ getCachedResults: (file, timestamp, cachePath) => {
15
+ const fileName = file.getFilePath().split('/').pop();
16
+ const fileNameHash = crypto_1.default.createHash('md5').update(file.getFilePath()).digest('hex');
17
+ const cacheFilePath = path_1.default.join(cachePath, `${fileNameHash}.json`);
18
+ if (!fs_1.default.existsSync(cacheFilePath)) {
19
+ logger_1.Logger.debug(`[${fileName}] No cached results`);
20
+ return;
21
+ }
22
+ try {
23
+ const cacheFile = JSON.parse(fs_1.default.readFileSync(cacheFilePath, 'utf8'));
24
+ if (!('version' in cacheFile) ||
25
+ !('timestamp' in cacheFile) ||
26
+ !('endpoints' in cacheFile) ||
27
+ typeof cacheFile.version !== 'number' ||
28
+ typeof cacheFile.timestamp !== 'number' ||
29
+ !Array.isArray(cacheFile.endpoints) ||
30
+ cacheFile.endpoints.length === 0) {
31
+ logger_1.Logger.debug(`[${fileName}] No cached results`);
32
+ return;
33
+ }
34
+ if (cacheFile.version !== CACHE_VERSION) {
35
+ logger_1.Logger.debug(`[${fileName}] Cache version mismatch`);
36
+ return;
37
+ }
38
+ if (cacheFile.timestamp < timestamp) {
39
+ logger_1.Logger.debug(`[${fileName}] Cache timestamp mismatch`);
40
+ return;
41
+ }
42
+ const endpoints = cacheFile.endpoints;
43
+ (0, assert_1.default)(endpoints[0].path);
44
+ (0, assert_1.default)(endpoints[0].method);
45
+ return { endpoints };
46
+ }
47
+ catch (error) {
48
+ logger_1.Logger.error(`[${fileName}] Error parsing cache file`, error);
49
+ exports.SourceFileCache.purgeCache(cacheFilePath);
50
+ return;
51
+ }
52
+ },
53
+ cacheResults: (file, timestamp, cachePath, endpoints) => {
54
+ const fileNameHash = crypto_1.default.createHash('md5').update(file.getFilePath()).digest('hex');
55
+ const cacheFilePath = path_1.default.join(cachePath, `${fileNameHash}.json`);
56
+ fs_1.default.mkdirSync(cachePath, { recursive: true });
57
+ fs_1.default.writeFileSync(cacheFilePath, JSON.stringify({ version: CACHE_VERSION, timestamp, endpoints }));
58
+ },
59
+ purgeCache: (cacheFilePath) => {
60
+ try {
61
+ fs_1.default.unlinkSync(cacheFilePath);
62
+ }
63
+ catch (error) {
64
+ logger_1.Logger.error(`Unable to remove cache file at ${cacheFilePath}`, error);
65
+ }
66
+ },
67
+ };
@@ -373,7 +373,7 @@ router.get('/test/39669151-c529-4bcd-86a5-a10de7834104/:foo', (ctx) => {
373
373
  parse: (v) => String(v),
374
374
  }),
375
375
  });
376
- foo;
376
+ return foo;
377
377
  });
378
378
  (0, useExposeApiModel_1.useExposeApiModel)();
379
379
  (0, useExposeApiModel_1.useExposeNamedApiModels)();
@@ -1 +1 @@
1
- {"version":3,"file":"generateComponentSchemas.d.ts","sourceRoot":"","sources":["../../../../src/openapi/generatorModule/generateComponentSchemas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAa,UAAU,EAAE,MAAM,aAAa,CAAA;AAEnD,eAAO,MAAM,wBAAwB,WAAY,gBAAgB,EAAE,+BAOlE,CAAA"}
1
+ {"version":3,"file":"generateComponentSchemas.d.ts","sourceRoot":"","sources":["../../../../src/openapi/generatorModule/generateComponentSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAa,UAAU,EAAE,MAAM,aAAa,CAAA;AAEnD,eAAO,MAAM,wBAAwB,WAAY,gBAAgB,EAAE,+BAOlE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"generatePaths.d.ts","sourceRoot":"","sources":["../../../../src/openapi/generatorModule/generatePaths.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAGvD,eAAO,MAAM,aAAa,cAAe,YAAY,EAAE,eAAe,kBAAkB;UAI/E,cAAc;WACb,cAAc;UACf,cAAc;YACZ,cAAc;aACb,cAAc;EA+HzB,CAAA"}
1
+ {"version":3,"file":"generatePaths.d.ts","sourceRoot":"","sources":["../../../../src/openapi/generatorModule/generatePaths.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAGvD,eAAO,MAAM,aAAa,cAAe,YAAY,EAAE,eAAe,kBAAkB;UAI/E,cAAc;WACb,cAAc;UACf,cAAc;YACZ,cAAc;aACb,cAAc;EAiIzB,CAAA"}
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generatePaths = void 0;
4
+ const logger_1 = require("../../utils/logger");
4
5
  const getSchema_1 = require("./getSchema");
5
6
  const generatePaths = (endpoints, preferences) => {
6
7
  const paths = {};
7
8
  const { allowOptionalPathParams } = preferences;
9
+ const startTime = performance.now();
8
10
  endpoints.forEach((endpoint) => {
9
11
  var _a;
10
12
  const path = endpoint.path
@@ -23,7 +25,7 @@ const generatePaths = (endpoints, preferences) => {
23
25
  in: 'path',
24
26
  description: param.optional && !allowOptionalPathParams
25
27
  ? `(Optional parameter) ${param.description}`
26
- : (_a = param.description) !== null && _a !== void 0 ? _a : '',
28
+ : ((_a = param.description) !== null && _a !== void 0 ? _a : ''),
27
29
  required: !allowOptionalPathParams || !param.optional,
28
30
  schema: (0, getSchema_1.getSchema)(param.signature),
29
31
  });
@@ -110,6 +112,7 @@ const generatePaths = (endpoints, preferences) => {
110
112
  };
111
113
  paths[path] = Object.assign(Object.assign({}, paths[path]), { [endpoint.method.toLowerCase()]: definition });
112
114
  });
115
+ logger_1.Logger.info(`Path generation took ${Math.round(performance.now() - startTime)}ms`);
113
116
  return paths;
114
117
  };
115
118
  exports.generatePaths = generatePaths;