@kevisual/router 0.0.3 → 0.0.4-alpha-7

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.3",
4
+ "version": "0.0.4-alpha-7",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -9,6 +9,7 @@
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "build": "npm run clean && rollup -c",
12
+ "build:app": "npm run build && rsync dist/*browser* ../deploy/dist",
12
13
  "watch": "rollup -c -w",
13
14
  "clean": "rm -rf dist"
14
15
  },
@@ -16,22 +17,23 @@
16
17
  "dist"
17
18
  ],
18
19
  "keywords": [],
19
- "author": "",
20
- "license": "ISC",
20
+ "author": "abearxiong",
21
+ "license": "MIT",
21
22
  "devDependencies": {
22
- "@rollup/plugin-commonjs": "^26.0.1",
23
- "@rollup/plugin-node-resolve": "^15.2.4",
24
- "@rollup/plugin-typescript": "^12.1.0",
23
+ "@rollup/plugin-commonjs": "^28.0.1",
24
+ "@rollup/plugin-node-resolve": "^15.3.0",
25
+ "@rollup/plugin-typescript": "^12.1.1",
25
26
  "@types/lodash-es": "^4.17.12",
26
- "@types/node": "^22.5.5",
27
- "@types/ws": "^8.5.12",
27
+ "@types/node": "^22.8.6",
28
+ "@types/ws": "^8.5.13",
28
29
  "lodash-es": "^4.17.21",
29
- "nanoid": "^5.0.7",
30
- "rollup": "^4.22.4",
30
+ "nanoid": "^5.0.8",
31
+ "rollup": "^4.24.3",
32
+ "rollup-plugin-dts": "^6.1.1",
31
33
  "ts-loader": "^9.5.1",
32
34
  "ts-node": "^10.9.2",
33
- "tslib": "^2.7.0",
34
- "typescript": "^5.6.2",
35
+ "tslib": "^2.8.1",
36
+ "typescript": "^5.6.3",
35
37
  "zod": "^3.23.8"
36
38
  },
37
39
  "repository": {
@@ -43,5 +45,15 @@
43
45
  },
44
46
  "publishConfig": {
45
47
  "access": "public"
48
+ },
49
+ "exports": {
50
+ ".": {
51
+ "import": "./dist/router.js",
52
+ "require": "./dist/router.js"
53
+ },
54
+ "./browser": {
55
+ "import": "./dist/router-browser.js",
56
+ "require": "./dist/router-browser.js"
57
+ }
46
58
  }
47
59
  }
