@kevisual/router 0.0.40 → 0.0.42

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.
@@ -707,8 +707,7 @@ class QueryRouterServer extends QueryRouter {
707
707
  async run(msg, ctx) {
708
708
  const handle = this.handle;
709
709
  if (handle) {
710
- const result = await this.call(msg, ctx);
711
- return handle(result);
710
+ return handle(msg, ctx);
712
711
  }
713
712
  return super.run(msg, ctx);
714
713
  }
@@ -3601,7 +3600,7 @@ function initializeContext(params) {
3601
3600
  external: params?.external ?? undefined,
3602
3601
  };
3603
3602
  }
3604
- function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
3603
+ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
3605
3604
  var _a;
3606
3605
  const def = schema._zod.def;
3607
3606
  // check for schema in seens
@@ -3633,7 +3632,7 @@ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
3633
3632
  if (parent) {
3634
3633
  // schema was cloned from another schema
3635
3634
  result.ref = parent;
3636
- process(parent, ctx, params);
3635
+ process$1(parent, ctx, params);
3637
3636
  ctx.seen.get(parent).isParent = true;
3638
3637
  }
3639
3638
  else if (schema._zod.processJSONSchema) {
@@ -3938,14 +3937,14 @@ function isTransforming(_schema, _ctx) {
3938
3937
  */
3939
3938
  const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3940
3939
  const ctx = initializeContext({ ...params, processors });
3941
- process(schema, ctx);
3940
+ process$1(schema, ctx);
3942
3941
  extractDefs(ctx, schema);
3943
3942
  return finalize(ctx, schema);
3944
3943
  };
3945
3944
  const createStandardJSONSchemaMethod = (schema, io) => (params) => {
3946
3945
  const { libraryOptions, target } = params ?? {};
3947
3946
  const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
3948
- process(schema, ctx);
3947
+ process$1(schema, ctx);
3949
3948
  extractDefs(ctx, schema);
3950
3949
  return finalize(ctx, schema);
3951
3950
  };
@@ -4079,7 +4078,7 @@ const arrayProcessor = (schema, ctx, _json, params) => {
4079
4078
  if (typeof maximum === "number")
4080
4079
  json.maxItems = maximum;
4081
4080
  json.type = "array";
4082
- json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
4081
+ json.items = process$1(def.element, ctx, { ...params, path: [...params.path, "items"] });
4083
4082
  };
4084
4083
  const objectProcessor = (schema, ctx, _json, params) => {
4085
4084
  const json = _json;
@@ -4088,7 +4087,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
4088
4087
  json.properties = {};
4089
4088
  const shape = def.shape;
4090
4089
  for (const key in shape) {
4091
- json.properties[key] = process(shape[key], ctx, {
4090
+ json.properties[key] = process$1(shape[key], ctx, {
4092
4091
  ...params,
4093
4092
  path: [...params.path, "properties", key],
4094
4093
  });
@@ -4118,7 +4117,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
4118
4117
  json.additionalProperties = false;
4119
4118
  }
4120
4119
  else if (def.catchall) {
4121
- json.additionalProperties = process(def.catchall, ctx, {
4120
+ json.additionalProperties = process$1(def.catchall, ctx, {
4122
4121
  ...params,
4123
4122
  path: [...params.path, "additionalProperties"],
4124
4123
  });
@@ -4129,7 +4128,7 @@ const unionProcessor = (schema, ctx, json, params) => {
4129
4128
  // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
4130
4129
  // This includes both z.xor() and discriminated unions
4131
4130
  const isExclusive = def.inclusive === false;
4132
- const options = def.options.map((x, i) => process(x, ctx, {
4131
+ const options = def.options.map((x, i) => process$1(x, ctx, {
4133
4132
  ...params,
4134
4133
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
4135
4134
  }));
@@ -4142,11 +4141,11 @@ const unionProcessor = (schema, ctx, json, params) => {
4142
4141
  };
4143
4142
  const intersectionProcessor = (schema, ctx, json, params) => {
4144
4143
  const def = schema._zod.def;
4145
- const a = process(def.left, ctx, {
4144
+ const a = process$1(def.left, ctx, {
4146
4145
  ...params,
4147
4146
  path: [...params.path, "allOf", 0],
4148
4147
  });
4149
- const b = process(def.right, ctx, {
4148
+ const b = process$1(def.right, ctx, {
4150
4149
  ...params,
4151
4150
  path: [...params.path, "allOf", 1],
4152
4151
  });
@@ -4159,7 +4158,7 @@ const intersectionProcessor = (schema, ctx, json, params) => {
4159
4158
  };
4160
4159
  const nullableProcessor = (schema, ctx, json, params) => {
4161
4160
  const def = schema._zod.def;
4162
- const inner = process(def.innerType, ctx, params);
4161
+ const inner = process$1(def.innerType, ctx, params);
4163
4162
  const seen = ctx.seen.get(schema);
4164
4163
  if (ctx.target === "openapi-3.0") {
4165
4164
  seen.ref = def.innerType;
@@ -4171,20 +4170,20 @@ const nullableProcessor = (schema, ctx, json, params) => {
4171
4170
  };
4172
4171
  const nonoptionalProcessor = (schema, ctx, _json, params) => {
4173
4172
  const def = schema._zod.def;
4174
- process(def.innerType, ctx, params);
4173
+ process$1(def.innerType, ctx, params);
4175
4174
  const seen = ctx.seen.get(schema);
4176
4175
  seen.ref = def.innerType;
4177
4176
  };
4178
4177
  const defaultProcessor = (schema, ctx, json, params) => {
4179
4178
  const def = schema._zod.def;
4180
- process(def.innerType, ctx, params);
4179
+ process$1(def.innerType, ctx, params);
4181
4180
  const seen = ctx.seen.get(schema);
4182
4181
  seen.ref = def.innerType;
4183
4182
  json.default = JSON.parse(JSON.stringify(def.defaultValue));
4184
4183
  };
4185
4184
  const prefaultProcessor = (schema, ctx, json, params) => {
4186
4185
  const def = schema._zod.def;
4187
- process(def.innerType, ctx, params);
4186
+ process$1(def.innerType, ctx, params);
4188
4187
  const seen = ctx.seen.get(schema);
4189
4188
  seen.ref = def.innerType;
4190
4189
  if (ctx.io === "input")
@@ -4192,7 +4191,7 @@ const prefaultProcessor = (schema, ctx, json, params) => {
4192
4191
  };
4193
4192
  const catchProcessor = (schema, ctx, json, params) => {
4194
4193
  const def = schema._zod.def;
4195
- process(def.innerType, ctx, params);
4194
+ process$1(def.innerType, ctx, params);
4196
4195
  const seen = ctx.seen.get(schema);
4197
4196
  seen.ref = def.innerType;
4198
4197
  let catchValue;
@@ -4207,20 +4206,20 @@ const catchProcessor = (schema, ctx, json, params) => {
4207
4206
  const pipeProcessor = (schema, ctx, _json, params) => {
4208
4207
  const def = schema._zod.def;
4209
4208
  const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
4210
- process(innerType, ctx, params);
4209
+ process$1(innerType, ctx, params);
4211
4210
  const seen = ctx.seen.get(schema);
4212
4211
  seen.ref = innerType;
4213
4212
  };
4214
4213
  const readonlyProcessor = (schema, ctx, json, params) => {
4215
4214
  const def = schema._zod.def;
4216
- process(def.innerType, ctx, params);
4215
+ process$1(def.innerType, ctx, params);
4217
4216
  const seen = ctx.seen.get(schema);
4218
4217
  seen.ref = def.innerType;
4219
4218
  json.readOnly = true;
4220
4219
  };
4221
4220
  const optionalProcessor = (schema, ctx, _json, params) => {
4222
4221
  const def = schema._zod.def;
4223
- process(def.innerType, ctx, params);
4222
+ process$1(def.innerType, ctx, params);
4224
4223
  const seen = ctx.seen.get(schema);
4225
4224
  seen.ref = def.innerType;
4226
4225
  };
@@ -4962,7 +4961,54 @@ const createSchema = (rule) => {
4962
4961
  }
4963
4962
  };
4964
4963
 
4964
+ typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
4965
+ // @ts-ignore
4966
+ typeof Deno !== 'undefined' && typeof Deno.version === 'object' && typeof Deno.version.deno === 'string';
4967
+ // @ts-ignore
4968
+ const isBun = typeof Bun !== 'undefined' && typeof Bun.version === 'string';
4969
+
4965
4970
  const parseBody = async (req) => {
4971
+ const resolveBody = (body) => {
4972
+ // 获取 Content-Type 头信息
4973
+ const contentType = req.headers['content-type'] || '';
4974
+ const resolve = (data) => {
4975
+ return data;
4976
+ };
4977
+ // 处理 application/json
4978
+ if (contentType.includes('application/json')) {
4979
+ return resolve(JSON.parse(body));
4980
+ }
4981
+ // 处理 application/x-www-form-urlencoded
4982
+ if (contentType.includes('application/x-www-form-urlencoded')) {
4983
+ const formData = new URLSearchParams(body);
4984
+ const result = {};
4985
+ formData.forEach((value, key) => {
4986
+ // 尝试将值解析为 JSON,如果失败则保留原始字符串
4987
+ try {
4988
+ result[key] = JSON.parse(value);
4989
+ }
4990
+ catch {
4991
+ result[key] = value;
4992
+ }
4993
+ });
4994
+ return resolve(result);
4995
+ }
4996
+ // 默认尝试 JSON 解析
4997
+ try {
4998
+ return resolve(JSON.parse(body));
4999
+ }
5000
+ catch {
5001
+ return resolve({});
5002
+ }
5003
+ };
5004
+ if (isBun) {
5005
+ // @ts-ignore
5006
+ const body = req.body;
5007
+ if (body) {
5008
+ return resolveBody(body);
5009
+ }
5010
+ return {};
5011
+ }
4966
5012
  return new Promise((resolve, reject) => {
4967
5013
  const arr = [];
4968
5014
  req.on('data', (chunk) => {
@@ -4971,36 +5017,7 @@ const parseBody = async (req) => {
4971
5017
  req.on('end', () => {
4972
5018
  try {
4973
5019
  const body = Buffer.concat(arr).toString();
4974
- // 获取 Content-Type 头信息
4975
- const contentType = req.headers['content-type'] || '';
4976
- // 处理 application/json
4977
- if (contentType.includes('application/json')) {
4978
- resolve(JSON.parse(body));
4979
- return;
4980
- }
4981
- // 处理 application/x-www-form-urlencoded
4982
- if (contentType.includes('application/x-www-form-urlencoded')) {
4983
- const formData = new URLSearchParams(body);
4984
- const result = {};
4985
- formData.forEach((value, key) => {
4986
- // 尝试将值解析为 JSON,如果失败则保留原始字符串
4987
- try {
4988
- result[key] = JSON.parse(value);
4989
- }
4990
- catch {
4991
- result[key] = value;
4992
- }
4993
- });
4994
- resolve(result);
4995
- return;
4996
- }
4997
- // 默认尝试 JSON 解析
4998
- try {
4999
- resolve(JSON.parse(body));
5000
- }
5001
- catch {
5002
- resolve({});
5003
- }
5020
+ resolve(resolveBody(body));
5004
5021
  }
5005
5022
  catch (e) {
5006
5023
  resolve({});
@@ -3272,7 +3272,9 @@ class LocalBitStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
3272
3272
  return new ArrayBuffer(this.valueHexView.byteLength + 1);
3273
3273
  }
3274
3274
  if (!this.valueHexView.byteLength) {
3275
- return EMPTY_BUFFER;
3275
+ const empty = new Uint8Array(1);
3276
+ empty[0] = 0;
3277
+ return empty.buffer;
3276
3278
  }
3277
3279
  const retView = new Uint8Array(this.valueHexView.length + 1);
3278
3280
  retView[0] = this.unusedBits;
@@ -420,7 +420,54 @@ function requireDist () {
420
420
 
421
421
  var distExports = requireDist();
422
422
 
423
+ typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
424
+ // @ts-ignore
425
+ typeof Deno !== 'undefined' && typeof Deno.version === 'object' && typeof Deno.version.deno === 'string';
426
+ // @ts-ignore
427
+ const isBun = typeof Bun !== 'undefined' && typeof Bun.version === 'string';
428
+
423
429
  const parseBody = async (req) => {
430
+ const resolveBody = (body) => {
431
+ // 获取 Content-Type 头信息
432
+ const contentType = req.headers['content-type'] || '';
433
+ const resolve = (data) => {
434
+ return data;
435
+ };
436
+ // 处理 application/json
437
+ if (contentType.includes('application/json')) {
438
+ return resolve(JSON.parse(body));
439
+ }
440
+ // 处理 application/x-www-form-urlencoded
441
+ if (contentType.includes('application/x-www-form-urlencoded')) {
442
+ const formData = new URLSearchParams(body);
443
+ const result = {};
444
+ formData.forEach((value, key) => {
445
+ // 尝试将值解析为 JSON,如果失败则保留原始字符串
446
+ try {
447
+ result[key] = JSON.parse(value);
448
+ }
449
+ catch {
450
+ result[key] = value;
451
+ }
452
+ });
453
+ return resolve(result);
454
+ }
455
+ // 默认尝试 JSON 解析
456
+ try {
457
+ return resolve(JSON.parse(body));
458
+ }
459
+ catch {
460
+ return resolve({});
461
+ }
462
+ };
463
+ if (isBun) {
464
+ // @ts-ignore
465
+ const body = req.body;
466
+ if (body) {
467
+ return resolveBody(body);
468
+ }
469
+ return {};
470
+ }
424
471
  return new Promise((resolve, reject) => {
425
472
  const arr = [];
426
473
  req.on('data', (chunk) => {
@@ -429,36 +476,7 @@ const parseBody = async (req) => {
429
476
  req.on('end', () => {
430
477
  try {
431
478
  const body = Buffer.concat(arr).toString();
432
- // 获取 Content-Type 头信息
433
- const contentType = req.headers['content-type'] || '';
434
- // 处理 application/json
435
- if (contentType.includes('application/json')) {
436
- resolve(JSON.parse(body));
437
- return;
438
- }
439
- // 处理 application/x-www-form-urlencoded
440
- if (contentType.includes('application/x-www-form-urlencoded')) {
441
- const formData = new URLSearchParams(body);
442
- const result = {};
443
- formData.forEach((value, key) => {
444
- // 尝试将值解析为 JSON,如果失败则保留原始字符串
445
- try {
446
- result[key] = JSON.parse(value);
447
- }
448
- catch {
449
- result[key] = value;
450
- }
451
- });
452
- resolve(result);
453
- return;
454
- }
455
- // 默认尝试 JSON 解析
456
- try {
457
- resolve(JSON.parse(body));
458
- }
459
- catch {
460
- resolve({});
461
- }
479
+ resolve(resolveBody(body));
462
480
  }
463
481
  catch (e) {
464
482
  resolve({});
@@ -539,6 +557,8 @@ class SimpleRouter {
539
557
  }
540
558
  isSse(req) {
541
559
  const { headers } = req;
560
+ if (!headers)
561
+ return false;
542
562
  if (headers['accept'] && headers['accept'].includes('text/event-stream')) {
543
563
  return true;
544
564
  }
package/dist/router.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import http, { IncomingMessage, ServerResponse } from 'node:http';
1
+ import http$1, { IncomingMessage, ServerResponse } from 'node:http';
2
2
  import https from 'node:https';
3
3
  import http2 from 'node:http2';
4
- import { z } from 'zod';
5
- import { WebSocketServer, WebSocket } from 'ws';
4
+ import * as http from 'http';
6
5
  import { IncomingMessage as IncomingMessage$1, ServerResponse as ServerResponse$1 } from 'http';
6
+ import { WebSocketServer, WebSocket } from 'ws';
7
+ import { z } from 'zod';
7
8
  import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
8
9
  import { Query, DataOpts, Result } from '@kevisual/query/query';
9
10
 
@@ -382,6 +383,68 @@ declare class QueryConnect {
382
383
  }[];
383
384
  }
384
385
 
386
+ type Listener$1 = {
387
+ id?: string;
388
+ io?: boolean;
389
+ path?: string;
390
+ fun: (...args: any[]) => Promise<void> | void;
391
+ };
392
+ type ListenerFun = (...args: any[]) => Promise<void> | void;
393
+ type OnListener = Listener$1 | Listener$1[] | ListenerFun | ListenerFun[];
394
+ type Cors$2 = {
395
+ /**
396
+ * @default '*''
397
+ */
398
+ origin?: string | undefined;
399
+ };
400
+ type ServerOpts<T = {}> = {
401
+ /**path default `/api/router` */
402
+ path?: string;
403
+ /**handle Fn */
404
+ handle?: (msg?: {
405
+ path: string;
406
+ key?: string;
407
+ [key: string]: any;
408
+ }, ctx?: {
409
+ req: http.IncomingMessage;
410
+ res: http.ServerResponse;
411
+ }) => any;
412
+ cors?: Cors$2;
413
+ io?: boolean;
414
+ } & T;
415
+ interface ServerType {
416
+ path?: string;
417
+ server?: any;
418
+ handle: ServerOpts['handle'];
419
+ setHandle(handle?: any): void;
420
+ listeners: Listener$1[];
421
+ listen(port: number, hostname?: string, backlog?: number, listeningListener?: () => void): void;
422
+ listen(port: number, hostname?: string, listeningListener?: () => void): void;
423
+ listen(port: number, backlog?: number, listeningListener?: () => void): void;
424
+ listen(port: number, listeningListener?: () => void): void;
425
+ listen(path: string, backlog?: number, listeningListener?: () => void): void;
426
+ listen(path: string, listeningListener?: () => void): void;
427
+ listen(handle: any, backlog?: number, listeningListener?: () => void): void;
428
+ listen(handle: any, listeningListener?: () => void): void;
429
+ /**
430
+ * 兜底监听,当除开 `/api/router` 之外的请求,框架只监听一个api,所以有其他的请求都执行其他的监听
431
+ * @description 主要是为了兼容其他的监听
432
+ * @param listener
433
+ */
434
+ on(listener: OnListener): void;
435
+ onWebSocket({ ws, message, pathname, token, id }: {
436
+ ws: WS;
437
+ message: string | Buffer;
438
+ pathname: string;
439
+ token?: string;
440
+ id?: string;
441
+ }): void;
442
+ }
443
+ type WS = {
444
+ send: (data: any) => void;
445
+ close: () => void;
446
+ };
447
+
385
448
  interface StringifyOptions {
386
449
  /**
387
450
  * Specifies a function that will be used to encode a [cookie-value](https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1).
@@ -477,7 +540,6 @@ interface SetCookie {
477
540
  */
478
541
  type SerializeOptions = StringifyOptions & Omit<SetCookie, "name" | "value">;
479
542
 
480
- type Listener = (...args: any[]) => void;
481
543
  type CookieFn = (name: string, value: string, options?: SerializeOptions, end?: boolean) => void;
482
544
  type HandleCtx = {
483
545
  req: IncomingMessage & {
@@ -490,38 +552,19 @@ type HandleCtx = {
490
552
  cookie: CookieFn;
491
553
  };
492
554
  };
493
- type Cors = {
555
+ type Cors$1 = {
494
556
  /**
495
557
  * @default '*''
496
558
  */
497
559
  origin?: string | undefined;
498
560
  };
499
- type ServerOpts = {
500
- /**path default `/api/router` */
501
- path?: string;
502
- /**handle Fn */
503
- handle?: (msg?: {
504
- path: string;
505
- key?: string;
506
- [key: string]: any;
507
- }, ctx?: {
508
- req: http.IncomingMessage;
509
- res: http.ServerResponse;
510
- }) => any;
511
- cors?: Cors;
512
- httpType?: 'http' | 'https' | 'http2';
513
- httpsKey?: string;
514
- httpsCert?: string;
515
- };
516
- declare class Server {
561
+ declare class ServerBase implements ServerType {
517
562
  path: string;
518
- private _server;
563
+ _server: any;
519
564
  handle: ServerOpts['handle'];
520
- private _callback;
521
- private cors;
522
- private hasOn;
523
- private httpType;
524
- private options;
565
+ _callback: any;
566
+ cors: Cors$1;
567
+ listeners: Listener$1[];
525
568
  constructor(opts?: ServerOpts);
526
569
  listen(port: number, hostname?: string, backlog?: number, listeningListener?: () => void): void;
527
570
  listen(port: number, hostname?: string, listeningListener?: () => void): void;
@@ -531,23 +574,80 @@ declare class Server {
531
574
  listen(path: string, listeningListener?: () => void): void;
532
575
  listen(handle: any, backlog?: number, listeningListener?: () => void): void;
533
576
  listen(handle: any, listeningListener?: () => void): void;
534
- createServer(): http.Server<typeof IncomingMessage, typeof ServerResponse> | http2.Http2SecureServer<typeof IncomingMessage, typeof ServerResponse, typeof http2.Http2ServerRequest, typeof http2.Http2ServerResponse>;
577
+ /**
578
+ * child class can custom listen method
579
+ * @param args
580
+ */
581
+ customListen(...args: any[]): void;
582
+ get handleServer(): any;
583
+ set handleServer(fn: any);
584
+ get callback(): any;
585
+ get server(): any;
535
586
  setHandle(handle?: any): void;
536
587
  /**
537
588
  * get callback
538
589
  * @returns
539
590
  */
540
591
  createCallback(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
541
- get handleServer(): any;
542
- set handleServer(fn: any);
592
+ on(listener: OnListener): void;
593
+ onWebSocket({ ws, message, pathname, token, id }: {
594
+ ws: any;
595
+ message: any;
596
+ pathname: any;
597
+ token: any;
598
+ id: any;
599
+ }): Promise<void>;
600
+ }
601
+
602
+ type WsServerBaseOpts = {
603
+ wss?: WebSocketServer | null;
604
+ path?: string;
605
+ };
606
+ type ListenerFn = (message: {
607
+ data: Record<string, any>;
608
+ ws: WebSocket;
609
+ end: (data: any) => any;
610
+ }) => Promise<any>;
611
+ type Listener<T = 'router' | 'chat' | 'ai'> = {
612
+ type: T;
613
+ path?: string;
614
+ listener: ListenerFn;
615
+ };
616
+ declare class WsServerBase {
617
+ wss: WebSocketServer | null;
618
+ listeners: Listener[];
619
+ listening: boolean;
620
+ server: ServerType;
621
+ constructor(opts: WsServerBaseOpts);
622
+ listen(): void;
623
+ }
624
+ declare class WsServer extends WsServerBase {
625
+ constructor(server: ServerType);
626
+ listen(): void;
627
+ }
628
+
629
+ type Cors = {
543
630
  /**
544
- * 兜底监听,当除开 `/api/router` 之外的请求,框架只监听一个api,所以有其他的请求都执行其他的监听
545
- * @description 主要是为了兼容其他的监听
546
- * @param listener
631
+ * @default '*''
547
632
  */
548
- on(listener: Listener | Listener[]): () => void;
549
- get callback(): any;
550
- get server(): http.Server<typeof IncomingMessage, typeof ServerResponse> | https.Server<typeof IncomingMessage, typeof ServerResponse> | http2.Http2SecureServer<typeof IncomingMessage, typeof ServerResponse, typeof http2.Http2ServerRequest, typeof http2.Http2ServerResponse>;
633
+ origin?: string | undefined;
634
+ };
635
+ type ServerNodeOpts = ServerOpts<{
636
+ httpType?: 'http' | 'https' | 'http2';
637
+ httpsKey?: string;
638
+ httpsCert?: string;
639
+ }>;
640
+ declare class ServerNode extends ServerBase implements ServerType {
641
+ _server: http$1.Server | https.Server | http2.Http2SecureServer;
642
+ _callback: any;
643
+ cors: Cors;
644
+ private httpType;
645
+ listeners: Listener$1[];
646
+ private options;
647
+ io: WsServer | undefined;
648
+ constructor(opts?: ServerNodeOpts);
649
+ customListen(...args: any[]): void;
650
+ createServer(): http$1.Server<typeof http$1.IncomingMessage, typeof http$1.ServerResponse> | http2.Http2SecureServer<typeof http$1.IncomingMessage, typeof http$1.ServerResponse, typeof http2.Http2ServerRequest, typeof http2.Http2ServerResponse>;
551
651
  }
552
652
 
553
653
  /**
@@ -631,36 +731,6 @@ declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
631
731
 
632
732
  type Schema = z.ZodType<any, any, any>;
633
733
 
634
- type WsServerBaseOpts = {
635
- wss?: WebSocketServer;
636
- path?: string;
637
- };
638
- type ListenerFn = (message: {
639
- data: Record<string, any>;
640
- ws: WebSocket;
641
- end: (data: any) => any;
642
- }) => Promise<any>;
643
- declare class WsServerBase {
644
- wss: WebSocketServer;
645
- path: string;
646
- listeners: {
647
- type: string;
648
- listener: ListenerFn;
649
- }[];
650
- listening: boolean;
651
- constructor(opts: WsServerBaseOpts);
652
- setPath(path: string): void;
653
- listen(): void;
654
- addListener(type: string, listener: ListenerFn): void;
655
- removeListener(type: string): void;
656
- }
657
- declare class WsServer extends WsServerBase {
658
- server: Server;
659
- constructor(server: Server, opts?: any);
660
- initListener(): void;
661
- listen(): void;
662
- }
663
-
664
734
  type RouteObject = {
665
735
  [key: string]: RouteOpts$1;
666
736
  };
@@ -740,17 +810,11 @@ type RouterHandle = (msg: {
740
810
  };
741
811
  type AppOptions<T = {}> = {
742
812
  router?: QueryRouter;
743
- server?: Server;
813
+ server?: ServerType;
744
814
  /** handle msg 关联 */
745
815
  routerHandle?: RouterHandle;
746
816
  routerContext?: RouteContext<T>;
747
- serverOptions?: ServerOpts;
748
- io?: boolean;
749
- ioOpts?: {
750
- routerHandle?: RouterHandle;
751
- routerContext?: RouteContext<T>;
752
- path?: string;
753
- };
817
+ serverOptions?: ServerNodeOpts;
754
818
  };
755
819
  type AppRouteContext<T = {}> = HandleCtx & RouteContext<T> & {
756
820
  app: App<T>;
@@ -761,8 +825,7 @@ type AppRouteContext<T = {}> = HandleCtx & RouteContext<T> & {
761
825
  */
762
826
  declare class App<U = {}> {
763
827
  router: QueryRouter;
764
- server: Server;
765
- io: WsServer;
828
+ server: ServerType;
766
829
  constructor(opts?: AppOptions<U>);
767
830
  listen(port: number, hostname?: string, backlog?: number, listeningListener?: () => void): void;
768
831
  listen(port: number, hostname?: string, listeningListener?: () => void): void;
@@ -825,5 +888,5 @@ declare class App<U = {}> {
825
888
  onServerRequest(fn: (req: IncomingMessage$1, res: ServerResponse$1) => void): void;
826
889
  }
827
890
 
828
- export { App, Connect, CustomError, Mini, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, Server, createSchema, define, handleServer, util };
891
+ export { App, Connect, CustomError, Mini, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, define, handleServer, util };
829
892
  export type { RouteArray, RouteContext, RouteMiddleware, RouteObject, RouteOpts, Rule, Run, Schema };