@kevisual/router 0.0.7 → 0.0.8-alpha.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/dist/router-browser.d.ts +7 -1
- package/dist/router-browser.js +20 -3
- package/dist/router-simple-lib.d.ts +3 -0
- package/dist/router-simple-lib.js +35 -0
- package/dist/router.d.ts +7 -1
- package/dist/router.js +21 -4
- package/package.json +7 -1
package/dist/router-browser.d.ts
CHANGED
|
@@ -70,6 +70,11 @@ type RouteContext<T = {
|
|
|
70
70
|
path: string;
|
|
71
71
|
key?: string;
|
|
72
72
|
payload?: any;
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
} | {
|
|
75
|
+
id: string;
|
|
76
|
+
apyload?: any;
|
|
77
|
+
[key: string]: any;
|
|
73
78
|
}, ctx?: RouteContext & {
|
|
74
79
|
[key: string]: any;
|
|
75
80
|
}) => Promise<any>;
|
|
@@ -264,7 +269,8 @@ declare class QueryRouter {
|
|
|
264
269
|
* @returns
|
|
265
270
|
*/
|
|
266
271
|
call(message: {
|
|
267
|
-
|
|
272
|
+
id?: string;
|
|
273
|
+
path?: string;
|
|
268
274
|
key?: string;
|
|
269
275
|
payload?: any;
|
|
270
276
|
}, ctx?: RouteContext & {
|
package/dist/router-browser.js
CHANGED
|
@@ -6016,7 +6016,7 @@ class QueryRouter {
|
|
|
6016
6016
|
ctx.body = null;
|
|
6017
6017
|
return ctx;
|
|
6018
6018
|
}
|
|
6019
|
-
ctx.query = ctx.nextQuery;
|
|
6019
|
+
ctx.query = { ...ctx.query, ...ctx.nextQuery };
|
|
6020
6020
|
ctx.nextQuery = {};
|
|
6021
6021
|
return await this.runRoute(path, key, ctx);
|
|
6022
6022
|
}
|
|
@@ -6043,7 +6043,7 @@ class QueryRouter {
|
|
|
6043
6043
|
*/
|
|
6044
6044
|
async parse(message, ctx) {
|
|
6045
6045
|
if (!message?.path) {
|
|
6046
|
-
return Promise.resolve({ code: 404, body: 'Not found path' });
|
|
6046
|
+
return Promise.resolve({ code: 404, body: null, message: 'Not found path' });
|
|
6047
6047
|
}
|
|
6048
6048
|
const { path, key = '', payload = {}, ...query } = message;
|
|
6049
6049
|
ctx = ctx || {};
|
|
@@ -6065,7 +6065,24 @@ class QueryRouter {
|
|
|
6065
6065
|
* @returns
|
|
6066
6066
|
*/
|
|
6067
6067
|
async call(message, ctx) {
|
|
6068
|
-
|
|
6068
|
+
let path = message.path;
|
|
6069
|
+
message.key;
|
|
6070
|
+
if (message.id) {
|
|
6071
|
+
const route = this.routes.find((r) => r.id === message.id);
|
|
6072
|
+
if (route) {
|
|
6073
|
+
path = route.path;
|
|
6074
|
+
route.key;
|
|
6075
|
+
}
|
|
6076
|
+
else {
|
|
6077
|
+
return { code: 404, body: null, message: 'Not found route' };
|
|
6078
|
+
}
|
|
6079
|
+
}
|
|
6080
|
+
else if (path) {
|
|
6081
|
+
return await this.parse({ ...message, path }, { ...this.context, ...ctx });
|
|
6082
|
+
}
|
|
6083
|
+
else {
|
|
6084
|
+
return { code: 404, body: null, message: 'Not found path' };
|
|
6085
|
+
}
|
|
6069
6086
|
}
|
|
6070
6087
|
/**
|
|
6071
6088
|
* 请求 result 的数据
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import xml2js from 'xml2js';
|
|
2
|
+
|
|
3
|
+
const parseXml = async (req) => {
|
|
4
|
+
return await new Promise((resolve) => {
|
|
5
|
+
// 读取请求数据
|
|
6
|
+
let data = '';
|
|
7
|
+
req.setEncoding('utf8');
|
|
8
|
+
// 监听data事件,接收数据片段
|
|
9
|
+
req.on('data', (chunk) => {
|
|
10
|
+
data += chunk;
|
|
11
|
+
});
|
|
12
|
+
// 当请求结束时处理数据
|
|
13
|
+
req.on('end', () => {
|
|
14
|
+
try {
|
|
15
|
+
// 使用xml2js解析XML
|
|
16
|
+
xml2js.parseString(data, function (err, result) {
|
|
17
|
+
if (err) {
|
|
18
|
+
console.error('XML解析错误:', err);
|
|
19
|
+
resolve(null);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const jsonString = JSON.stringify(result);
|
|
23
|
+
resolve(jsonString);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error('处理请求时出错:', error);
|
|
29
|
+
resolve(null);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { parseXml };
|
package/dist/router.d.ts
CHANGED
|
@@ -75,6 +75,11 @@ type RouteContext<T = {
|
|
|
75
75
|
path: string;
|
|
76
76
|
key?: string;
|
|
77
77
|
payload?: any;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
} | {
|
|
80
|
+
id: string;
|
|
81
|
+
apyload?: any;
|
|
82
|
+
[key: string]: any;
|
|
78
83
|
}, ctx?: RouteContext & {
|
|
79
84
|
[key: string]: any;
|
|
80
85
|
}) => Promise<any>;
|
|
@@ -269,7 +274,8 @@ declare class QueryRouter {
|
|
|
269
274
|
* @returns
|
|
270
275
|
*/
|
|
271
276
|
call(message: {
|
|
272
|
-
|
|
277
|
+
id?: string;
|
|
278
|
+
path?: string;
|
|
273
279
|
key?: string;
|
|
274
280
|
payload?: any;
|
|
275
281
|
}, ctx?: RouteContext & {
|
package/dist/router.js
CHANGED
|
@@ -6035,7 +6035,7 @@ class QueryRouter {
|
|
|
6035
6035
|
ctx.body = null;
|
|
6036
6036
|
return ctx;
|
|
6037
6037
|
}
|
|
6038
|
-
ctx.query = ctx.nextQuery;
|
|
6038
|
+
ctx.query = { ...ctx.query, ...ctx.nextQuery };
|
|
6039
6039
|
ctx.nextQuery = {};
|
|
6040
6040
|
return await this.runRoute(path, key, ctx);
|
|
6041
6041
|
}
|
|
@@ -6062,7 +6062,7 @@ class QueryRouter {
|
|
|
6062
6062
|
*/
|
|
6063
6063
|
async parse(message, ctx) {
|
|
6064
6064
|
if (!message?.path) {
|
|
6065
|
-
return Promise.resolve({ code: 404, body: 'Not found path' });
|
|
6065
|
+
return Promise.resolve({ code: 404, body: null, message: 'Not found path' });
|
|
6066
6066
|
}
|
|
6067
6067
|
const { path, key = '', payload = {}, ...query } = message;
|
|
6068
6068
|
ctx = ctx || {};
|
|
@@ -6084,7 +6084,24 @@ class QueryRouter {
|
|
|
6084
6084
|
* @returns
|
|
6085
6085
|
*/
|
|
6086
6086
|
async call(message, ctx) {
|
|
6087
|
-
|
|
6087
|
+
let path = message.path;
|
|
6088
|
+
message.key;
|
|
6089
|
+
if (message.id) {
|
|
6090
|
+
const route = this.routes.find((r) => r.id === message.id);
|
|
6091
|
+
if (route) {
|
|
6092
|
+
path = route.path;
|
|
6093
|
+
route.key;
|
|
6094
|
+
}
|
|
6095
|
+
else {
|
|
6096
|
+
return { code: 404, body: null, message: 'Not found route' };
|
|
6097
|
+
}
|
|
6098
|
+
}
|
|
6099
|
+
else if (path) {
|
|
6100
|
+
return await this.parse({ ...message, path }, { ...this.context, ...ctx });
|
|
6101
|
+
}
|
|
6102
|
+
else {
|
|
6103
|
+
return { code: 404, body: null, message: 'Not found path' };
|
|
6104
|
+
}
|
|
6088
6105
|
}
|
|
6089
6106
|
/**
|
|
6090
6107
|
* 请求 result 的数据
|
|
@@ -6319,7 +6336,7 @@ const handleServer = async (req, res) => {
|
|
|
6319
6336
|
const handle = createHandleCtx(req, res);
|
|
6320
6337
|
const cookies = handle.req.cookies;
|
|
6321
6338
|
if (!token) {
|
|
6322
|
-
token = cookies.token;
|
|
6339
|
+
token = cookies.token; // cookie优先
|
|
6323
6340
|
}
|
|
6324
6341
|
if (token) {
|
|
6325
6342
|
token = token.replace('Bearer ', '');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@kevisual/router",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8-alpha.2",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@types/lodash-es": "^4.17.12",
|
|
27
27
|
"@types/node": "^22.13.4",
|
|
28
28
|
"@types/ws": "^8.5.14",
|
|
29
|
+
"@types/xml2js": "^0.4.14",
|
|
29
30
|
"cookie": "^1.0.2",
|
|
30
31
|
"lodash-es": "^4.17.21",
|
|
31
32
|
"nanoid": "^5.1.0",
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
"ts-node": "^10.9.2",
|
|
36
37
|
"tslib": "^2.8.1",
|
|
37
38
|
"typescript": "^5.7.3",
|
|
39
|
+
"xml2js": "^0.6.2",
|
|
38
40
|
"zod": "^3.24.2"
|
|
39
41
|
},
|
|
40
42
|
"repository": {
|
|
@@ -65,6 +67,10 @@
|
|
|
65
67
|
"./simple": {
|
|
66
68
|
"import": "./dist/router-simple.js",
|
|
67
69
|
"require": "./dist/router-simple.js"
|
|
70
|
+
},
|
|
71
|
+
"./simple-lib": {
|
|
72
|
+
"import": "./dist/router-simple-lib.js",
|
|
73
|
+
"require": "./dist/router-simple-lib.js"
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
76
|
}
|