@kevisual/router 0.0.4-alpha-7 → 0.0.4

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.
@@ -188,6 +188,7 @@ declare class Route {
188
188
  declare class QueryRouter {
189
189
  routes: Route[];
190
190
  maxNextRoute: number;
191
+ context?: RouteContext;
191
192
  constructor();
192
193
  add(route: Route): void;
193
194
  /**
@@ -231,6 +232,7 @@ declare class QueryRouter {
231
232
  }, ctx?: RouteContext & {
232
233
  [key: string]: any;
233
234
  }): Promise<any>;
235
+ setContext(ctx: RouteContext): Promise<void>;
234
236
  getList(): RouteInfo[];
235
237
  getHandle<T = any>(router: QueryRouter, wrapperFn?: HandleFn<T>, ctx?: RouteContext): (msg: {
236
238
  path: string;
@@ -5641,6 +5641,7 @@ class Route {
5641
5641
  class QueryRouter {
5642
5642
  routes;
5643
5643
  maxNextRoute = 40;
5644
+ context = {}; // default context for call
5644
5645
  constructor() {
5645
5646
  this.routes = [];
5646
5647
  }
@@ -5867,7 +5868,10 @@ class QueryRouter {
5867
5868
  return await this.runRoute(path, key, ctx);
5868
5869
  }
5869
5870
  async call(message, ctx) {
5870
- return await this.parse(message, ctx);
5871
+ return await this.parse(message, { ...this.context, ...ctx });
5872
+ }
5873
+ async setContext(ctx) {
5874
+ this.context = ctx;
5871
5875
  }
5872
5876
  getList() {
5873
5877
  return this.routes.map((r) => {
@@ -5912,6 +5916,7 @@ class QueryRouterServer extends QueryRouter {
5912
5916
  constructor(opts) {
5913
5917
  super();
5914
5918
  this.handle = this.getHandle(this, opts?.handleFn, opts?.context);
5919
+ this.setContext(opts?.context);
5915
5920
  }
5916
5921
  setHandle(wrapperFn, ctx) {
5917
5922
  this.handle = this.getHandle(this, wrapperFn, ctx);
@@ -0,0 +1,15 @@
1
+ type Attributes = {
2
+ name: string;
3
+ value: string;
4
+ };
5
+ type AltNames = {
6
+ type: number;
7
+ value?: string;
8
+ ip?: string;
9
+ };
10
+ declare const createCert: (attrs?: Attributes[], altNames?: AltNames[]) => {
11
+ key: string;
12
+ cert: string;
13
+ };
14
+
15
+ export { createCert };