@lark-apaas/devtool-kits 0.1.0-alpha.0 → 0.1.0-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/README.md +383 -185
- package/dist/error.html +345 -0
- package/dist/index.cjs +512 -248
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -3
- package/dist/index.d.ts +57 -3
- package/dist/index.js +860 -598
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
1
2
|
import { Router, RequestHandler, Application } from 'express';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -13,6 +14,47 @@ type PostprocessStats = {
|
|
|
13
14
|
};
|
|
14
15
|
declare function postprocessDrizzleSchema(targetPath: string): PostprocessStats | undefined;
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Proxy Error Handler 选项
|
|
19
|
+
*/
|
|
20
|
+
interface ProxyErrorOptions {
|
|
21
|
+
/** 日志目录路径 */
|
|
22
|
+
logDir?: string;
|
|
23
|
+
/** 读取最近多少条错误日志 */
|
|
24
|
+
maxErrorLogs?: number;
|
|
25
|
+
/** 日志文件名(默认为 app.log) */
|
|
26
|
+
logFileName?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* HTTP Proxy 错误处理器
|
|
30
|
+
* 用于 http-proxy 的 onError 回调
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
35
|
+
* import { handleDevProxyError } from '@lark-apaas/devtool-kits';
|
|
36
|
+
*
|
|
37
|
+
* // 基础用法
|
|
38
|
+
* const proxy = createProxyMiddleware({
|
|
39
|
+
* target: 'http://localhost:3000',
|
|
40
|
+
* onError: handleDevProxyError
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // 自定义配置
|
|
44
|
+
* const proxy = createProxyMiddleware({
|
|
45
|
+
* target: 'http://localhost:3000',
|
|
46
|
+
* onError: (err, req, res) => {
|
|
47
|
+
* handleDevProxyError(err, req, res, {
|
|
48
|
+
* logDir: './logs',
|
|
49
|
+
* maxErrorLogs: 50,
|
|
50
|
+
* logFileName: 'app.log'
|
|
51
|
+
* });
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function handleDevProxyError(err: Error, _req: IncomingMessage, res: ServerResponse, options?: ProxyErrorOptions): void;
|
|
57
|
+
|
|
16
58
|
/**
|
|
17
59
|
* Shared context passed to all middlewares
|
|
18
60
|
*/
|
|
@@ -119,6 +161,8 @@ interface OpenapiMiddlewareOptions {
|
|
|
119
161
|
openapiFilePath: string;
|
|
120
162
|
/** Enable source code enhancement */
|
|
121
163
|
enableEnhancement?: boolean;
|
|
164
|
+
/** Server directory for source code scanning (defaults to context.rootDir) */
|
|
165
|
+
serverDir?: string;
|
|
122
166
|
}
|
|
123
167
|
|
|
124
168
|
/**
|
|
@@ -127,7 +171,7 @@ interface OpenapiMiddlewareOptions {
|
|
|
127
171
|
*/
|
|
128
172
|
declare function createOpenapiMiddleware(options: OpenapiMiddlewareOptions): RouteMiddleware;
|
|
129
173
|
|
|
130
|
-
interface DevLogsMiddlewareOptions {
|
|
174
|
+
interface DevLogsMiddlewareOptions$1 {
|
|
131
175
|
/** Directory containing log files */
|
|
132
176
|
logDir?: string;
|
|
133
177
|
}
|
|
@@ -135,7 +179,17 @@ interface DevLogsMiddlewareOptions {
|
|
|
135
179
|
* Creates dev logs middleware for viewing application logs
|
|
136
180
|
* Supports both rspack/webpack and Vite dev servers
|
|
137
181
|
*/
|
|
138
|
-
declare function createDevLogsMiddleware(options?: DevLogsMiddlewareOptions): RouteMiddleware;
|
|
182
|
+
declare function createDevLogsMiddleware(options?: DevLogsMiddlewareOptions$1): RouteMiddleware;
|
|
183
|
+
|
|
184
|
+
interface DevLogsMiddlewareOptions {
|
|
185
|
+
logDir?: string;
|
|
186
|
+
fileName?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Creates dev logs middleware for viewing application logs
|
|
190
|
+
* Supports both rspack/webpack and Vite dev servers
|
|
191
|
+
*/
|
|
192
|
+
declare function createCollectLogsMiddleware(options?: DevLogsMiddlewareOptions): RouteMiddleware;
|
|
139
193
|
|
|
140
194
|
/**
|
|
141
195
|
* Register middlewares for Express-compatible servers or Vite
|
|
@@ -176,4 +230,4 @@ declare function createDevLogsMiddleware(options?: DevLogsMiddlewareOptions): Ro
|
|
|
176
230
|
*/
|
|
177
231
|
declare function registerMiddlewares(server: ExpressApp | ViteMiddleware, middlewares: Middleware[], options?: Partial<MiddlewareContext>): Promise<void>;
|
|
178
232
|
|
|
179
|
-
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type RouteInfo, type RouteMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, normalizeBasePath, postprocessDrizzleSchema, registerMiddlewares };
|
|
233
|
+
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, handleDevProxyError, normalizeBasePath, postprocessDrizzleSchema, registerMiddlewares };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
1
2
|
import { Router, RequestHandler, Application } from 'express';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -13,6 +14,47 @@ type PostprocessStats = {
|
|
|
13
14
|
};
|
|
14
15
|
declare function postprocessDrizzleSchema(targetPath: string): PostprocessStats | undefined;
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Proxy Error Handler 选项
|
|
19
|
+
*/
|
|
20
|
+
interface ProxyErrorOptions {
|
|
21
|
+
/** 日志目录路径 */
|
|
22
|
+
logDir?: string;
|
|
23
|
+
/** 读取最近多少条错误日志 */
|
|
24
|
+
maxErrorLogs?: number;
|
|
25
|
+
/** 日志文件名(默认为 app.log) */
|
|
26
|
+
logFileName?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* HTTP Proxy 错误处理器
|
|
30
|
+
* 用于 http-proxy 的 onError 回调
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
35
|
+
* import { handleDevProxyError } from '@lark-apaas/devtool-kits';
|
|
36
|
+
*
|
|
37
|
+
* // 基础用法
|
|
38
|
+
* const proxy = createProxyMiddleware({
|
|
39
|
+
* target: 'http://localhost:3000',
|
|
40
|
+
* onError: handleDevProxyError
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // 自定义配置
|
|
44
|
+
* const proxy = createProxyMiddleware({
|
|
45
|
+
* target: 'http://localhost:3000',
|
|
46
|
+
* onError: (err, req, res) => {
|
|
47
|
+
* handleDevProxyError(err, req, res, {
|
|
48
|
+
* logDir: './logs',
|
|
49
|
+
* maxErrorLogs: 50,
|
|
50
|
+
* logFileName: 'app.log'
|
|
51
|
+
* });
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function handleDevProxyError(err: Error, _req: IncomingMessage, res: ServerResponse, options?: ProxyErrorOptions): void;
|
|
57
|
+
|
|
16
58
|
/**
|
|
17
59
|
* Shared context passed to all middlewares
|
|
18
60
|
*/
|
|
@@ -119,6 +161,8 @@ interface OpenapiMiddlewareOptions {
|
|
|
119
161
|
openapiFilePath: string;
|
|
120
162
|
/** Enable source code enhancement */
|
|
121
163
|
enableEnhancement?: boolean;
|
|
164
|
+
/** Server directory for source code scanning (defaults to context.rootDir) */
|
|
165
|
+
serverDir?: string;
|
|
122
166
|
}
|
|
123
167
|
|
|
124
168
|
/**
|
|
@@ -127,7 +171,7 @@ interface OpenapiMiddlewareOptions {
|
|
|
127
171
|
*/
|
|
128
172
|
declare function createOpenapiMiddleware(options: OpenapiMiddlewareOptions): RouteMiddleware;
|
|
129
173
|
|
|
130
|
-
interface DevLogsMiddlewareOptions {
|
|
174
|
+
interface DevLogsMiddlewareOptions$1 {
|
|
131
175
|
/** Directory containing log files */
|
|
132
176
|
logDir?: string;
|
|
133
177
|
}
|
|
@@ -135,7 +179,17 @@ interface DevLogsMiddlewareOptions {
|
|
|
135
179
|
* Creates dev logs middleware for viewing application logs
|
|
136
180
|
* Supports both rspack/webpack and Vite dev servers
|
|
137
181
|
*/
|
|
138
|
-
declare function createDevLogsMiddleware(options?: DevLogsMiddlewareOptions): RouteMiddleware;
|
|
182
|
+
declare function createDevLogsMiddleware(options?: DevLogsMiddlewareOptions$1): RouteMiddleware;
|
|
183
|
+
|
|
184
|
+
interface DevLogsMiddlewareOptions {
|
|
185
|
+
logDir?: string;
|
|
186
|
+
fileName?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Creates dev logs middleware for viewing application logs
|
|
190
|
+
* Supports both rspack/webpack and Vite dev servers
|
|
191
|
+
*/
|
|
192
|
+
declare function createCollectLogsMiddleware(options?: DevLogsMiddlewareOptions): RouteMiddleware;
|
|
139
193
|
|
|
140
194
|
/**
|
|
141
195
|
* Register middlewares for Express-compatible servers or Vite
|
|
@@ -176,4 +230,4 @@ declare function createDevLogsMiddleware(options?: DevLogsMiddlewareOptions): Ro
|
|
|
176
230
|
*/
|
|
177
231
|
declare function registerMiddlewares(server: ExpressApp | ViteMiddleware, middlewares: Middleware[], options?: Partial<MiddlewareContext>): Promise<void>;
|
|
178
232
|
|
|
179
|
-
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type RouteInfo, type RouteMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, normalizeBasePath, postprocessDrizzleSchema, registerMiddlewares };
|
|
233
|
+
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, handleDevProxyError, normalizeBasePath, postprocessDrizzleSchema, registerMiddlewares };
|