@lark-apaas/devtool-kits 1.2.17-alpha.5 → 1.2.17-alpha.6
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 +0 -43
- package/dist/index.cjs +7 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -37
- package/dist/index.d.ts +1 -37
- package/dist/index.js +6 -108
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
import { Router, RequestHandler, Application } from 'express';
|
|
3
|
-
import { ServerResponse as ServerResponse$1, IncomingMessage as IncomingMessage$1 } from 'http';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* 标准化基础路径,确保以 '/' 开头且不包含 trailing slash
|
|
@@ -197,41 +196,6 @@ interface DevLogsMiddlewareOptions {
|
|
|
197
196
|
*/
|
|
198
197
|
declare function createCollectLogsMiddleware(options?: DevLogsMiddlewareOptions): RouteMiddleware;
|
|
199
198
|
|
|
200
|
-
/**
|
|
201
|
-
* Express/Connect 兼容层
|
|
202
|
-
* 让 middleware 同时支持 Express 和 Vite/Connect
|
|
203
|
-
*/
|
|
204
|
-
|
|
205
|
-
type AnyResponse = ServerResponse$1 & {
|
|
206
|
-
status?: (code: number) => AnyResponse;
|
|
207
|
-
json?: (data: unknown) => void;
|
|
208
|
-
send?: (data: unknown) => void;
|
|
209
|
-
};
|
|
210
|
-
type AnyRequest = IncomingMessage$1 & {
|
|
211
|
-
query?: Record<string, string>;
|
|
212
|
-
params?: Record<string, string>;
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* 发送 JSON 响应,兼容 Express 和 Connect
|
|
216
|
-
*/
|
|
217
|
-
declare function sendJson(res: AnyResponse, data: unknown, statusCode?: number): void;
|
|
218
|
-
/**
|
|
219
|
-
* 发送错误响应
|
|
220
|
-
*/
|
|
221
|
-
declare function sendError(res: AnyResponse, message: string, error?: unknown, statusCode?: number): void;
|
|
222
|
-
/**
|
|
223
|
-
* 发送成功响应
|
|
224
|
-
*/
|
|
225
|
-
declare function sendSuccess(res: AnyResponse, data?: Record<string, unknown>): void;
|
|
226
|
-
/**
|
|
227
|
-
* 获取 query 参数,兼容 Express 和 Connect
|
|
228
|
-
*/
|
|
229
|
-
declare function getQuery(req: AnyRequest): Record<string, string>;
|
|
230
|
-
/**
|
|
231
|
-
* 获取单个 query 参数
|
|
232
|
-
*/
|
|
233
|
-
declare function getQueryParam(req: AnyRequest, key: string): string | undefined;
|
|
234
|
-
|
|
235
199
|
/**
|
|
236
200
|
* Register middlewares for Express-compatible servers or Vite
|
|
237
201
|
* @param server - Express app or Vite middleware instance
|
|
@@ -271,4 +235,4 @@ declare function getQueryParam(req: AnyRequest, key: string): string | undefined
|
|
|
271
235
|
*/
|
|
272
236
|
declare function registerMiddlewares(server: ExpressApp | ViteMiddleware, middlewares: Middleware[], options?: Partial<MiddlewareContext>): Promise<void>;
|
|
273
237
|
|
|
274
|
-
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type Options, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware,
|
|
238
|
+
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type Options, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, handleDevProxyError, normalizeBasePath, parseAndGenerateNestResourceTemplate, postprocessDrizzleSchema, registerMiddlewares };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
import { Router, RequestHandler, Application } from 'express';
|
|
3
|
-
import { ServerResponse as ServerResponse$1, IncomingMessage as IncomingMessage$1 } from 'http';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* 标准化基础路径,确保以 '/' 开头且不包含 trailing slash
|
|
@@ -197,41 +196,6 @@ interface DevLogsMiddlewareOptions {
|
|
|
197
196
|
*/
|
|
198
197
|
declare function createCollectLogsMiddleware(options?: DevLogsMiddlewareOptions): RouteMiddleware;
|
|
199
198
|
|
|
200
|
-
/**
|
|
201
|
-
* Express/Connect 兼容层
|
|
202
|
-
* 让 middleware 同时支持 Express 和 Vite/Connect
|
|
203
|
-
*/
|
|
204
|
-
|
|
205
|
-
type AnyResponse = ServerResponse$1 & {
|
|
206
|
-
status?: (code: number) => AnyResponse;
|
|
207
|
-
json?: (data: unknown) => void;
|
|
208
|
-
send?: (data: unknown) => void;
|
|
209
|
-
};
|
|
210
|
-
type AnyRequest = IncomingMessage$1 & {
|
|
211
|
-
query?: Record<string, string>;
|
|
212
|
-
params?: Record<string, string>;
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* 发送 JSON 响应,兼容 Express 和 Connect
|
|
216
|
-
*/
|
|
217
|
-
declare function sendJson(res: AnyResponse, data: unknown, statusCode?: number): void;
|
|
218
|
-
/**
|
|
219
|
-
* 发送错误响应
|
|
220
|
-
*/
|
|
221
|
-
declare function sendError(res: AnyResponse, message: string, error?: unknown, statusCode?: number): void;
|
|
222
|
-
/**
|
|
223
|
-
* 发送成功响应
|
|
224
|
-
*/
|
|
225
|
-
declare function sendSuccess(res: AnyResponse, data?: Record<string, unknown>): void;
|
|
226
|
-
/**
|
|
227
|
-
* 获取 query 参数,兼容 Express 和 Connect
|
|
228
|
-
*/
|
|
229
|
-
declare function getQuery(req: AnyRequest): Record<string, string>;
|
|
230
|
-
/**
|
|
231
|
-
* 获取单个 query 参数
|
|
232
|
-
*/
|
|
233
|
-
declare function getQueryParam(req: AnyRequest, key: string): string | undefined;
|
|
234
|
-
|
|
235
199
|
/**
|
|
236
200
|
* Register middlewares for Express-compatible servers or Vite
|
|
237
201
|
* @param server - Express app or Vite middleware instance
|
|
@@ -271,4 +235,4 @@ declare function getQueryParam(req: AnyRequest, key: string): string | undefined
|
|
|
271
235
|
*/
|
|
272
236
|
declare function registerMiddlewares(server: ExpressApp | ViteMiddleware, middlewares: Middleware[], options?: Partial<MiddlewareContext>): Promise<void>;
|
|
273
237
|
|
|
274
|
-
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type Options, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware,
|
|
238
|
+
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type Options, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, handleDevProxyError, normalizeBasePath, parseAndGenerateNestResourceTemplate, postprocessDrizzleSchema, registerMiddlewares };
|
package/dist/index.js
CHANGED
|
@@ -1894,8 +1894,10 @@ function parsePinoLog(line, source) {
|
|
|
1894
1894
|
statusCode: pinoLog.status_code,
|
|
1895
1895
|
durationMs: pinoLog.duration_ms,
|
|
1896
1896
|
ip: pinoLog.ip,
|
|
1897
|
+
referer: pinoLog.referer,
|
|
1897
1898
|
requestBody: pinoLog.request_body,
|
|
1898
|
-
responseBody: pinoLog.response_body
|
|
1899
|
+
responseBody: pinoLog.response_body,
|
|
1900
|
+
queryParams: pinoLog.query_params
|
|
1899
1901
|
},
|
|
1900
1902
|
tags: [
|
|
1901
1903
|
source
|
|
@@ -2800,7 +2802,8 @@ function parsePinoLog2(line, source) {
|
|
|
2800
2802
|
durationMs: pinoLog.duration_ms,
|
|
2801
2803
|
ip: pinoLog.ip,
|
|
2802
2804
|
requestBody: pinoLog.request_body,
|
|
2803
|
-
responseBody: pinoLog.response_body
|
|
2805
|
+
responseBody: pinoLog.response_body,
|
|
2806
|
+
queryParams: pinoLog.query_params
|
|
2804
2807
|
},
|
|
2805
2808
|
tags: [
|
|
2806
2809
|
source
|
|
@@ -3449,100 +3452,7 @@ function createCollectLogsMiddleware(options = {}) {
|
|
|
3449
3452
|
}
|
|
3450
3453
|
__name(createCollectLogsMiddleware, "createCollectLogsMiddleware");
|
|
3451
3454
|
|
|
3452
|
-
// src/middlewares/compat.ts
|
|
3453
|
-
function sendJson(res, data, statusCode = 200) {
|
|
3454
|
-
const statusFn = res.status;
|
|
3455
|
-
const jsonFn = res.json;
|
|
3456
|
-
if (typeof statusFn === "function" && typeof jsonFn === "function") {
|
|
3457
|
-
statusFn.call(res, statusCode);
|
|
3458
|
-
jsonFn.call(res, data);
|
|
3459
|
-
} else {
|
|
3460
|
-
res.statusCode = statusCode;
|
|
3461
|
-
res.setHeader("Content-Type", "application/json");
|
|
3462
|
-
res.end(JSON.stringify(data));
|
|
3463
|
-
}
|
|
3464
|
-
}
|
|
3465
|
-
__name(sendJson, "sendJson");
|
|
3466
|
-
function sendError(res, message, error, statusCode = 500) {
|
|
3467
|
-
const errorData = {
|
|
3468
|
-
message,
|
|
3469
|
-
...error ? {
|
|
3470
|
-
error: serializeError3(error)
|
|
3471
|
-
} : {}
|
|
3472
|
-
};
|
|
3473
|
-
sendJson(res, errorData, statusCode);
|
|
3474
|
-
}
|
|
3475
|
-
__name(sendError, "sendError");
|
|
3476
|
-
function sendSuccess(res, data) {
|
|
3477
|
-
sendJson(res, {
|
|
3478
|
-
success: true,
|
|
3479
|
-
...data
|
|
3480
|
-
}, 200);
|
|
3481
|
-
}
|
|
3482
|
-
__name(sendSuccess, "sendSuccess");
|
|
3483
|
-
function getQuery(req) {
|
|
3484
|
-
if (req.query) {
|
|
3485
|
-
return req.query;
|
|
3486
|
-
}
|
|
3487
|
-
const url = new URL(req.url || "", `http://${req.headers.host}`);
|
|
3488
|
-
return Object.fromEntries(url.searchParams.entries());
|
|
3489
|
-
}
|
|
3490
|
-
__name(getQuery, "getQuery");
|
|
3491
|
-
function getQueryParam(req, key) {
|
|
3492
|
-
const query = getQuery(req);
|
|
3493
|
-
return query[key];
|
|
3494
|
-
}
|
|
3495
|
-
__name(getQueryParam, "getQueryParam");
|
|
3496
|
-
function serializeError3(error) {
|
|
3497
|
-
if (error instanceof Error) {
|
|
3498
|
-
return {
|
|
3499
|
-
name: error.name,
|
|
3500
|
-
message: error.message,
|
|
3501
|
-
stack: error.stack
|
|
3502
|
-
};
|
|
3503
|
-
}
|
|
3504
|
-
return {
|
|
3505
|
-
message: String(error)
|
|
3506
|
-
};
|
|
3507
|
-
}
|
|
3508
|
-
__name(serializeError3, "serializeError");
|
|
3509
|
-
|
|
3510
3455
|
// src/middlewares/index.ts
|
|
3511
|
-
function enhanceForCompat(req, res) {
|
|
3512
|
-
if (!res.status) {
|
|
3513
|
-
res.status = function(code) {
|
|
3514
|
-
res.statusCode = code;
|
|
3515
|
-
return res;
|
|
3516
|
-
};
|
|
3517
|
-
}
|
|
3518
|
-
if (!res.json) {
|
|
3519
|
-
res.json = function(data) {
|
|
3520
|
-
res.setHeader("Content-Type", "application/json");
|
|
3521
|
-
res.end(JSON.stringify(data));
|
|
3522
|
-
return res;
|
|
3523
|
-
};
|
|
3524
|
-
}
|
|
3525
|
-
if (!res.send) {
|
|
3526
|
-
res.send = function(data) {
|
|
3527
|
-
if (typeof data === "object" && data !== null) {
|
|
3528
|
-
res.setHeader("Content-Type", "application/json");
|
|
3529
|
-
res.end(JSON.stringify(data));
|
|
3530
|
-
} else {
|
|
3531
|
-
res.end(String(data));
|
|
3532
|
-
}
|
|
3533
|
-
return res;
|
|
3534
|
-
};
|
|
3535
|
-
}
|
|
3536
|
-
if (!req.query) {
|
|
3537
|
-
const url = new URL(req.url || "", `http://${req.headers.host || "localhost"}`);
|
|
3538
|
-
req.query = Object.fromEntries(url.searchParams.entries());
|
|
3539
|
-
}
|
|
3540
|
-
}
|
|
3541
|
-
__name(enhanceForCompat, "enhanceForCompat");
|
|
3542
|
-
function isConnectServer(server) {
|
|
3543
|
-
return typeof server === "function" && !("set" in server) && !("engine" in server);
|
|
3544
|
-
}
|
|
3545
|
-
__name(isConnectServer, "isConnectServer");
|
|
3546
3456
|
function isRouteMiddleware(middleware) {
|
|
3547
3457
|
return "createRouter" in middleware && middleware.createRouter !== void 0;
|
|
3548
3458
|
}
|
|
@@ -3595,13 +3505,6 @@ async function registerMiddlewares(server, middlewares, options) {
|
|
|
3595
3505
|
rootDir: process.cwd(),
|
|
3596
3506
|
...options
|
|
3597
3507
|
};
|
|
3598
|
-
if (isConnectServer(server)) {
|
|
3599
|
-
server.use((req, res, next) => {
|
|
3600
|
-
enhanceForCompat(req, res);
|
|
3601
|
-
next();
|
|
3602
|
-
});
|
|
3603
|
-
console.log("[Middleware] Registered Express compatibility layer for Connect/Vite");
|
|
3604
|
-
}
|
|
3605
3508
|
const allMiddlewares = [
|
|
3606
3509
|
...middlewares
|
|
3607
3510
|
];
|
|
@@ -3632,15 +3535,10 @@ export {
|
|
|
3632
3535
|
createCollectLogsMiddleware,
|
|
3633
3536
|
createDevLogsMiddleware,
|
|
3634
3537
|
createOpenapiMiddleware,
|
|
3635
|
-
getQuery,
|
|
3636
|
-
getQueryParam,
|
|
3637
3538
|
handleDevProxyError,
|
|
3638
3539
|
normalizeBasePath,
|
|
3639
3540
|
parseAndGenerateNestResourceTemplate,
|
|
3640
3541
|
postprocessDrizzleSchema,
|
|
3641
|
-
registerMiddlewares
|
|
3642
|
-
sendError,
|
|
3643
|
-
sendJson,
|
|
3644
|
-
sendSuccess
|
|
3542
|
+
registerMiddlewares
|
|
3645
3543
|
};
|
|
3646
3544
|
//# sourceMappingURL=index.js.map
|