@kevisual/router 0.0.11 → 0.0.12
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/router-sign.js +1 -1
- package/dist/router.js +26 -21
- package/mod.ts +13 -0
- package/package.json +21 -11
- package/src/app.ts +2 -0
- package/src/server/ws-server.ts +2 -0
- package/src/mod.ts +0 -13
package/dist/router-sign.js
CHANGED
package/dist/router.js
CHANGED
|
@@ -1,34 +1,20 @@
|
|
|
1
|
-
import { webcrypto } from 'node:crypto';
|
|
2
1
|
import http from 'node:http';
|
|
3
2
|
import https from 'node:https';
|
|
4
3
|
import http2 from 'node:http2';
|
|
5
4
|
import url from 'node:url';
|
|
6
|
-
import { WebSocketServer } from 'ws';
|
|
7
5
|
|
|
8
6
|
const urlAlphabet =
|
|
9
7
|
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
function fillPool(bytes) {
|
|
14
|
-
if (!pool || pool.length < bytes) {
|
|
15
|
-
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
16
|
-
webcrypto.getRandomValues(pool);
|
|
17
|
-
poolOffset = 0;
|
|
18
|
-
} else if (poolOffset + bytes > pool.length) {
|
|
19
|
-
webcrypto.getRandomValues(pool);
|
|
20
|
-
poolOffset = 0;
|
|
21
|
-
}
|
|
22
|
-
poolOffset += bytes;
|
|
23
|
-
}
|
|
24
|
-
function nanoid(size = 21) {
|
|
25
|
-
fillPool((size |= 0));
|
|
9
|
+
/* @ts-self-types="./index.d.ts" */
|
|
10
|
+
let nanoid = (size = 21) => {
|
|
26
11
|
let id = '';
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)));
|
|
13
|
+
while (size--) {
|
|
14
|
+
id += urlAlphabet[bytes[size] & 63];
|
|
29
15
|
}
|
|
30
16
|
return id
|
|
31
|
-
}
|
|
17
|
+
};
|
|
32
18
|
|
|
33
19
|
/** 自定义错误 */
|
|
34
20
|
class CustomError extends Error {
|
|
@@ -6835,6 +6821,24 @@ class Server {
|
|
|
6835
6821
|
}
|
|
6836
6822
|
}
|
|
6837
6823
|
|
|
6824
|
+
var browser;
|
|
6825
|
+
var hasRequiredBrowser;
|
|
6826
|
+
|
|
6827
|
+
function requireBrowser () {
|
|
6828
|
+
if (hasRequiredBrowser) return browser;
|
|
6829
|
+
hasRequiredBrowser = 1;
|
|
6830
|
+
|
|
6831
|
+
browser = function () {
|
|
6832
|
+
throw new Error(
|
|
6833
|
+
'ws does not work in the browser. Browser clients must use the native ' +
|
|
6834
|
+
'WebSocket object'
|
|
6835
|
+
);
|
|
6836
|
+
};
|
|
6837
|
+
return browser;
|
|
6838
|
+
}
|
|
6839
|
+
|
|
6840
|
+
var browserExports = requireBrowser();
|
|
6841
|
+
|
|
6838
6842
|
const parseIfJson = (input) => {
|
|
6839
6843
|
try {
|
|
6840
6844
|
// 尝试解析 JSON
|
|
@@ -6850,6 +6854,7 @@ const parseIfJson = (input) => {
|
|
|
6850
6854
|
return input;
|
|
6851
6855
|
};
|
|
6852
6856
|
|
|
6857
|
+
// @ts-type=ws
|
|
6853
6858
|
class WsServerBase {
|
|
6854
6859
|
wss;
|
|
6855
6860
|
path;
|
|
@@ -6936,7 +6941,7 @@ class WsServerBase {
|
|
|
6936
6941
|
class WsServer extends WsServerBase {
|
|
6937
6942
|
server;
|
|
6938
6943
|
constructor(server, opts) {
|
|
6939
|
-
const wss = new WebSocketServer({ noServer: true });
|
|
6944
|
+
const wss = new browserExports.WebSocketServer({ noServer: true });
|
|
6940
6945
|
const path = server.path;
|
|
6941
6946
|
super({ wss });
|
|
6942
6947
|
this.server = server;
|
package/mod.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Route, QueryRouter, QueryRouterServer } from './src/route.ts';
|
|
2
|
+
|
|
3
|
+
export { App } from './src/app.ts';
|
|
4
|
+
|
|
5
|
+
export { Route, QueryRouter, QueryRouterServer };
|
|
6
|
+
|
|
7
|
+
export { Rule, Schema, createSchema } from './src/validator/index.ts';
|
|
8
|
+
|
|
9
|
+
export type { RouteContext, RouteOpts } from './src/route.ts';
|
|
10
|
+
|
|
11
|
+
export type { Run } from './src/route.ts';
|
|
12
|
+
|
|
13
|
+
export { CustomError } from './src/result/error.ts';
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@kevisual/router",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"description": "",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"main": "./dist/router.js",
|
|
8
|
+
"types": "./dist/router.d.ts",
|
|
7
9
|
"scripts": {
|
|
8
10
|
"build": "npm run clean && rollup -c",
|
|
9
11
|
"build:app": "npm run build && rsync dist/*browser* ../deploy/dist",
|
|
@@ -12,12 +14,14 @@
|
|
|
12
14
|
},
|
|
13
15
|
"files": [
|
|
14
16
|
"dist",
|
|
15
|
-
"src"
|
|
17
|
+
"src",
|
|
18
|
+
"mod.ts"
|
|
16
19
|
],
|
|
17
20
|
"keywords": [],
|
|
18
21
|
"author": "abearxiong",
|
|
19
22
|
"license": "MIT",
|
|
20
23
|
"devDependencies": {
|
|
24
|
+
"@rollup/plugin-alias": "^5.1.1",
|
|
21
25
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
22
26
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
23
27
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
@@ -34,6 +38,7 @@
|
|
|
34
38
|
"ts-node": "^10.9.2",
|
|
35
39
|
"tslib": "^2.8.1",
|
|
36
40
|
"typescript": "^5.8.3",
|
|
41
|
+
"ws": "npm:@kevisual/ws",
|
|
37
42
|
"xml2js": "^0.6.2",
|
|
38
43
|
"zod": "^3.24.3"
|
|
39
44
|
},
|
|
@@ -43,8 +48,7 @@
|
|
|
43
48
|
},
|
|
44
49
|
"dependencies": {
|
|
45
50
|
"path-to-regexp": "^8.2.0",
|
|
46
|
-
"selfsigned": "^2.4.1"
|
|
47
|
-
"ws": "^8.18.1"
|
|
51
|
+
"selfsigned": "^2.4.1"
|
|
48
52
|
},
|
|
49
53
|
"publishConfig": {
|
|
50
54
|
"access": "public"
|
|
@@ -52,27 +56,33 @@
|
|
|
52
56
|
"exports": {
|
|
53
57
|
".": {
|
|
54
58
|
"import": "./dist/router.js",
|
|
55
|
-
"require": "./dist/router.js"
|
|
59
|
+
"require": "./dist/router.js",
|
|
60
|
+
"types": "./dist/router.d.ts"
|
|
56
61
|
},
|
|
57
62
|
"./browser": {
|
|
58
63
|
"import": "./dist/router-browser.js",
|
|
59
|
-
"require": "./dist/router-browser.js"
|
|
64
|
+
"require": "./dist/router-browser.js",
|
|
65
|
+
"types": "./dist/router-browser.d.ts"
|
|
60
66
|
},
|
|
61
67
|
"./sign": {
|
|
62
68
|
"import": "./dist/router-sign.js",
|
|
63
|
-
"require": "./dist/router-sign.js"
|
|
69
|
+
"require": "./dist/router-sign.js",
|
|
70
|
+
"types": "./dist/router-sign.d.ts"
|
|
64
71
|
},
|
|
65
72
|
"./simple": {
|
|
66
73
|
"import": "./dist/router-simple.js",
|
|
67
|
-
"require": "./dist/router-simple.js"
|
|
74
|
+
"require": "./dist/router-simple.js",
|
|
75
|
+
"types": "./dist/router-simple.d.ts"
|
|
68
76
|
},
|
|
69
77
|
"./simple-lib": {
|
|
70
78
|
"import": "./dist/router-simple-lib.js",
|
|
71
|
-
"require": "./dist/router-simple-lib.js"
|
|
79
|
+
"require": "./dist/router-simple-lib.js",
|
|
80
|
+
"types": "./dist/router-simple-lib.d.ts"
|
|
72
81
|
},
|
|
73
82
|
"./mod.ts": {
|
|
74
|
-
"import": "./
|
|
75
|
-
"require": "./
|
|
83
|
+
"import": "./mod.ts",
|
|
84
|
+
"require": "./mod.ts",
|
|
85
|
+
"types": "./mod.d.ts"
|
|
76
86
|
}
|
|
77
87
|
}
|
|
78
88
|
}
|
package/src/app.ts
CHANGED
package/src/server/ws-server.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
// @ts-type=ws
|
|
1
2
|
import { WebSocketServer } from 'ws';
|
|
2
3
|
import type { WebSocket } from 'ws';
|
|
3
4
|
import { Server } from './server.ts';
|
|
4
5
|
import { parseIfJson } from '../utils/parse.ts';
|
|
5
6
|
|
|
7
|
+
|
|
6
8
|
export const createWsServer = (server: Server) => {
|
|
7
9
|
// 将 WebSocket 服务器附加到 HTTP 服务器
|
|
8
10
|
const wss = new WebSocketServer({ server: server.server as any });
|
package/src/mod.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Route, QueryRouter, QueryRouterServer } from './route.ts';
|
|
2
|
-
|
|
3
|
-
export { App } from './app.ts';
|
|
4
|
-
|
|
5
|
-
export { Route, QueryRouter, QueryRouterServer };
|
|
6
|
-
|
|
7
|
-
export { Rule, Schema, createSchema } from './validator/index.ts';
|
|
8
|
-
|
|
9
|
-
export type { RouteContext, RouteOpts } from './route.ts';
|
|
10
|
-
|
|
11
|
-
export type { Run } from './route.ts';
|
|
12
|
-
|
|
13
|
-
export { CustomError } from './result/error.ts';
|