befly 3.24.0 → 3.24.2
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/hooks/parser.js +2 -10
- package/index.js +3 -3
- package/lib/xmlParse.js +32 -0
- package/package.json +2 -2
- package/plugins/xmlParse.js +8 -0
- package/scripts/syncDb/index.js +1 -1
package/hooks/parser.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { XMLParser } from "fast-xml-parser";
|
|
3
|
-
|
|
1
|
+
import { xmlParse } from "../lib/xmlParse.js";
|
|
4
2
|
import { ErrorResponse } from "../utils/response.js";
|
|
5
3
|
|
|
6
|
-
const xmlParser = new XMLParser();
|
|
7
|
-
|
|
8
4
|
/**
|
|
9
5
|
* 请求参数解析钩子
|
|
10
6
|
* - GET 请求:解析 URL 查询参数
|
|
@@ -37,12 +33,8 @@ export default {
|
|
|
37
33
|
} else if (contentType.includes("application/xml") || contentType.includes("text/xml")) {
|
|
38
34
|
// XML 格式
|
|
39
35
|
const text = await ctx.req.text();
|
|
40
|
-
const parsed = xmlParser.parse(text);
|
|
41
|
-
// 提取根节点内容(如 xml),使 body 扁平化
|
|
42
|
-
const rootKey = Object.keys(parsed)[0];
|
|
43
|
-
const body = rootKey && typeof parsed[rootKey] === "object" ? parsed[rootKey] : parsed;
|
|
44
36
|
// 合并 URL 参数和请求体(请求体优先)
|
|
45
|
-
ctx.body = Object.assign({}, queryParams,
|
|
37
|
+
ctx.body = Object.assign({}, queryParams, xmlParse(text));
|
|
46
38
|
} else {
|
|
47
39
|
// 不支持的 Content-Type
|
|
48
40
|
ctx.response = ErrorResponse(
|
package/index.js
CHANGED
|
@@ -32,7 +32,9 @@ import { scanSources } from "./utils/scanSources.js";
|
|
|
32
32
|
import { isPrimaryProcess } from "./utils/is.js";
|
|
33
33
|
import { deepMerge } from "./utils/deepMerge.js";
|
|
34
34
|
|
|
35
|
-
export {
|
|
35
|
+
export { syncDb } from "./scripts/syncDb/index.js";
|
|
36
|
+
export { xmlParse } from "./lib/xmlParse.js";
|
|
37
|
+
export { Logger };
|
|
36
38
|
|
|
37
39
|
function prefixMenuPaths(menus, prefix) {
|
|
38
40
|
return menus.map((menu) => {
|
|
@@ -267,5 +269,3 @@ export class Befly {
|
|
|
267
269
|
}
|
|
268
270
|
}
|
|
269
271
|
}
|
|
270
|
-
|
|
271
|
-
export { Logger };
|
package/lib/xmlParse.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { XMLParser } from "fast-xml-parser";
|
|
2
|
+
|
|
3
|
+
import { isPlainObject, isString } from "../utils/is.js";
|
|
4
|
+
|
|
5
|
+
const xmlParser = new XMLParser();
|
|
6
|
+
|
|
7
|
+
function normalizeXmlBody(parsed) {
|
|
8
|
+
if (!isPlainObject(parsed)) {
|
|
9
|
+
return parsed;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const rootKeys = Object.keys(parsed).filter((key) => !key.startsWith("?"));
|
|
13
|
+
if (rootKeys.length !== 1) {
|
|
14
|
+
return parsed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rootKey = rootKeys[0];
|
|
18
|
+
return isPlainObject(parsed[rootKey]) ? parsed[rootKey] : parsed;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function xmlParse(value) {
|
|
22
|
+
if (!isString(value) || value.length < 1) {
|
|
23
|
+
throw new Error("xmlParse 输入必须是非空字符串", {
|
|
24
|
+
cause: null,
|
|
25
|
+
code: "validation",
|
|
26
|
+
subsystem: "xml",
|
|
27
|
+
operation: "xmlParse"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return normalizeXmlBody(xmlParser.parse(value));
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.24.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.24.2",
|
|
4
|
+
"gitHead": "048b4d2576e1e344949ef3b111255dcab9800b9f",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
package/scripts/syncDb/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { applySyncDbDiff } from "./diff.js";
|
|
|
6
6
|
import { prepareSyncDbBaseContext } from "./context.js";
|
|
7
7
|
import { printSyncDbDiffSummary, printSyncDbProcessLog, writeSyncDbReport } from "./report.js";
|
|
8
8
|
|
|
9
|
-
export async function
|
|
9
|
+
export async function syncDb(mysqlConfig) {
|
|
10
10
|
const reportPath = resolve(join(process.cwd(), "db.sync.md"));
|
|
11
11
|
try {
|
|
12
12
|
printSyncDbProcessLog("开始执行应用");
|