@kevisual/router 0.0.21-beta → 0.0.22

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/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.21-beta",
4
+ "version": "0.0.22",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
@@ -21,19 +21,19 @@
21
21
  "author": "abearxiong",
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@kevisual/query": "^0.0.18",
24
+ "@kevisual/query": "^0.0.25",
25
25
  "@rollup/plugin-alias": "^5.1.1",
26
26
  "@rollup/plugin-commonjs": "^28.0.3",
27
27
  "@rollup/plugin-node-resolve": "^16.0.1",
28
28
  "@rollup/plugin-typescript": "^12.1.2",
29
29
  "@types/lodash-es": "^4.17.12",
30
- "@types/node": "^22.15.18",
30
+ "@types/node": "^22.15.29",
31
31
  "@types/ws": "^8.18.1",
32
32
  "@types/xml2js": "^0.4.14",
33
33
  "cookie": "^1.0.2",
34
34
  "lodash-es": "^4.17.21",
35
35
  "nanoid": "^5.1.5",
36
- "rollup": "^4.40.2",
36
+ "rollup": "^4.41.1",
37
37
  "rollup-plugin-dts": "^6.2.1",
38
38
  "ts-loader": "^9.5.2",
39
39
  "ts-node": "^10.9.2",
@@ -41,7 +41,7 @@
41
41
  "typescript": "^5.8.3",
42
42
  "ws": "npm:@kevisual/ws",
43
43
  "xml2js": "^0.6.2",
44
- "zod": "^3.24.4"
44
+ "zod": "^3.25.51"
45
45
  },
46
46
  "repository": {
47
47
  "type": "git",
@@ -89,6 +89,10 @@
89
89
  "import": "./mod.ts",
90
90
  "require": "./mod.ts",
91
91
  "types": "./mod.d.ts"
92
+ },
93
+ "./src/*": {
94
+ "import": "./src/*",
95
+ "require": "./src/*"
92
96
  }
93
97
  }
94
98
  }
package/readme.md CHANGED
@@ -1,23 +1,15 @@
1
1
  # router
2
2
 
3
- ```
3
+ ```ts
4
4
  import { App } from '@kevisual/router';
5
5
 
6
6
  const app = new App();
7
7
  app.listen(4002);
8
8
 
9
- new app.Route('demo', '01')
10
- .define(async (ctx) => {
11
- ctx.body = '01';
12
- return ctx;
13
- })
14
- .addTo(app);
15
-
16
9
  app
17
10
  .route({path:'demo', key: '02})
18
11
  .define(async (ctx) => {
19
12
  ctx.body = '02';
20
- return ctx;
21
13
  })
22
14
  .addTo(app);
23
15
 
@@ -25,7 +17,6 @@ app
25
17
  .route('demo', '03')
26
18
  .define(async (ctx) => {
27
19
  ctx.body = '03';
28
- return ctx;
29
20
  })
30
21
  .addTo(app);
31
22
  ```
package/src/app.ts CHANGED
@@ -2,6 +2,8 @@ import { QueryRouter, Route, RouteContext, RouteOpts } from './route.ts';
2
2
  import { Server, ServerOpts, HandleCtx } from './server/server.ts';
3
3
  import { WsServer } from './server/ws-server.ts';
4
4
  import { CustomError } from './result/error.ts';
5
+ import { handleServer } from './server/handle-server.ts';
6
+ import { IncomingMessage, ServerResponse } from 'http';
5
7
 
6
8
  type RouterHandle = (msg: { path: string; [key: string]: any }) => { code: string; data?: any; message?: string; [key: string]: any };
7
9
  type AppOptions<T = {}> = {
@@ -100,6 +102,9 @@ export class App<T = {}, U = AppReqRes> {
100
102
  throw(...args: any[]) {
101
103
  throw new CustomError(...args);
102
104
  }
105
+ static handleRequest(req: IncomingMessage, res: ServerResponse) {
106
+ return handleServer(req, res);
107
+ }
103
108
  }
104
109
 
105
110
  export * from './browser.ts';
@@ -8,8 +8,8 @@ type BaseRule = {
8
8
 
9
9
  type RuleString = {
10
10
  type: 'string';
11
- minLength?: number;
12
- maxLength?: number;
11
+ min?: number;
12
+ max?: number;
13
13
  regex?: string;
14
14
  } & BaseRule;
15
15
 
@@ -26,8 +26,6 @@ type RuleBoolean = {
26
26
  type RuleArray = {
27
27
  type: 'array';
28
28
  items: Rule;
29
- minItems?: number;
30
- maxItems?: number;
31
29
  } & BaseRule;
32
30
 
33
31
  type RuleObject = {
@@ -45,8 +43,8 @@ export const schemaFormRule = (rule: Rule): z.ZodType<any, any, any> => {
45
43
  switch (rule.type) {
46
44
  case 'string':
47
45
  let stringSchema = z.string();
48
- if (rule.minLength) stringSchema = stringSchema.min(rule.minLength, `String must be at least ${rule.minLength} characters long.`);
49
- if (rule.maxLength) stringSchema = stringSchema.max(rule.maxLength, `String must not exceed ${rule.maxLength} characters.`);
46
+ if (rule.min) stringSchema = stringSchema.min(rule.min, `String must be at least ${rule.min} characters long.`);
47
+ if (rule.max) stringSchema = stringSchema.max(rule.max, `String must not exceed ${rule.max} characters.`);
50
48
  if (rule.regex) stringSchema = stringSchema.regex(new RegExp(rule.regex), 'Invalid format');
51
49
  return stringSchema;
52
50
  case 'number':