@kevisual/router 0.0.21-beta → 0.0.21

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.
@@ -12,8 +12,8 @@ type BaseRule = {
12
12
  };
13
13
  type RuleString = {
14
14
  type: 'string';
15
- minLength?: number;
16
- maxLength?: number;
15
+ min?: number;
16
+ max?: number;
17
17
  regex?: string;
18
18
  } & BaseRule;
19
19
  type RuleNumber = {
@@ -27,8 +27,6 @@ type RuleBoolean = {
27
27
  type RuleArray = {
28
28
  type: 'array';
29
29
  items: Rule;
30
- minItems?: number;
31
- maxItems?: number;
32
30
  } & BaseRule;
33
31
  type RuleObject = {
34
32
  type: 'object';
@@ -4499,10 +4499,10 @@ const schemaFormRule = (rule) => {
4499
4499
  switch (rule.type) {
4500
4500
  case 'string':
4501
4501
  let stringSchema = z.string();
4502
- if (rule.minLength)
4503
- stringSchema = stringSchema.min(rule.minLength, `String must be at least ${rule.minLength} characters long.`);
4504
- if (rule.maxLength)
4505
- stringSchema = stringSchema.max(rule.maxLength, `String must not exceed ${rule.maxLength} characters.`);
4502
+ if (rule.min)
4503
+ stringSchema = stringSchema.min(rule.min, `String must be at least ${rule.min} characters long.`);
4504
+ if (rule.max)
4505
+ stringSchema = stringSchema.max(rule.max, `String must not exceed ${rule.max} characters.`);
4506
4506
  if (rule.regex)
4507
4507
  stringSchema = stringSchema.regex(new RegExp(rule.regex), 'Invalid format');
4508
4508
  return stringSchema;
package/dist/router.d.ts CHANGED
@@ -5,6 +5,7 @@ import https from 'node:https';
5
5
  import http2 from 'node:http2';
6
6
  import * as cookie from 'cookie';
7
7
  import { WebSocketServer, WebSocket } from 'ws';
8
+ import { IncomingMessage as IncomingMessage$1, ServerResponse as ServerResponse$1 } from 'http';
8
9
  import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
9
10
  import { Query, DataOpts, Result } from '@kevisual/query/query';
10
11
 
@@ -15,8 +16,8 @@ type BaseRule = {
15
16
  };
16
17
  type RuleString = {
17
18
  type: 'string';
18
- minLength?: number;
19
- maxLength?: number;
19
+ min?: number;
20
+ max?: number;
20
21
  regex?: string;
21
22
  } & BaseRule;
22
23
  type RuleNumber = {
@@ -30,8 +31,6 @@ type RuleBoolean = {
30
31
  type RuleArray = {
31
32
  type: 'array';
32
33
  items: Rule;
33
- minItems?: number;
34
- maxItems?: number;
35
34
  } & BaseRule;
36
35
  type RuleObject = {
37
36
  type: 'object';
@@ -716,6 +715,10 @@ declare class App<T = {}, U = AppReqRes> {
716
715
  importRoutes(routes: any[]): void;
717
716
  importApp(app: App): void;
718
717
  throw(code?: number | string, message?: string, tips?: string): void;
718
+ static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<{
719
+ cookies: Record<string, string>;
720
+ token: string;
721
+ }>;
719
722
  }
720
723
 
721
724
  export { App, Connect, CustomError, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, Server, createSchema, define, handleServer, util };
package/dist/router.js CHANGED
@@ -4521,10 +4521,10 @@ const schemaFormRule = (rule) => {
4521
4521
  switch (rule.type) {
4522
4522
  case 'string':
4523
4523
  let stringSchema = z.string();
4524
- if (rule.minLength)
4525
- stringSchema = stringSchema.min(rule.minLength, `String must be at least ${rule.minLength} characters long.`);
4526
- if (rule.maxLength)
4527
- stringSchema = stringSchema.max(rule.maxLength, `String must not exceed ${rule.maxLength} characters.`);
4524
+ if (rule.min)
4525
+ stringSchema = stringSchema.min(rule.min, `String must be at least ${rule.min} characters long.`);
4526
+ if (rule.max)
4527
+ stringSchema = stringSchema.max(rule.max, `String must not exceed ${rule.max} characters.`);
4528
4528
  if (rule.regex)
4529
4529
  stringSchema = stringSchema.regex(new RegExp(rule.regex), 'Invalid format');
4530
4530
  return stringSchema;
@@ -12169,6 +12169,9 @@ class App {
12169
12169
  throw(...args) {
12170
12170
  throw new CustomError(...args);
12171
12171
  }
12172
+ static handleRequest(req, res) {
12173
+ return handleServer(req, res);
12174
+ }
12172
12175
  }
12173
12176
 
12174
12177
  export { App, Connect, CustomError, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, ZodType as Schema, Server, createSchema, define, handleServer, util };
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.21",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
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':