fix
This commit is contained in:
2
.cnb.yml
2
.cnb.yml
@@ -17,7 +17,7 @@ $:
|
|||||||
- vscode
|
- vscode
|
||||||
- docker
|
- docker
|
||||||
imports: !reference [.common_env, imports]
|
imports: !reference [.common_env, imports]
|
||||||
stages: !reference [.dev_tempalte, stages]
|
stages: !reference [.dev_template, stages]
|
||||||
|
|
||||||
.common_sync_to_gitea: &common_sync_to_gitea
|
.common_sync_to_gitea: &common_sync_to_gitea
|
||||||
- <<: *common_env
|
- <<: *common_env
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
"@kevisual/local-proxy": "^0.0.8",
|
"@kevisual/local-proxy": "^0.0.8",
|
||||||
"@kevisual/query": "^0.0.38",
|
"@kevisual/query": "^0.0.38",
|
||||||
"@kevisual/use-config": "^1.0.28",
|
"@kevisual/use-config": "^1.0.28",
|
||||||
"@opencode-ai/plugin": "^1.1.44",
|
"@opencode-ai/plugin": "^1.1.47",
|
||||||
"@rollup/plugin-alias": "^6.0.0",
|
"@rollup/plugin-alias": "^6.0.0",
|
||||||
"@rollup/plugin-commonjs": "29.0.0",
|
"@rollup/plugin-commonjs": "29.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||||
|
|||||||
18
pnpm-lock.yaml
generated
18
pnpm-lock.yaml
generated
@@ -31,8 +31,8 @@ importers:
|
|||||||
specifier: ^1.0.28
|
specifier: ^1.0.28
|
||||||
version: 1.0.28(dotenv@17.2.3)
|
version: 1.0.28(dotenv@17.2.3)
|
||||||
'@opencode-ai/plugin':
|
'@opencode-ai/plugin':
|
||||||
specifier: ^1.1.44
|
specifier: ^1.1.47
|
||||||
version: 1.1.44
|
version: 1.1.47
|
||||||
'@rollup/plugin-alias':
|
'@rollup/plugin-alias':
|
||||||
specifier: ^6.0.0
|
specifier: ^6.0.0
|
||||||
version: 6.0.0(rollup@4.57.1)
|
version: 6.0.0(rollup@4.57.1)
|
||||||
@@ -351,11 +351,11 @@ packages:
|
|||||||
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
|
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
|
||||||
engines: {node: '>= 8'}
|
engines: {node: '>= 8'}
|
||||||
|
|
||||||
'@opencode-ai/plugin@1.1.44':
|
'@opencode-ai/plugin@1.1.47':
|
||||||
resolution: {integrity: sha512-5w66Dq2Fugwgr2yrd8obvnlIEjBOuya82UgfR/3z3EzlyNDi2sitQSYbz7CcOtwd89eZ0n/tH/JX2KDGVuzxTQ==}
|
resolution: {integrity: sha512-gNMPz72altieDfLhUw3VAT1xbduKi3w3wZ57GLeS7qU9W474HdvdIiLBnt2Xq3U7Ko0/0tvK3nzCker6IIDqmQ==}
|
||||||
|
|
||||||
'@opencode-ai/sdk@1.1.44':
|
'@opencode-ai/sdk@1.1.47':
|
||||||
resolution: {integrity: sha512-coQgtSSCbY46/GY+M5zG0rChiLSJWSjPERRt5L1hbjvDWvErelVV0ILPbd1+3CwJLFTedBYgotby2TcO8U0IfQ==}
|
resolution: {integrity: sha512-s3PBHwk1sP6Zt/lJxIWSBWZ1TnrI1nFxSP97LCODUytouAQgbygZ1oDH7O2sGMBEuGdA8B1nNSPla0aRSN3IpA==}
|
||||||
|
|
||||||
'@rollup/plugin-alias@6.0.0':
|
'@rollup/plugin-alias@6.0.0':
|
||||||
resolution: {integrity: sha512-tPCzJOtS7uuVZd+xPhoy5W4vThe6KWXNmsFCNktaAh5RTqcLiSfT4huPQIXkgJ6YCOjJHvecOAzQxLFhPxKr+g==}
|
resolution: {integrity: sha512-tPCzJOtS7uuVZd+xPhoy5W4vThe6KWXNmsFCNktaAh5RTqcLiSfT4huPQIXkgJ6YCOjJHvecOAzQxLFhPxKr+g==}
|
||||||
@@ -1365,12 +1365,12 @@ snapshots:
|
|||||||
'@nodelib/fs.scandir': 2.1.5
|
'@nodelib/fs.scandir': 2.1.5
|
||||||
fastq: 1.20.1
|
fastq: 1.20.1
|
||||||
|
|
||||||
'@opencode-ai/plugin@1.1.44':
|
'@opencode-ai/plugin@1.1.47':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@opencode-ai/sdk': 1.1.44
|
'@opencode-ai/sdk': 1.1.47
|
||||||
zod: 4.1.8
|
zod: 4.1.8
|
||||||
|
|
||||||
'@opencode-ai/sdk@1.1.44': {}
|
'@opencode-ai/sdk@1.1.47': {}
|
||||||
|
|
||||||
'@rollup/plugin-alias@6.0.0(rollup@4.57.1)':
|
'@rollup/plugin-alias@6.0.0(rollup@4.57.1)':
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { QueryRouter, Route, RouteContext, RouteOpts } from './route.ts';
|
import { AddOpts, QueryRouter, Route, RouteContext, RouteOpts } from './route.ts';
|
||||||
import { ServerNode, ServerNodeOpts } from './server/server.ts';
|
import { ServerNode, ServerNodeOpts } from './server/server.ts';
|
||||||
import { HandleCtx } from './server/server-base.ts';
|
import { HandleCtx } from './server/server-base.ts';
|
||||||
import { ServerType } from './server/server-type.ts';
|
import { ServerType } from './server/server-type.ts';
|
||||||
@@ -64,8 +64,8 @@ export class App<U = {}> extends QueryRouter {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.server.listen(...args);
|
this.server.listen(...args);
|
||||||
}
|
}
|
||||||
addRoute(route: Route) {
|
addRoute(route: Route, opts?: AddOpts) {
|
||||||
super.add(route);
|
super.add(route, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
Route = Route;
|
Route = Route;
|
||||||
|
|||||||
27
src/route.ts
27
src/route.ts
@@ -231,8 +231,8 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
addTo(router: QueryRouter | { add: (route: Route) => void;[key: string]: any }) {
|
addTo(router: QueryRouter | { add: (route: Route) => void;[key: string]: any }, opts?: AddOpts) {
|
||||||
router.add(this);
|
router.add(this, opts);
|
||||||
}
|
}
|
||||||
setData(data: any) {
|
setData(data: any) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@@ -244,6 +244,10 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @parmas override 是否覆盖已存在的route,默认true
|
||||||
|
*/
|
||||||
|
export type AddOpts = { override?: boolean };
|
||||||
export class QueryRouter {
|
export class QueryRouter {
|
||||||
appId: string = '';
|
appId: string = '';
|
||||||
routes: Route[];
|
routes: Route[];
|
||||||
@@ -252,11 +256,20 @@ export class QueryRouter {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.routes = [];
|
this.routes = [];
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
add(route: Route) {
|
* add route
|
||||||
|
* @param route
|
||||||
|
* @param opts
|
||||||
|
*/
|
||||||
|
add(route: Route, opts?: AddOpts) {
|
||||||
|
const override = opts?.override ?? true;
|
||||||
const has = this.routes.findIndex((r) => r.path === route.path && r.key === route.key);
|
const has = this.routes.findIndex((r) => r.path === route.path && r.key === route.key);
|
||||||
|
|
||||||
if (has !== -1) {
|
if (has !== -1) {
|
||||||
// remove the old route
|
if (!override) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 如果存在,且override为true,则覆盖
|
||||||
this.routes.splice(has, 1);
|
this.routes.splice(has, 1);
|
||||||
}
|
}
|
||||||
this.routes.push(route);
|
this.routes.push(route);
|
||||||
@@ -664,8 +677,8 @@ export class QueryRouterServer extends QueryRouter {
|
|||||||
setHandle(wrapperFn?: HandleFn, ctx?: RouteContext) {
|
setHandle(wrapperFn?: HandleFn, ctx?: RouteContext) {
|
||||||
this.handle = this.getHandle(this, wrapperFn, ctx);
|
this.handle = this.getHandle(this, wrapperFn, ctx);
|
||||||
}
|
}
|
||||||
addRoute(route: Route) {
|
addRoute(route: Route, opts?: AddOpts) {
|
||||||
this.add(route);
|
this.add(route, opts);
|
||||||
}
|
}
|
||||||
Route = Route;
|
Route = Route;
|
||||||
route(opts: RouteOpts): Route<Required<RouteContext>>;
|
route(opts: RouteOpts): Route<Required<RouteContext>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user