@kevisual/router 0.0.82 → 0.0.83
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 +14 -11
- package/dist/opencode.d.ts +10 -7
- package/dist/router-browser.d.ts +13 -7
- package/dist/router-browser.js +14 -11
- package/dist/router-define.d.ts +10 -7
- package/dist/router.d.ts +13 -7
- package/dist/router.js +14 -11
- package/dist/ws.d.ts +10 -7
- package/package.json +1 -1
- package/src/result/error.ts +22 -0
- package/src/route.ts +6 -20
package/dist/app.js
CHANGED
|
@@ -3051,6 +3051,18 @@ class CustomError extends Error {
|
|
|
3051
3051
|
static isError(error) {
|
|
3052
3052
|
return error instanceof CustomError || typeof error === "object" && error !== null && "code" in error;
|
|
3053
3053
|
}
|
|
3054
|
+
static throw(...args) {
|
|
3055
|
+
const [args0, args1] = args;
|
|
3056
|
+
if (args0 && typeof args0 === "object") {
|
|
3057
|
+
throw new CustomError(args0);
|
|
3058
|
+
}
|
|
3059
|
+
if (args1 && typeof args1 === "object") {
|
|
3060
|
+
throw new CustomError(args0, args1);
|
|
3061
|
+
} else if (args1) {
|
|
3062
|
+
throw new CustomError(args0, { message: args1 });
|
|
3063
|
+
}
|
|
3064
|
+
throw new CustomError(args0);
|
|
3065
|
+
}
|
|
3054
3066
|
parse(e) {
|
|
3055
3067
|
if (e) {
|
|
3056
3068
|
return CustomError.parseError(e);
|
|
@@ -17000,7 +17012,7 @@ class Route {
|
|
|
17000
17012
|
router.add(this, opts);
|
|
17001
17013
|
}
|
|
17002
17014
|
throw(...args) {
|
|
17003
|
-
throw
|
|
17015
|
+
CustomError.throw(...args);
|
|
17004
17016
|
}
|
|
17005
17017
|
}
|
|
17006
17018
|
var toJSONSchemaRoute = (route) => {
|
|
@@ -17298,16 +17310,7 @@ class QueryRouter {
|
|
|
17298
17310
|
this.importRoutes(router.routes);
|
|
17299
17311
|
}
|
|
17300
17312
|
throw(...args) {
|
|
17301
|
-
|
|
17302
|
-
if (args0 && typeof args0 === "object") {
|
|
17303
|
-
throw new CustomError(args0);
|
|
17304
|
-
}
|
|
17305
|
-
if (args1 && typeof args1 === "object") {
|
|
17306
|
-
throw new CustomError(args0, args1);
|
|
17307
|
-
} else if (args1) {
|
|
17308
|
-
throw new CustomError(args0, { message: args1 });
|
|
17309
|
-
}
|
|
17310
|
-
throw new CustomError(args0);
|
|
17313
|
+
CustomError.throw(...args);
|
|
17311
17314
|
}
|
|
17312
17315
|
hasRoute(path, key = "") {
|
|
17313
17316
|
return this.routes.find((r) => r.path === path && r.key === key);
|
package/dist/opencode.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ type CustomErrorOptions = {
|
|
|
10
10
|
code?: number;
|
|
11
11
|
message?: string;
|
|
12
12
|
};
|
|
13
|
+
interface throwError {
|
|
14
|
+
throw(code?: number | string, message?: string): void;
|
|
15
|
+
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
16
|
+
throw(opts?: CustomErrorOptions): void;
|
|
17
|
+
}
|
|
13
18
|
|
|
14
19
|
declare class MockProcess {
|
|
15
20
|
emitter?: EventEmitter;
|
|
@@ -98,7 +103,7 @@ type RouteContext<T = {
|
|
|
98
103
|
[key: string]: any;
|
|
99
104
|
}) => Promise<any>;
|
|
100
105
|
index?: number;
|
|
101
|
-
throw?:
|
|
106
|
+
throw?: throwError['throw'];
|
|
102
107
|
/** 是否需要序列化, 使用JSON.stringify和JSON.parse */
|
|
103
108
|
needSerialize?: boolean;
|
|
104
109
|
} & T;
|
|
@@ -141,7 +146,7 @@ declare const pickValue: readonly ["path", "key", "id", "description", "type", "
|
|
|
141
146
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
142
147
|
declare class Route<U = {
|
|
143
148
|
[key: string]: any;
|
|
144
|
-
}, T extends SimpleObject = SimpleObject> {
|
|
149
|
+
}, T extends SimpleObject = SimpleObject> implements throwError {
|
|
145
150
|
/**
|
|
146
151
|
* 一级路径
|
|
147
152
|
*/
|
|
@@ -181,7 +186,7 @@ declare class Route<U = {
|
|
|
181
186
|
add: (route: Route) => void;
|
|
182
187
|
[key: string]: any;
|
|
183
188
|
}, opts?: AddOpts): void;
|
|
184
|
-
throw(
|
|
189
|
+
throw(...args: any[]): void;
|
|
185
190
|
}
|
|
186
191
|
/**
|
|
187
192
|
* @parmas overwrite 是否覆盖已存在的route,默认true
|
|
@@ -189,7 +194,7 @@ declare class Route<U = {
|
|
|
189
194
|
type AddOpts = {
|
|
190
195
|
overwrite?: boolean;
|
|
191
196
|
};
|
|
192
|
-
declare class QueryRouter {
|
|
197
|
+
declare class QueryRouter implements throwError {
|
|
193
198
|
appId: string;
|
|
194
199
|
routes: Route[];
|
|
195
200
|
maxNextRoute: number;
|
|
@@ -320,9 +325,7 @@ declare class QueryRouter {
|
|
|
320
325
|
}, SimpleObject>[];
|
|
321
326
|
importRoutes(routes: Route[]): void;
|
|
322
327
|
importRouter(router: QueryRouter): void;
|
|
323
|
-
throw(
|
|
324
|
-
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
325
|
-
throw(opts?: CustomErrorOptions): void;
|
|
328
|
+
throw(...args: any[]): void;
|
|
326
329
|
hasRoute(path: string, key?: string): Route<{
|
|
327
330
|
[key: string]: any;
|
|
328
331
|
}, SimpleObject>;
|
package/dist/router-browser.d.ts
CHANGED
|
@@ -26,12 +26,20 @@ declare class CustomError extends Error {
|
|
|
26
26
|
* @returns
|
|
27
27
|
*/
|
|
28
28
|
static isError(error: unknown): error is CustomError;
|
|
29
|
+
static throw(code?: number | string, message?: string): void;
|
|
30
|
+
static throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
31
|
+
static throw(opts?: CustomErrorOptions): void;
|
|
29
32
|
parse(e?: CustomError): {
|
|
30
33
|
code: number;
|
|
31
34
|
data: any;
|
|
32
35
|
message: string;
|
|
33
36
|
};
|
|
34
37
|
}
|
|
38
|
+
interface throwError {
|
|
39
|
+
throw(code?: number | string, message?: string): void;
|
|
40
|
+
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
41
|
+
throw(opts?: CustomErrorOptions): void;
|
|
42
|
+
}
|
|
35
43
|
|
|
36
44
|
declare class MockProcess {
|
|
37
45
|
emitter?: EventEmitter;
|
|
@@ -136,7 +144,7 @@ type RouteContext<T = {
|
|
|
136
144
|
[key: string]: any;
|
|
137
145
|
}) => Promise<any>;
|
|
138
146
|
index?: number;
|
|
139
|
-
throw?:
|
|
147
|
+
throw?: throwError['throw'];
|
|
140
148
|
/** 是否需要序列化, 使用JSON.stringify和JSON.parse */
|
|
141
149
|
needSerialize?: boolean;
|
|
142
150
|
} & T;
|
|
@@ -193,7 +201,7 @@ declare const createSkill: <T = SimpleObject$1>(skill: Skill<T>) => Skill<T>;
|
|
|
193
201
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
194
202
|
declare class Route<U = {
|
|
195
203
|
[key: string]: any;
|
|
196
|
-
}, T extends SimpleObject$1 = SimpleObject$1> {
|
|
204
|
+
}, T extends SimpleObject$1 = SimpleObject$1> implements throwError {
|
|
197
205
|
/**
|
|
198
206
|
* 一级路径
|
|
199
207
|
*/
|
|
@@ -233,7 +241,7 @@ declare class Route<U = {
|
|
|
233
241
|
add: (route: Route) => void;
|
|
234
242
|
[key: string]: any;
|
|
235
243
|
}, opts?: AddOpts): void;
|
|
236
|
-
throw(
|
|
244
|
+
throw(...args: any[]): void;
|
|
237
245
|
}
|
|
238
246
|
declare const toJSONSchema: (args: any, opts?: {
|
|
239
247
|
mergeObject?: boolean;
|
|
@@ -258,7 +266,7 @@ declare const fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?:
|
|
|
258
266
|
type AddOpts = {
|
|
259
267
|
overwrite?: boolean;
|
|
260
268
|
};
|
|
261
|
-
declare class QueryRouter {
|
|
269
|
+
declare class QueryRouter implements throwError {
|
|
262
270
|
appId: string;
|
|
263
271
|
routes: Route[];
|
|
264
272
|
maxNextRoute: number;
|
|
@@ -389,9 +397,7 @@ declare class QueryRouter {
|
|
|
389
397
|
}, SimpleObject$1>[];
|
|
390
398
|
importRoutes(routes: Route[]): void;
|
|
391
399
|
importRouter(router: QueryRouter): void;
|
|
392
|
-
throw(
|
|
393
|
-
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
394
|
-
throw(opts?: CustomErrorOptions): void;
|
|
400
|
+
throw(...args: any[]): void;
|
|
395
401
|
hasRoute(path: string, key?: string): Route<{
|
|
396
402
|
[key: string]: any;
|
|
397
403
|
}, SimpleObject$1>;
|
package/dist/router-browser.js
CHANGED
|
@@ -240,6 +240,18 @@ class CustomError extends Error {
|
|
|
240
240
|
static isError(error) {
|
|
241
241
|
return error instanceof CustomError || typeof error === "object" && error !== null && "code" in error;
|
|
242
242
|
}
|
|
243
|
+
static throw(...args) {
|
|
244
|
+
const [args0, args1] = args;
|
|
245
|
+
if (args0 && typeof args0 === "object") {
|
|
246
|
+
throw new CustomError(args0);
|
|
247
|
+
}
|
|
248
|
+
if (args1 && typeof args1 === "object") {
|
|
249
|
+
throw new CustomError(args0, args1);
|
|
250
|
+
} else if (args1) {
|
|
251
|
+
throw new CustomError(args0, { message: args1 });
|
|
252
|
+
}
|
|
253
|
+
throw new CustomError(args0);
|
|
254
|
+
}
|
|
243
255
|
parse(e) {
|
|
244
256
|
if (e) {
|
|
245
257
|
return CustomError.parseError(e);
|
|
@@ -14164,7 +14176,7 @@ class Route {
|
|
|
14164
14176
|
router.add(this, opts);
|
|
14165
14177
|
}
|
|
14166
14178
|
throw(...args) {
|
|
14167
|
-
throw
|
|
14179
|
+
CustomError.throw(...args);
|
|
14168
14180
|
}
|
|
14169
14181
|
}
|
|
14170
14182
|
var toJSONSchemaRoute = (route) => {
|
|
@@ -14462,16 +14474,7 @@ class QueryRouter {
|
|
|
14462
14474
|
this.importRoutes(router.routes);
|
|
14463
14475
|
}
|
|
14464
14476
|
throw(...args) {
|
|
14465
|
-
|
|
14466
|
-
if (args0 && typeof args0 === "object") {
|
|
14467
|
-
throw new CustomError(args0);
|
|
14468
|
-
}
|
|
14469
|
-
if (args1 && typeof args1 === "object") {
|
|
14470
|
-
throw new CustomError(args0, args1);
|
|
14471
|
-
} else if (args1) {
|
|
14472
|
-
throw new CustomError(args0, { message: args1 });
|
|
14473
|
-
}
|
|
14474
|
-
throw new CustomError(args0);
|
|
14477
|
+
CustomError.throw(...args);
|
|
14475
14478
|
}
|
|
14476
14479
|
hasRoute(path, key = "") {
|
|
14477
14480
|
return this.routes.find((r) => r.path === path && r.key === key);
|
package/dist/router-define.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ type CustomErrorOptions = {
|
|
|
7
7
|
code?: number;
|
|
8
8
|
message?: string;
|
|
9
9
|
};
|
|
10
|
+
interface throwError {
|
|
11
|
+
throw(code?: number | string, message?: string): void;
|
|
12
|
+
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
13
|
+
throw(opts?: CustomErrorOptions): void;
|
|
14
|
+
}
|
|
10
15
|
|
|
11
16
|
declare class MockProcess {
|
|
12
17
|
emitter?: EventEmitter;
|
|
@@ -95,7 +100,7 @@ type RouteContext<T = {
|
|
|
95
100
|
[key: string]: any;
|
|
96
101
|
}) => Promise<any>;
|
|
97
102
|
index?: number;
|
|
98
|
-
throw?:
|
|
103
|
+
throw?: throwError['throw'];
|
|
99
104
|
/** 是否需要序列化, 使用JSON.stringify和JSON.parse */
|
|
100
105
|
needSerialize?: boolean;
|
|
101
106
|
} & T;
|
|
@@ -138,7 +143,7 @@ declare const pickValue: readonly ["path", "key", "id", "description", "type", "
|
|
|
138
143
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
139
144
|
declare class Route<U = {
|
|
140
145
|
[key: string]: any;
|
|
141
|
-
}, T extends SimpleObject$1 = SimpleObject$1> {
|
|
146
|
+
}, T extends SimpleObject$1 = SimpleObject$1> implements throwError {
|
|
142
147
|
/**
|
|
143
148
|
* 一级路径
|
|
144
149
|
*/
|
|
@@ -178,7 +183,7 @@ declare class Route<U = {
|
|
|
178
183
|
add: (route: Route) => void;
|
|
179
184
|
[key: string]: any;
|
|
180
185
|
}, opts?: AddOpts): void;
|
|
181
|
-
throw(
|
|
186
|
+
throw(...args: any[]): void;
|
|
182
187
|
}
|
|
183
188
|
/**
|
|
184
189
|
* @parmas overwrite 是否覆盖已存在的route,默认true
|
|
@@ -186,7 +191,7 @@ declare class Route<U = {
|
|
|
186
191
|
type AddOpts = {
|
|
187
192
|
overwrite?: boolean;
|
|
188
193
|
};
|
|
189
|
-
declare class QueryRouter {
|
|
194
|
+
declare class QueryRouter implements throwError {
|
|
190
195
|
appId: string;
|
|
191
196
|
routes: Route[];
|
|
192
197
|
maxNextRoute: number;
|
|
@@ -317,9 +322,7 @@ declare class QueryRouter {
|
|
|
317
322
|
}, SimpleObject$1>[];
|
|
318
323
|
importRoutes(routes: Route[]): void;
|
|
319
324
|
importRouter(router: QueryRouter): void;
|
|
320
|
-
throw(
|
|
321
|
-
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
322
|
-
throw(opts?: CustomErrorOptions): void;
|
|
325
|
+
throw(...args: any[]): void;
|
|
323
326
|
hasRoute(path: string, key?: string): Route<{
|
|
324
327
|
[key: string]: any;
|
|
325
328
|
}, SimpleObject$1>;
|
package/dist/router.d.ts
CHANGED
|
@@ -32,12 +32,20 @@ declare class CustomError extends Error {
|
|
|
32
32
|
* @returns
|
|
33
33
|
*/
|
|
34
34
|
static isError(error: unknown): error is CustomError;
|
|
35
|
+
static throw(code?: number | string, message?: string): void;
|
|
36
|
+
static throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
37
|
+
static throw(opts?: CustomErrorOptions): void;
|
|
35
38
|
parse(e?: CustomError): {
|
|
36
39
|
code: number;
|
|
37
40
|
data: any;
|
|
38
41
|
message: string;
|
|
39
42
|
};
|
|
40
43
|
}
|
|
44
|
+
interface throwError {
|
|
45
|
+
throw(code?: number | string, message?: string): void;
|
|
46
|
+
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
47
|
+
throw(opts?: CustomErrorOptions): void;
|
|
48
|
+
}
|
|
41
49
|
|
|
42
50
|
declare class MockProcess {
|
|
43
51
|
emitter?: EventEmitter;
|
|
@@ -142,7 +150,7 @@ type RouteContext<T = {
|
|
|
142
150
|
[key: string]: any;
|
|
143
151
|
}) => Promise<any>;
|
|
144
152
|
index?: number;
|
|
145
|
-
throw?:
|
|
153
|
+
throw?: throwError['throw'];
|
|
146
154
|
/** 是否需要序列化, 使用JSON.stringify和JSON.parse */
|
|
147
155
|
needSerialize?: boolean;
|
|
148
156
|
} & T;
|
|
@@ -199,7 +207,7 @@ declare const createSkill: <T = SimpleObject$1>(skill: Skill<T>) => Skill<T>;
|
|
|
199
207
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
200
208
|
declare class Route<U = {
|
|
201
209
|
[key: string]: any;
|
|
202
|
-
}, T extends SimpleObject$1 = SimpleObject$1> {
|
|
210
|
+
}, T extends SimpleObject$1 = SimpleObject$1> implements throwError {
|
|
203
211
|
/**
|
|
204
212
|
* 一级路径
|
|
205
213
|
*/
|
|
@@ -239,7 +247,7 @@ declare class Route<U = {
|
|
|
239
247
|
add: (route: Route) => void;
|
|
240
248
|
[key: string]: any;
|
|
241
249
|
}, opts?: AddOpts): void;
|
|
242
|
-
throw(
|
|
250
|
+
throw(...args: any[]): void;
|
|
243
251
|
}
|
|
244
252
|
declare const toJSONSchema: (args: any, opts?: {
|
|
245
253
|
mergeObject?: boolean;
|
|
@@ -264,7 +272,7 @@ declare const fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?:
|
|
|
264
272
|
type AddOpts = {
|
|
265
273
|
overwrite?: boolean;
|
|
266
274
|
};
|
|
267
|
-
declare class QueryRouter {
|
|
275
|
+
declare class QueryRouter implements throwError {
|
|
268
276
|
appId: string;
|
|
269
277
|
routes: Route[];
|
|
270
278
|
maxNextRoute: number;
|
|
@@ -395,9 +403,7 @@ declare class QueryRouter {
|
|
|
395
403
|
}, SimpleObject$1>[];
|
|
396
404
|
importRoutes(routes: Route[]): void;
|
|
397
405
|
importRouter(router: QueryRouter): void;
|
|
398
|
-
throw(
|
|
399
|
-
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
400
|
-
throw(opts?: CustomErrorOptions): void;
|
|
406
|
+
throw(...args: any[]): void;
|
|
401
407
|
hasRoute(path: string, key?: string): Route<{
|
|
402
408
|
[key: string]: any;
|
|
403
409
|
}, SimpleObject$1>;
|
package/dist/router.js
CHANGED
|
@@ -3051,6 +3051,18 @@ class CustomError extends Error {
|
|
|
3051
3051
|
static isError(error) {
|
|
3052
3052
|
return error instanceof CustomError || typeof error === "object" && error !== null && "code" in error;
|
|
3053
3053
|
}
|
|
3054
|
+
static throw(...args) {
|
|
3055
|
+
const [args0, args1] = args;
|
|
3056
|
+
if (args0 && typeof args0 === "object") {
|
|
3057
|
+
throw new CustomError(args0);
|
|
3058
|
+
}
|
|
3059
|
+
if (args1 && typeof args1 === "object") {
|
|
3060
|
+
throw new CustomError(args0, args1);
|
|
3061
|
+
} else if (args1) {
|
|
3062
|
+
throw new CustomError(args0, { message: args1 });
|
|
3063
|
+
}
|
|
3064
|
+
throw new CustomError(args0);
|
|
3065
|
+
}
|
|
3054
3066
|
parse(e) {
|
|
3055
3067
|
if (e) {
|
|
3056
3068
|
return CustomError.parseError(e);
|
|
@@ -16997,7 +17009,7 @@ class Route {
|
|
|
16997
17009
|
router.add(this, opts);
|
|
16998
17010
|
}
|
|
16999
17011
|
throw(...args) {
|
|
17000
|
-
throw
|
|
17012
|
+
CustomError.throw(...args);
|
|
17001
17013
|
}
|
|
17002
17014
|
}
|
|
17003
17015
|
var toJSONSchemaRoute = (route) => {
|
|
@@ -17295,16 +17307,7 @@ class QueryRouter {
|
|
|
17295
17307
|
this.importRoutes(router.routes);
|
|
17296
17308
|
}
|
|
17297
17309
|
throw(...args) {
|
|
17298
|
-
|
|
17299
|
-
if (args0 && typeof args0 === "object") {
|
|
17300
|
-
throw new CustomError(args0);
|
|
17301
|
-
}
|
|
17302
|
-
if (args1 && typeof args1 === "object") {
|
|
17303
|
-
throw new CustomError(args0, args1);
|
|
17304
|
-
} else if (args1) {
|
|
17305
|
-
throw new CustomError(args0, { message: args1 });
|
|
17306
|
-
}
|
|
17307
|
-
throw new CustomError(args0);
|
|
17310
|
+
CustomError.throw(...args);
|
|
17308
17311
|
}
|
|
17309
17312
|
hasRoute(path, key = "") {
|
|
17310
17313
|
return this.routes.find((r) => r.path === path && r.key === key);
|
package/dist/ws.d.ts
CHANGED
|
@@ -57,6 +57,11 @@ type CustomErrorOptions = {
|
|
|
57
57
|
code?: number;
|
|
58
58
|
message?: string;
|
|
59
59
|
};
|
|
60
|
+
interface throwError {
|
|
61
|
+
throw(code?: number | string, message?: string): void;
|
|
62
|
+
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
63
|
+
throw(opts?: CustomErrorOptions): void;
|
|
64
|
+
}
|
|
60
65
|
|
|
61
66
|
declare class MockProcess {
|
|
62
67
|
emitter?: EventEmitter;
|
|
@@ -145,7 +150,7 @@ type RouteContext<T = {
|
|
|
145
150
|
[key: string]: any;
|
|
146
151
|
}) => Promise<any>;
|
|
147
152
|
index?: number;
|
|
148
|
-
throw?:
|
|
153
|
+
throw?: throwError['throw'];
|
|
149
154
|
/** 是否需要序列化, 使用JSON.stringify和JSON.parse */
|
|
150
155
|
needSerialize?: boolean;
|
|
151
156
|
} & T;
|
|
@@ -188,7 +193,7 @@ declare const pickValue: readonly ["path", "key", "id", "description", "type", "
|
|
|
188
193
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
189
194
|
declare class Route<U = {
|
|
190
195
|
[key: string]: any;
|
|
191
|
-
}, T extends SimpleObject = SimpleObject> {
|
|
196
|
+
}, T extends SimpleObject = SimpleObject> implements throwError {
|
|
192
197
|
/**
|
|
193
198
|
* 一级路径
|
|
194
199
|
*/
|
|
@@ -228,7 +233,7 @@ declare class Route<U = {
|
|
|
228
233
|
add: (route: Route) => void;
|
|
229
234
|
[key: string]: any;
|
|
230
235
|
}, opts?: AddOpts): void;
|
|
231
|
-
throw(
|
|
236
|
+
throw(...args: any[]): void;
|
|
232
237
|
}
|
|
233
238
|
/**
|
|
234
239
|
* @parmas overwrite 是否覆盖已存在的route,默认true
|
|
@@ -236,7 +241,7 @@ declare class Route<U = {
|
|
|
236
241
|
type AddOpts = {
|
|
237
242
|
overwrite?: boolean;
|
|
238
243
|
};
|
|
239
|
-
declare class QueryRouter {
|
|
244
|
+
declare class QueryRouter implements throwError {
|
|
240
245
|
appId: string;
|
|
241
246
|
routes: Route[];
|
|
242
247
|
maxNextRoute: number;
|
|
@@ -367,9 +372,7 @@ declare class QueryRouter {
|
|
|
367
372
|
}, SimpleObject>[];
|
|
368
373
|
importRoutes(routes: Route[]): void;
|
|
369
374
|
importRouter(router: QueryRouter): void;
|
|
370
|
-
throw(
|
|
371
|
-
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
372
|
-
throw(opts?: CustomErrorOptions): void;
|
|
375
|
+
throw(...args: any[]): void;
|
|
373
376
|
hasRoute(path: string, key?: string): Route<{
|
|
374
377
|
[key: string]: any;
|
|
375
378
|
}, SimpleObject>;
|
package/package.json
CHANGED
package/src/result/error.ts
CHANGED
|
@@ -47,6 +47,22 @@ export class CustomError extends Error {
|
|
|
47
47
|
static isError(error: unknown): error is CustomError {
|
|
48
48
|
return error instanceof CustomError || (typeof error === 'object' && error !== null && 'code' in error);
|
|
49
49
|
}
|
|
50
|
+
static throw(code?: number | string, message?: string): void;
|
|
51
|
+
static throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
52
|
+
static throw(opts?: CustomErrorOptions): void;
|
|
53
|
+
static throw(...args: any[]) {
|
|
54
|
+
const [args0, args1] = args;
|
|
55
|
+
if (args0 && typeof args0 === 'object') {
|
|
56
|
+
throw new CustomError(args0);
|
|
57
|
+
}
|
|
58
|
+
if (args1 && typeof args1 === 'object') {
|
|
59
|
+
throw new CustomError(args0, args1);
|
|
60
|
+
} else if (args1) {
|
|
61
|
+
throw new CustomError(args0, { message: args1 });
|
|
62
|
+
}
|
|
63
|
+
// args1 不存在;
|
|
64
|
+
throw new CustomError(args0);
|
|
65
|
+
}
|
|
50
66
|
parse(e?: CustomError) {
|
|
51
67
|
if (e) {
|
|
52
68
|
return CustomError.parseError(e);
|
|
@@ -61,6 +77,12 @@ export class CustomError extends Error {
|
|
|
61
77
|
}
|
|
62
78
|
}
|
|
63
79
|
|
|
80
|
+
export interface throwError {
|
|
81
|
+
throw(code?: number | string, message?: string): void;
|
|
82
|
+
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
83
|
+
throw(opts?: CustomErrorOptions): void;
|
|
84
|
+
}
|
|
85
|
+
|
|
64
86
|
/*
|
|
65
87
|
try {
|
|
66
88
|
//
|
package/src/route.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomError, CustomErrorOptions } from './result/error.ts';
|
|
1
|
+
import { CustomError, throwError, CustomErrorOptions } from './result/error.ts';
|
|
2
2
|
import { pick } from './utils/pick.ts';
|
|
3
3
|
import { listenProcess, MockProcess } from './utils/listen-process.ts';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -56,7 +56,7 @@ export type RouteContext<T = { code?: number }, S = any> = {
|
|
|
56
56
|
/** 请求 route的返回结果,解析了body为data,就类同于 query.post获取的数据*/
|
|
57
57
|
run?: (message: { path: string; key?: string; payload?: any }, ctx?: RouteContext & { [key: string]: any }) => Promise<any>;
|
|
58
58
|
index?: number;
|
|
59
|
-
throw?:
|
|
59
|
+
throw?: throwError['throw'];
|
|
60
60
|
/** 是否需要序列化, 使用JSON.stringify和JSON.parse */
|
|
61
61
|
needSerialize?: boolean;
|
|
62
62
|
} & T;
|
|
@@ -123,7 +123,7 @@ export const createSkill = <T = SimpleObject>(skill: Skill<T>): Skill<T> => {
|
|
|
123
123
|
|
|
124
124
|
export type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
125
125
|
|
|
126
|
-
export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleObject> {
|
|
126
|
+
export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleObject> implements throwError {
|
|
127
127
|
/**
|
|
128
128
|
* 一级路径
|
|
129
129
|
*/
|
|
@@ -242,9 +242,8 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
|
|
|
242
242
|
addTo(router: QueryRouter | { add: (route: Route) => void;[key: string]: any }, opts?: AddOpts) {
|
|
243
243
|
router.add(this, opts);
|
|
244
244
|
}
|
|
245
|
-
throw(code?: number | string, message?: string, tips?: string): void;
|
|
246
245
|
throw(...args: any[]) {
|
|
247
|
-
throw
|
|
246
|
+
CustomError.throw(...args);
|
|
248
247
|
}
|
|
249
248
|
}
|
|
250
249
|
|
|
@@ -263,7 +262,7 @@ export const fromJSONSchema = schema.fromJSONSchema;
|
|
|
263
262
|
* @parmas overwrite 是否覆盖已存在的route,默认true
|
|
264
263
|
*/
|
|
265
264
|
export type AddOpts = { overwrite?: boolean };
|
|
266
|
-
export class QueryRouter {
|
|
265
|
+
export class QueryRouter implements throwError {
|
|
267
266
|
appId: string = '';
|
|
268
267
|
routes: Route[];
|
|
269
268
|
maxNextRoute = 40;
|
|
@@ -610,21 +609,8 @@ export class QueryRouter {
|
|
|
610
609
|
importRouter(router: QueryRouter) {
|
|
611
610
|
this.importRoutes(router.routes);
|
|
612
611
|
}
|
|
613
|
-
throw(code?: number | string, message?: string): void;
|
|
614
|
-
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
615
|
-
throw(opts?: CustomErrorOptions): void;
|
|
616
612
|
throw(...args: any[]) {
|
|
617
|
-
|
|
618
|
-
if (args0 && typeof args0 === 'object') {
|
|
619
|
-
throw new CustomError(args0);
|
|
620
|
-
}
|
|
621
|
-
if (args1 && typeof args1 === 'object') {
|
|
622
|
-
throw new CustomError(args0, args1);
|
|
623
|
-
} else if (args1) {
|
|
624
|
-
throw new CustomError(args0, { message: args1 });
|
|
625
|
-
}
|
|
626
|
-
// args1 不存在;
|
|
627
|
-
throw new CustomError(args0);
|
|
613
|
+
CustomError.throw(...args);
|
|
628
614
|
}
|
|
629
615
|
hasRoute(path: string, key: string = '') {
|
|
630
616
|
return this.routes.find((r) => r.path === path && r.key === key);
|