@kevisual/router 0.0.5 → 0.0.6-alpha-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 +40 -10
- package/dist/router-browser.js +26 -3
- package/dist/router.d.ts +48 -11
- package/dist/router.js +29 -3
- package/package.json +1 -1
package/dist/router-browser.d.ts
CHANGED
|
@@ -65,9 +65,18 @@ type RouteContext<T = {
|
|
|
65
65
|
end?: boolean;
|
|
66
66
|
queryRouter?: QueryRouter;
|
|
67
67
|
error?: any;
|
|
68
|
+
/** 请求 route的返回结果,包函ctx */
|
|
68
69
|
call?: (message: {
|
|
69
70
|
path: string;
|
|
70
|
-
key
|
|
71
|
+
key?: string;
|
|
72
|
+
payload?: any;
|
|
73
|
+
}, ctx?: RouteContext & {
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
}) => Promise<any>;
|
|
76
|
+
/** 请求 route的返回结果,不包函ctx */
|
|
77
|
+
queryRoute?: (message: {
|
|
78
|
+
path: string;
|
|
79
|
+
key?: string;
|
|
71
80
|
payload?: any;
|
|
72
81
|
}, ctx?: RouteContext & {
|
|
73
82
|
[key: string]: any;
|
|
@@ -225,13 +234,36 @@ declare class QueryRouter {
|
|
|
225
234
|
}, ctx?: RouteContext & {
|
|
226
235
|
[key: string]: any;
|
|
227
236
|
}): Promise<any>;
|
|
237
|
+
/**
|
|
238
|
+
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
239
|
+
* @param message
|
|
240
|
+
* @param ctx
|
|
241
|
+
* @returns
|
|
242
|
+
*/
|
|
228
243
|
call(message: {
|
|
229
244
|
path: string;
|
|
230
|
-
key
|
|
245
|
+
key?: string;
|
|
231
246
|
payload?: any;
|
|
232
247
|
}, ctx?: RouteContext & {
|
|
233
248
|
[key: string]: any;
|
|
234
249
|
}): Promise<any>;
|
|
250
|
+
/**
|
|
251
|
+
* 请求 result 的数据
|
|
252
|
+
* @param message
|
|
253
|
+
* @param ctx
|
|
254
|
+
* @returns
|
|
255
|
+
*/
|
|
256
|
+
queryRoute(message: {
|
|
257
|
+
path: string;
|
|
258
|
+
key?: string;
|
|
259
|
+
payload?: any;
|
|
260
|
+
}, ctx?: RouteContext & {
|
|
261
|
+
[key: string]: any;
|
|
262
|
+
}): Promise<{
|
|
263
|
+
code: any;
|
|
264
|
+
data: any;
|
|
265
|
+
message: any;
|
|
266
|
+
}>;
|
|
235
267
|
setContext(ctx: RouteContext): Promise<void>;
|
|
236
268
|
getList(): RouteInfo[];
|
|
237
269
|
getHandle<T = any>(router: QueryRouter, wrapperFn?: HandleFn<T>, ctx?: RouteContext): (msg: {
|
|
@@ -284,16 +316,14 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
284
316
|
route(path: string, key?: string): Route;
|
|
285
317
|
route(path: string, opts?: RouteOpts): Route;
|
|
286
318
|
route(path: string, key?: string, opts?: RouteOpts): Route;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
[key: string]: any;
|
|
293
|
-
}): Promise<any>;
|
|
319
|
+
/**
|
|
320
|
+
* 等于queryRoute,但是调用了handle
|
|
321
|
+
* @param param0
|
|
322
|
+
* @returns
|
|
323
|
+
*/
|
|
294
324
|
run({ path, key, payload }: {
|
|
295
325
|
path: string;
|
|
296
|
-
key
|
|
326
|
+
key?: string;
|
|
297
327
|
payload?: any;
|
|
298
328
|
}): Promise<any>;
|
|
299
329
|
}
|
package/dist/router-browser.js
CHANGED
|
@@ -5865,12 +5865,33 @@ class QueryRouter {
|
|
|
5865
5865
|
// TODO: 是否需要queryRouter,函数内部处理router路由执行,这应该是避免去内部去包含的功能过
|
|
5866
5866
|
ctx.queryRouter = this;
|
|
5867
5867
|
ctx.call = this.call.bind(this);
|
|
5868
|
+
ctx.queryRoute = this.queryRoute.bind(this);
|
|
5868
5869
|
ctx.index = 0;
|
|
5869
5870
|
return await this.runRoute(path, key, ctx);
|
|
5870
5871
|
}
|
|
5872
|
+
/**
|
|
5873
|
+
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
5874
|
+
* @param message
|
|
5875
|
+
* @param ctx
|
|
5876
|
+
* @returns
|
|
5877
|
+
*/
|
|
5871
5878
|
async call(message, ctx) {
|
|
5872
5879
|
return await this.parse(message, { ...this.context, ...ctx });
|
|
5873
5880
|
}
|
|
5881
|
+
/**
|
|
5882
|
+
* 请求 result 的数据
|
|
5883
|
+
* @param message
|
|
5884
|
+
* @param ctx
|
|
5885
|
+
* @returns
|
|
5886
|
+
*/
|
|
5887
|
+
async queryRoute(message, ctx) {
|
|
5888
|
+
const res = await this.parse(message, { ...this.context, ...ctx });
|
|
5889
|
+
return {
|
|
5890
|
+
code: res.code,
|
|
5891
|
+
data: res.body,
|
|
5892
|
+
message: res.message,
|
|
5893
|
+
};
|
|
5894
|
+
}
|
|
5874
5895
|
async setContext(ctx) {
|
|
5875
5896
|
this.context = ctx;
|
|
5876
5897
|
}
|
|
@@ -5947,9 +5968,11 @@ class QueryRouterServer extends QueryRouter {
|
|
|
5947
5968
|
}
|
|
5948
5969
|
return new Route(path, key, opts);
|
|
5949
5970
|
}
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5971
|
+
/**
|
|
5972
|
+
* 等于queryRoute,但是调用了handle
|
|
5973
|
+
* @param param0
|
|
5974
|
+
* @returns
|
|
5975
|
+
*/
|
|
5953
5976
|
async run({ path, key, payload }) {
|
|
5954
5977
|
const handle = this.handle;
|
|
5955
5978
|
const resultError = (error, code = 500) => {
|
package/dist/router.d.ts
CHANGED
|
@@ -68,9 +68,18 @@ type RouteContext<T = {
|
|
|
68
68
|
end?: boolean;
|
|
69
69
|
queryRouter?: QueryRouter;
|
|
70
70
|
error?: any;
|
|
71
|
+
/** 请求 route的返回结果,包函ctx */
|
|
71
72
|
call?: (message: {
|
|
72
73
|
path: string;
|
|
73
|
-
key
|
|
74
|
+
key?: string;
|
|
75
|
+
payload?: any;
|
|
76
|
+
}, ctx?: RouteContext & {
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
}) => Promise<any>;
|
|
79
|
+
/** 请求 route的返回结果,不包函ctx */
|
|
80
|
+
queryRoute?: (message: {
|
|
81
|
+
path: string;
|
|
82
|
+
key?: string;
|
|
74
83
|
payload?: any;
|
|
75
84
|
}, ctx?: RouteContext & {
|
|
76
85
|
[key: string]: any;
|
|
@@ -228,13 +237,36 @@ declare class QueryRouter {
|
|
|
228
237
|
}, ctx?: RouteContext & {
|
|
229
238
|
[key: string]: any;
|
|
230
239
|
}): Promise<any>;
|
|
240
|
+
/**
|
|
241
|
+
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
242
|
+
* @param message
|
|
243
|
+
* @param ctx
|
|
244
|
+
* @returns
|
|
245
|
+
*/
|
|
231
246
|
call(message: {
|
|
232
247
|
path: string;
|
|
233
|
-
key
|
|
248
|
+
key?: string;
|
|
234
249
|
payload?: any;
|
|
235
250
|
}, ctx?: RouteContext & {
|
|
236
251
|
[key: string]: any;
|
|
237
252
|
}): Promise<any>;
|
|
253
|
+
/**
|
|
254
|
+
* 请求 result 的数据
|
|
255
|
+
* @param message
|
|
256
|
+
* @param ctx
|
|
257
|
+
* @returns
|
|
258
|
+
*/
|
|
259
|
+
queryRoute(message: {
|
|
260
|
+
path: string;
|
|
261
|
+
key?: string;
|
|
262
|
+
payload?: any;
|
|
263
|
+
}, ctx?: RouteContext & {
|
|
264
|
+
[key: string]: any;
|
|
265
|
+
}): Promise<{
|
|
266
|
+
code: any;
|
|
267
|
+
data: any;
|
|
268
|
+
message: any;
|
|
269
|
+
}>;
|
|
238
270
|
setContext(ctx: RouteContext): Promise<void>;
|
|
239
271
|
getList(): RouteInfo[];
|
|
240
272
|
getHandle<T = any>(router: QueryRouter, wrapperFn?: HandleFn<T>, ctx?: RouteContext): (msg: {
|
|
@@ -287,16 +319,14 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
287
319
|
route(path: string, key?: string): Route;
|
|
288
320
|
route(path: string, opts?: RouteOpts): Route;
|
|
289
321
|
route(path: string, key?: string, opts?: RouteOpts): Route;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
[key: string]: any;
|
|
296
|
-
}): Promise<any>;
|
|
322
|
+
/**
|
|
323
|
+
* 等于queryRoute,但是调用了handle
|
|
324
|
+
* @param param0
|
|
325
|
+
* @returns
|
|
326
|
+
*/
|
|
297
327
|
run({ path, key, payload }: {
|
|
298
328
|
path: string;
|
|
299
|
-
key
|
|
329
|
+
key?: string;
|
|
300
330
|
payload?: any;
|
|
301
331
|
}): Promise<any>;
|
|
302
332
|
}
|
|
@@ -505,11 +535,18 @@ declare class App<T = {}> {
|
|
|
505
535
|
route(path: string, key?: string, opts?: RouteOpts): Route;
|
|
506
536
|
call(message: {
|
|
507
537
|
path: string;
|
|
508
|
-
key
|
|
538
|
+
key?: string;
|
|
509
539
|
payload?: any;
|
|
510
540
|
}, ctx?: RouteContext & {
|
|
511
541
|
[key: string]: any;
|
|
512
542
|
}): Promise<any>;
|
|
543
|
+
queryRoute(path: string, key?: string, payload?: any, ctx?: RouteContext & {
|
|
544
|
+
[key: string]: any;
|
|
545
|
+
}): Promise<{
|
|
546
|
+
code: any;
|
|
547
|
+
data: any;
|
|
548
|
+
message: any;
|
|
549
|
+
}>;
|
|
513
550
|
exportRoutes(): Route[];
|
|
514
551
|
importRoutes(routes: any[]): void;
|
|
515
552
|
importApp(app: App): void;
|
package/dist/router.js
CHANGED
|
@@ -5884,12 +5884,33 @@ class QueryRouter {
|
|
|
5884
5884
|
// TODO: 是否需要queryRouter,函数内部处理router路由执行,这应该是避免去内部去包含的功能过
|
|
5885
5885
|
ctx.queryRouter = this;
|
|
5886
5886
|
ctx.call = this.call.bind(this);
|
|
5887
|
+
ctx.queryRoute = this.queryRoute.bind(this);
|
|
5887
5888
|
ctx.index = 0;
|
|
5888
5889
|
return await this.runRoute(path, key, ctx);
|
|
5889
5890
|
}
|
|
5891
|
+
/**
|
|
5892
|
+
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
5893
|
+
* @param message
|
|
5894
|
+
* @param ctx
|
|
5895
|
+
* @returns
|
|
5896
|
+
*/
|
|
5890
5897
|
async call(message, ctx) {
|
|
5891
5898
|
return await this.parse(message, { ...this.context, ...ctx });
|
|
5892
5899
|
}
|
|
5900
|
+
/**
|
|
5901
|
+
* 请求 result 的数据
|
|
5902
|
+
* @param message
|
|
5903
|
+
* @param ctx
|
|
5904
|
+
* @returns
|
|
5905
|
+
*/
|
|
5906
|
+
async queryRoute(message, ctx) {
|
|
5907
|
+
const res = await this.parse(message, { ...this.context, ...ctx });
|
|
5908
|
+
return {
|
|
5909
|
+
code: res.code,
|
|
5910
|
+
data: res.body,
|
|
5911
|
+
message: res.message,
|
|
5912
|
+
};
|
|
5913
|
+
}
|
|
5893
5914
|
async setContext(ctx) {
|
|
5894
5915
|
this.context = ctx;
|
|
5895
5916
|
}
|
|
@@ -5966,9 +5987,11 @@ class QueryRouterServer extends QueryRouter {
|
|
|
5966
5987
|
}
|
|
5967
5988
|
return new Route(path, key, opts);
|
|
5968
5989
|
}
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5990
|
+
/**
|
|
5991
|
+
* 等于queryRoute,但是调用了handle
|
|
5992
|
+
* @param param0
|
|
5993
|
+
* @returns
|
|
5994
|
+
*/
|
|
5972
5995
|
async run({ path, key, payload }) {
|
|
5973
5996
|
const handle = this.handle;
|
|
5974
5997
|
const resultError = (error, code = 500) => {
|
|
@@ -6482,6 +6505,9 @@ class App {
|
|
|
6482
6505
|
const router = this.router;
|
|
6483
6506
|
return await router.call(message, ctx);
|
|
6484
6507
|
}
|
|
6508
|
+
async queryRoute(path, key, payload, ctx) {
|
|
6509
|
+
return await this.router.queryRoute({ path, key, payload }, ctx);
|
|
6510
|
+
}
|
|
6485
6511
|
exportRoutes() {
|
|
6486
6512
|
return this.router.exportRoutes();
|
|
6487
6513
|
}
|