@kevisual/router 0.0.80 → 0.0.81

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/app.js CHANGED
@@ -2316,9 +2316,9 @@ var require_websocket = __commonJS((exports, module) => {
2316
2316
  emitErrorAndClose(websocket, err);
2317
2317
  });
2318
2318
  req.on("response", (res) => {
2319
- const location = res.headers.location;
2319
+ const location2 = res.headers.location;
2320
2320
  const statusCode = res.statusCode;
2321
- if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2321
+ if (location2 && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2322
2322
  if (++websocket._redirects > opts.maxRedirects) {
2323
2323
  abortHandshake(websocket, req, "Maximum redirects exceeded");
2324
2324
  return;
@@ -2326,9 +2326,9 @@ var require_websocket = __commonJS((exports, module) => {
2326
2326
  req.abort();
2327
2327
  let addr;
2328
2328
  try {
2329
- addr = new URL2(location, address);
2329
+ addr = new URL2(location2, address);
2330
2330
  } catch (e) {
2331
- const err = new SyntaxError(`Invalid URL: ${location}`);
2331
+ const err = new SyntaxError(`Invalid URL: ${location2}`);
2332
2332
  emitErrorAndClose(websocket, err);
2333
2333
  return;
2334
2334
  }
@@ -3019,18 +3019,14 @@ class CustomError extends Error {
3019
3019
  code;
3020
3020
  data;
3021
3021
  message;
3022
- tips;
3023
- constructor(code, message, tips) {
3024
- super(message || String(code));
3025
- this.name = "CustomError";
3026
- if (typeof code === "number") {
3027
- this.code = code;
3028
- this.message = message;
3029
- } else {
3030
- this.code = 500;
3031
- this.message = code;
3032
- }
3033
- this.tips = tips;
3022
+ constructor(code, opts) {
3023
+ let message = opts?.message || String(code);
3024
+ const cause = opts?.cause;
3025
+ super(message, { cause });
3026
+ this.name = "RouterError";
3027
+ let codeNum = opts?.code || (typeof code === "number" ? code : undefined);
3028
+ this.code = codeNum ?? 500;
3029
+ this.message = message;
3034
3030
  Error.captureStackTrace(this, this.constructor);
3035
3031
  }
3036
3032
  static fromCode(code) {
@@ -3045,8 +3041,7 @@ class CustomError extends Error {
3045
3041
  return {
3046
3042
  code: e?.code,
3047
3043
  data: e?.data,
3048
- message: e?.message,
3049
- tips: e?.tips
3044
+ message: e?.message
3050
3045
  };
3051
3046
  }
3052
3047
  static isError(error) {
@@ -3060,8 +3055,7 @@ class CustomError extends Error {
3060
3055
  return {
3061
3056
  code: e2?.code,
3062
3057
  data: e2?.data,
3063
- message: e2?.message,
3064
- tips: e2?.tips
3058
+ message: e2?.message
3065
3059
  };
3066
3060
  }
3067
3061
  }
@@ -18321,7 +18315,8 @@ class App extends QueryRouter {
18321
18315
  }
18322
18316
  }
18323
18317
 
18324
- // node_modules/.pnpm/@kevisual+context@0.0.6/node_modules/@kevisual/context/dist/app.js
18318
+ // node_modules/.pnpm/@kevisual+context@0.0.8/node_modules/@kevisual/context/dist/app.js
18319
+ var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
18325
18320
  function getDefaultExportFromCjs(x) {
18326
18321
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
18327
18322
  }
@@ -18785,7 +18780,7 @@ var useEnv = (initEnv, initKey = "config", isOverwrite) => {
18785
18780
  }
18786
18781
  return gt[initKey];
18787
18782
  };
18788
- var useEnvKey = (key, init, initKey = "config") => {
18783
+ var useEnvKey = (key, init, initKey = "config", opts = {}) => {
18789
18784
  const _env = useEnv({}, initKey);
18790
18785
  if (key && typeof _env[key] !== "undefined") {
18791
18786
  return _env[key];
@@ -18811,12 +18806,13 @@ var useEnvKey = (key, init, initKey = "config") => {
18811
18806
  const voidFn = async () => {
18812
18807
  return _env[key];
18813
18808
  };
18809
+ const timeout = opts.timeout || 5 * 60 * 1000;
18814
18810
  const checkFn = async () => {
18815
18811
  const loadRes = await baseLoad.load(voidFn, {
18816
18812
  key,
18817
18813
  isReRun: true,
18818
18814
  checkSuccess: () => _env[key],
18819
- timeout: 5 * 60 * 1000,
18815
+ timeout,
18820
18816
  interval: 1000
18821
18817
  });
18822
18818
  if (loadRes.code !== 200) {
@@ -18832,27 +18828,28 @@ var useEnvKey = (key, init, initKey = "config") => {
18832
18828
  };
18833
18829
  var useEnvKeyNew = (key, initKey = "config", opts) => {
18834
18830
  const _env = useEnv({}, initKey);
18831
+ const timeout = opts?.timeout;
18835
18832
  if (key) {
18836
18833
  delete _env[key];
18837
18834
  }
18838
18835
  if (opts?.getNew && opts.init) {
18839
- return useEnvKey(key, opts.init, initKey);
18836
+ return useEnvKey(key, opts.init, initKey, { timeout });
18840
18837
  } else if (opts?.getNew) {
18841
- return useEnvKey(key, null, initKey);
18838
+ return useEnvKey(key, null, initKey, { timeout });
18842
18839
  }
18843
18840
  };
18844
- var useContextKey = (key, init, isNew) => {
18845
- if (isNew) {
18846
- return useEnvKeyNew(key, "context", { getNew: true, init });
18841
+ var useContextKey = (key, init, opts) => {
18842
+ if (opts?.isNew) {
18843
+ return useEnvKeyNew(key, "context", { getNew: true, init, ...opts });
18847
18844
  }
18848
- return useEnvKey(key, init, "context");
18845
+ return useEnvKey(key, init, "context", opts);
18849
18846
  };
18850
18847
  var use = useContextKey;
18851
- var useConfigKey = (key, init, isNew) => {
18852
- if (isNew) {
18853
- return useEnvKeyNew(key, "config", { getNew: true, init });
18848
+ var useConfigKey = (key, init, opts) => {
18849
+ if (opts?.isNew) {
18850
+ return useEnvKeyNew(key, "config", { getNew: true, init, ...opts });
18854
18851
  }
18855
- return useEnvKey(key, init, "config");
18852
+ return useEnvKey(key, init, "config", opts);
18856
18853
  };
18857
18854
 
18858
18855
  class InitEnv {
@@ -19522,7 +19519,7 @@ app
19522
19519
  10. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
19523
19520
  `;
19524
19521
  // package.json
19525
- var version2 = "0.0.80";
19522
+ var version2 = "0.0.81";
19526
19523
 
19527
19524
  // agent/routes/route-create.ts
19528
19525
  app.route({
package/dist/opencode.js CHANGED
@@ -203,7 +203,8 @@ var require_eventemitter3 = __commonJS((exports, module) => {
203
203
  }
204
204
  });
205
205
 
206
- // node_modules/.pnpm/@kevisual+context@0.0.6/node_modules/@kevisual/context/dist/app.js
206
+ // node_modules/.pnpm/@kevisual+context@0.0.8/node_modules/@kevisual/context/dist/app.js
207
+ var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
207
208
  function getDefaultExportFromCjs(x) {
208
209
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
209
210
  }
@@ -667,7 +668,7 @@ var useEnv = (initEnv, initKey = "config", isOverwrite) => {
667
668
  }
668
669
  return gt[initKey];
669
670
  };
670
- var useEnvKey = (key, init, initKey = "config") => {
671
+ var useEnvKey = (key, init, initKey = "config", opts = {}) => {
671
672
  const _env = useEnv({}, initKey);
672
673
  if (key && typeof _env[key] !== "undefined") {
673
674
  return _env[key];
@@ -693,12 +694,13 @@ var useEnvKey = (key, init, initKey = "config") => {
693
694
  const voidFn = async () => {
694
695
  return _env[key];
695
696
  };
697
+ const timeout = opts.timeout || 5 * 60 * 1000;
696
698
  const checkFn = async () => {
697
699
  const loadRes = await baseLoad.load(voidFn, {
698
700
  key,
699
701
  isReRun: true,
700
702
  checkSuccess: () => _env[key],
701
- timeout: 5 * 60 * 1000,
703
+ timeout,
702
704
  interval: 1000
703
705
  });
704
706
  if (loadRes.code !== 200) {
@@ -714,27 +716,28 @@ var useEnvKey = (key, init, initKey = "config") => {
714
716
  };
715
717
  var useEnvKeyNew = (key, initKey = "config", opts) => {
716
718
  const _env = useEnv({}, initKey);
719
+ const timeout = opts?.timeout;
717
720
  if (key) {
718
721
  delete _env[key];
719
722
  }
720
723
  if (opts?.getNew && opts.init) {
721
- return useEnvKey(key, opts.init, initKey);
724
+ return useEnvKey(key, opts.init, initKey, { timeout });
722
725
  } else if (opts?.getNew) {
723
- return useEnvKey(key, null, initKey);
726
+ return useEnvKey(key, null, initKey, { timeout });
724
727
  }
725
728
  };
726
- var useContextKey = (key, init, isNew) => {
727
- if (isNew) {
728
- return useEnvKeyNew(key, "context", { getNew: true, init });
729
+ var useContextKey = (key, init, opts) => {
730
+ if (opts?.isNew) {
731
+ return useEnvKeyNew(key, "context", { getNew: true, init, ...opts });
729
732
  }
730
- return useEnvKey(key, init, "context");
733
+ return useEnvKey(key, init, "context", opts);
731
734
  };
732
735
  var use = useContextKey;
733
- var useConfigKey = (key, init, isNew) => {
734
- if (isNew) {
735
- return useEnvKeyNew(key, "config", { getNew: true, init });
736
+ var useConfigKey = (key, init, opts) => {
737
+ if (opts?.isNew) {
738
+ return useEnvKeyNew(key, "config", { getNew: true, init, ...opts });
736
739
  }
737
- return useEnvKey(key, init, "config");
740
+ return useEnvKey(key, init, "config", opts);
738
741
  };
739
742
 
740
743
  class InitEnv {
@@ -498,20 +498,23 @@ declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
498
498
 
499
499
  type Schema = z.ZodType<any, any, any>;
500
500
 
501
+ type CustomErrorOptions = {
502
+ cause?: Error | string;
503
+ code?: number;
504
+ message?: string;
505
+ };
501
506
  /** 自定义错误 */
502
507
  declare class CustomError extends Error {
503
508
  code?: number;
504
509
  data?: any;
505
510
  message: string;
506
- tips?: string;
507
- constructor(code?: number | string, message?: string, tips?: string);
511
+ constructor(code?: number | string, opts?: CustomErrorOptions);
508
512
  static fromCode(code?: number): CustomError;
509
513
  static fromErrorData(code?: number, data?: any): CustomError;
510
514
  static parseError(e: CustomError): {
511
515
  code: number;
512
516
  data: any;
513
517
  message: string;
514
- tips: string;
515
518
  };
516
519
  /**
517
520
  * 判断 throw 的错误是否不是当前这个错误
@@ -523,7 +526,6 @@ declare class CustomError extends Error {
523
526
  code: number;
524
527
  data: any;
525
528
  message: string;
526
- tips: string;
527
529
  };
528
530
  }
529
531
 
@@ -208,18 +208,14 @@ class CustomError extends Error {
208
208
  code;
209
209
  data;
210
210
  message;
211
- tips;
212
- constructor(code, message, tips) {
213
- super(message || String(code));
214
- this.name = "CustomError";
215
- if (typeof code === "number") {
216
- this.code = code;
217
- this.message = message;
218
- } else {
219
- this.code = 500;
220
- this.message = code;
221
- }
222
- this.tips = tips;
211
+ constructor(code, opts) {
212
+ let message = opts?.message || String(code);
213
+ const cause = opts?.cause;
214
+ super(message, { cause });
215
+ this.name = "RouterError";
216
+ let codeNum = opts?.code || (typeof code === "number" ? code : undefined);
217
+ this.code = codeNum ?? 500;
218
+ this.message = message;
223
219
  Error.captureStackTrace(this, this.constructor);
224
220
  }
225
221
  static fromCode(code) {
@@ -234,8 +230,7 @@ class CustomError extends Error {
234
230
  return {
235
231
  code: e?.code,
236
232
  data: e?.data,
237
- message: e?.message,
238
- tips: e?.tips
233
+ message: e?.message
239
234
  };
240
235
  }
241
236
  static isError(error) {
@@ -249,8 +244,7 @@ class CustomError extends Error {
249
244
  return {
250
245
  code: e2?.code,
251
246
  data: e2?.data,
252
- message: e2?.message,
253
- tips: e2?.tips
247
+ message: e2?.message
254
248
  };
255
249
  }
256
250
  }
package/dist/router.d.ts CHANGED
@@ -504,20 +504,23 @@ declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
504
504
 
505
505
  type Schema = z.ZodType<any, any, any>;
506
506
 
507
+ type CustomErrorOptions = {
508
+ cause?: Error | string;
509
+ code?: number;
510
+ message?: string;
511
+ };
507
512
  /** 自定义错误 */
508
513
  declare class CustomError extends Error {
509
514
  code?: number;
510
515
  data?: any;
511
516
  message: string;
512
- tips?: string;
513
- constructor(code?: number | string, message?: string, tips?: string);
517
+ constructor(code?: number | string, opts?: CustomErrorOptions);
514
518
  static fromCode(code?: number): CustomError;
515
519
  static fromErrorData(code?: number, data?: any): CustomError;
516
520
  static parseError(e: CustomError): {
517
521
  code: number;
518
522
  data: any;
519
523
  message: string;
520
- tips: string;
521
524
  };
522
525
  /**
523
526
  * 判断 throw 的错误是否不是当前这个错误
@@ -529,7 +532,6 @@ declare class CustomError extends Error {
529
532
  code: number;
530
533
  data: any;
531
534
  message: string;
532
- tips: string;
533
535
  };
534
536
  }
535
537
 
package/dist/router.js CHANGED
@@ -3019,18 +3019,14 @@ class CustomError extends Error {
3019
3019
  code;
3020
3020
  data;
3021
3021
  message;
3022
- tips;
3023
- constructor(code, message, tips) {
3024
- super(message || String(code));
3025
- this.name = "CustomError";
3026
- if (typeof code === "number") {
3027
- this.code = code;
3028
- this.message = message;
3029
- } else {
3030
- this.code = 500;
3031
- this.message = code;
3032
- }
3033
- this.tips = tips;
3022
+ constructor(code, opts) {
3023
+ let message = opts?.message || String(code);
3024
+ const cause = opts?.cause;
3025
+ super(message, { cause });
3026
+ this.name = "RouterError";
3027
+ let codeNum = opts?.code || (typeof code === "number" ? code : undefined);
3028
+ this.code = codeNum ?? 500;
3029
+ this.message = message;
3034
3030
  Error.captureStackTrace(this, this.constructor);
3035
3031
  }
3036
3032
  static fromCode(code) {
@@ -3045,8 +3041,7 @@ class CustomError extends Error {
3045
3041
  return {
3046
3042
  code: e?.code,
3047
3043
  data: e?.data,
3048
- message: e?.message,
3049
- tips: e?.tips
3044
+ message: e?.message
3050
3045
  };
3051
3046
  }
3052
3047
  static isError(error) {
@@ -3060,8 +3055,7 @@ class CustomError extends Error {
3060
3055
  return {
3061
3056
  code: e2?.code,
3062
3057
  data: e2?.data,
3063
- message: e2?.message,
3064
- tips: e2?.tips
3058
+ message: e2?.message
3065
3059
  };
3066
3060
  }
3067
3061
  }
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.80",
4
+ "version": "0.0.81",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
@@ -23,21 +23,21 @@
23
23
  "license": "MIT",
24
24
  "devDependencies": {
25
25
  "@kevisual/code-builder": "^0.0.6",
26
- "@kevisual/context": "^0.0.6",
26
+ "@kevisual/context": "^0.0.8",
27
27
  "@kevisual/dts": "^0.0.4",
28
28
  "@kevisual/js-filter": "^0.0.5",
29
29
  "@kevisual/local-proxy": "^0.0.8",
30
- "@kevisual/query": "^0.0.47",
30
+ "@kevisual/query": "^0.0.49",
31
31
  "@kevisual/use-config": "^1.0.30",
32
- "@opencode-ai/plugin": "^1.2.6",
32
+ "@opencode-ai/plugin": "^1.2.10",
33
33
  "@types/bun": "^1.3.9",
34
- "@types/node": "^25.2.3",
34
+ "@types/node": "^25.3.0",
35
35
  "@types/send": "^1.2.1",
36
36
  "@types/ws": "^8.18.1",
37
37
  "@types/xml2js": "^0.4.14",
38
38
  "eventemitter3": "^5.0.4",
39
39
  "fast-glob": "^3.3.3",
40
- "hono": "^4.11.9",
40
+ "hono": "^4.12.0",
41
41
  "nanoid": "^5.1.6",
42
42
  "path-to-regexp": "^8.3.0",
43
43
  "send": "^1.2.1",
@@ -1,20 +1,21 @@
1
+ type CustomErrorOptions = {
2
+ cause?: Error | string;
3
+ code?: number;
4
+ message?: string;
5
+ }
1
6
  /** 自定义错误 */
2
7
  export class CustomError extends Error {
3
8
  code?: number;
4
9
  data?: any;
5
10
  message: string;
6
- tips?: string;
7
- constructor(code?: number | string, message?: string, tips?: string) {
8
- super(message || String(code));
9
- this.name = 'CustomError';
10
- if (typeof code === 'number') {
11
- this.code = code;
12
- this.message = message!;
13
- } else {
14
- this.code = 500;
15
- this.message = code!;
16
- }
17
- this.tips = tips;
11
+ constructor(code?: number | string, opts?: CustomErrorOptions) {
12
+ let message = opts?.message || String(code);
13
+ const cause = opts?.cause;
14
+ super(message, { cause });
15
+ this.name = 'RouterError';
16
+ let codeNum = opts?.code || (typeof code === 'number' ? code : undefined);
17
+ this.code = codeNum ?? 500;
18
+ this.message = message!;
18
19
  // 这一步可不写,默认会保存堆栈追踪信息到自定义错误构造函数之前,
19
20
  // 而如果写成 `Error.captureStackTrace(this)` 则自定义错误的构造函数也会被保存到堆栈追踪信息
20
21
  Error.captureStackTrace(this, this.constructor);
@@ -31,8 +32,7 @@ export class CustomError extends Error {
31
32
  return {
32
33
  code: e?.code,
33
34
  data: e?.data,
34
- message: e?.message,
35
- tips: e?.tips,
35
+ message: e?.message
36
36
  };
37
37
  }
38
38
  /**
@@ -52,7 +52,6 @@ export class CustomError extends Error {
52
52
  code: e?.code,
53
53
  data: e?.data,
54
54
  message: e?.message,
55
- tips: e?.tips,
56
55
  };
57
56
  }
58
57
  }