package/dist/app.d.ts DELETED
@@ -1,60 +0,0 @@
1
- import { QueryRouter, Route, RouteContext, RouteOpts } from './route.ts';
2
- import { Server, Cors } from './server/server.ts';
3
- import { WsServer } from './server/ws-server.ts';
4
- type RouterHandle = (msg: {
5
- path: string;
6
- [key: string]: any;
7
- }) => {
8
- code: string;
9
- data?: any;
10
- message?: string;
11
- [key: string]: any;
12
- };
13
- type AppOptions<T = {}> = {
14
- router?: QueryRouter;
15
- server?: Server;
16
- /** handle msg 关联 */
17
- routerHandle?: RouterHandle;
18
- routerContext?: RouteContext<T>;
19
- serverOptions?: {
20
- path?: string;
21
- cors?: Cors;
22
- handle?: any;
23
- };
24
- io?: boolean;
25
- ioOpts?: {
26
- routerHandle?: RouterHandle;
27
- routerContext?: RouteContext<T>;
28
- path?: string;
29
- };
30
- };
31
- export declare class App<T = {}> {
32
- router: QueryRouter;
33
- server: Server;
34
- io: WsServer;
35
- constructor(opts?: AppOptions<T>);
36
- listen(port: number, hostname?: string, backlog?: number, listeningListener?: () => void): void;
37
- listen(port: number, hostname?: string, listeningListener?: () => void): void;
38
- listen(port: number, backlog?: number, listeningListener?: () => void): void;
39
- listen(port: number, listeningListener?: () => void): void;
40
- listen(path: string, backlog?: number, listeningListener?: () => void): void;
41
- listen(path: string, listeningListener?: () => void): void;
42
- listen(handle: any, backlog?: number, listeningListener?: () => void): void;
43
- listen(handle: any, listeningListener?: () => void): void;
44
- use(path: string, fn: (ctx: any) => any, opts?: RouteOpts): void;
45
- addRoute(route: Route): void;
46
- add: (route: Route) => void;
47
- Route: typeof Route;
48
- route(opts: RouteOpts): Route;
49
- route(path: string, key?: string): Route;
50
- route(path: string, opts?: RouteOpts): Route;
51
- route(path: string, key?: string, opts?: RouteOpts): Route;
52
- call(message: {
53
- path: string;
54
- key: string;
55
- payload?: any;
56
- }, ctx?: RouteContext & {
57
- [key: string]: any;
58
- }): Promise<any>;
59
- }
60
- export {};
package/dist/connect.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { RouteContext } from './route.ts';
2
- export declare class Connect {
3
- path: string;
4
- key?: string;
5
- _fn?: (ctx?: RouteContext) => Promise<RouteContext>;
6
- description?: string;
7
- connects: {
8
- path: string;
9
- key?: string;
10
- }[];
11
- share: boolean;
12
- constructor(path: string);
13
- use(path: string): void;
14
- useList(paths: string[]): void;
15
- useConnect(connect: Connect): void;
16
- useConnectList(connects: Connect[]): void;
17
- getPathList(): string[];
18
- set fn(fn: (ctx?: RouteContext) => Promise<RouteContext>);
19
- get fn(): (ctx?: RouteContext) => Promise<RouteContext>;
20
- }
21
- export declare class QueryConnect {
22
- connects: Connect[];
23
- constructor();
24
- add(connect: Connect): void;
25
- remove(connect: Connect): void;
26
- getList(): {
27
- path: string;
28
- key: string;
29
- }[];
30
- }
package/dist/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- export { Route, QueryRouter, QueryRouterServer } from './route.ts';
2
- export { Connect, QueryConnect } from './connect.ts';
3
- export type { RouteContext, RouteOpts } from './route.ts';
4
- export type { Run } from './route.ts';
5
- export { Server, handleServer } from './server/index.ts';
6
- /**
7
- * 自定义错误
8
- */
9
- export { CustomError } from './result/error.ts';
10
- /**
11
- * 返回结果
12
- */
13
- export { Result } from './result/index.ts';
14
- export { Rule, Schema, createSchema } from './validator/index.ts';
15
- export { App } from './app.ts';
package/dist/io.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare class IOApp {
2
- constructor();
3
- }
@@ -1,22 +0,0 @@
1
- /** 自定义错误 */
2
- export declare class CustomError extends Error {
3
- code?: number;
4
- data?: any;
5
- message: string;
6
- tips?: string;
7
- constructor(code?: number | string, message?: string, tips?: string);
8
- static fromCode(code?: number): CustomError;
9
- static fromErrorData(code?: number, data?: any): CustomError;
10
- static parseError(e: CustomError): {
11
- code: number;
12
- data: any;
13
- message: string;
14
- tips: string;
15
- };
16
- parse(e?: CustomError): {
17
- code: number;
18
- data: any;
19
- message: string;
20
- tips: string;
21
- };
22
- }
@@ -1,27 +0,0 @@
1
- export declare const Code400: {
2
- code: number;
3
- msg: string;
4
- zn: string;
5
- }[];
6
- export declare const ResultCode: {
7
- code: number;
8
- msg: string;
9
- zn: string;
10
- }[];
11
- type ResultProps = {
12
- code?: number;
13
- msg?: string;
14
- userTip?: string;
15
- };
16
- export declare const Result: {
17
- ({ code, msg, userTip, ...other }: ResultProps): {
18
- code: number;
19
- msg: string;
20
- userTip: any;
21
- };
22
- success(data?: any): {
23
- code: number;
24
- data: any;
25
- };
26
- };
27
- export {};
@@ -1,10 +0,0 @@
1
- import { IncomingMessage, ServerResponse } from 'http';
2
- /**
3
- * get params and body
4
- * @param req
5
- * @param res
6
- * @returns
7
- */
8
- export declare const handleServer: (req: IncomingMessage, res: ServerResponse) => Promise<{
9
- token: string;
10
- }>;
@@ -1,2 +0,0 @@
1
- export { Server } from './server.ts';
2
- export { handleServer } from './handle-server.ts';
@@ -1,2 +0,0 @@
1
- import * as http from 'http';
2
- export declare const parseBody: (req: http.IncomingMessage) => Promise<unknown>;
@@ -1,54 +0,0 @@
1
- import http, { IncomingMessage, ServerResponse } from 'http';
2
- export type Listener = (...args: any[]) => void;
3
- export type Cors = {
4
- /**
5
- * @default '*''
6
- */
7
- origin?: string | undefined;
8
- };
9
- type ServerOpts = {
10
- /**path default `/api/router` */
11
- path?: string;
12
- /**handle Fn */
13
- handle?: (msg?: {
14
- path: string;
15
- key?: string;
16
- [key: string]: any;
17
- }) => any;
18
- cors?: Cors;
19
- };
20
- export declare const resultError: (error: string, code?: number) => string;
21
- export declare class Server {
22
- path: string;
23
- private _server;
24
- handle: ServerOpts['handle'];
25
- private _callback;
26
- private cors;
27
- private hasOn;
28
- constructor(opts?: ServerOpts);
29
- listen(port: number, hostname?: string, backlog?: number, listeningListener?: () => void): void;
30
- listen(port: number, hostname?: string, listeningListener?: () => void): void;
31
- listen(port: number, backlog?: number, listeningListener?: () => void): void;
32
- listen(port: number, listeningListener?: () => void): void;
33
- listen(path: string, backlog?: number, listeningListener?: () => void): void;
34
- listen(path: string, listeningListener?: () => void): void;
35
- listen(handle: any, backlog?: number, listeningListener?: () => void): void;
36
- listen(handle: any, listeningListener?: () => void): void;
37
- setHandle(handle?: any): void;
38
- /**
39
- * get callback
40
- * @returns
41
- */
42
- createCallback(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
43
- get handleServer(): any;
44
- set handleServer(fn: any);
45
- /**
46
- * 兜底监听,当除开 `/api/router` 之外的请求,框架只监听一个api,所以有其他的请求都执行其他的监听
47
- * @description 主要是为了兼容其他的监听
48
- * @param listener
49
- */
50
- on(listener: Listener | Listener[]): void;
51
- get callback(): any;
52
- get server(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
53
- }
54
- export {};
@@ -1,37 +0,0 @@
1
- import { WebSocketServer, WebSocket } from 'ws';
2
- import { Server } from './server.ts';
3
- export declare const createWsServer: (server: Server) => import("ws").Server<typeof import("ws"), typeof import("http").IncomingMessage>;
4
- type WsServerBaseOpts = {
5
- wss?: WebSocketServer;
6
- path?: string;
7
- };
8
- export type ListenerFn = (message: {
9
- data: Record<string, any>;
10
- ws: WebSocket;
11
- end: (data: any) => any;
12
- }) => Promise<any>;
13
- export type Listener<T = 'router' | 'chat' | 'ai'> = {
14
- type: T;
15
- listener: ListenerFn;
16
- };
17
- export declare class WsServerBase {
18
- wss: WebSocketServer;
19
- path: string;
20
- listeners: {
21
- type: string;
22
- listener: ListenerFn;
23
- }[];
24
- listening: boolean;
25
- constructor(opts: WsServerBaseOpts);
26
- setPath(path: string): void;
27
- listen(): void;
28
- addListener(type: string, listener: ListenerFn): void;
29
- removeListener(type: string): void;
30
- }
31
- export declare class WsServer extends WsServerBase {
32
- server: Server;
33
- constructor(server: Server, opts?: any);
34
- initListener(): void;
35
- listen(): void;
36
- }
37
- export {};
package/dist/static.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export declare const parseIfJson: (input: string) => {
2
- [key: string]: any;
3
- } | string;
@@ -1 +0,0 @@
1
- export declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
@@ -1 +0,0 @@
1
- export * from './rule.ts';
@@ -1,40 +0,0 @@
1
- import { z, Schema } from 'zod';
2
- export { Schema };
3
- type BaseRule = {
4
- value?: any;
5
- required?: boolean;
6
- message?: string;
7
- };
8
- type RuleString = {
9
- type: 'string';
10
- minLength?: number;
11
- maxLength?: number;
12
- regex?: string;
13
- } & BaseRule;
14
- type RuleNumber = {
15
- type: 'number';
16
- min?: number;
17
- max?: number;
18
- } & BaseRule;
19
- type RuleBoolean = {
20
- type: 'boolean';
21
- } & BaseRule;
22
- type RuleArray = {
23
- type: 'array';
24
- items: Rule;
25
- minItems?: number;
26
- maxItems?: number;
27
- } & BaseRule;
28
- type RuleObject = {
29
- type: 'object';
30
- properties: {
31
- [key: string]: Rule;
32
- };
33
- } & BaseRule;
34
- type RuleAny = {
35
- type: 'any';
36
- } & BaseRule;
37
- export type Rule = RuleString | RuleNumber | RuleBoolean | RuleArray | RuleObject | RuleAny;
38
- export declare const schemaFormRule: (rule: Rule) => z.ZodType<any, any, any>;
39
- export declare const createSchema: (rule: Rule) => Schema;
40
- export declare const createSchemaList: (rules: Rule[]) => z.ZodType<any, z.ZodTypeDef, any>[];