@lark-apaas/coding-preset-vite-react 1.0.13-alpha.10 → 1.0.13-alpha.11
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/lib/plugins/server-log.d.ts +1 -4
- package/lib/plugins/server-log.d.ts.map +1 -1
- package/lib/plugins/server-log.js +1 -4
- package/lib/plugins/server-log.js.map +1 -1
- package/lib/server-log/openapi/index.d.ts +3 -4
- package/lib/server-log/openapi/index.d.ts.map +1 -1
- package/lib/server-log/openapi/index.js +5 -22
- package/lib/server-log/openapi/index.js.map +1 -1
- package/lib/server-log/openapi/router.d.ts +5 -8
- package/lib/server-log/openapi/router.d.ts.map +1 -1
- package/lib/server-log/openapi/router.js +6 -10
- package/lib/server-log/openapi/router.js.map +1 -1
- package/lib/server-log/openapi/types.d.ts +2 -43
- package/lib/server-log/openapi/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/server-log/openapi/controller.d.ts +0 -7
- package/lib/server-log/openapi/controller.d.ts.map +0 -1
- package/lib/server-log/openapi/controller.js +0 -60
- package/lib/server-log/openapi/controller.js.map +0 -1
- package/lib/server-log/openapi/services.d.ts +0 -15
- package/lib/server-log/openapi/services.d.ts.map +0 -1
- package/lib/server-log/openapi/services.js +0 -276
- package/lib/server-log/openapi/services.js.map +0 -1
- package/lib/server-log/openapi/utils.d.ts +0 -18
- package/lib/server-log/openapi/utils.d.ts.map +0 -1
- package/lib/server-log/openapi/utils.js +0 -128
- package/lib/server-log/openapi/utils.js.map +0 -1
|
@@ -40,10 +40,7 @@ export interface ServerLogPluginOptions {
|
|
|
40
40
|
logDir?: string;
|
|
41
41
|
/** 挂载基路径(沙箱 base path),内部把 routes 挂到 `<basePath>/dev/logs/...` */
|
|
42
42
|
basePath?: string;
|
|
43
|
-
/**
|
|
44
|
-
* 项目根目录,用来定位 openapi 相关文件(`./client/src/api/gen/openapi.json`
|
|
45
|
-
* / `./docs/openapi.json` / `./server`)。默认 `process.cwd()`
|
|
46
|
-
*/
|
|
43
|
+
/** 项目根目录,用来定位 `./docs/openapi.json`。默认 `process.cwd()` */
|
|
47
44
|
rootDir?: string;
|
|
48
45
|
}
|
|
49
46
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-log.d.ts","sourceRoot":"","sources":["../../src/plugins/server-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAKlD,MAAM,WAAW,sBAAsB;IACrC,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB
|
|
1
|
+
{"version":3,"file":"server-log.d.ts","sourceRoot":"","sources":["../../src/plugins/server-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAKlD,MAAM,WAAW,sBAAsB;IACrC,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,MAAM,CA6B5E;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -60,13 +60,10 @@ function serverLogPlugin(options = {}) {
|
|
|
60
60
|
(0, dev_logs_1.createDevLogsMiddleware)({
|
|
61
61
|
logDir,
|
|
62
62
|
}),
|
|
63
|
-
// 注册 openapi middleware ——
|
|
63
|
+
// 注册 openapi middleware —— 提供 /dev/openapi/spec,妙搭「开放 API」面板消费
|
|
64
64
|
// (commit e66dd8d8 引入 openapiSpecFilePath 时遗漏了本包)
|
|
65
65
|
(0, openapi_1.createOpenapiMiddleware)({
|
|
66
|
-
openapiFilePath: node_path_1.default.resolve(rootDir, './client/src/api/gen/openapi.json'),
|
|
67
66
|
openapiSpecFilePath: node_path_1.default.resolve(rootDir, './docs/openapi.json'),
|
|
68
|
-
serverDir: node_path_1.default.resolve(rootDir, './server'),
|
|
69
|
-
enableEnhancement: true,
|
|
70
67
|
}),
|
|
71
68
|
], {
|
|
72
69
|
basePath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-log.js","sourceRoot":"","sources":["../../src/plugins/server-log.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;;;;;
|
|
1
|
+
{"version":3,"file":"server-log.js","sourceRoot":"","sources":["../../src/plugins/server-log.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;;;;;AAqBH,0CA6BC;AAhDD,0DAA6B;AAE7B,qDAA6D;AAC7D,qDAAiE;AACjE,mDAAgE;AAWhE;;;GAGG;AACH,SAAgB,eAAe,CAAC,UAAkC,EAAE;IAClE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,QAAQ,CAAC;IACjE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAEjD,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,KAAK,EAAE,OAAO;QACd,eAAe,CAAC,MAAqB;YACnC,IAAA,8BAAmB,EACjB,MAAM,CAAC,WAAW,EAClB;gBACE,IAAA,kCAAuB,EAAC;oBACtB,MAAM;iBACP,CAAC;gBACF,+DAA+D;gBAC/D,kDAAkD;gBAClD,IAAA,iCAAuB,EAAC;oBACtB,mBAAmB,EAAE,mBAAI,CAAC,OAAO,CAAC,OAAO,EAAE,qBAAqB,CAAC;iBAClE,CAAC;aACH,EACD;gBACE,QAAQ;gBACR,KAAK,EAAE,IAAI;gBACX,OAAO;aACR,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,kBAAe,eAAe,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { RouteMiddleware } from '../types';
|
|
2
2
|
import type { OpenapiMiddlewareOptions } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* Creates OpenAPI middleware that serves
|
|
5
|
-
*
|
|
4
|
+
* Creates OpenAPI middleware that serves /dev/openapi/spec —— 妙搭「开放 API」
|
|
5
|
+
* 面板消费的端点,直接读 docs/openapi.json 并过滤成 /openapi/* 子集。
|
|
6
6
|
*/
|
|
7
7
|
export declare function createOpenapiMiddleware(options: OpenapiMiddlewareOptions): RouteMiddleware;
|
|
8
|
-
export type { OpenapiMiddlewareOptions
|
|
9
|
-
export { enhanceOpenApiWithSourceInfo, parseApiRoutes } from './services';
|
|
8
|
+
export type { OpenapiMiddlewareOptions } from './types';
|
|
10
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,UAAU,CAAC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,UAAU,CAAC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAcxD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,eAAe,CAc1F;AAGD,YAAY,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseApiRoutes = exports.enhanceOpenApiWithSourceInfo = void 0;
|
|
4
3
|
exports.createOpenapiMiddleware = createOpenapiMiddleware;
|
|
5
4
|
const router_1 = require("./router");
|
|
6
5
|
/**
|
|
7
6
|
* Routes provided by OpenAPI middleware
|
|
8
7
|
*/
|
|
9
8
|
const OPENAPI_ROUTES = [
|
|
10
|
-
{
|
|
11
|
-
method: 'GET',
|
|
12
|
-
path: '/openapi.json',
|
|
13
|
-
description: 'Serve enhanced OpenAPI specification with source code references',
|
|
14
|
-
},
|
|
15
9
|
{
|
|
16
10
|
method: 'GET',
|
|
17
11
|
path: '/openapi/spec',
|
|
@@ -19,30 +13,19 @@ const OPENAPI_ROUTES = [
|
|
|
19
13
|
},
|
|
20
14
|
];
|
|
21
15
|
/**
|
|
22
|
-
* Creates OpenAPI middleware that serves
|
|
23
|
-
*
|
|
16
|
+
* Creates OpenAPI middleware that serves /dev/openapi/spec —— 妙搭「开放 API」
|
|
17
|
+
* 面板消费的端点,直接读 docs/openapi.json 并过滤成 /openapi/* 子集。
|
|
24
18
|
*/
|
|
25
19
|
function createOpenapiMiddleware(options) {
|
|
26
|
-
const {
|
|
27
|
-
const routes = openapiSpecFilePath
|
|
28
|
-
? OPENAPI_ROUTES
|
|
29
|
-
: OPENAPI_ROUTES.filter((route) => route.path !== '/openapi/spec');
|
|
20
|
+
const { openapiSpecFilePath } = options;
|
|
30
21
|
return {
|
|
31
22
|
name: 'openapi',
|
|
32
23
|
mountPath: '/dev',
|
|
33
|
-
routes,
|
|
24
|
+
routes: OPENAPI_ROUTES,
|
|
34
25
|
enabled: (context) => context.isDev,
|
|
35
26
|
createRouter: (context) => {
|
|
36
|
-
return (0, router_1.createOpenapiRouter)({
|
|
37
|
-
openapiFilePath,
|
|
38
|
-
openapiSpecFilePath,
|
|
39
|
-
enableEnhancement,
|
|
40
|
-
serverDir,
|
|
41
|
-
}, context);
|
|
27
|
+
return (0, router_1.createOpenapiRouter)({ openapiSpecFilePath }, context);
|
|
42
28
|
},
|
|
43
29
|
};
|
|
44
30
|
}
|
|
45
|
-
var services_1 = require("./services");
|
|
46
|
-
Object.defineProperty(exports, "enhanceOpenApiWithSourceInfo", { enumerable: true, get: function () { return services_1.enhanceOpenApiWithSourceInfo; } });
|
|
47
|
-
Object.defineProperty(exports, "parseApiRoutes", { enumerable: true, get: function () { return services_1.parseApiRoutes; } });
|
|
48
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server-log/openapi/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server-log/openapi/index.ts"],"names":[],"mappings":";;AAmBA,0DAcC;AA/BD,qCAA+C;AAE/C;;GAEG;AACH,MAAM,cAAc,GAAgB;IAClC;QACE,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,4CAA4C;KAC1D;CACF,CAAC;AAEF;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,OAAiC;IACvE,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IAExC,OAAO;QACL,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,MAAM;QACjB,MAAM,EAAE,cAAc;QAEtB,OAAO,EAAE,CAAC,OAA0B,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK;QAEtD,YAAY,EAAE,CAAC,OAA0B,EAAE,EAAE;YAC3C,OAAO,IAAA,4BAAmB,EAAC,EAAE,mBAAmB,EAAE,EAAE,OAAO,CAAC,CAAC;QAC/D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -4,17 +4,14 @@ import type { MiddlewareContext } from '../types';
|
|
|
4
4
|
* Options for creating OpenAPI router
|
|
5
5
|
*/
|
|
6
6
|
export interface OpenapiRouterOptions {
|
|
7
|
-
/** Path to the
|
|
8
|
-
|
|
9
|
-
/** Path to the OpenAPI spec source file for /openapi/spec; when omitted, the route is not registered */
|
|
10
|
-
openapiSpecFilePath?: string;
|
|
11
|
-
/** Enable source code enhancement */
|
|
12
|
-
enableEnhancement: boolean;
|
|
13
|
-
/** Server directory for source code scanning */
|
|
14
|
-
serverDir?: string;
|
|
7
|
+
/** Path to the OpenAPI spec source file for /openapi/spec */
|
|
8
|
+
openapiSpecFilePath: string;
|
|
15
9
|
}
|
|
16
10
|
/**
|
|
17
11
|
* Create OpenAPI router
|
|
12
|
+
*
|
|
13
|
+
* 仅提供 GET /openapi/spec —— 妙搭「开放 API」面板消费的端点,
|
|
14
|
+
* 直接读 docs/openapi.json 并过滤成 /openapi/* 的子集($refs 展平)。
|
|
18
15
|
*/
|
|
19
16
|
export declare function createOpenapiRouter(options: OpenapiRouterOptions, context: MiddlewareContext): Router;
|
|
20
17
|
//# sourceMappingURL=router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/router.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/router.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6DAA6D;IAC7D,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,iBAAiB,GACzB,MAAM,CAQR"}
|
|
@@ -5,22 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createOpenapiRouter = createOpenapiRouter;
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const controller_1 = require("./controller");
|
|
9
8
|
const spec_controller_1 = require("./spec-controller");
|
|
10
9
|
/**
|
|
11
10
|
* Create OpenAPI router
|
|
11
|
+
*
|
|
12
|
+
* 仅提供 GET /openapi/spec —— 妙搭「开放 API」面板消费的端点,
|
|
13
|
+
* 直接读 docs/openapi.json 并过滤成 /openapi/* 的子集($refs 展平)。
|
|
12
14
|
*/
|
|
13
15
|
function createOpenapiRouter(options, context) {
|
|
14
|
-
const {
|
|
16
|
+
const { openapiSpecFilePath } = options;
|
|
15
17
|
const router = express_1.default.Router();
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
router.get('/openapi.json', (req, res) => handler(req, res, context));
|
|
19
|
-
// GET /openapi/spec - Serve filtered OpenAPI spec for /openapi/* with refs resolved
|
|
20
|
-
if (openapiSpecFilePath) {
|
|
21
|
-
const specHandler = (0, spec_controller_1.createOpenapiSpecHandler)(openapiSpecFilePath);
|
|
22
|
-
router.get('/openapi/spec', (req, res) => specHandler(req, res, context));
|
|
23
|
-
}
|
|
18
|
+
const specHandler = (0, spec_controller_1.createOpenapiSpecHandler)(openapiSpecFilePath);
|
|
19
|
+
router.get('/openapi/spec', (req, res) => specHandler(req, res, context));
|
|
24
20
|
return router;
|
|
25
21
|
}
|
|
26
22
|
//# sourceMappingURL=router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/server-log/openapi/router.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/server-log/openapi/router.ts"],"names":[],"mappings":";;;;;AAkBA,kDAWC;AA7BD,sDAA0C;AAE1C,uDAA6D;AAU7D;;;;;GAKG;AACH,SAAgB,mBAAmB,CACjC,OAA6B,EAC7B,OAA0B;IAE1B,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM,MAAM,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,MAAM,WAAW,GAAG,IAAA,0CAAwB,EAAC,mBAAmB,CAAC,CAAC;IAClE,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IAE1E,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -2,49 +2,8 @@
|
|
|
2
2
|
* Options for OpenAPI middleware
|
|
3
3
|
*/
|
|
4
4
|
export interface OpenapiMiddlewareOptions {
|
|
5
|
-
/** Path to the openapi.
|
|
6
|
-
|
|
7
|
-
/** Path to the OpenAPI spec source file (when set, serves /openapi/spec with /openapi/* filtered and $refs resolved) */
|
|
8
|
-
openapiSpecFilePath?: string;
|
|
9
|
-
/** Enable source code enhancement */
|
|
10
|
-
enableEnhancement?: boolean;
|
|
11
|
-
/** Server directory for source code scanning (defaults to context.rootDir) */
|
|
12
|
-
serverDir?: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Source file information for API endpoint
|
|
16
|
-
*/
|
|
17
|
-
export interface SourceInfo {
|
|
18
|
-
file: string;
|
|
19
|
-
line: number;
|
|
20
|
-
method: string;
|
|
21
|
-
controllerPath: string;
|
|
22
|
-
routePath: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Options for enhancing OpenAPI specification
|
|
26
|
-
*/
|
|
27
|
-
export interface EnhanceOptions {
|
|
28
|
-
openapiPath?: string;
|
|
29
|
-
serverDir?: string;
|
|
30
|
-
openapiData?: any;
|
|
31
|
-
writeFile?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Statistics about the enhancement process
|
|
35
|
-
*/
|
|
36
|
-
export interface EnhanceStats {
|
|
37
|
-
duration: number;
|
|
38
|
-
controllersFound: number;
|
|
39
|
-
endpointsExtracted: number;
|
|
40
|
-
endpointsEnhanced: number;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Result of OpenAPI enhancement
|
|
44
|
-
*/
|
|
45
|
-
export interface EnhanceResult {
|
|
46
|
-
openapi: any;
|
|
47
|
-
stats: EnhanceStats;
|
|
5
|
+
/** Path to the OpenAPI spec source file. Serves /openapi/spec with /openapi/* filtered and $refs resolved. */
|
|
6
|
+
openapiSpecFilePath: string;
|
|
48
7
|
}
|
|
49
8
|
/**
|
|
50
9
|
* OpenAPI cache entry
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,8GAA8G;IAC9G,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/coding-preset-vite-react",
|
|
3
|
-
"version": "1.0.13-alpha.
|
|
3
|
+
"version": "1.0.13-alpha.11",
|
|
4
4
|
"description": "Vite 8 preset for miaoda-coding vite-react (jsPage) templates — pure frontend, no fullstack baggage",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Request, Response } from 'express';
|
|
2
|
-
import type { MiddlewareContext } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Create OpenAPI request handler with caching
|
|
5
|
-
*/
|
|
6
|
-
export declare function createOpenapiHandler(openapiFilePath: string, enableEnhancement: boolean, serverDir?: string): (_req: Request, res: Response, context: MiddlewareContext) => Promise<Response<any, Record<string, any>> | undefined>;
|
|
7
|
-
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/controller.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,OAAO,EAC1B,SAAS,CAAC,EAAE,MAAM,IAKJ,MAAM,OAAO,EAAE,KAAK,QAAQ,EAAE,SAAS,iBAAiB,6DAiDvE"}
|
|
@@ -1,60 +0,0 @@
|
|
|
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.createOpenapiHandler = createOpenapiHandler;
|
|
7
|
-
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
-
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
9
|
-
const services_1 = require("./services");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
/**
|
|
12
|
-
* Create OpenAPI request handler with caching
|
|
13
|
-
*/
|
|
14
|
-
function createOpenapiHandler(openapiFilePath, enableEnhancement, serverDir) {
|
|
15
|
-
// In-memory cache
|
|
16
|
-
let cache = null;
|
|
17
|
-
return async (_req, res, context) => {
|
|
18
|
-
try {
|
|
19
|
-
// Read OpenAPI file
|
|
20
|
-
const fileBuffer = await promises_1.default.readFile(openapiFilePath, 'utf-8');
|
|
21
|
-
// Calculate file hash for cache invalidation
|
|
22
|
-
const currentHash = node_crypto_1.default.createHash('md5').update(fileBuffer).digest('hex');
|
|
23
|
-
// Use cache if file content hasn't changed
|
|
24
|
-
if (cache && cache.fileHash === currentHash) {
|
|
25
|
-
return res.json(cache.data);
|
|
26
|
-
}
|
|
27
|
-
// Parse OpenAPI
|
|
28
|
-
let payload = JSON.parse(fileBuffer);
|
|
29
|
-
// Enhance with x-source if enabled
|
|
30
|
-
if (enableEnhancement && context.isDev) {
|
|
31
|
-
const { openapi: enhancedPayload, stats } = await (0, services_1.enhanceOpenApiWithSourceInfo)({
|
|
32
|
-
openapiData: payload,
|
|
33
|
-
writeFile: false, // Don't write to file, keep in memory
|
|
34
|
-
serverDir: serverDir || context.rootDir, // Use provided serverDir or fallback to context.rootDir
|
|
35
|
-
});
|
|
36
|
-
payload = enhancedPayload;
|
|
37
|
-
// Log performance
|
|
38
|
-
console.log(`[OpenAPI] Enhanced in ${stats.duration}ms (${stats.endpointsEnhanced} endpoints)`);
|
|
39
|
-
}
|
|
40
|
-
// Transform paths: remove basePath prefix from all API paths
|
|
41
|
-
const result = (0, utils_1.transformOpenapiPaths)(payload, context.basePath);
|
|
42
|
-
// Update cache
|
|
43
|
-
cache = {
|
|
44
|
-
data: result,
|
|
45
|
-
fileHash: currentHash,
|
|
46
|
-
};
|
|
47
|
-
res.json(result);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
52
|
-
res.status(500).json({
|
|
53
|
-
error: 'Failed to load OpenAPI spec',
|
|
54
|
-
message,
|
|
55
|
-
});
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=controller.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/server-log/openapi/controller.ts"],"names":[],"mappings":";;;;;AAaA,oDAyDC;AAtED,gEAAkC;AAClC,8DAAiC;AAEjC,yCAA0D;AAC1D,mCAAgD;AAMhD;;GAEG;AACH,SAAgB,oBAAoB,CAClC,eAAuB,EACvB,iBAA0B,EAC1B,SAAkB;IAElB,kBAAkB;IAClB,IAAI,KAAK,GAAwB,IAAI,CAAC;IAEtC,OAAO,KAAK,EAAE,IAAa,EAAE,GAAa,EAAE,OAA0B,EAAE,EAAE;QACxE,IAAI,CAAC;YACH,oBAAoB;YACpB,MAAM,UAAU,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YAE/D,6CAA6C;YAC7C,MAAM,WAAW,GAAG,qBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAE9E,2CAA2C;YAC3C,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;gBAC5C,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC9B,CAAC;YAED,gBAAgB;YAChB,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAErC,mCAAmC;YACnC,IAAI,iBAAiB,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBACvC,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,GAAG,MAAM,IAAA,uCAA4B,EAAC;oBAC7E,WAAW,EAAE,OAAO;oBACpB,SAAS,EAAE,KAAK,EAAE,sCAAsC;oBACxD,SAAS,EAAE,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE,wDAAwD;iBAClG,CAAC,CAAC;gBACH,OAAO,GAAG,eAAe,CAAC;gBAE1B,kBAAkB;gBAClB,OAAO,CAAC,GAAG,CAAC,yBAAyB,KAAK,CAAC,QAAQ,OAAO,KAAK,CAAC,iBAAiB,aAAa,CAAC,CAAC;YAClG,CAAC;YAED,6DAA6D;YAC7D,MAAM,MAAM,GAAG,IAAA,6BAAqB,EAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;YAEhE,eAAe;YACf,KAAK,GAAG;gBACN,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,WAAW;aACtB,CAAC;YAEF,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjB,OAAO;QACT,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YACzE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,6BAA6B;gBACpC,OAAO;aACR,CAAC,CAAC;YACH,OAAO;QACT,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { EnhanceOptions, EnhanceResult } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Enhances OpenAPI JSON with source file location metadata
|
|
4
|
-
* Can be called programmatically or run as a script
|
|
5
|
-
*/
|
|
6
|
-
export declare function enhanceOpenApiWithSourceInfo(options?: EnhanceOptions): Promise<EnhanceResult>;
|
|
7
|
-
/**
|
|
8
|
-
* Scan serverDir for NestJS controller files and extract all parameterized API routes.
|
|
9
|
-
* Synchronous — safe to call at preset config time (before bundling).
|
|
10
|
-
*/
|
|
11
|
-
export declare function parseApiRoutes(serverDir: string): Array<{
|
|
12
|
-
method: string;
|
|
13
|
-
path: string;
|
|
14
|
-
}>;
|
|
15
|
-
//# sourceMappingURL=services.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/services.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGzE;;;GAGG;AACH,wBAAsB,4BAA4B,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAoCvG;AA8MD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAQzF"}
|
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.enhanceOpenApiWithSourceInfo = enhanceOpenApiWithSourceInfo;
|
|
40
|
-
exports.parseApiRoutes = parseApiRoutes;
|
|
41
|
-
const node_fs_1 = require("node:fs");
|
|
42
|
-
const fsSync = __importStar(require("node:fs"));
|
|
43
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
44
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
45
|
-
const utils_1 = require("./utils");
|
|
46
|
-
/**
|
|
47
|
-
* Enhances OpenAPI JSON with source file location metadata
|
|
48
|
-
* Can be called programmatically or run as a script
|
|
49
|
-
*/
|
|
50
|
-
async function enhanceOpenApiWithSourceInfo(options = {}) {
|
|
51
|
-
const startTime = Date.now();
|
|
52
|
-
const openapiPath = options.openapiPath || node_path_1.default.resolve(__dirname, '../client/src/api/gen/openapi.json');
|
|
53
|
-
const serverDir = options.serverDir || node_path_1.default.resolve(__dirname, '../server');
|
|
54
|
-
const writeFile = options.writeFile !== false;
|
|
55
|
-
let openapi;
|
|
56
|
-
if (options.openapiData) {
|
|
57
|
-
// Use provided data (for in-memory enhancement)
|
|
58
|
-
openapi = JSON.parse(JSON.stringify(options.openapiData)); // Deep clone
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
// Read from file
|
|
62
|
-
const openapiContent = await node_fs_1.promises.readFile(openapiPath, 'utf-8');
|
|
63
|
-
openapi = JSON.parse(openapiContent);
|
|
64
|
-
}
|
|
65
|
-
const controllerFiles = await (0, utils_1.findControllerFiles)(serverDir);
|
|
66
|
-
const sourceMap = await (0, utils_1.buildSourceMap)(controllerFiles, processControllerFile);
|
|
67
|
-
const enhanced = (0, utils_1.enhanceOpenApiPaths)(openapi, sourceMap);
|
|
68
|
-
if (writeFile) {
|
|
69
|
-
await node_fs_1.promises.writeFile(openapiPath, JSON.stringify(openapi, null, 2) + '\n', 'utf-8');
|
|
70
|
-
}
|
|
71
|
-
const duration = Date.now() - startTime;
|
|
72
|
-
return {
|
|
73
|
-
openapi,
|
|
74
|
-
stats: {
|
|
75
|
-
duration,
|
|
76
|
-
controllersFound: controllerFiles.length,
|
|
77
|
-
endpointsExtracted: sourceMap.size,
|
|
78
|
-
endpointsEnhanced: enhanced,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Process a single controller file
|
|
84
|
-
*/
|
|
85
|
-
async function processControllerFile(filePath) {
|
|
86
|
-
const relativePath = node_path_1.default.relative(process.cwd(), filePath);
|
|
87
|
-
// Parse file
|
|
88
|
-
const content = await node_fs_1.promises.readFile(filePath, 'utf-8');
|
|
89
|
-
const sourceFile = typescript_1.default.createSourceFile(filePath, content, typescript_1.default.ScriptTarget.Latest, true);
|
|
90
|
-
return extractControllerMetadata(sourceFile, relativePath);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Extract controller metadata from TypeScript source file
|
|
94
|
-
*/
|
|
95
|
-
function extractControllerMetadata(sourceFile, filePath) {
|
|
96
|
-
const metadata = new Map();
|
|
97
|
-
let controllerPath = '';
|
|
98
|
-
let className = '';
|
|
99
|
-
// Helper function to get decorators from both old and new TypeScript APIs
|
|
100
|
-
function getDecorators(node) {
|
|
101
|
-
// TypeScript 5.x: decorators are in modifiers array
|
|
102
|
-
if ('modifiers' in node && Array.isArray(node.modifiers)) {
|
|
103
|
-
return node.modifiers.filter((mod) => mod.kind === typescript_1.default.SyntaxKind.Decorator);
|
|
104
|
-
}
|
|
105
|
-
// TypeScript 4.x: decorators are in decorators array
|
|
106
|
-
if ('decorators' in node && Array.isArray(node.decorators)) {
|
|
107
|
-
return node.decorators;
|
|
108
|
-
}
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
|
-
function visit(node) {
|
|
112
|
-
// Extract @Controller decorator and its path
|
|
113
|
-
if (typescript_1.default.isClassDeclaration(node)) {
|
|
114
|
-
const decorators = getDecorators(node);
|
|
115
|
-
// Extract class name
|
|
116
|
-
if (node.name) {
|
|
117
|
-
className = node.name.getText(sourceFile);
|
|
118
|
-
}
|
|
119
|
-
for (const decorator of decorators) {
|
|
120
|
-
if (typescript_1.default.isCallExpression(decorator.expression)) {
|
|
121
|
-
const expression = decorator.expression;
|
|
122
|
-
const decoratorName = expression.expression.getText(sourceFile);
|
|
123
|
-
if (decoratorName === 'Controller') {
|
|
124
|
-
if (expression.arguments.length > 0) {
|
|
125
|
-
const arg = expression.arguments[0];
|
|
126
|
-
if (typescript_1.default.isStringLiteral(arg)) {
|
|
127
|
-
controllerPath = arg.text;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Extract methods with HTTP decorators
|
|
135
|
-
if (typescript_1.default.isMethodDeclaration(node) && node.name) {
|
|
136
|
-
const methodName = node.name.getText(sourceFile);
|
|
137
|
-
let httpMethod = '';
|
|
138
|
-
let routePath = '';
|
|
139
|
-
const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
140
|
-
const decorators = getDecorators(node);
|
|
141
|
-
for (const decorator of decorators) {
|
|
142
|
-
if (typescript_1.default.isCallExpression(decorator.expression)) {
|
|
143
|
-
const decoratorName = decorator.expression.expression.getText(sourceFile);
|
|
144
|
-
if (['Get', 'Post', 'Put', 'Delete', 'Patch', 'Options', 'Head', 'All'].includes(decoratorName)) {
|
|
145
|
-
httpMethod = decoratorName.toLowerCase();
|
|
146
|
-
if (decorator.expression.arguments.length > 0) {
|
|
147
|
-
const arg = decorator.expression.arguments[0];
|
|
148
|
-
if (typescript_1.default.isStringLiteral(arg)) {
|
|
149
|
-
routePath = arg.text;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (httpMethod && methodName && className) {
|
|
156
|
-
const operationId = `${className}_${methodName}`;
|
|
157
|
-
metadata.set(operationId, {
|
|
158
|
-
file: filePath,
|
|
159
|
-
line: line + 1,
|
|
160
|
-
method: httpMethod,
|
|
161
|
-
controllerPath,
|
|
162
|
-
routePath,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
typescript_1.default.forEachChild(node, visit);
|
|
167
|
-
}
|
|
168
|
-
visit(sourceFile);
|
|
169
|
-
return metadata;
|
|
170
|
-
}
|
|
171
|
-
// --- API Route Parsing (synchronous, for build-time injection) ---
|
|
172
|
-
const HTTP_DECORATOR_NAMES = ['Get', 'Post', 'Put', 'Delete', 'Patch', 'Options', 'Head', 'All'];
|
|
173
|
-
function findControllerFilesSync(dir) {
|
|
174
|
-
const files = [];
|
|
175
|
-
function scan(currentDir) {
|
|
176
|
-
let entries;
|
|
177
|
-
try {
|
|
178
|
-
entries = fsSync.readdirSync(currentDir, { withFileTypes: true });
|
|
179
|
-
}
|
|
180
|
-
catch {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
for (const entry of entries) {
|
|
184
|
-
const fullPath = node_path_1.default.join(currentDir, entry.name);
|
|
185
|
-
if (entry.isDirectory()) {
|
|
186
|
-
scan(fullPath);
|
|
187
|
-
}
|
|
188
|
-
else if (entry.isFile() && entry.name.endsWith('.controller.ts')) {
|
|
189
|
-
files.push(fullPath);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
scan(dir);
|
|
194
|
-
return files;
|
|
195
|
-
}
|
|
196
|
-
function normalizeApiPath(controllerPath, routePath) {
|
|
197
|
-
const combined = routePath ? `${controllerPath}/${routePath}` : controllerPath;
|
|
198
|
-
let normalized = combined.replace(/\/+/g, '/');
|
|
199
|
-
if (!normalized.startsWith('/'))
|
|
200
|
-
normalized = `/${normalized}`;
|
|
201
|
-
if (normalized.length > 1 && normalized.endsWith('/'))
|
|
202
|
-
normalized = normalized.slice(0, -1);
|
|
203
|
-
return normalized;
|
|
204
|
-
}
|
|
205
|
-
function parseControllerRoutes(filePath) {
|
|
206
|
-
let content;
|
|
207
|
-
try {
|
|
208
|
-
content = fsSync.readFileSync(filePath, 'utf-8');
|
|
209
|
-
}
|
|
210
|
-
catch {
|
|
211
|
-
return [];
|
|
212
|
-
}
|
|
213
|
-
const sourceFile = typescript_1.default.createSourceFile(filePath, content, typescript_1.default.ScriptTarget.Latest, true);
|
|
214
|
-
const routes = [];
|
|
215
|
-
function getDecoratorsCompat(node) {
|
|
216
|
-
if ('modifiers' in node && Array.isArray(node.modifiers)) {
|
|
217
|
-
return node.modifiers.filter((mod) => mod.kind === typescript_1.default.SyntaxKind.Decorator);
|
|
218
|
-
}
|
|
219
|
-
if ('decorators' in node && Array.isArray(node.decorators)) {
|
|
220
|
-
return node.decorators;
|
|
221
|
-
}
|
|
222
|
-
return [];
|
|
223
|
-
}
|
|
224
|
-
function getStringArg(expr) {
|
|
225
|
-
if (expr.arguments.length > 0 && typescript_1.default.isStringLiteral(expr.arguments[0])) {
|
|
226
|
-
return expr.arguments[0].text;
|
|
227
|
-
}
|
|
228
|
-
return '';
|
|
229
|
-
}
|
|
230
|
-
function visit(node) {
|
|
231
|
-
if (typescript_1.default.isClassDeclaration(node)) {
|
|
232
|
-
let controllerPath = '';
|
|
233
|
-
for (const dec of getDecoratorsCompat(node)) {
|
|
234
|
-
if (typescript_1.default.isCallExpression(dec.expression)) {
|
|
235
|
-
const name = dec.expression.expression.getText(sourceFile);
|
|
236
|
-
if (name === 'Controller') {
|
|
237
|
-
controllerPath = getStringArg(dec.expression);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
for (const member of node.members) {
|
|
243
|
-
if (!typescript_1.default.isMethodDeclaration(member))
|
|
244
|
-
continue;
|
|
245
|
-
for (const dec of getDecoratorsCompat(member)) {
|
|
246
|
-
if (!typescript_1.default.isCallExpression(dec.expression))
|
|
247
|
-
continue;
|
|
248
|
-
const decoratorName = dec.expression.expression.getText(sourceFile);
|
|
249
|
-
if (!HTTP_DECORATOR_NAMES.includes(decoratorName))
|
|
250
|
-
continue;
|
|
251
|
-
const routePath = getStringArg(dec.expression);
|
|
252
|
-
const fullPath = normalizeApiPath(controllerPath, routePath);
|
|
253
|
-
const method = decoratorName === 'All' ? '*' : decoratorName.toUpperCase();
|
|
254
|
-
routes.push({ method, path: fullPath });
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
typescript_1.default.forEachChild(node, visit);
|
|
259
|
-
}
|
|
260
|
-
visit(sourceFile);
|
|
261
|
-
return routes;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Scan serverDir for NestJS controller files and extract all parameterized API routes.
|
|
265
|
-
* Synchronous — safe to call at preset config time (before bundling).
|
|
266
|
-
*/
|
|
267
|
-
function parseApiRoutes(serverDir) {
|
|
268
|
-
const resolvedDir = node_path_1.default.resolve(serverDir);
|
|
269
|
-
const controllerFiles = findControllerFilesSync(resolvedDir);
|
|
270
|
-
const routes = [];
|
|
271
|
-
for (const filePath of controllerFiles) {
|
|
272
|
-
routes.push(...parseControllerRoutes(filePath));
|
|
273
|
-
}
|
|
274
|
-
return routes;
|
|
275
|
-
}
|
|
276
|
-
//# sourceMappingURL=services.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"services.js","sourceR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@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { SourceInfo } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Find all controller files in a directory
|
|
4
|
-
*/
|
|
5
|
-
export declare function findControllerFiles(dir: string): Promise<string[]>;
|
|
6
|
-
/**
|
|
7
|
-
* Build source map from controller files
|
|
8
|
-
*/
|
|
9
|
-
export declare function buildSourceMap(controllerFiles: string[], processFile: (filePath: string) => Promise<Map<string, SourceInfo>>): Promise<Map<string, SourceInfo>>;
|
|
10
|
-
/**
|
|
11
|
-
* Enhance OpenAPI paths with source information
|
|
12
|
-
*/
|
|
13
|
-
export declare function enhanceOpenApiPaths(openapi: any, sourceMap: Map<string, SourceInfo>): number;
|
|
14
|
-
/**
|
|
15
|
-
* Transform OpenAPI paths by removing basePath prefix
|
|
16
|
-
*/
|
|
17
|
-
export declare function transformOpenapiPaths(openapi: any, basePath: string): any;
|
|
18
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/server-log/openapi/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAmBxE;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,eAAe,EAAE,MAAM,EAAE,EACzB,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAClE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAqBlC;AAqCD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,MAAM,CAyB5F;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,CAgBzE"}
|
|
@@ -1,128 +0,0 @@
|
|
|
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.findControllerFiles = findControllerFiles;
|
|
7
|
-
exports.buildSourceMap = buildSourceMap;
|
|
8
|
-
exports.enhanceOpenApiPaths = enhanceOpenApiPaths;
|
|
9
|
-
exports.transformOpenapiPaths = transformOpenapiPaths;
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const node_fs_1 = require("node:fs");
|
|
12
|
-
/**
|
|
13
|
-
* Find all controller files in a directory
|
|
14
|
-
*/
|
|
15
|
-
async function findControllerFiles(dir) {
|
|
16
|
-
const files = [];
|
|
17
|
-
async function scan(currentDir) {
|
|
18
|
-
const entries = await node_fs_1.promises.readdir(currentDir, { withFileTypes: true });
|
|
19
|
-
for (const entry of entries) {
|
|
20
|
-
const fullPath = node_path_1.default.join(currentDir, entry.name);
|
|
21
|
-
if (entry.isDirectory()) {
|
|
22
|
-
await scan(fullPath);
|
|
23
|
-
}
|
|
24
|
-
else if (entry.isFile() && entry.name.endsWith('.controller.ts')) {
|
|
25
|
-
files.push(fullPath);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
await scan(dir);
|
|
30
|
-
return files;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Build source map from controller files
|
|
34
|
-
*/
|
|
35
|
-
async function buildSourceMap(controllerFiles, processFile) {
|
|
36
|
-
const sourceMap = new Map();
|
|
37
|
-
// Process files in parallel with a concurrency limit
|
|
38
|
-
const concurrency = 10;
|
|
39
|
-
const results = [];
|
|
40
|
-
for (let i = 0; i < controllerFiles.length; i += concurrency) {
|
|
41
|
-
const batch = controllerFiles.slice(i, i + concurrency);
|
|
42
|
-
const batchResults = await Promise.all(batch.map((filePath) => processFile(filePath)));
|
|
43
|
-
results.push(...batchResults);
|
|
44
|
-
}
|
|
45
|
-
// Merge results
|
|
46
|
-
for (const metadata of results) {
|
|
47
|
-
for (const [operationId, info] of metadata.entries()) {
|
|
48
|
-
sourceMap.set(operationId, info);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return sourceMap;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Try to match operationId with different formats
|
|
55
|
-
* Supports:
|
|
56
|
-
* - Direct match: ClassName_methodName
|
|
57
|
-
* - Camel case: classNameMethodName
|
|
58
|
-
* - Method only: methodName
|
|
59
|
-
*/
|
|
60
|
-
function findSourceInfo(operationId, sourceMap) {
|
|
61
|
-
// Try direct match first
|
|
62
|
-
const directMatch = sourceMap.get(operationId);
|
|
63
|
-
if (directMatch) {
|
|
64
|
-
return directMatch;
|
|
65
|
-
}
|
|
66
|
-
// Try matching with different formats
|
|
67
|
-
for (const [key, value] of sourceMap.entries()) {
|
|
68
|
-
// key format: ClassName_methodName
|
|
69
|
-
const [className, methodName] = key.split('_');
|
|
70
|
-
if (!className || !methodName)
|
|
71
|
-
continue;
|
|
72
|
-
// Try camelCase format: classNameMethodName
|
|
73
|
-
const camelCaseId = className.charAt(0).toLowerCase() + className.slice(1) + methodName.charAt(0).toUpperCase() + methodName.slice(1);
|
|
74
|
-
if (operationId === camelCaseId) {
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
// Try method name only
|
|
78
|
-
if (operationId === methodName) {
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Enhance OpenAPI paths with source information
|
|
86
|
-
*/
|
|
87
|
-
function enhanceOpenApiPaths(openapi, sourceMap) {
|
|
88
|
-
let enhancedCount = 0;
|
|
89
|
-
if (!openapi.paths) {
|
|
90
|
-
return enhancedCount;
|
|
91
|
-
}
|
|
92
|
-
for (const pathItem of Object.values(openapi.paths)) {
|
|
93
|
-
if (!pathItem || typeof pathItem !== 'object')
|
|
94
|
-
continue;
|
|
95
|
-
for (const operation of Object.values(pathItem)) {
|
|
96
|
-
if (operation && typeof operation === 'object' && 'operationId' in operation) {
|
|
97
|
-
const sourceInfo = findSourceInfo(operation.operationId, sourceMap);
|
|
98
|
-
if (sourceInfo) {
|
|
99
|
-
operation['x-source'] = {
|
|
100
|
-
file: sourceInfo.file,
|
|
101
|
-
line: sourceInfo.line,
|
|
102
|
-
};
|
|
103
|
-
enhancedCount++;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return enhancedCount;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Transform OpenAPI paths by removing basePath prefix
|
|
112
|
-
*/
|
|
113
|
-
function transformOpenapiPaths(openapi, basePath) {
|
|
114
|
-
if (basePath === '/' || !openapi.paths) {
|
|
115
|
-
return openapi;
|
|
116
|
-
}
|
|
117
|
-
const newPaths = {};
|
|
118
|
-
Object.keys(openapi.paths).forEach((key) => {
|
|
119
|
-
const staticApiKey = key.startsWith(basePath) ? key.slice(basePath.length) : key;
|
|
120
|
-
newPaths[staticApiKey] = openapi.paths[key];
|
|
121
|
-
});
|
|
122
|
-
return {
|
|
123
|
-
...openapi,
|
|
124
|
-
paths: newPaths,
|
|
125
|
-
basePath,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/server-log/openapi/utils.ts"],"names":[],"mappings":";;;;;AAOA,kDAmBC;AAKD,wCAwBC;AAwCD,kDAyBC;AAKD,sDAgBC;AA7ID,0DAA6B;AAC7B,qCAA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