@lark-apaas/coding-preset-vite-react 1.0.13-alpha.0 → 1.0.13-alpha.10
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/index.d.ts +9 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +153 -114
- package/lib/index.js.map +1 -1
- package/lib/plugins/{basename-injection.d.ts → basename.d.ts} +4 -4
- package/lib/plugins/basename.d.ts.map +1 -0
- package/lib/plugins/{basename-injection.js → basename.js} +7 -15
- package/lib/plugins/basename.js.map +1 -0
- package/lib/plugins/capabilities.d.ts +9 -6
- package/lib/plugins/capabilities.d.ts.map +1 -1
- package/lib/plugins/capabilities.js +27 -29
- package/lib/plugins/capabilities.js.map +1 -1
- package/lib/plugins/dev-proxy.d.ts +41 -0
- package/lib/plugins/dev-proxy.d.ts.map +1 -0
- package/lib/plugins/dev-proxy.js +229 -0
- package/lib/plugins/dev-proxy.js.map +1 -0
- package/lib/plugins/fonts-mirror.d.ts.map +1 -1
- package/lib/plugins/fonts-mirror.js +28 -0
- package/lib/plugins/fonts-mirror.js.map +1 -1
- package/lib/plugins/html-output.d.ts +21 -0
- package/lib/plugins/html-output.d.ts.map +1 -0
- package/lib/plugins/html-output.js +171 -0
- package/lib/plugins/html-output.js.map +1 -0
- package/lib/plugins/server-log.d.ts +55 -0
- package/lib/plugins/server-log.d.ts.map +1 -0
- package/lib/plugins/server-log.js +80 -0
- package/lib/plugins/server-log.js.map +1 -0
- package/lib/plugins/view-context.d.ts +0 -5
- package/lib/plugins/view-context.d.ts.map +1 -1
- package/lib/plugins/view-context.js +0 -3
- package/lib/plugins/view-context.js.map +1 -1
- package/lib/server-log/compat.d.ts +36 -0
- package/lib/server-log/compat.d.ts.map +1 -0
- package/lib/server-log/compat.js +73 -0
- package/lib/server-log/compat.js.map +1 -0
- package/lib/server-log/dev-logs/api-list-handler.d.ts +6 -0
- package/lib/server-log/dev-logs/api-list-handler.d.ts.map +1 -0
- package/lib/server-log/dev-logs/api-list-handler.js +132 -0
- package/lib/server-log/dev-logs/api-list-handler.js.map +1 -0
- package/lib/server-log/dev-logs/controller.d.ts +45 -0
- package/lib/server-log/dev-logs/controller.d.ts.map +1 -0
- package/lib/server-log/dev-logs/controller.js +239 -0
- package/lib/server-log/dev-logs/controller.js.map +1 -0
- package/lib/server-log/dev-logs/health.controller.d.ts +15 -0
- package/lib/server-log/dev-logs/health.controller.d.ts.map +1 -0
- package/lib/server-log/dev-logs/health.controller.js +79 -0
- package/lib/server-log/dev-logs/health.controller.js.map +1 -0
- package/lib/server-log/dev-logs/helper/path-matcher.d.ts +117 -0
- package/lib/server-log/dev-logs/helper/path-matcher.d.ts.map +1 -0
- package/lib/server-log/dev-logs/helper/path-matcher.js +214 -0
- package/lib/server-log/dev-logs/helper/path-matcher.js.map +1 -0
- package/lib/server-log/dev-logs/index.d.ts +12 -0
- package/lib/server-log/dev-logs/index.d.ts.map +1 -0
- package/lib/server-log/dev-logs/index.js +61 -0
- package/lib/server-log/dev-logs/index.js.map +1 -0
- package/lib/server-log/dev-logs/router.d.ts +7 -0
- package/lib/server-log/dev-logs/router.d.ts.map +1 -0
- package/lib/server-log/dev-logs/router.js +40 -0
- package/lib/server-log/dev-logs/router.js.map +1 -0
- package/lib/server-log/dev-logs/services/capability.service.d.ts +33 -0
- package/lib/server-log/dev-logs/services/capability.service.d.ts.map +1 -0
- package/lib/server-log/dev-logs/services/capability.service.js +127 -0
- package/lib/server-log/dev-logs/services/capability.service.js.map +1 -0
- package/lib/server-log/dev-logs/services/file-reader.d.ts +10 -0
- package/lib/server-log/dev-logs/services/file-reader.d.ts.map +1 -0
- package/lib/server-log/dev-logs/services/file-reader.js +67 -0
- package/lib/server-log/dev-logs/services/file-reader.js.map +1 -0
- package/lib/server-log/dev-logs/services/index.d.ts +8 -0
- package/lib/server-log/dev-logs/services/index.d.ts.map +1 -0
- package/lib/server-log/dev-logs/services/index.js +30 -0
- package/lib/server-log/dev-logs/services/index.js.map +1 -0
- package/lib/server-log/dev-logs/services/parsers.d.ts +23 -0
- package/lib/server-log/dev-logs/services/parsers.d.ts.map +1 -0
- package/lib/server-log/dev-logs/services/parsers.js +157 -0
- package/lib/server-log/dev-logs/services/parsers.js.map +1 -0
- package/lib/server-log/dev-logs/services/server-log.service.d.ts +17 -0
- package/lib/server-log/dev-logs/services/server-log.service.d.ts.map +1 -0
- package/lib/server-log/dev-logs/services/server-log.service.js +119 -0
- package/lib/server-log/dev-logs/services/server-log.service.js.map +1 -0
- package/lib/server-log/dev-logs/services/trace.service.d.ts +14 -0
- package/lib/server-log/dev-logs/services/trace.service.d.ts.map +1 -0
- package/lib/server-log/dev-logs/services/trace.service.js +162 -0
- package/lib/server-log/dev-logs/services/trace.service.js.map +1 -0
- package/lib/server-log/dev-logs/services/trigger.service.d.ts +14 -0
- package/lib/server-log/dev-logs/services/trigger.service.d.ts.map +1 -0
- package/lib/server-log/dev-logs/services/trigger.service.js +153 -0
- package/lib/server-log/dev-logs/services/trigger.service.js.map +1 -0
- package/lib/server-log/dev-logs/services.d.ts +7 -0
- package/lib/server-log/dev-logs/services.d.ts.map +1 -0
- package/lib/server-log/dev-logs/services.js +20 -0
- package/lib/server-log/dev-logs/services.js.map +1 -0
- package/lib/server-log/dev-logs/sse/client-manager.d.ts +61 -0
- package/lib/server-log/dev-logs/sse/client-manager.d.ts.map +1 -0
- package/lib/server-log/dev-logs/sse/client-manager.js +140 -0
- package/lib/server-log/dev-logs/sse/client-manager.js.map +1 -0
- package/lib/server-log/dev-logs/sse/index.d.ts +5 -0
- package/lib/server-log/dev-logs/sse/index.d.ts.map +1 -0
- package/lib/server-log/dev-logs/sse/index.js +11 -0
- package/lib/server-log/dev-logs/sse/index.js.map +1 -0
- package/lib/server-log/dev-logs/sse/log-watcher.d.ts +51 -0
- package/lib/server-log/dev-logs/sse/log-watcher.d.ts.map +1 -0
- package/lib/server-log/dev-logs/sse/log-watcher.js +381 -0
- package/lib/server-log/dev-logs/sse/log-watcher.js.map +1 -0
- package/lib/server-log/dev-logs/sse/sse.controller.d.ts +25 -0
- package/lib/server-log/dev-logs/sse/sse.controller.d.ts.map +1 -0
- package/lib/server-log/dev-logs/sse/sse.controller.js +95 -0
- package/lib/server-log/dev-logs/sse/sse.controller.js.map +1 -0
- package/lib/server-log/dev-logs/types.d.ts +104 -0
- package/lib/server-log/dev-logs/types.d.ts.map +1 -0
- package/lib/server-log/dev-logs/types.js +3 -0
- package/lib/server-log/dev-logs/types.js.map +1 -0
- package/lib/server-log/dev-logs/utils.d.ts +68 -0
- package/lib/server-log/dev-logs/utils.d.ts.map +1 -0
- package/lib/server-log/dev-logs/utils.js +151 -0
- package/lib/server-log/dev-logs/utils.js.map +1 -0
- package/lib/server-log/openapi/controller.d.ts +7 -0
- package/lib/server-log/openapi/controller.d.ts.map +1 -0
- package/lib/server-log/openapi/controller.js +60 -0
- package/lib/server-log/openapi/controller.js.map +1 -0
- package/lib/server-log/openapi/index.d.ts +10 -0
- package/lib/server-log/openapi/index.d.ts.map +1 -0
- package/lib/server-log/openapi/index.js +48 -0
- package/lib/server-log/openapi/index.js.map +1 -0
- package/lib/server-log/openapi/router.d.ts +20 -0
- package/lib/server-log/openapi/router.d.ts.map +1 -0
- package/lib/server-log/openapi/router.js +26 -0
- package/lib/server-log/openapi/router.js.map +1 -0
- package/lib/server-log/openapi/services.d.ts +15 -0
- package/lib/server-log/openapi/services.d.ts.map +1 -0
- package/lib/server-log/openapi/services.js +276 -0
- package/lib/server-log/openapi/services.js.map +1 -0
- package/lib/server-log/openapi/spec-controller.d.ts +4 -0
- package/lib/server-log/openapi/spec-controller.d.ts.map +1 -0
- package/lib/server-log/openapi/spec-controller.js +136 -0
- package/lib/server-log/openapi/spec-controller.js.map +1 -0
- package/lib/server-log/openapi/types.d.ts +56 -0
- package/lib/server-log/openapi/types.d.ts.map +1 -0
- package/lib/server-log/openapi/types.js +3 -0
- package/lib/server-log/openapi/types.js.map +1 -0
- package/lib/server-log/openapi/utils.d.ts +18 -0
- package/lib/server-log/openapi/utils.d.ts.map +1 -0
- package/lib/server-log/openapi/utils.js +128 -0
- package/lib/server-log/openapi/utils.js.map +1 -0
- package/lib/server-log/register.d.ts +34 -0
- package/lib/server-log/register.d.ts.map +1 -0
- package/lib/server-log/register.js +196 -0
- package/lib/server-log/register.js.map +1 -0
- package/lib/server-log/types.d.ts +99 -0
- package/lib/server-log/types.d.ts.map +1 -0
- package/lib/server-log/types.js +3 -0
- package/lib/server-log/types.js.map +1 -0
- package/lib/utils/local-dev.d.ts +46 -0
- package/lib/utils/local-dev.d.ts.map +1 -0
- package/lib/utils/local-dev.js +96 -0
- package/lib/utils/local-dev.js.map +1 -0
- package/lib/utils/proxy-error.d.ts +29 -0
- package/lib/utils/proxy-error.d.ts.map +1 -0
- package/lib/utils/proxy-error.js +158 -0
- package/lib/utils/proxy-error.js.map +1 -0
- package/package.json +3 -1
- package/lib/plugins/basename-injection.d.ts.map +0 -1
- package/lib/plugins/basename-injection.js.map +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { LogEntry } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve log directory path
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveLogDir(provided?: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Get relative path from current working directory
|
|
8
|
+
*/
|
|
9
|
+
export declare function getRelativePath(filePath: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Check if file exists
|
|
12
|
+
*/
|
|
13
|
+
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* Parse a log line as JSON
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseLogLine(line: string): LogEntry | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Extract number from message using regex pattern
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractNumber(message: string, pattern: RegExp): number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Parse limit parameter with default and max value
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseLimit(value: string | undefined, defaultValue: number, maxValue: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Parse positive integer with fallback
|
|
28
|
+
*/
|
|
29
|
+
export declare function parsePositiveInt(value: string | undefined, fallback: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve log file path with security checks
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveLogFilePath(baseDir: string, fileName: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Check if actual request path matches expected OpenAPI/Swagger path pattern
|
|
36
|
+
*
|
|
37
|
+
* @param actualPath - The actual request path from logs (e.g., /api/users/123)
|
|
38
|
+
* @param pattern - The OpenAPI path pattern to match against (e.g., /api/users/{id})
|
|
39
|
+
* @returns true if the path matches the pattern
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* matchesPath('/api/users/123', '/api/users/{id}') // true
|
|
43
|
+
* matchesPath('/api/users/123', '/api/users') // true (prefix match)
|
|
44
|
+
* matchesPath('/api/posts/456', '/api/users/{id}') // false
|
|
45
|
+
*/
|
|
46
|
+
export declare function matchesPath(actualPath: string | undefined, pattern: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Check if actual request method matches expected HTTP method
|
|
49
|
+
*
|
|
50
|
+
* @param actualMethod - The actual request method from logs (e.g., 'GET', 'POST')
|
|
51
|
+
* @param expectedMethod - The expected HTTP method to match against (e.g., 'GET')
|
|
52
|
+
* @returns true if the method matches (case-insensitive)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* matchesMethod('GET', 'GET') // true
|
|
56
|
+
* matchesMethod('get', 'GET') // true
|
|
57
|
+
* matchesMethod('POST', 'GET') // false
|
|
58
|
+
* matchesMethod(undefined, 'GET') // false
|
|
59
|
+
*/
|
|
60
|
+
export declare function matchesMethod(actualMethod: string | undefined, expectedMethod: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Serialize error for JSON response
|
|
63
|
+
*/
|
|
64
|
+
export declare function serializeError(error: unknown): {
|
|
65
|
+
name?: string;
|
|
66
|
+
message: string;
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/server-log/dev-logs/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAKvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAS/D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQlF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAWpG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOpF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAgB5E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEpF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAK/F;AAGD;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAIjF"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveLogDir = resolveLogDir;
|
|
4
|
+
exports.getRelativePath = getRelativePath;
|
|
5
|
+
exports.fileExists = fileExists;
|
|
6
|
+
exports.parseLogLine = parseLogLine;
|
|
7
|
+
exports.extractNumber = extractNumber;
|
|
8
|
+
exports.parseLimit = parseLimit;
|
|
9
|
+
exports.parsePositiveInt = parsePositiveInt;
|
|
10
|
+
exports.resolveLogFilePath = resolveLogFilePath;
|
|
11
|
+
exports.matchesPath = matchesPath;
|
|
12
|
+
exports.matchesMethod = matchesMethod;
|
|
13
|
+
exports.serializeError = serializeError;
|
|
14
|
+
const node_fs_1 = require("node:fs");
|
|
15
|
+
const node_path_1 = require("node:path");
|
|
16
|
+
const path_matcher_1 = require("./helper/path-matcher");
|
|
17
|
+
/**
|
|
18
|
+
* Resolve log directory path
|
|
19
|
+
*/
|
|
20
|
+
function resolveLogDir(provided) {
|
|
21
|
+
if (!provided) {
|
|
22
|
+
return (0, node_path_1.join)(process.cwd(), 'logs');
|
|
23
|
+
}
|
|
24
|
+
return (0, node_path_1.isAbsolute)(provided) ? provided : (0, node_path_1.join)(process.cwd(), provided);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get relative path from current working directory
|
|
28
|
+
*/
|
|
29
|
+
function getRelativePath(filePath) {
|
|
30
|
+
return (0, node_path_1.relative)(process.cwd(), filePath);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if file exists
|
|
34
|
+
*/
|
|
35
|
+
async function fileExists(filePath) {
|
|
36
|
+
try {
|
|
37
|
+
await node_fs_1.promises.access(filePath);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse a log line as JSON
|
|
46
|
+
*/
|
|
47
|
+
function parseLogLine(line) {
|
|
48
|
+
const trimmed = line.trim();
|
|
49
|
+
if (!trimmed)
|
|
50
|
+
return undefined;
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(trimmed);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Extract number from message using regex pattern
|
|
60
|
+
*/
|
|
61
|
+
function extractNumber(message, pattern) {
|
|
62
|
+
if (typeof message !== 'string')
|
|
63
|
+
return undefined;
|
|
64
|
+
const match = message.match(pattern);
|
|
65
|
+
if (!match)
|
|
66
|
+
return undefined;
|
|
67
|
+
const value = Number(match[1]);
|
|
68
|
+
return Number.isFinite(value) ? value : undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Parse limit parameter with default and max value
|
|
72
|
+
*/
|
|
73
|
+
function parseLimit(value, defaultValue, maxValue) {
|
|
74
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
75
|
+
return defaultValue;
|
|
76
|
+
}
|
|
77
|
+
const parsed = Number(value);
|
|
78
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
79
|
+
return Math.min(Math.floor(parsed), maxValue);
|
|
80
|
+
}
|
|
81
|
+
return defaultValue;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Parse positive integer with fallback
|
|
85
|
+
*/
|
|
86
|
+
function parsePositiveInt(value, fallback) {
|
|
87
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
88
|
+
return fallback;
|
|
89
|
+
}
|
|
90
|
+
const parsed = Number(value);
|
|
91
|
+
return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : fallback;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Resolve log file path with security checks
|
|
95
|
+
*/
|
|
96
|
+
function resolveLogFilePath(baseDir, fileName) {
|
|
97
|
+
const sanitized = fileName.replace(/\\/g, '/');
|
|
98
|
+
const segments = sanitized.split('/').filter(Boolean);
|
|
99
|
+
if (segments.some((segment) => segment === '..')) {
|
|
100
|
+
throw new Error('Invalid log file path');
|
|
101
|
+
}
|
|
102
|
+
const resolved = (0, node_path_1.join)(baseDir, segments.join('/'));
|
|
103
|
+
const rel = (0, node_path_1.relative)(baseDir, resolved);
|
|
104
|
+
if (rel.startsWith('..')) {
|
|
105
|
+
throw new Error('Access to the specified log file is denied');
|
|
106
|
+
}
|
|
107
|
+
return resolved;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Check if actual request path matches expected OpenAPI/Swagger path pattern
|
|
111
|
+
*
|
|
112
|
+
* @param actualPath - The actual request path from logs (e.g., /api/users/123)
|
|
113
|
+
* @param pattern - The OpenAPI path pattern to match against (e.g., /api/users/{id})
|
|
114
|
+
* @returns true if the path matches the pattern
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* matchesPath('/api/users/123', '/api/users/{id}') // true
|
|
118
|
+
* matchesPath('/api/users/123', '/api/users') // true (prefix match)
|
|
119
|
+
* matchesPath('/api/posts/456', '/api/users/{id}') // false
|
|
120
|
+
*/
|
|
121
|
+
function matchesPath(actualPath, pattern) {
|
|
122
|
+
return (0, path_matcher_1.matchesPathPattern)(actualPath, pattern);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Check if actual request method matches expected HTTP method
|
|
126
|
+
*
|
|
127
|
+
* @param actualMethod - The actual request method from logs (e.g., 'GET', 'POST')
|
|
128
|
+
* @param expectedMethod - The expected HTTP method to match against (e.g., 'GET')
|
|
129
|
+
* @returns true if the method matches (case-insensitive)
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* matchesMethod('GET', 'GET') // true
|
|
133
|
+
* matchesMethod('get', 'GET') // true
|
|
134
|
+
* matchesMethod('POST', 'GET') // false
|
|
135
|
+
* matchesMethod(undefined, 'GET') // false
|
|
136
|
+
*/
|
|
137
|
+
function matchesMethod(actualMethod, expectedMethod) {
|
|
138
|
+
if (!actualMethod || !expectedMethod) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return actualMethod.toUpperCase() === expectedMethod.toUpperCase();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Serialize error for JSON response
|
|
145
|
+
*/
|
|
146
|
+
function serializeError(error) {
|
|
147
|
+
return error instanceof Error
|
|
148
|
+
? { name: error.name, message: error.message }
|
|
149
|
+
: { message: String(error) };
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/server-log/dev-logs/utils.ts"],"names":[],"mappings":";;AAQA,sCAKC;AAKD,0CAEC;AAKD,gCAOC;AAKD,oCASC;AAKD,sCAQC;AAKD,gCAWC;AAKD,4CAOC;AAKD,gDAgBC;AAcD,kCAEC;AAeD,sCAKC;AAMD,wCAIC;AA1JD,qCAAyC;AACzC,yCAAuD;AAEvD,wDAA2D;AAE3D;;GAEG;AACH,SAAgB,aAAa,CAAC,QAAiB;IAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAA,gBAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,IAAA,sBAAU,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAA,gBAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,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AAM,GAAG,GAAG,IAAA,oBAAQ,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAExC,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,WAAW,CAAC,UAA8B,EAAE,OAAe;IACzE,OAAO,IAAA,iCAAkB,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAAC,YAAgC,EAAE,cAAsB;IACpF,IAAI,CAAC,YAAY,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,YAAY,CAAC,WAAW,EAAE,KAAK,cAAc,CAAC,WAAW,EAAE,CAAC;AACrE,CAAC;AAGD;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,KAAK;QAC3B,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;QAC9C,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,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AW;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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RouteMiddleware } from '../types';
|
|
2
|
+
import type { OpenapiMiddlewareOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates OpenAPI middleware that serves enhanced openapi.json
|
|
5
|
+
* Supports both rspack/webpack and Vite dev servers
|
|
6
|
+
*/
|
|
7
|
+
export declare function createOpenapiMiddleware(options: OpenapiMiddlewareOptions): RouteMiddleware;
|
|
8
|
+
export type { OpenapiMiddlewareOptions, SourceInfo, EnhanceOptions, EnhanceResult } from './types';
|
|
9
|
+
export { enhanceOpenApiWithSourceInfo, parseApiRoutes } from './services';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAmBxD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,eAAe,CA0B1F;AAGD,YAAY,EAAE,wBAAwB,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnG,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseApiRoutes = exports.enhanceOpenApiWithSourceInfo = void 0;
|
|
4
|
+
exports.createOpenapiMiddleware = createOpenapiMiddleware;
|
|
5
|
+
const router_1 = require("./router");
|
|
6
|
+
/**
|
|
7
|
+
* Routes provided by OpenAPI middleware
|
|
8
|
+
*/
|
|
9
|
+
const OPENAPI_ROUTES = [
|
|
10
|
+
{
|
|
11
|
+
method: 'GET',
|
|
12
|
+
path: '/openapi.json',
|
|
13
|
+
description: 'Serve enhanced OpenAPI specification with source code references',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
method: 'GET',
|
|
17
|
+
path: '/openapi/spec',
|
|
18
|
+
description: 'Serve OpenAPI specification for /openapi/*',
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Creates OpenAPI middleware that serves enhanced openapi.json
|
|
23
|
+
* Supports both rspack/webpack and Vite dev servers
|
|
24
|
+
*/
|
|
25
|
+
function createOpenapiMiddleware(options) {
|
|
26
|
+
const { openapiFilePath, openapiSpecFilePath, enableEnhancement = true, serverDir } = options;
|
|
27
|
+
const routes = openapiSpecFilePath
|
|
28
|
+
? OPENAPI_ROUTES
|
|
29
|
+
: OPENAPI_ROUTES.filter((route) => route.path !== '/openapi/spec');
|
|
30
|
+
return {
|
|
31
|
+
name: 'openapi',
|
|
32
|
+
mountPath: '/dev',
|
|
33
|
+
routes,
|
|
34
|
+
enabled: (context) => context.isDev,
|
|
35
|
+
createRouter: (context) => {
|
|
36
|
+
return (0, router_1.createOpenapiRouter)({
|
|
37
|
+
openapiFilePath,
|
|
38
|
+
openapiSpecFilePath,
|
|
39
|
+
enableEnhancement,
|
|
40
|
+
serverDir,
|
|
41
|
+
}, context);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
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
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server-log/openapi/index.ts"],"names":[],"mappings":";;;AAwBA,0DA0BC;AAhDD,qCAA+C;AAE/C;;GAEG;AACH,MAAM,cAAc,GAAgB;IAClC;QACE,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,kEAAkE;KAChF;IACD;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,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,GAAG,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9F,MAAM,MAAM,GAAG,mBAAmB;QAChC,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC;IAErE,OAAO;QACL,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,MAAM;QACjB,MAAM;QAEN,OAAO,EAAE,CAAC,OAA0B,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK;QAEtD,YAAY,EAAE,CAAC,OAA0B,EAAE,EAAE;YAC3C,OAAO,IAAA,4BAAmB,EACxB;gBACE,eAAe;gBACf,mBAAmB;gBACnB,iBAAiB;gBACjB,SAAS;aACV,EACD,OAAO,CACR,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAID,uCAA0E;AAAjE,wHAAA,4BAA4B,OAAA;AAAE,0GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import type { MiddlewareContext } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Options for creating OpenAPI router
|
|
5
|
+
*/
|
|
6
|
+
export interface OpenapiRouterOptions {
|
|
7
|
+
/** Path to the openapi.json file */
|
|
8
|
+
openapiFilePath: string;
|
|
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;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create OpenAPI router
|
|
18
|
+
*/
|
|
19
|
+
export declare function createOpenapiRouter(options: OpenapiRouterOptions, context: MiddlewareContext): Router;
|
|
20
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +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;AAIlD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,oCAAoC;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,wGAAwG;IACxG,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,qCAAqC;IACrC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,iBAAiB,GACzB,MAAM,CAeR"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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.createOpenapiRouter = createOpenapiRouter;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const controller_1 = require("./controller");
|
|
9
|
+
const spec_controller_1 = require("./spec-controller");
|
|
10
|
+
/**
|
|
11
|
+
* Create OpenAPI router
|
|
12
|
+
*/
|
|
13
|
+
function createOpenapiRouter(options, context) {
|
|
14
|
+
const { openapiFilePath, openapiSpecFilePath, enableEnhancement, serverDir } = options;
|
|
15
|
+
const router = express_1.default.Router();
|
|
16
|
+
const handler = (0, controller_1.createOpenapiHandler)(openapiFilePath, enableEnhancement, serverDir);
|
|
17
|
+
// GET /openapi.json - Serve enhanced OpenAPI specification with x-source
|
|
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
|
+
}
|
|
24
|
+
return router;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/server-log/openapi/router.ts"],"names":[],"mappings":";;;;;AAsBA,kDAkBC;AAxCD,sDAA0C;AAE1C,6CAAoD;AACpD,uDAA6D;AAgB7D;;GAEG;AACH,SAAgB,mBAAmB,CACjC,OAA6B,EAC7B,OAA0B;IAE1B,MAAM,EAAE,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACvF,MAAM,MAAM,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAC;IAChC,MAAM,OAAO,GAAG,IAAA,iCAAoB,EAAC,eAAe,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC;IAEpF,yEAAyE;IACzE,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IAEtE,oFAAoF;IACpF,IAAI,mBAAmB,EAAE,CAAC;QACxB,MAAM,WAAW,GAAG,IAAA,0CAAwB,EAAC,mBAAmB,CAAC,CAAC;QAClE,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|