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.
- package/cli/prettyprint.ts +4 -3
- package/dist/cli/prettyprint.d.ts.map +1 -1
- package/dist/cli/prettyprint.js +4 -3
- package/dist/src/errors/BaseHttpError.d.ts.map +1 -1
- package/dist/src/hooks/useCookieParams.js +1 -1
- package/dist/src/hooks/useHeaderParams.js +1 -1
- package/dist/src/hooks/usePathParams.js +1 -1
- package/dist/src/hooks/useQueryParams.js +1 -1
- package/dist/src/hooks/useRequestBody.js +1 -1
- package/dist/src/hooks/useRequestRawBody.js +1 -1
- package/dist/src/openapi/analyzerModule/analyzerModule.d.ts +20 -1
- package/dist/src/openapi/analyzerModule/analyzerModule.d.ts.map +1 -1
- package/dist/src/openapi/analyzerModule/analyzerModule.js +53 -9
- package/dist/src/openapi/analyzerModule/getSourceFileTimestamp.d.ts +6 -0
- package/dist/src/openapi/analyzerModule/getSourceFileTimestamp.d.ts.map +1 -0
- package/dist/src/openapi/analyzerModule/getSourceFileTimestamp.js +49 -0
- package/dist/src/openapi/analyzerModule/nodeParsers.d.ts.map +1 -1
- package/dist/src/openapi/analyzerModule/nodeParsers.js +15 -0
- package/dist/src/openapi/analyzerModule/parseEndpoint.d.ts.map +1 -1
- package/dist/src/openapi/analyzerModule/parseEndpoint.js +9 -8
- package/dist/src/openapi/analyzerModule/parseExposedModels.d.ts.map +1 -1
- package/dist/src/openapi/analyzerModule/sourceFileCache.d.ts +10 -0
- package/dist/src/openapi/analyzerModule/sourceFileCache.d.ts.map +1 -0
- package/dist/src/openapi/analyzerModule/sourceFileCache.js +67 -0
- package/dist/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.js +1 -1
- package/dist/src/openapi/generatorModule/generateComponentSchemas.d.ts.map +1 -1
- package/dist/src/openapi/generatorModule/generatePaths.d.ts.map +1 -1
- package/dist/src/openapi/generatorModule/generatePaths.js +4 -1
- package/dist/src/openapi/generatorModule/getSchema.d.ts.map +1 -1
- package/dist/src/openapi/generatorModule/getSchema.js +3 -0
- package/dist/src/utils/TypeUtils.d.ts.map +1 -1
- package/dist/src/utils/logger.d.ts +10 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +73 -0
- package/dist/src/validators/types.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/eslint.config.mjs +42 -0
- package/package.json +1 -1
- package/src/errors/BaseHttpError.ts +4 -1
- package/src/hooks/authentication/useAuth.ts +1 -1
- package/src/hooks/authentication/useOptionalAuth.ts +1 -1
- package/src/hooks/useCookieParams.ts +4 -4
- package/src/hooks/useExposeApiModel/useExposeApiModel.spec.data.ts +2 -0
- package/src/hooks/useHeaderParams.ts +4 -4
- package/src/hooks/usePathParams.ts +5 -5
- package/src/hooks/useQueryParams.ts +4 -4
- package/src/hooks/useRequestBody.spec.ts +4 -0
- package/src/hooks/useRequestBody.ts +5 -5
- package/src/hooks/useRequestRawBody.spec.ts +7 -7
- package/src/hooks/useRequestRawBody.ts +2 -2
- package/src/hooks/useReturnValue.ts +1 -1
- package/src/openapi/analyzerModule/analyzerModule.ts +91 -11
- package/src/openapi/analyzerModule/getSourceFileTimestamp.ts +59 -0
- package/src/openapi/analyzerModule/nodeParsers.ts +26 -9
- package/src/openapi/analyzerModule/parseEndpoint.ts +17 -15
- package/src/openapi/analyzerModule/parseExposedModels.ts +0 -1
- package/src/openapi/analyzerModule/sourceFileCache.ts +84 -0
- package/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.ts +6 -6
- package/src/openapi/analyzerModule/test/openApiAnalyzer.spec.ts +3 -4
- package/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts +4 -4
- package/src/openapi/discoveryModule/discoverRouters/discoverRouters.ts +3 -3
- package/src/openapi/generatorModule/generateComponentSchemas.ts +0 -1
- package/src/openapi/generatorModule/generatePaths.ts +4 -2
- package/src/openapi/generatorModule/getSchema.ts +3 -0
- package/src/openapi/generatorModule/test/openApiGenerator.spec.ts +5 -5
- package/src/openapi/manager/OpenApiManager.ts +2 -2
- package/src/router/Router.ts +8 -8
- package/src/test/app.ts +2 -2
- package/src/utils/TypeUtils.ts +15 -15
- package/src/utils/logger.ts +71 -0
- package/src/utils/mockContext.ts +6 -6
- package/src/utils/printers.spec.ts +5 -5
- package/src/utils/validationMessages.ts +2 -2
- package/src/validators/InternalParamWrappers.ts +1 -1
- package/src/validators/ParamWrappers.ts +3 -3
- package/src/validators/types.ts +2 -2
- package/.eslintrc.js +0 -26
package/cli/prettyprint.ts
CHANGED
|
@@ -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
|
-
|
|
10
|
+
Logger.info(`${file.path}`)
|
|
10
11
|
file.routers.forEach((r) => {
|
|
11
|
-
|
|
12
|
+
Logger.info(`└ ${r.name}`)
|
|
12
13
|
r.endpoints.forEach((e) => {
|
|
13
|
-
|
|
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;
|
|
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"}
|
package/dist/cli/prettyprint.js
CHANGED
|
@@ -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
|
-
|
|
11
|
+
logger_1.Logger.info(`${file.path}`);
|
|
11
12
|
file.routers.forEach((r) => {
|
|
12
|
-
|
|
13
|
+
logger_1.Logger.info(`└ ${r.name}`);
|
|
13
14
|
r.endpoints.forEach((e) => {
|
|
14
|
-
|
|
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;
|
|
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"}
|
|
@@ -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;
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
117
|
-
|
|
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.
|
|
121
|
-
if (
|
|
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":"
|
|
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":"
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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":"
|
|
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":"
|
|
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;
|
|
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;
|