@kevisual/router 0.0.34 → 0.0.35
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 +24 -2
- package/dist/router-browser.js +24 -36
- package/dist/router.d.ts +24 -2
- package/dist/router.js +24 -36
- package/package.json +1 -1
- package/src/route.ts +23 -33
package/dist/router-browser.d.ts
CHANGED
|
@@ -312,6 +312,7 @@ declare class QueryRouter {
|
|
|
312
312
|
* 请求 result 的数据
|
|
313
313
|
* @param message
|
|
314
314
|
* @param ctx
|
|
315
|
+
* @deprecated use run or call instead
|
|
315
316
|
* @returns
|
|
316
317
|
*/
|
|
317
318
|
queryRoute(message: {
|
|
@@ -326,6 +327,24 @@ declare class QueryRouter {
|
|
|
326
327
|
data: any;
|
|
327
328
|
message: any;
|
|
328
329
|
}>;
|
|
330
|
+
/**
|
|
331
|
+
* Router Run获取数据
|
|
332
|
+
* @param message
|
|
333
|
+
* @param ctx
|
|
334
|
+
* @returns
|
|
335
|
+
*/
|
|
336
|
+
run(message: {
|
|
337
|
+
id?: string;
|
|
338
|
+
path?: string;
|
|
339
|
+
key?: string;
|
|
340
|
+
payload?: any;
|
|
341
|
+
}, ctx?: RouteContext & {
|
|
342
|
+
[key: string]: any;
|
|
343
|
+
}): Promise<{
|
|
344
|
+
code: any;
|
|
345
|
+
data: any;
|
|
346
|
+
message: any;
|
|
347
|
+
}>;
|
|
329
348
|
/**
|
|
330
349
|
* 设置上下文
|
|
331
350
|
* @description 这里的上下文是为了在handle函数中使用
|
|
@@ -417,7 +436,7 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
417
436
|
prompt(description: string): Route<Required<RouteContext>>;
|
|
418
437
|
prompt(description: Function): Route<Required<RouteContext>>;
|
|
419
438
|
/**
|
|
420
|
-
*
|
|
439
|
+
* 调用了handle
|
|
421
440
|
* @param param0
|
|
422
441
|
* @returns
|
|
423
442
|
*/
|
|
@@ -425,9 +444,12 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
425
444
|
path: string;
|
|
426
445
|
key?: string;
|
|
427
446
|
payload?: any;
|
|
447
|
+
}, ctx?: RouteContext & {
|
|
448
|
+
[key: string]: any;
|
|
428
449
|
}): Promise<any>;
|
|
429
450
|
}
|
|
430
|
-
declare
|
|
451
|
+
declare class Mini extends QueryRouterServer {
|
|
452
|
+
}
|
|
431
453
|
|
|
432
454
|
/** 自定义错误 */
|
|
433
455
|
declare class CustomError extends Error {
|
package/dist/router-browser.js
CHANGED
|
@@ -5332,6 +5332,7 @@ class QueryRouter {
|
|
|
5332
5332
|
* 请求 result 的数据
|
|
5333
5333
|
* @param message
|
|
5334
5334
|
* @param ctx
|
|
5335
|
+
* @deprecated use run or call instead
|
|
5335
5336
|
* @returns
|
|
5336
5337
|
*/
|
|
5337
5338
|
async queryRoute(message, ctx) {
|
|
@@ -5342,6 +5343,20 @@ class QueryRouter {
|
|
|
5342
5343
|
message: res.message,
|
|
5343
5344
|
};
|
|
5344
5345
|
}
|
|
5346
|
+
/**
|
|
5347
|
+
* Router Run获取数据
|
|
5348
|
+
* @param message
|
|
5349
|
+
* @param ctx
|
|
5350
|
+
* @returns
|
|
5351
|
+
*/
|
|
5352
|
+
async run(message, ctx) {
|
|
5353
|
+
const res = await this.call(message, { ...this.context, ...ctx });
|
|
5354
|
+
return {
|
|
5355
|
+
code: res.code,
|
|
5356
|
+
data: res.body,
|
|
5357
|
+
message: res.message,
|
|
5358
|
+
};
|
|
5359
|
+
}
|
|
5345
5360
|
/**
|
|
5346
5361
|
* 设置上下文
|
|
5347
5362
|
* @description 这里的上下文是为了在handle函数中使用
|
|
@@ -5362,18 +5377,7 @@ class QueryRouter {
|
|
|
5362
5377
|
return async (msg, handleContext) => {
|
|
5363
5378
|
try {
|
|
5364
5379
|
const context = { ...ctx, ...handleContext };
|
|
5365
|
-
|
|
5366
|
-
const route = router.routes.find((r) => r.id === msg.id);
|
|
5367
|
-
if (route) {
|
|
5368
|
-
msg.path = route.path;
|
|
5369
|
-
msg.key = route.key;
|
|
5370
|
-
}
|
|
5371
|
-
else {
|
|
5372
|
-
return { code: 404, message: 'Not found route' };
|
|
5373
|
-
}
|
|
5374
|
-
}
|
|
5375
|
-
// @ts-ignore
|
|
5376
|
-
const res = await router.parse(msg, context);
|
|
5380
|
+
const res = await router.call(msg, context);
|
|
5377
5381
|
if (wrapperFn) {
|
|
5378
5382
|
res.data = res.body;
|
|
5379
5383
|
return wrapperFn(res, context);
|
|
@@ -5485,37 +5489,21 @@ class QueryRouterServer extends QueryRouter {
|
|
|
5485
5489
|
return new Route('', '', { description });
|
|
5486
5490
|
}
|
|
5487
5491
|
/**
|
|
5488
|
-
*
|
|
5492
|
+
* 调用了handle
|
|
5489
5493
|
* @param param0
|
|
5490
5494
|
* @returns
|
|
5491
5495
|
*/
|
|
5492
|
-
async run({ path, key, payload }) {
|
|
5496
|
+
async run({ path, key, payload }, ctx) {
|
|
5493
5497
|
const handle = this.handle;
|
|
5494
|
-
|
|
5495
|
-
const
|
|
5496
|
-
|
|
5497
|
-
message: error,
|
|
5498
|
-
};
|
|
5499
|
-
return r;
|
|
5500
|
-
};
|
|
5501
|
-
try {
|
|
5502
|
-
const end = handle({ path, key, ...payload });
|
|
5503
|
-
return end;
|
|
5504
|
-
}
|
|
5505
|
-
catch (e) {
|
|
5506
|
-
if (e.code && typeof e.code === 'number') {
|
|
5507
|
-
return {
|
|
5508
|
-
code: e.code,
|
|
5509
|
-
message: e.message,
|
|
5510
|
-
};
|
|
5511
|
-
}
|
|
5512
|
-
else {
|
|
5513
|
-
return resultError('Router Server error');
|
|
5514
|
-
}
|
|
5498
|
+
if (handle) {
|
|
5499
|
+
const result = await this.call({ path, key, payload }, ctx);
|
|
5500
|
+
return handle(result);
|
|
5515
5501
|
}
|
|
5502
|
+
return super.run({ path, key, payload }, ctx);
|
|
5516
5503
|
}
|
|
5517
5504
|
}
|
|
5518
|
-
|
|
5505
|
+
class Mini extends QueryRouterServer {
|
|
5506
|
+
}
|
|
5519
5507
|
|
|
5520
5508
|
const parseBody = async (req) => {
|
|
5521
5509
|
return new Promise((resolve, reject) => {
|
package/dist/router.d.ts
CHANGED
|
@@ -316,6 +316,7 @@ declare class QueryRouter {
|
|
|
316
316
|
* 请求 result 的数据
|
|
317
317
|
* @param message
|
|
318
318
|
* @param ctx
|
|
319
|
+
* @deprecated use run or call instead
|
|
319
320
|
* @returns
|
|
320
321
|
*/
|
|
321
322
|
queryRoute(message: {
|
|
@@ -330,6 +331,24 @@ declare class QueryRouter {
|
|
|
330
331
|
data: any;
|
|
331
332
|
message: any;
|
|
332
333
|
}>;
|
|
334
|
+
/**
|
|
335
|
+
* Router Run获取数据
|
|
336
|
+
* @param message
|
|
337
|
+
* @param ctx
|
|
338
|
+
* @returns
|
|
339
|
+
*/
|
|
340
|
+
run(message: {
|
|
341
|
+
id?: string;
|
|
342
|
+
path?: string;
|
|
343
|
+
key?: string;
|
|
344
|
+
payload?: any;
|
|
345
|
+
}, ctx?: RouteContext & {
|
|
346
|
+
[key: string]: any;
|
|
347
|
+
}): Promise<{
|
|
348
|
+
code: any;
|
|
349
|
+
data: any;
|
|
350
|
+
message: any;
|
|
351
|
+
}>;
|
|
333
352
|
/**
|
|
334
353
|
* 设置上下文
|
|
335
354
|
* @description 这里的上下文是为了在handle函数中使用
|
|
@@ -421,7 +440,7 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
421
440
|
prompt(description: string): Route<Required<RouteContext>>;
|
|
422
441
|
prompt(description: Function): Route<Required<RouteContext>>;
|
|
423
442
|
/**
|
|
424
|
-
*
|
|
443
|
+
* 调用了handle
|
|
425
444
|
* @param param0
|
|
426
445
|
* @returns
|
|
427
446
|
*/
|
|
@@ -429,9 +448,12 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
429
448
|
path: string;
|
|
430
449
|
key?: string;
|
|
431
450
|
payload?: any;
|
|
451
|
+
}, ctx?: RouteContext & {
|
|
452
|
+
[key: string]: any;
|
|
432
453
|
}): Promise<any>;
|
|
433
454
|
}
|
|
434
|
-
declare
|
|
455
|
+
declare class Mini extends QueryRouterServer {
|
|
456
|
+
}
|
|
435
457
|
|
|
436
458
|
declare class Connect {
|
|
437
459
|
path: string;
|
package/dist/router.js
CHANGED
|
@@ -5354,6 +5354,7 @@ class QueryRouter {
|
|
|
5354
5354
|
* 请求 result 的数据
|
|
5355
5355
|
* @param message
|
|
5356
5356
|
* @param ctx
|
|
5357
|
+
* @deprecated use run or call instead
|
|
5357
5358
|
* @returns
|
|
5358
5359
|
*/
|
|
5359
5360
|
async queryRoute(message, ctx) {
|
|
@@ -5364,6 +5365,20 @@ class QueryRouter {
|
|
|
5364
5365
|
message: res.message,
|
|
5365
5366
|
};
|
|
5366
5367
|
}
|
|
5368
|
+
/**
|
|
5369
|
+
* Router Run获取数据
|
|
5370
|
+
* @param message
|
|
5371
|
+
* @param ctx
|
|
5372
|
+
* @returns
|
|
5373
|
+
*/
|
|
5374
|
+
async run(message, ctx) {
|
|
5375
|
+
const res = await this.call(message, { ...this.context, ...ctx });
|
|
5376
|
+
return {
|
|
5377
|
+
code: res.code,
|
|
5378
|
+
data: res.body,
|
|
5379
|
+
message: res.message,
|
|
5380
|
+
};
|
|
5381
|
+
}
|
|
5367
5382
|
/**
|
|
5368
5383
|
* 设置上下文
|
|
5369
5384
|
* @description 这里的上下文是为了在handle函数中使用
|
|
@@ -5384,18 +5399,7 @@ class QueryRouter {
|
|
|
5384
5399
|
return async (msg, handleContext) => {
|
|
5385
5400
|
try {
|
|
5386
5401
|
const context = { ...ctx, ...handleContext };
|
|
5387
|
-
|
|
5388
|
-
const route = router.routes.find((r) => r.id === msg.id);
|
|
5389
|
-
if (route) {
|
|
5390
|
-
msg.path = route.path;
|
|
5391
|
-
msg.key = route.key;
|
|
5392
|
-
}
|
|
5393
|
-
else {
|
|
5394
|
-
return { code: 404, message: 'Not found route' };
|
|
5395
|
-
}
|
|
5396
|
-
}
|
|
5397
|
-
// @ts-ignore
|
|
5398
|
-
const res = await router.parse(msg, context);
|
|
5402
|
+
const res = await router.call(msg, context);
|
|
5399
5403
|
if (wrapperFn) {
|
|
5400
5404
|
res.data = res.body;
|
|
5401
5405
|
return wrapperFn(res, context);
|
|
@@ -5507,37 +5511,21 @@ class QueryRouterServer extends QueryRouter {
|
|
|
5507
5511
|
return new Route('', '', { description });
|
|
5508
5512
|
}
|
|
5509
5513
|
/**
|
|
5510
|
-
*
|
|
5514
|
+
* 调用了handle
|
|
5511
5515
|
* @param param0
|
|
5512
5516
|
* @returns
|
|
5513
5517
|
*/
|
|
5514
|
-
async run({ path, key, payload }) {
|
|
5518
|
+
async run({ path, key, payload }, ctx) {
|
|
5515
5519
|
const handle = this.handle;
|
|
5516
|
-
|
|
5517
|
-
const
|
|
5518
|
-
|
|
5519
|
-
message: error,
|
|
5520
|
-
};
|
|
5521
|
-
return r;
|
|
5522
|
-
};
|
|
5523
|
-
try {
|
|
5524
|
-
const end = handle({ path, key, ...payload });
|
|
5525
|
-
return end;
|
|
5526
|
-
}
|
|
5527
|
-
catch (e) {
|
|
5528
|
-
if (e.code && typeof e.code === 'number') {
|
|
5529
|
-
return {
|
|
5530
|
-
code: e.code,
|
|
5531
|
-
message: e.message,
|
|
5532
|
-
};
|
|
5533
|
-
}
|
|
5534
|
-
else {
|
|
5535
|
-
return resultError('Router Server error');
|
|
5536
|
-
}
|
|
5520
|
+
if (handle) {
|
|
5521
|
+
const result = await this.call({ path, key, payload }, ctx);
|
|
5522
|
+
return handle(result);
|
|
5537
5523
|
}
|
|
5524
|
+
return super.run({ path, key, payload }, ctx);
|
|
5538
5525
|
}
|
|
5539
5526
|
}
|
|
5540
|
-
|
|
5527
|
+
class Mini extends QueryRouterServer {
|
|
5528
|
+
}
|
|
5541
5529
|
|
|
5542
5530
|
class Connect {
|
|
5543
5531
|
path;
|
package/package.json
CHANGED
package/src/route.ts
CHANGED
|
@@ -628,6 +628,7 @@ export class QueryRouter {
|
|
|
628
628
|
* 请求 result 的数据
|
|
629
629
|
* @param message
|
|
630
630
|
* @param ctx
|
|
631
|
+
* @deprecated use run or call instead
|
|
631
632
|
* @returns
|
|
632
633
|
*/
|
|
633
634
|
async queryRoute(message: { id?: string; path: string; key?: string; payload?: any }, ctx?: RouteContext & { [key: string]: any }) {
|
|
@@ -638,6 +639,20 @@ export class QueryRouter {
|
|
|
638
639
|
message: res.message,
|
|
639
640
|
};
|
|
640
641
|
}
|
|
642
|
+
/**
|
|
643
|
+
* Router Run获取数据
|
|
644
|
+
* @param message
|
|
645
|
+
* @param ctx
|
|
646
|
+
* @returns
|
|
647
|
+
*/
|
|
648
|
+
async run(message: { id?: string; path?: string; key?: string; payload?: any }, ctx?: RouteContext & { [key: string]: any }) {
|
|
649
|
+
const res = await this.call(message, { ...this.context, ...ctx });
|
|
650
|
+
return {
|
|
651
|
+
code: res.code,
|
|
652
|
+
data: res.body,
|
|
653
|
+
message: res.message,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
641
656
|
/**
|
|
642
657
|
* 设置上下文
|
|
643
658
|
* @description 这里的上下文是为了在handle函数中使用
|
|
@@ -658,17 +673,7 @@ export class QueryRouter {
|
|
|
658
673
|
return async (msg: { id?: string; path?: string; key?: string;[key: string]: any }, handleContext?: RouteContext) => {
|
|
659
674
|
try {
|
|
660
675
|
const context = { ...ctx, ...handleContext };
|
|
661
|
-
|
|
662
|
-
const route = router.routes.find((r) => r.id === msg.id);
|
|
663
|
-
if (route) {
|
|
664
|
-
msg.path = route.path;
|
|
665
|
-
msg.key = route.key;
|
|
666
|
-
} else {
|
|
667
|
-
return { code: 404, message: 'Not found route' };
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
// @ts-ignore
|
|
671
|
-
const res = await router.parse(msg, context);
|
|
676
|
+
const res = await router.call(msg, context);
|
|
672
677
|
if (wrapperFn) {
|
|
673
678
|
res.data = res.body;
|
|
674
679
|
return wrapperFn(res, context);
|
|
@@ -796,34 +801,19 @@ export class QueryRouterServer extends QueryRouter {
|
|
|
796
801
|
}
|
|
797
802
|
|
|
798
803
|
/**
|
|
799
|
-
*
|
|
804
|
+
* 调用了handle
|
|
800
805
|
* @param param0
|
|
801
806
|
* @returns
|
|
802
807
|
*/
|
|
803
|
-
async run({ path, key, payload }: { path: string; key?: string; payload?: any }) {
|
|
808
|
+
async run({ path, key, payload }: { path: string; key?: string; payload?: any }, ctx?: RouteContext & { [key: string]: any }) {
|
|
804
809
|
const handle = this.handle;
|
|
805
|
-
|
|
806
|
-
const
|
|
807
|
-
|
|
808
|
-
message: error,
|
|
809
|
-
};
|
|
810
|
-
return r;
|
|
811
|
-
};
|
|
812
|
-
try {
|
|
813
|
-
const end = handle({ path, key, ...payload });
|
|
814
|
-
return end;
|
|
815
|
-
} catch (e) {
|
|
816
|
-
if (e.code && typeof e.code === 'number') {
|
|
817
|
-
return {
|
|
818
|
-
code: e.code,
|
|
819
|
-
message: e.message,
|
|
820
|
-
};
|
|
821
|
-
} else {
|
|
822
|
-
return resultError('Router Server error');
|
|
823
|
-
}
|
|
810
|
+
if (handle) {
|
|
811
|
+
const result = await this.call({ path, key, payload }, ctx);
|
|
812
|
+
return handle(result);
|
|
824
813
|
}
|
|
814
|
+
return super.run({ path, key, payload }, ctx);
|
|
825
815
|
}
|
|
826
816
|
}
|
|
827
817
|
|
|
828
818
|
|
|
829
|
-
export
|
|
819
|
+
export class Mini extends QueryRouterServer {}
|