@kevisual/router 0.0.8-alpha.3 → 0.0.9
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 +2 -0
- package/dist/router-browser.js +7 -4
- package/dist/router.d.ts +2 -0
- package/dist/router.js +8 -5
- package/package.json +1 -1
package/dist/router-browser.d.ts
CHANGED
|
@@ -88,6 +88,8 @@ type RouteContext<T = {
|
|
|
88
88
|
}) => Promise<any>;
|
|
89
89
|
index?: number;
|
|
90
90
|
throw?: (code?: number | string, message?: string, tips?: string) => void;
|
|
91
|
+
/** 是否需要序列化 */
|
|
92
|
+
needSerialize?: boolean;
|
|
91
93
|
} & T;
|
|
92
94
|
type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
|
|
93
95
|
type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
package/dist/router-browser.js
CHANGED
|
@@ -6028,8 +6028,6 @@ class QueryRouter {
|
|
|
6028
6028
|
ctx.nextQuery = {};
|
|
6029
6029
|
return await this.runRoute(path, key, ctx);
|
|
6030
6030
|
}
|
|
6031
|
-
// clear body
|
|
6032
|
-
ctx.body = JSON.parse(JSON.stringify(ctx.body || ''));
|
|
6033
6031
|
if (!ctx.code)
|
|
6034
6032
|
ctx.code = 200;
|
|
6035
6033
|
return ctx;
|
|
@@ -6064,7 +6062,12 @@ class QueryRouter {
|
|
|
6064
6062
|
ctx.call = this.call.bind(this);
|
|
6065
6063
|
ctx.queryRoute = this.queryRoute.bind(this);
|
|
6066
6064
|
ctx.index = 0;
|
|
6067
|
-
|
|
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;
|
|
6068
6071
|
}
|
|
6069
6072
|
/**
|
|
6070
6073
|
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
@@ -6160,7 +6163,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
6160
6163
|
constructor(opts) {
|
|
6161
6164
|
super();
|
|
6162
6165
|
this.handle = this.getHandle(this, opts?.handleFn, opts?.context);
|
|
6163
|
-
this.setContext(opts?.context);
|
|
6166
|
+
this.setContext({ needSerialize: false, ...opts?.context });
|
|
6164
6167
|
}
|
|
6165
6168
|
setHandle(wrapperFn, ctx) {
|
|
6166
6169
|
this.handle = this.getHandle(this, wrapperFn, ctx);
|
package/dist/router.d.ts
CHANGED
|
@@ -93,6 +93,8 @@ type RouteContext<T = {
|
|
|
93
93
|
}) => Promise<any>;
|
|
94
94
|
index?: number;
|
|
95
95
|
throw?: (code?: number | string, message?: string, tips?: string) => void;
|
|
96
|
+
/** 是否需要序列化 */
|
|
97
|
+
needSerialize?: boolean;
|
|
96
98
|
} & T;
|
|
97
99
|
type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
|
|
98
100
|
type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
package/dist/router.js
CHANGED
|
@@ -6047,8 +6047,6 @@ class QueryRouter {
|
|
|
6047
6047
|
ctx.nextQuery = {};
|
|
6048
6048
|
return await this.runRoute(path, key, ctx);
|
|
6049
6049
|
}
|
|
6050
|
-
// clear body
|
|
6051
|
-
ctx.body = JSON.parse(JSON.stringify(ctx.body || ''));
|
|
6052
6050
|
if (!ctx.code)
|
|
6053
6051
|
ctx.code = 200;
|
|
6054
6052
|
return ctx;
|
|
@@ -6083,7 +6081,12 @@ class QueryRouter {
|
|
|
6083
6081
|
ctx.call = this.call.bind(this);
|
|
6084
6082
|
ctx.queryRoute = this.queryRoute.bind(this);
|
|
6085
6083
|
ctx.index = 0;
|
|
6086
|
-
|
|
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;
|
|
6087
6090
|
}
|
|
6088
6091
|
/**
|
|
6089
6092
|
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
@@ -6179,7 +6182,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
6179
6182
|
constructor(opts) {
|
|
6180
6183
|
super();
|
|
6181
6184
|
this.handle = this.getHandle(this, opts?.handleFn, opts?.context);
|
|
6182
|
-
this.setContext(opts?.context);
|
|
6185
|
+
this.setContext({ needSerialize: false, ...opts?.context });
|
|
6183
6186
|
}
|
|
6184
6187
|
setHandle(wrapperFn, ctx) {
|
|
6185
6188
|
this.handle = this.getHandle(this, wrapperFn, ctx);
|
|
@@ -6985,7 +6988,7 @@ class App {
|
|
|
6985
6988
|
const router = opts?.router || new QueryRouter();
|
|
6986
6989
|
const server = opts?.server || new Server(opts?.serverOptions || {});
|
|
6987
6990
|
server.setHandle(router.getHandle(router, opts?.routerHandle, opts?.routerContext));
|
|
6988
|
-
router.setContext(opts?.routerContext);
|
|
6991
|
+
router.setContext({ needSerialize: true, ...opts?.routerContext });
|
|
6989
6992
|
this.router = router;
|
|
6990
6993
|
this.server = server;
|
|
6991
6994
|
if (opts?.io) {
|