@kevisual/router 0.0.32 → 0.0.34

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.
@@ -56,9 +56,19 @@ type HttpChainOpts = {
56
56
  req?: Req;
57
57
  res?: ServerResponse;
58
58
  simpleRouter?: SimpleRouter;
59
+ server?: Server;
59
60
  };
61
+ /**
62
+ * HttpChain 类, 用于链式调用,router.get内部使用
63
+ */
60
64
  declare class HttpChain {
65
+ /**
66
+ * 请求对象, 每一次请求都是不一样的
67
+ */
61
68
  req: Req;
69
+ /**
70
+ * 响应对象, 每一次请求响应都是不一样的
71
+ */
62
72
  res: ServerResponse;
63
73
  simpleRouter: SimpleRouter;
64
74
  server: Server;
@@ -84,7 +94,14 @@ declare class HttpChain {
84
94
  */
85
95
  end(data: SimpleObject | string): this;
86
96
  listen(opts: ListenOptions, callback?: () => void): this;
87
- parse(): () => void;
97
+ /**
98
+ * 外部 parse 方法
99
+ * @returns
100
+ */
101
+ parse(opts?: {
102
+ listenOptions?: ListenOptions;
103
+ listenCallBack?: () => void;
104
+ }): () => void;
88
105
  getString(value: string | SimpleObject): string;
89
106
  sse(value: string | SimpleObject): this;
90
107
  close(): this;
@@ -593,16 +593,29 @@ class SimpleRouter {
593
593
  return new HttpChain(opts);
594
594
  }
595
595
  }
596
+ /**
597
+ * HttpChain 类, 用于链式调用,router.get内部使用
598
+ */
596
599
  class HttpChain {
600
+ /**
601
+ * 请求对象, 每一次请求都是不一样的
602
+ */
597
603
  req;
604
+ /**
605
+ * 响应对象, 每一次请求响应都是不一样的
606
+ */
598
607
  res;
599
608
  simpleRouter;
600
609
  server;
601
610
  hasSetHeader = false;
602
611
  isSseSet = false;
603
612
  constructor(opts) {
604
- this.req = opts?.req;
605
- this.res = opts?.res;
613
+ if (opts?.res) {
614
+ this.res = opts.res;
615
+ }
616
+ if (opts?.req) {
617
+ this.req = opts.req;
618
+ }
606
619
  this.simpleRouter = opts?.simpleRouter;
607
620
  }
608
621
  setReq(req) {
@@ -675,7 +688,12 @@ class HttpChain {
675
688
  this.server.listen(opts, callback);
676
689
  return this;
677
690
  }
678
- parse() {
691
+ /**
692
+ * 外部 parse 方法
693
+ * @returns
694
+ */
695
+ parse(opts) {
696
+ const { listenOptions, listenCallBack } = opts || {};
679
697
  if (!this.server || !this.simpleRouter) {
680
698
  throw new Error('Server and SimpleRouter must be set before calling parse');
681
699
  }
@@ -692,6 +710,9 @@ class HttpChain {
692
710
  }
693
711
  }
694
712
  };
713
+ if (listenOptions) {
714
+ this.server.listen(listenOptions, listenCallBack);
715
+ }
695
716
  this.server.on('request', listener);
696
717
  return () => {
697
718
  that.server.removeListener('request', listener);
package/dist/router.d.ts CHANGED
@@ -175,7 +175,6 @@ declare class Route<U = {
175
175
  */
176
176
  key?: string;
177
177
  id?: string;
178
- share?: boolean;
179
178
  run?: Run;
180
179
  nextRoute?: NextRoute;
181
180
  description?: string;
@@ -369,6 +368,7 @@ declare class QueryRouter {
369
368
  hasRoute(path: string, key?: string): Route<{
370
369
  [key: string]: any;
371
370
  }>;
371
+ createRouteList(force?: boolean): void;
372
372
  /**
373
373
  * 等待程序运行, 获取到message的数据,就执行
374
374
  *
@@ -384,6 +384,7 @@ declare class QueryRouter {
384
384
  }, opts?: {
385
385
  emitter?: any;
386
386
  timeout?: number;
387
+ getList?: boolean;
387
388
  }): Promise<void>;
388
389
  }
389
390
  type QueryRouterServerOpts = {