@kevisual/router 0.0.71 → 0.0.72
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.d.ts +5 -0
- package/dist/app.js +19504 -0
- package/dist/opencode.d.ts +2 -2
- package/dist/opencode.js +13380 -14323
- package/dist/router-browser.d.ts +19 -20
- package/dist/router-browser.js +14046 -15099
- package/dist/router-define.d.ts +394 -3
- package/dist/router-define.js +126 -124
- package/dist/router-simple.js +665 -759
- package/dist/router.d.ts +19 -20
- package/dist/router.js +17822 -21151
- package/dist/ws.d.ts +2 -2
- package/dist/ws.js +2980 -150
- package/package.json +19 -54
- package/src/app.ts +2 -2
- package/src/browser.ts +1 -1
- package/src/index.ts +1 -1
- package/src/route.ts +10 -10
- package/src/router-define.ts +1 -1
- package/src/utils/random.ts +8 -0
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@kevisual/router",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.72",
|
|
5
5
|
"description": "",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/router.js",
|
|
8
8
|
"types": "./dist/router.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "npm run clean &&
|
|
11
|
-
"watch": "
|
|
10
|
+
"build": "npm run clean && bun bun.config.ts",
|
|
11
|
+
"watch": "bun bun.config.ts --watch",
|
|
12
12
|
"clean": "rm -rf dist"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
@@ -21,36 +21,27 @@
|
|
|
21
21
|
"keywords": [],
|
|
22
22
|
"author": "abearxiong",
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"packageManager": "pnpm@10.
|
|
24
|
+
"packageManager": "pnpm@10.29.3",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@kevisual/
|
|
27
|
-
"@kevisual/
|
|
26
|
+
"@kevisual/code-builder": "^0.0.6",
|
|
27
|
+
"@kevisual/context": "^0.0.6",
|
|
28
|
+
"@kevisual/dts": "^0.0.4",
|
|
28
29
|
"@kevisual/js-filter": "^0.0.5",
|
|
29
30
|
"@kevisual/local-proxy": "^0.0.8",
|
|
30
|
-
"@kevisual/query": "^0.0.
|
|
31
|
+
"@kevisual/query": "^0.0.40",
|
|
31
32
|
"@kevisual/use-config": "^1.0.30",
|
|
32
|
-
"@opencode-ai/plugin": "^1.
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
36
|
-
"@rollup/plugin-typescript": "^12.3.0",
|
|
37
|
-
"@types/bun": "^1.3.8",
|
|
38
|
-
"@types/node": "^25.2.0",
|
|
33
|
+
"@opencode-ai/plugin": "^1.2.6",
|
|
34
|
+
"@types/bun": "^1.3.9",
|
|
35
|
+
"@types/node": "^25.2.3",
|
|
39
36
|
"@types/send": "^1.2.1",
|
|
40
37
|
"@types/ws": "^8.18.1",
|
|
41
38
|
"@types/xml2js": "^0.4.14",
|
|
42
39
|
"eventemitter3": "^5.0.4",
|
|
43
40
|
"fast-glob": "^3.3.3",
|
|
44
|
-
"hono": "^4.11.
|
|
41
|
+
"hono": "^4.11.9",
|
|
45
42
|
"nanoid": "^5.1.6",
|
|
46
43
|
"path-to-regexp": "^8.3.0",
|
|
47
|
-
"rollup": "^4.57.1",
|
|
48
|
-
"rollup-plugin-dts": "^6.3.0",
|
|
49
44
|
"send": "^1.2.1",
|
|
50
|
-
"ts-loader": "^9.5.4",
|
|
51
|
-
"ts-node": "^10.9.2",
|
|
52
|
-
"tslib": "^2.8.1",
|
|
53
|
-
"tsx": "^4.21.0",
|
|
54
45
|
"typescript": "^5.9.3",
|
|
55
46
|
"ws": "npm:@kevisual/ws",
|
|
56
47
|
"xml2js": "^0.6.2",
|
|
@@ -67,41 +58,15 @@
|
|
|
67
58
|
"access": "public"
|
|
68
59
|
},
|
|
69
60
|
"exports": {
|
|
70
|
-
".":
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"types": "./dist/router.d.ts"
|
|
74
|
-
},
|
|
75
|
-
"./browser": {
|
|
76
|
-
"import": "./dist/router-browser.js",
|
|
77
|
-
"require": "./dist/router-browser.js",
|
|
78
|
-
"types": "./dist/router-browser.d.ts"
|
|
79
|
-
},
|
|
80
|
-
"./simple": {
|
|
81
|
-
"import": "./dist/router-simple.js",
|
|
82
|
-
"require": "./dist/router-simple.js",
|
|
83
|
-
"types": "./dist/router-simple.d.ts"
|
|
84
|
-
},
|
|
61
|
+
".": "./dist/router.js",
|
|
62
|
+
"./browser": "./dist/router-browser.js",
|
|
63
|
+
"./simple": "./dist/router-simple.js",
|
|
85
64
|
"./opencode": "./dist/opencode.js",
|
|
86
65
|
"./skill": "./dist/app.js",
|
|
87
|
-
"./define":
|
|
88
|
-
"import": "./dist/router-define.js",
|
|
89
|
-
"require": "./dist/router-define.js",
|
|
90
|
-
"types": "./dist/router-define.d.ts"
|
|
91
|
-
},
|
|
66
|
+
"./define": "./dist/router-define.js",
|
|
92
67
|
"./ws": "./dist/ws.js",
|
|
93
|
-
"./mod.ts":
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"types": "./mod.d.ts"
|
|
97
|
-
},
|
|
98
|
-
"./src/*": {
|
|
99
|
-
"import": "./src/*",
|
|
100
|
-
"require": "./src/*"
|
|
101
|
-
},
|
|
102
|
-
"./modules/*": {
|
|
103
|
-
"import": "./src/modules/*",
|
|
104
|
-
"require": "./src/modules/*"
|
|
105
|
-
}
|
|
68
|
+
"./mod.ts": "./mod.ts",
|
|
69
|
+
"./src/*": "./src/*",
|
|
70
|
+
"./modules/*": "./src/modules/*"
|
|
106
71
|
}
|
|
107
72
|
}
|
package/src/app.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { handleServer } from './server/handle-server.ts';
|
|
|
6
6
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
7
7
|
import { isBun } from './utils/is-engine.ts';
|
|
8
8
|
import { BunServer } from './server/server-bun.ts';
|
|
9
|
-
import {
|
|
9
|
+
import { randomId } from './utils/random.ts';
|
|
10
10
|
|
|
11
11
|
type RouterHandle = (msg: { path: string;[key: string]: any }) => { code: string; data?: any; message?: string;[key: string]: any };
|
|
12
12
|
type AppOptions<T = {}> = {
|
|
@@ -48,7 +48,7 @@ export class App<U = {}> extends QueryRouter {
|
|
|
48
48
|
if (opts?.appId) {
|
|
49
49
|
this.appId = opts.appId;
|
|
50
50
|
} else {
|
|
51
|
-
this.appId =
|
|
51
|
+
this.appId = randomId(16, 'rand-');
|
|
52
52
|
}
|
|
53
53
|
router.appId = this.appId;
|
|
54
54
|
}
|
package/src/browser.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { Rule, Schema, } from './validator/index.ts';
|
|
|
4
4
|
|
|
5
5
|
export { createSchema } from './validator/index.ts';
|
|
6
6
|
|
|
7
|
-
export type { RouteContext, RouteOpts, RouteMiddleware } from './route.ts';
|
|
7
|
+
export type { RouteContext, RouteOpts, RouteInfo, RouteMiddleware } from './route.ts';
|
|
8
8
|
|
|
9
9
|
export type { Run, Skill } from './route.ts';
|
|
10
10
|
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { Rule, Schema, } from './validator/index.ts';
|
|
|
4
4
|
|
|
5
5
|
export { createSchema } from './validator/index.ts';
|
|
6
6
|
|
|
7
|
-
export type { RouteContext, RouteOpts, RouteMiddleware } from './route.ts';
|
|
7
|
+
export type { RouteContext, RouteOpts, RouteInfo, RouteMiddleware } from './route.ts';
|
|
8
8
|
|
|
9
9
|
export type { Run, Skill } from './route.ts';
|
|
10
10
|
|
package/src/route.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { nanoid } from 'nanoid';
|
|
2
1
|
import { CustomError } from './result/error.ts';
|
|
3
2
|
import { pick } from './utils/pick.ts';
|
|
4
3
|
import { listenProcess, MockProcess } from './utils/listen-process.ts';
|
|
5
4
|
import { z } from 'zod';
|
|
6
|
-
|
|
5
|
+
import { randomId } from './utils/random.ts';
|
|
7
6
|
export type RouterContextT = { code?: number;[key: string]: any };
|
|
8
7
|
export type RouteContext<T = { code?: number }, S = any> = {
|
|
9
8
|
/**
|
|
@@ -114,6 +113,7 @@ export const createSkill = <T = SimpleObject>(skill: Skill<T>): Skill<T> => {
|
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
export type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
116
|
+
|
|
117
117
|
export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleObject> {
|
|
118
118
|
/**
|
|
119
119
|
* 一级路径
|
|
@@ -137,14 +137,14 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
|
|
|
137
137
|
isDebug?: boolean;
|
|
138
138
|
constructor(path: string = '', key: string = '', opts?: RouteOpts) {
|
|
139
139
|
if (!path) {
|
|
140
|
-
path =
|
|
140
|
+
path = randomId(8, 'rand-');
|
|
141
141
|
}
|
|
142
142
|
path = path.trim();
|
|
143
143
|
key = key.trim();
|
|
144
144
|
this.path = path;
|
|
145
145
|
this.key = key;
|
|
146
146
|
if (opts) {
|
|
147
|
-
this.id = opts.id ||
|
|
147
|
+
this.id = opts.id || randomId(12, 'rand-');
|
|
148
148
|
if (!opts.id && opts.idUsePath) {
|
|
149
149
|
const delimiter = opts.delimiter ?? '$#$';
|
|
150
150
|
this.id = path + delimiter + key;
|
|
@@ -159,7 +159,7 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
|
|
|
159
159
|
this.path = opts.path || path;
|
|
160
160
|
} else {
|
|
161
161
|
this.middleware = [];
|
|
162
|
-
this.id =
|
|
162
|
+
this.id = randomId(12, 'rand-');
|
|
163
163
|
}
|
|
164
164
|
this.isDebug = opts?.isDebug ?? false;
|
|
165
165
|
}
|
|
@@ -215,10 +215,10 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
|
|
|
215
215
|
return this;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
update(opts: DefineRouteOpts,
|
|
218
|
+
update(opts: DefineRouteOpts, onlyUpdateList?: string[]): this {
|
|
219
219
|
const keys = Object.keys(opts);
|
|
220
220
|
const defaultCheckList = ['path', 'key', 'run', 'nextRoute', 'description', 'metadata', 'middleware', 'type', 'isDebug'];
|
|
221
|
-
checkList =
|
|
221
|
+
const checkList = onlyUpdateList || defaultCheckList;
|
|
222
222
|
for (let item of keys) {
|
|
223
223
|
if (!checkList.includes(item)) {
|
|
224
224
|
continue;
|
|
@@ -316,8 +316,8 @@ export class QueryRouter {
|
|
|
316
316
|
* remove route by id
|
|
317
317
|
* @param uniqueId
|
|
318
318
|
*/
|
|
319
|
-
removeById(
|
|
320
|
-
this.routes = this.routes.filter((r) => r.id !==
|
|
319
|
+
removeById(uniqueId: string) {
|
|
320
|
+
this.routes = this.routes.filter((r) => r.id !== uniqueId);
|
|
321
321
|
}
|
|
322
322
|
/**
|
|
323
323
|
* 执行route
|
|
@@ -724,7 +724,7 @@ export class QueryRouterServer extends QueryRouter {
|
|
|
724
724
|
if (opts?.appId) {
|
|
725
725
|
this.appId = opts.appId;
|
|
726
726
|
} else {
|
|
727
|
-
this.appId =
|
|
727
|
+
this.appId = randomId(16);
|
|
728
728
|
}
|
|
729
729
|
}
|
|
730
730
|
setHandle(wrapperFn?: HandleFn, ctx?: RouteContext) {
|
package/src/router-define.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { QueryRouterServer, RouteOpts, Run, RouteMiddleware } from '
|
|
1
|
+
import type { QueryRouterServer, RouteOpts, Run, RouteMiddleware } from './route.ts';
|
|
2
2
|
import type { DataOpts, Query, Result } from '@kevisual/query/query';
|
|
3
3
|
// export type RouteObject<T extends readonly string[]> = {
|
|
4
4
|
// [K in T[number]]: RouteOpts;
|