@kevisual/router 0.0.64 → 0.0.65

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.
@@ -152,17 +152,28 @@ declare class Route<U = {
152
152
  addTo(router: QueryRouter | {
153
153
  add: (route: Route) => void;
154
154
  [key: string]: any;
155
- }): void;
155
+ }, opts?: AddOpts): void;
156
156
  setData(data: any): this;
157
157
  throw(code?: number | string, message?: string, tips?: string): void;
158
158
  }
159
+ /**
160
+ * @parmas override 是否覆盖已存在的route,默认true
161
+ */
162
+ type AddOpts = {
163
+ override?: boolean;
164
+ };
159
165
  declare class QueryRouter {
160
166
  appId: string;
161
167
  routes: Route[];
162
168
  maxNextRoute: number;
163
169
  context?: RouteContext;
164
170
  constructor();
165
- add(route: Route): void;
171
+ /**
172
+ * add route
173
+ * @param route
174
+ * @param opts
175
+ */
176
+ add(route: Route, opts?: AddOpts): void;
166
177
  /**
167
178
  * remove route by path and key
168
179
  * @param route
@@ -340,7 +351,7 @@ declare class QueryRouterServer extends QueryRouter {
340
351
  handle: any;
341
352
  constructor(opts?: QueryRouterServerOpts);
342
353
  setHandle(wrapperFn?: HandleFn, ctx?: RouteContext): void;
343
- addRoute(route: Route): void;
354
+ addRoute(route: Route, opts?: AddOpts): void;
344
355
  Route: typeof Route;
345
356
  route(opts: RouteOpts): Route<Required<RouteContext>>;
346
357
  route(path: string, key?: string): Route<Required<RouteContext>>;
@@ -633,7 +644,7 @@ declare class App<U = {}> extends QueryRouter {
633
644
  listen(path: string, listeningListener?: () => void): void;
634
645
  listen(handle: any, backlog?: number, listeningListener?: () => void): void;
635
646
  listen(handle: any, listeningListener?: () => void): void;
636
- addRoute(route: Route): void;
647
+ addRoute(route: Route, opts?: AddOpts): void;
637
648
  Route: typeof Route;
638
649
  route(opts: RouteOpts<AppRouteContext<U>>): Route<AppRouteContext<U>>;
639
650
  route(path: string, key?: string): Route<AppRouteContext<U>>;
@@ -164,17 +164,28 @@ declare class Route<U = {
164
164
  addTo(router: QueryRouter | {
165
165
  add: (route: Route) => void;
166
166
  [key: string]: any;
167
- }): void;
167
+ }, opts?: AddOpts): void;
168
168
  setData(data: any): this;
169
169
  throw(code?: number | string, message?: string, tips?: string): void;
170
170
  }
171
+ /**
172
+ * @parmas override 是否覆盖已存在的route,默认true
173
+ */
174
+ type AddOpts = {
175
+ override?: boolean;
176
+ };
171
177
  declare class QueryRouter {
172
178
  appId: string;
173
179
  routes: Route[];
174
180
  maxNextRoute: number;
175
181
  context?: RouteContext;
176
182
  constructor();
177
- add(route: Route): void;
183
+ /**
184
+ * add route
185
+ * @param route
186
+ * @param opts
187
+ */
188
+ add(route: Route, opts?: AddOpts): void;
178
189
  /**
179
190
  * remove route by path and key
180
191
  * @param route
@@ -352,7 +363,7 @@ declare class QueryRouterServer extends QueryRouter {
352
363
  handle: any;
353
364
  constructor(opts?: QueryRouterServerOpts);
354
365
  setHandle(wrapperFn?: HandleFn, ctx?: RouteContext): void;
355
- addRoute(route: Route): void;
366
+ addRoute(route: Route, opts?: AddOpts): void;
356
367
  Route: typeof Route;
357
368
  route(opts: RouteOpts): Route<Required<RouteContext>>;
358
369
  route(path: string, key?: string): Route<Required<RouteContext>>;
@@ -15033,8 +15033,8 @@ class Route {
15033
15033
  }
15034
15034
  return this;
15035
15035
  }
15036
- addTo(router) {
15037
- router.add(this);
15036
+ addTo(router, opts) {
15037
+ router.add(this, opts);
15038
15038
  }
15039
15039
  setData(data) {
15040
15040
  this.data = data;
@@ -15052,10 +15052,19 @@ class QueryRouter {
15052
15052
  constructor() {
15053
15053
  this.routes = [];
15054
15054
  }
15055
- add(route) {
15055
+ /**
15056
+ * add route
15057
+ * @param route
15058
+ * @param opts
15059
+ */
15060
+ add(route, opts) {
15061
+ const override = opts?.override ?? true;
15056
15062
  const has = this.routes.findIndex((r) => r.path === route.path && r.key === route.key);
15057
15063
  if (has !== -1) {
15058
- // remove the old route
15064
+ if (!override) {
15065
+ return;
15066
+ }
15067
+ // 如果存在,且override为true,则覆盖
15059
15068
  this.routes.splice(has, 1);
15060
15069
  }
15061
15070
  this.routes.push(route);
@@ -15460,8 +15469,8 @@ class QueryRouterServer extends QueryRouter {
15460
15469
  setHandle(wrapperFn, ctx) {
15461
15470
  this.handle = this.getHandle(this, wrapperFn, ctx);
15462
15471
  }
15463
- addRoute(route) {
15464
- this.add(route);
15472
+ addRoute(route, opts) {
15473
+ this.add(route, opts);
15465
15474
  }
15466
15475
  Route = Route;
15467
15476
  route(...args) {
package/dist/router.d.ts CHANGED
@@ -170,17 +170,28 @@ declare class Route<U = {
170
170
  addTo(router: QueryRouter | {
171
171
  add: (route: Route) => void;
172
172
  [key: string]: any;
173
- }): void;
173
+ }, opts?: AddOpts): void;
174
174
  setData(data: any): this;
175
175
  throw(code?: number | string, message?: string, tips?: string): void;
176
176
  }
177
+ /**
178
+ * @parmas override 是否覆盖已存在的route,默认true
179
+ */
180
+ type AddOpts = {
181
+ override?: boolean;
182
+ };
177
183
  declare class QueryRouter {
178
184
  appId: string;
179
185
  routes: Route[];
180
186
  maxNextRoute: number;
181
187
  context?: RouteContext;
182
188
  constructor();
183
- add(route: Route): void;
189
+ /**
190
+ * add route
191
+ * @param route
192
+ * @param opts
193
+ */
194
+ add(route: Route, opts?: AddOpts): void;
184
195
  /**
185
196
  * remove route by path and key
186
197
  * @param route
@@ -358,7 +369,7 @@ declare class QueryRouterServer extends QueryRouter {
358
369
  handle: any;
359
370
  constructor(opts?: QueryRouterServerOpts);
360
371
  setHandle(wrapperFn?: HandleFn, ctx?: RouteContext): void;
361
- addRoute(route: Route): void;
372
+ addRoute(route: Route, opts?: AddOpts): void;
362
373
  Route: typeof Route;
363
374
  route(opts: RouteOpts): Route<Required<RouteContext>>;
364
375
  route(path: string, key?: string): Route<Required<RouteContext>>;
@@ -898,7 +909,7 @@ declare class App<U = {}> extends QueryRouter {
898
909
  listen(path: string, listeningListener?: () => void): void;
899
910
  listen(handle: any, backlog?: number, listeningListener?: () => void): void;
900
911
  listen(handle: any, listeningListener?: () => void): void;
901
- addRoute(route: Route): void;
912
+ addRoute(route: Route, opts?: AddOpts): void;
902
913
  Route: typeof Route;
903
914
  route(opts: RouteOpts<AppRouteContext<U>>): Route<AppRouteContext<U>>;
904
915
  route(path: string, key?: string): Route<AppRouteContext<U>>;
package/dist/router.js CHANGED
@@ -15057,8 +15057,8 @@ class Route {
15057
15057
  }
15058
15058
  return this;
15059
15059
  }
15060
- addTo(router) {
15061
- router.add(this);
15060
+ addTo(router, opts) {
15061
+ router.add(this, opts);
15062
15062
  }
15063
15063
  setData(data) {
15064
15064
  this.data = data;
@@ -15076,10 +15076,19 @@ class QueryRouter {
15076
15076
  constructor() {
15077
15077
  this.routes = [];
15078
15078
  }
15079
- add(route) {
15079
+ /**
15080
+ * add route
15081
+ * @param route
15082
+ * @param opts
15083
+ */
15084
+ add(route, opts) {
15085
+ const override = opts?.override ?? true;
15080
15086
  const has = this.routes.findIndex((r) => r.path === route.path && r.key === route.key);
15081
15087
  if (has !== -1) {
15082
- // remove the old route
15088
+ if (!override) {
15089
+ return;
15090
+ }
15091
+ // 如果存在,且override为true,则覆盖
15083
15092
  this.routes.splice(has, 1);
15084
15093
  }
15085
15094
  this.routes.push(route);
@@ -15484,8 +15493,8 @@ class QueryRouterServer extends QueryRouter {
15484
15493
  setHandle(wrapperFn, ctx) {
15485
15494
  this.handle = this.getHandle(this, wrapperFn, ctx);
15486
15495
  }
15487
- addRoute(route) {
15488
- this.add(route);
15496
+ addRoute(route, opts) {
15497
+ this.add(route, opts);
15489
15498
  }
15490
15499
  Route = Route;
15491
15500
  route(...args) {
@@ -21691,8 +21700,8 @@ class App extends QueryRouter {
21691
21700
  // @ts-ignore
21692
21701
  this.server.listen(...args);
21693
21702
  }
21694
- addRoute(route) {
21695
- super.add(route);
21703
+ addRoute(route, opts) {
21704
+ super.add(route, opts);
21696
21705
  }
21697
21706
  Route = Route;
21698
21707
  route(...args) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@kevisual/router",
4
- "version": "0.0.64",
4
+ "version": "0.0.65",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
@@ -28,7 +28,7 @@
28
28
  "@kevisual/local-proxy": "^0.0.8",
29
29
  "@kevisual/query": "^0.0.38",
30
30
  "@kevisual/use-config": "^1.0.28",
31
- "@opencode-ai/plugin": "^1.1.44",
31
+ "@opencode-ai/plugin": "^1.1.47",
32
32
  "@rollup/plugin-alias": "^6.0.0",
33
33
  "@rollup/plugin-commonjs": "29.0.0",
34
34
  "@rollup/plugin-node-resolve": "^16.0.3",
@@ -102,4 +102,4 @@
102
102
  "require": "./src/modules/*"
103
103
  }
104
104
  }
105
- }
105
+ }
package/src/app.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { QueryRouter, Route, RouteContext, RouteOpts } from './route.ts';
1
+ import { AddOpts, QueryRouter, Route, RouteContext, RouteOpts } from './route.ts';
2
2
  import { ServerNode, ServerNodeOpts } from './server/server.ts';
3
3
  import { HandleCtx } from './server/server-base.ts';
4
4
  import { ServerType } from './server/server-type.ts';
@@ -64,8 +64,8 @@ export class App<U = {}> extends QueryRouter {
64
64
  // @ts-ignore
65
65
  this.server.listen(...args);
66
66
  }
67
- addRoute(route: Route) {
68
- super.add(route);
67
+ addRoute(route: Route, opts?: AddOpts) {
68
+ super.add(route, opts);
69
69
  }
70
70
 
71
71
  Route = Route;
package/src/route.ts CHANGED
@@ -231,8 +231,8 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
231
231
  }
232
232
  return this;
233
233
  }
234
- addTo(router: QueryRouter | { add: (route: Route) => void;[key: string]: any }) {
235
- router.add(this);
234
+ addTo(router: QueryRouter | { add: (route: Route) => void;[key: string]: any }, opts?: AddOpts) {
235
+ router.add(this, opts);
236
236
  }
237
237
  setData(data: any) {
238
238
  this.data = data;
@@ -244,6 +244,10 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
244
244
  }
245
245
  }
246
246
 
247
+ /**
248
+ * @parmas override 是否覆盖已存在的route,默认true
249
+ */
250
+ export type AddOpts = { override?: boolean };
247
251
  export class QueryRouter {
248
252
  appId: string = '';
249
253
  routes: Route[];
@@ -252,11 +256,20 @@ export class QueryRouter {
252
256
  constructor() {
253
257
  this.routes = [];
254
258
  }
255
-
256
- add(route: Route) {
259
+ /**
260
+ * add route
261
+ * @param route
262
+ * @param opts
263
+ */
264
+ add(route: Route, opts?: AddOpts) {
265
+ const override = opts?.override ?? true;
257
266
  const has = this.routes.findIndex((r) => r.path === route.path && r.key === route.key);
267
+
258
268
  if (has !== -1) {
259
- // remove the old route
269
+ if (!override) {
270
+ return;
271
+ }
272
+ // 如果存在,且override为true,则覆盖
260
273
  this.routes.splice(has, 1);
261
274
  }
262
275
  this.routes.push(route);
@@ -664,8 +677,8 @@ export class QueryRouterServer extends QueryRouter {
664
677
  setHandle(wrapperFn?: HandleFn, ctx?: RouteContext) {
665
678
  this.handle = this.getHandle(this, wrapperFn, ctx);
666
679
  }
667
- addRoute(route: Route) {
668
- this.add(route);
680
+ addRoute(route: Route, opts?: AddOpts) {
681
+ this.add(route, opts);
669
682
  }
670
683
  Route = Route;
671
684
  route(opts: RouteOpts): Route<Required<RouteContext>>;