@kevisual/router 0.0.8 → 0.0.10-beta.1
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 +1 -9
- package/dist/router-browser.js +7 -16
- package/dist/router.d.ts +1 -9
- package/dist/router.js +8 -17
- package/package.json +10 -10
package/dist/router-browser.d.ts
CHANGED
|
@@ -87,9 +87,9 @@ type RouteContext<T = {
|
|
|
87
87
|
[key: string]: any;
|
|
88
88
|
}) => Promise<any>;
|
|
89
89
|
index?: number;
|
|
90
|
+
throw?: (code?: number | string, message?: string, tips?: string) => void;
|
|
90
91
|
/** 是否需要序列化 */
|
|
91
92
|
needSerialize?: boolean;
|
|
92
|
-
throw?: (code?: number | string, message?: string, tips?: string) => void;
|
|
93
93
|
} & T;
|
|
94
94
|
type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
|
|
95
95
|
type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
|
@@ -127,10 +127,6 @@ type RouteOpts = {
|
|
|
127
127
|
*/
|
|
128
128
|
idUsePath?: boolean;
|
|
129
129
|
isDebug?: boolean;
|
|
130
|
-
/**
|
|
131
|
-
* 是否需要序列化
|
|
132
|
-
*/
|
|
133
|
-
needSerialize?: boolean;
|
|
134
130
|
};
|
|
135
131
|
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'verify' | 'verifyKey' | 'nextRoute'>;
|
|
136
132
|
declare const pickValue: readonly ["path", "key", "id", "description", "type", "validator", "middleware"];
|
|
@@ -169,10 +165,6 @@ declare class Route<U = {
|
|
|
169
165
|
* 是否开启debug,开启后会打印错误信息
|
|
170
166
|
*/
|
|
171
167
|
isDebug?: boolean;
|
|
172
|
-
/**
|
|
173
|
-
* 是否需要序列化
|
|
174
|
-
*/
|
|
175
|
-
needSerialize?: boolean;
|
|
176
168
|
constructor(path: string, key?: string, opts?: RouteOpts);
|
|
177
169
|
private createSchema;
|
|
178
170
|
/**
|
package/dist/router-browser.js
CHANGED
|
@@ -5646,16 +5646,11 @@ class Route {
|
|
|
5646
5646
|
* 是否开启debug,开启后会打印错误信息
|
|
5647
5647
|
*/
|
|
5648
5648
|
isDebug;
|
|
5649
|
-
/**
|
|
5650
|
-
* 是否需要序列化
|
|
5651
|
-
*/
|
|
5652
|
-
needSerialize;
|
|
5653
5649
|
constructor(path, key = '', opts) {
|
|
5654
5650
|
path = path.trim();
|
|
5655
5651
|
key = key.trim();
|
|
5656
5652
|
this.path = path;
|
|
5657
5653
|
this.key = key;
|
|
5658
|
-
this.needSerialize = opts?.needSerialize ?? true;
|
|
5659
5654
|
if (opts) {
|
|
5660
5655
|
this.id = opts.id || nanoid();
|
|
5661
5656
|
if (!opts.id && opts.idUsePath) {
|
|
@@ -6033,15 +6028,6 @@ class QueryRouter {
|
|
|
6033
6028
|
ctx.nextQuery = {};
|
|
6034
6029
|
return await this.runRoute(path, key, ctx);
|
|
6035
6030
|
}
|
|
6036
|
-
try {
|
|
6037
|
-
if (route.needSerialize) {
|
|
6038
|
-
// clear body
|
|
6039
|
-
ctx.body = JSON.parse(JSON.stringify(ctx.body || ''));
|
|
6040
|
-
}
|
|
6041
|
-
}
|
|
6042
|
-
catch (e) {
|
|
6043
|
-
console.log('serialize error', e);
|
|
6044
|
-
}
|
|
6045
6031
|
if (!ctx.code)
|
|
6046
6032
|
ctx.code = 200;
|
|
6047
6033
|
return ctx;
|
|
@@ -6076,7 +6062,12 @@ class QueryRouter {
|
|
|
6076
6062
|
ctx.call = this.call.bind(this);
|
|
6077
6063
|
ctx.queryRoute = this.queryRoute.bind(this);
|
|
6078
6064
|
ctx.index = 0;
|
|
6079
|
-
|
|
6065
|
+
const res = await this.runRoute(path, key, ctx);
|
|
6066
|
+
const serialize = ctx.needSerialize ?? true; // 是否需要序列化
|
|
6067
|
+
if (serialize) {
|
|
6068
|
+
res.body = JSON.parse(JSON.stringify(res.body || ''));
|
|
6069
|
+
}
|
|
6070
|
+
return res;
|
|
6080
6071
|
}
|
|
6081
6072
|
/**
|
|
6082
6073
|
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
@@ -6172,7 +6163,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
6172
6163
|
constructor(opts) {
|
|
6173
6164
|
super();
|
|
6174
6165
|
this.handle = this.getHandle(this, opts?.handleFn, opts?.context);
|
|
6175
|
-
this.setContext(opts?.context);
|
|
6166
|
+
this.setContext({ needSerialize: false, ...opts?.context });
|
|
6176
6167
|
}
|
|
6177
6168
|
setHandle(wrapperFn, ctx) {
|
|
6178
6169
|
this.handle = this.getHandle(this, wrapperFn, ctx);
|
package/dist/router.d.ts
CHANGED
|
@@ -92,9 +92,9 @@ type RouteContext<T = {
|
|
|
92
92
|
[key: string]: any;
|
|
93
93
|
}) => Promise<any>;
|
|
94
94
|
index?: number;
|
|
95
|
+
throw?: (code?: number | string, message?: string, tips?: string) => void;
|
|
95
96
|
/** 是否需要序列化 */
|
|
96
97
|
needSerialize?: boolean;
|
|
97
|
-
throw?: (code?: number | string, message?: string, tips?: string) => void;
|
|
98
98
|
} & T;
|
|
99
99
|
type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
|
|
100
100
|
type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
|
@@ -132,10 +132,6 @@ type RouteOpts = {
|
|
|
132
132
|
*/
|
|
133
133
|
idUsePath?: boolean;
|
|
134
134
|
isDebug?: boolean;
|
|
135
|
-
/**
|
|
136
|
-
* 是否需要序列化
|
|
137
|
-
*/
|
|
138
|
-
needSerialize?: boolean;
|
|
139
135
|
};
|
|
140
136
|
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'verify' | 'verifyKey' | 'nextRoute'>;
|
|
141
137
|
declare const pickValue: readonly ["path", "key", "id", "description", "type", "validator", "middleware"];
|
|
@@ -174,10 +170,6 @@ declare class Route<U = {
|
|
|
174
170
|
* 是否开启debug,开启后会打印错误信息
|
|
175
171
|
*/
|
|
176
172
|
isDebug?: boolean;
|
|
177
|
-
/**
|
|
178
|
-
* 是否需要序列化
|
|
179
|
-
*/
|
|
180
|
-
needSerialize?: boolean;
|
|
181
173
|
constructor(path: string, key?: string, opts?: RouteOpts);
|
|
182
174
|
private createSchema;
|
|
183
175
|
/**
|
package/dist/router.js
CHANGED
|
@@ -5665,16 +5665,11 @@ class Route {
|
|
|
5665
5665
|
* 是否开启debug,开启后会打印错误信息
|
|
5666
5666
|
*/
|
|
5667
5667
|
isDebug;
|
|
5668
|
-
/**
|
|
5669
|
-
* 是否需要序列化
|
|
5670
|
-
*/
|
|
5671
|
-
needSerialize;
|
|
5672
5668
|
constructor(path, key = '', opts) {
|
|
5673
5669
|
path = path.trim();
|
|
5674
5670
|
key = key.trim();
|
|
5675
5671
|
this.path = path;
|
|
5676
5672
|
this.key = key;
|
|
5677
|
-
this.needSerialize = opts?.needSerialize ?? true;
|
|
5678
5673
|
if (opts) {
|
|
5679
5674
|
this.id = opts.id || nanoid();
|
|
5680
5675
|
if (!opts.id && opts.idUsePath) {
|
|
@@ -6052,15 +6047,6 @@ class QueryRouter {
|
|
|
6052
6047
|
ctx.nextQuery = {};
|
|
6053
6048
|
return await this.runRoute(path, key, ctx);
|
|
6054
6049
|
}
|
|
6055
|
-
try {
|
|
6056
|
-
if (route.needSerialize) {
|
|
6057
|
-
// clear body
|
|
6058
|
-
ctx.body = JSON.parse(JSON.stringify(ctx.body || ''));
|
|
6059
|
-
}
|
|
6060
|
-
}
|
|
6061
|
-
catch (e) {
|
|
6062
|
-
console.log('serialize error', e);
|
|
6063
|
-
}
|
|
6064
6050
|
if (!ctx.code)
|
|
6065
6051
|
ctx.code = 200;
|
|
6066
6052
|
return ctx;
|
|
@@ -6095,7 +6081,12 @@ class QueryRouter {
|
|
|
6095
6081
|
ctx.call = this.call.bind(this);
|
|
6096
6082
|
ctx.queryRoute = this.queryRoute.bind(this);
|
|
6097
6083
|
ctx.index = 0;
|
|
6098
|
-
|
|
6084
|
+
const res = await this.runRoute(path, key, ctx);
|
|
6085
|
+
const serialize = ctx.needSerialize ?? true; // 是否需要序列化
|
|
6086
|
+
if (serialize) {
|
|
6087
|
+
res.body = JSON.parse(JSON.stringify(res.body || ''));
|
|
6088
|
+
}
|
|
6089
|
+
return res;
|
|
6099
6090
|
}
|
|
6100
6091
|
/**
|
|
6101
6092
|
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
@@ -6191,7 +6182,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
6191
6182
|
constructor(opts) {
|
|
6192
6183
|
super();
|
|
6193
6184
|
this.handle = this.getHandle(this, opts?.handleFn, opts?.context);
|
|
6194
|
-
this.setContext(opts?.context);
|
|
6185
|
+
this.setContext({ needSerialize: false, ...opts?.context });
|
|
6195
6186
|
}
|
|
6196
6187
|
setHandle(wrapperFn, ctx) {
|
|
6197
6188
|
this.handle = this.getHandle(this, wrapperFn, ctx);
|
|
@@ -6997,7 +6988,7 @@ class App {
|
|
|
6997
6988
|
const router = opts?.router || new QueryRouter();
|
|
6998
6989
|
const server = opts?.server || new Server(opts?.serverOptions || {});
|
|
6999
6990
|
server.setHandle(router.getHandle(router, opts?.routerHandle, opts?.routerContext));
|
|
7000
|
-
router.setContext(opts?.routerContext);
|
|
6991
|
+
router.setContext({ needSerialize: true, ...opts?.routerContext });
|
|
7001
6992
|
this.router = router;
|
|
7002
6993
|
this.server = server;
|
|
7003
6994
|
if (opts?.io) {
|
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.10-beta.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -20,22 +20,22 @@
|
|
|
20
20
|
"author": "abearxiong",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
24
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
23
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
24
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
25
25
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
26
26
|
"@types/lodash-es": "^4.17.12",
|
|
27
|
-
"@types/node": "^22.13.
|
|
28
|
-
"@types/ws": "^8.
|
|
27
|
+
"@types/node": "^22.13.11",
|
|
28
|
+
"@types/ws": "^8.18.0",
|
|
29
29
|
"@types/xml2js": "^0.4.14",
|
|
30
30
|
"cookie": "^1.0.2",
|
|
31
31
|
"lodash-es": "^4.17.21",
|
|
32
|
-
"nanoid": "^5.1.
|
|
33
|
-
"rollup": "^4.
|
|
34
|
-
"rollup-plugin-dts": "^6.
|
|
32
|
+
"nanoid": "^5.1.5",
|
|
33
|
+
"rollup": "^4.36.0",
|
|
34
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
35
35
|
"ts-loader": "^9.5.2",
|
|
36
36
|
"ts-node": "^10.9.2",
|
|
37
37
|
"tslib": "^2.8.1",
|
|
38
|
-
"typescript": "^5.
|
|
38
|
+
"typescript": "^5.8.2",
|
|
39
39
|
"xml2js": "^0.6.2",
|
|
40
40
|
"zod": "^3.24.2"
|
|
41
41
|
},
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"path-to-regexp": "^8.2.0",
|
|
48
48
|
"selfsigned": "^2.4.1",
|
|
49
|
-
"ws": "^8.18.
|
|
49
|
+
"ws": "^8.18.1"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|