@kevisual/router 0.1.5 → 0.1.6
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 +35 -2
- package/dist/commander.d.ts +5 -0
- package/dist/opencode.d.ts +5 -0
- package/dist/router-browser.d.ts +5 -0
- package/dist/router-browser.js +34 -1
- package/dist/router-define.d.ts +5 -0
- package/dist/router.d.ts +5 -0
- package/dist/router.js +34 -1
- package/dist/ws.d.ts +5 -0
- package/package.json +1 -1
- package/src/route.ts +40 -1
package/dist/app.js
CHANGED
|
@@ -17656,7 +17656,7 @@ class QueryRouter {
|
|
|
17656
17656
|
console.error("=====debug====:", e);
|
|
17657
17657
|
console.error("=====debug====:[path:key]:", `${route.path}-${route.key}`);
|
|
17658
17658
|
}
|
|
17659
|
-
if (e instanceof CustomError) {
|
|
17659
|
+
if (e instanceof CustomError || e?.code) {
|
|
17660
17660
|
ctx.code = e.code;
|
|
17661
17661
|
ctx.message = e.message;
|
|
17662
17662
|
} else {
|
|
@@ -17919,6 +17919,39 @@ class QueryRouterServer extends QueryRouter {
|
|
|
17919
17919
|
const { path, key, id } = api2;
|
|
17920
17920
|
return this.run({ path, key, id, payload }, ctx);
|
|
17921
17921
|
}
|
|
17922
|
+
async createAuth(fun) {
|
|
17923
|
+
this.route({
|
|
17924
|
+
path: "auth",
|
|
17925
|
+
key: "auth",
|
|
17926
|
+
id: "auth",
|
|
17927
|
+
description: "token验证"
|
|
17928
|
+
}).define(async (ctx) => {
|
|
17929
|
+
if (fun) {
|
|
17930
|
+
await fun(ctx, "auth");
|
|
17931
|
+
}
|
|
17932
|
+
}).addTo(this, { overwrite: false });
|
|
17933
|
+
this.route({
|
|
17934
|
+
path: "auth-admin",
|
|
17935
|
+
key: "auth-admin",
|
|
17936
|
+
id: "auth-admin",
|
|
17937
|
+
description: "admin token验证",
|
|
17938
|
+
middleware: ["auth"]
|
|
17939
|
+
}).define(async (ctx) => {
|
|
17940
|
+
if (fun) {
|
|
17941
|
+
await fun(ctx, "auth-admin");
|
|
17942
|
+
}
|
|
17943
|
+
}).addTo(this, { overwrite: false });
|
|
17944
|
+
this.route({
|
|
17945
|
+
path: "auth-can",
|
|
17946
|
+
key: "auth-can",
|
|
17947
|
+
id: "auth-can",
|
|
17948
|
+
description: "权限验证"
|
|
17949
|
+
}).define(async (ctx) => {
|
|
17950
|
+
if (fun) {
|
|
17951
|
+
await fun(ctx, "auth-can");
|
|
17952
|
+
}
|
|
17953
|
+
}).addTo(this, { overwrite: false });
|
|
17954
|
+
}
|
|
17922
17955
|
}
|
|
17923
17956
|
|
|
17924
17957
|
// src/server/server.ts
|
|
@@ -20075,7 +20108,7 @@ app
|
|
|
20075
20108
|
10. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
|
|
20076
20109
|
`;
|
|
20077
20110
|
// package.json
|
|
20078
|
-
var version2 = "0.1.
|
|
20111
|
+
var version2 = "0.1.5";
|
|
20079
20112
|
|
|
20080
20113
|
// agent/routes/route-create.ts
|
|
20081
20114
|
app.route({
|
package/dist/commander.d.ts
CHANGED
|
@@ -452,6 +452,11 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
452
452
|
args?: any;
|
|
453
453
|
};
|
|
454
454
|
} = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<any>;
|
|
455
|
+
/**
|
|
456
|
+
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
457
|
+
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
458
|
+
*/
|
|
459
|
+
createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
|
|
455
460
|
}
|
|
456
461
|
/** JSON Schema 基本类型映射到 TypeScript 类型 */
|
|
457
462
|
type JsonSchemaTypeToTS<T> = T extends {
|
package/dist/opencode.d.ts
CHANGED
|
@@ -452,6 +452,11 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
452
452
|
args?: any;
|
|
453
453
|
};
|
|
454
454
|
} = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<any>;
|
|
455
|
+
/**
|
|
456
|
+
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
457
|
+
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
458
|
+
*/
|
|
459
|
+
createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
|
|
455
460
|
}
|
|
456
461
|
/** JSON Schema 基本类型映射到 TypeScript 类型 */
|
|
457
462
|
type JsonSchemaTypeToTS<T> = T extends {
|
package/dist/router-browser.d.ts
CHANGED
|
@@ -524,6 +524,11 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
524
524
|
args?: any;
|
|
525
525
|
};
|
|
526
526
|
} = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<any>;
|
|
527
|
+
/**
|
|
528
|
+
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
529
|
+
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
530
|
+
*/
|
|
531
|
+
createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
|
|
527
532
|
}
|
|
528
533
|
declare class Mini extends QueryRouterServer {
|
|
529
534
|
}
|
package/dist/router-browser.js
CHANGED
|
@@ -32920,7 +32920,7 @@ class QueryRouter {
|
|
|
32920
32920
|
console.error("=====debug====:", e);
|
|
32921
32921
|
console.error("=====debug====:[path:key]:", `${route.path}-${route.key}`);
|
|
32922
32922
|
}
|
|
32923
|
-
if (e instanceof CustomError) {
|
|
32923
|
+
if (e instanceof CustomError || e?.code) {
|
|
32924
32924
|
ctx.code = e.code;
|
|
32925
32925
|
ctx.message = e.message;
|
|
32926
32926
|
} else {
|
|
@@ -33183,6 +33183,39 @@ class QueryRouterServer extends QueryRouter {
|
|
|
33183
33183
|
const { path, key, id } = api2;
|
|
33184
33184
|
return this.run({ path, key, id, payload }, ctx);
|
|
33185
33185
|
}
|
|
33186
|
+
async createAuth(fun) {
|
|
33187
|
+
this.route({
|
|
33188
|
+
path: "auth",
|
|
33189
|
+
key: "auth",
|
|
33190
|
+
id: "auth",
|
|
33191
|
+
description: "token验证"
|
|
33192
|
+
}).define(async (ctx) => {
|
|
33193
|
+
if (fun) {
|
|
33194
|
+
await fun(ctx, "auth");
|
|
33195
|
+
}
|
|
33196
|
+
}).addTo(this, { overwrite: false });
|
|
33197
|
+
this.route({
|
|
33198
|
+
path: "auth-admin",
|
|
33199
|
+
key: "auth-admin",
|
|
33200
|
+
id: "auth-admin",
|
|
33201
|
+
description: "admin token验证",
|
|
33202
|
+
middleware: ["auth"]
|
|
33203
|
+
}).define(async (ctx) => {
|
|
33204
|
+
if (fun) {
|
|
33205
|
+
await fun(ctx, "auth-admin");
|
|
33206
|
+
}
|
|
33207
|
+
}).addTo(this, { overwrite: false });
|
|
33208
|
+
this.route({
|
|
33209
|
+
path: "auth-can",
|
|
33210
|
+
key: "auth-can",
|
|
33211
|
+
id: "auth-can",
|
|
33212
|
+
description: "权限验证"
|
|
33213
|
+
}).define(async (ctx) => {
|
|
33214
|
+
if (fun) {
|
|
33215
|
+
await fun(ctx, "auth-can");
|
|
33216
|
+
}
|
|
33217
|
+
}).addTo(this, { overwrite: false });
|
|
33218
|
+
}
|
|
33186
33219
|
}
|
|
33187
33220
|
|
|
33188
33221
|
class Mini extends QueryRouterServer {
|
package/dist/router-define.d.ts
CHANGED
|
@@ -449,6 +449,11 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
449
449
|
args?: any;
|
|
450
450
|
};
|
|
451
451
|
} = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<any>;
|
|
452
|
+
/**
|
|
453
|
+
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
454
|
+
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
455
|
+
*/
|
|
456
|
+
createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
|
|
452
457
|
}
|
|
453
458
|
/** JSON Schema 基本类型映射到 TypeScript 类型 */
|
|
454
459
|
type JsonSchemaTypeToTS<T> = T extends {
|
package/dist/router.d.ts
CHANGED
|
@@ -530,6 +530,11 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
530
530
|
args?: any;
|
|
531
531
|
};
|
|
532
532
|
} = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<any>;
|
|
533
|
+
/**
|
|
534
|
+
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
535
|
+
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
536
|
+
*/
|
|
537
|
+
createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
|
|
533
538
|
}
|
|
534
539
|
declare class Mini extends QueryRouterServer {
|
|
535
540
|
}
|
package/dist/router.js
CHANGED
|
@@ -17653,7 +17653,7 @@ class QueryRouter {
|
|
|
17653
17653
|
console.error("=====debug====:", e);
|
|
17654
17654
|
console.error("=====debug====:[path:key]:", `${route.path}-${route.key}`);
|
|
17655
17655
|
}
|
|
17656
|
-
if (e instanceof CustomError) {
|
|
17656
|
+
if (e instanceof CustomError || e?.code) {
|
|
17657
17657
|
ctx.code = e.code;
|
|
17658
17658
|
ctx.message = e.message;
|
|
17659
17659
|
} else {
|
|
@@ -17916,6 +17916,39 @@ class QueryRouterServer extends QueryRouter {
|
|
|
17916
17916
|
const { path, key, id } = api2;
|
|
17917
17917
|
return this.run({ path, key, id, payload }, ctx);
|
|
17918
17918
|
}
|
|
17919
|
+
async createAuth(fun) {
|
|
17920
|
+
this.route({
|
|
17921
|
+
path: "auth",
|
|
17922
|
+
key: "auth",
|
|
17923
|
+
id: "auth",
|
|
17924
|
+
description: "token验证"
|
|
17925
|
+
}).define(async (ctx) => {
|
|
17926
|
+
if (fun) {
|
|
17927
|
+
await fun(ctx, "auth");
|
|
17928
|
+
}
|
|
17929
|
+
}).addTo(this, { overwrite: false });
|
|
17930
|
+
this.route({
|
|
17931
|
+
path: "auth-admin",
|
|
17932
|
+
key: "auth-admin",
|
|
17933
|
+
id: "auth-admin",
|
|
17934
|
+
description: "admin token验证",
|
|
17935
|
+
middleware: ["auth"]
|
|
17936
|
+
}).define(async (ctx) => {
|
|
17937
|
+
if (fun) {
|
|
17938
|
+
await fun(ctx, "auth-admin");
|
|
17939
|
+
}
|
|
17940
|
+
}).addTo(this, { overwrite: false });
|
|
17941
|
+
this.route({
|
|
17942
|
+
path: "auth-can",
|
|
17943
|
+
key: "auth-can",
|
|
17944
|
+
id: "auth-can",
|
|
17945
|
+
description: "权限验证"
|
|
17946
|
+
}).define(async (ctx) => {
|
|
17947
|
+
if (fun) {
|
|
17948
|
+
await fun(ctx, "auth-can");
|
|
17949
|
+
}
|
|
17950
|
+
}).addTo(this, { overwrite: false });
|
|
17951
|
+
}
|
|
17919
17952
|
}
|
|
17920
17953
|
|
|
17921
17954
|
class Mini extends QueryRouterServer {
|
package/dist/ws.d.ts
CHANGED
|
@@ -499,6 +499,11 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
499
499
|
args?: any;
|
|
500
500
|
};
|
|
501
501
|
} = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<any>;
|
|
502
|
+
/**
|
|
503
|
+
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
504
|
+
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
505
|
+
*/
|
|
506
|
+
createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
|
|
502
507
|
}
|
|
503
508
|
/** JSON Schema 基本类型映射到 TypeScript 类型 */
|
|
504
509
|
type JsonSchemaTypeToTS<T> = T extends {
|
package/package.json
CHANGED
package/src/route.ts
CHANGED
|
@@ -434,7 +434,7 @@ export class QueryRouter<T extends SimpleObject = SimpleObject> implements throw
|
|
|
434
434
|
console.error('=====debug====:', e);
|
|
435
435
|
console.error('=====debug====:[path:key]:', `${route.path}-${route.key}`);
|
|
436
436
|
}
|
|
437
|
-
if (e instanceof CustomError) {
|
|
437
|
+
if (e instanceof CustomError || e?.code) {
|
|
438
438
|
ctx.code = e.code;
|
|
439
439
|
ctx.message = e.message;
|
|
440
440
|
} else {
|
|
@@ -782,6 +782,45 @@ export class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Qu
|
|
|
782
782
|
const { path, key, id } = api as any;
|
|
783
783
|
return this.run({ path, key, id, payload }, ctx);
|
|
784
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
787
|
+
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
788
|
+
*/
|
|
789
|
+
async createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any) {
|
|
790
|
+
this.route({
|
|
791
|
+
path: 'auth',
|
|
792
|
+
key: 'auth',
|
|
793
|
+
id: 'auth',
|
|
794
|
+
description: 'token验证',
|
|
795
|
+
}).define(async (ctx) => {
|
|
796
|
+
if (fun) {
|
|
797
|
+
await fun(ctx, 'auth');
|
|
798
|
+
}
|
|
799
|
+
}).addTo(this, { overwrite: false });
|
|
800
|
+
|
|
801
|
+
this.route({
|
|
802
|
+
path: 'auth-admin',
|
|
803
|
+
key: 'auth-admin',
|
|
804
|
+
id: 'auth-admin',
|
|
805
|
+
description: 'admin token验证',
|
|
806
|
+
middleware: ['auth']
|
|
807
|
+
}).define(async (ctx) => {
|
|
808
|
+
if (fun) {
|
|
809
|
+
await fun(ctx, 'auth-admin');
|
|
810
|
+
}
|
|
811
|
+
}).addTo(this, { overwrite: false });
|
|
812
|
+
|
|
813
|
+
this.route({
|
|
814
|
+
path: 'auth-can',
|
|
815
|
+
key: 'auth-can',
|
|
816
|
+
id: 'auth-can',
|
|
817
|
+
description: '权限验证'
|
|
818
|
+
}).define(async (ctx) => {
|
|
819
|
+
if (fun) {
|
|
820
|
+
await fun(ctx, 'auth-can');
|
|
821
|
+
}
|
|
822
|
+
}).addTo(this, { overwrite: false });
|
|
823
|
+
}
|
|
785
824
|
}
|
|
786
825
|
|
|
787
826
|
|