@kevisual/router 0.0.41 → 0.0.43

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.
@@ -3600,7 +3600,7 @@ function initializeContext(params) {
3600
3600
  external: params?.external ?? undefined,
3601
3601
  };
3602
3602
  }
3603
- function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
3603
+ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
3604
3604
  var _a;
3605
3605
  const def = schema._zod.def;
3606
3606
  // check for schema in seens
@@ -3632,7 +3632,7 @@ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
3632
3632
  if (parent) {
3633
3633
  // schema was cloned from another schema
3634
3634
  result.ref = parent;
3635
- process(parent, ctx, params);
3635
+ process$1(parent, ctx, params);
3636
3636
  ctx.seen.get(parent).isParent = true;
3637
3637
  }
3638
3638
  else if (schema._zod.processJSONSchema) {
@@ -3937,14 +3937,14 @@ function isTransforming(_schema, _ctx) {
3937
3937
  */
3938
3938
  const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3939
3939
  const ctx = initializeContext({ ...params, processors });
3940
- process(schema, ctx);
3940
+ process$1(schema, ctx);
3941
3941
  extractDefs(ctx, schema);
3942
3942
  return finalize(ctx, schema);
3943
3943
  };
3944
3944
  const createStandardJSONSchemaMethod = (schema, io) => (params) => {
3945
3945
  const { libraryOptions, target } = params ?? {};
3946
3946
  const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
3947
- process(schema, ctx);
3947
+ process$1(schema, ctx);
3948
3948
  extractDefs(ctx, schema);
3949
3949
  return finalize(ctx, schema);
3950
3950
  };
@@ -4078,7 +4078,7 @@ const arrayProcessor = (schema, ctx, _json, params) => {
4078
4078
  if (typeof maximum === "number")
4079
4079
  json.maxItems = maximum;
4080
4080
  json.type = "array";
4081
- json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
4081
+ json.items = process$1(def.element, ctx, { ...params, path: [...params.path, "items"] });
4082
4082
  };
4083
4083
  const objectProcessor = (schema, ctx, _json, params) => {
4084
4084
  const json = _json;
@@ -4087,7 +4087,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
4087
4087
  json.properties = {};
4088
4088
  const shape = def.shape;
4089
4089
  for (const key in shape) {
4090
- json.properties[key] = process(shape[key], ctx, {
4090
+ json.properties[key] = process$1(shape[key], ctx, {
4091
4091
  ...params,
4092
4092
  path: [...params.path, "properties", key],
4093
4093
  });
@@ -4117,7 +4117,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
4117
4117
  json.additionalProperties = false;
4118
4118
  }
4119
4119
  else if (def.catchall) {
4120
- json.additionalProperties = process(def.catchall, ctx, {
4120
+ json.additionalProperties = process$1(def.catchall, ctx, {
4121
4121
  ...params,
4122
4122
  path: [...params.path, "additionalProperties"],
4123
4123
  });
@@ -4128,7 +4128,7 @@ const unionProcessor = (schema, ctx, json, params) => {
4128
4128
  // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
4129
4129
  // This includes both z.xor() and discriminated unions
4130
4130
  const isExclusive = def.inclusive === false;
4131
- const options = def.options.map((x, i) => process(x, ctx, {
4131
+ const options = def.options.map((x, i) => process$1(x, ctx, {
4132
4132
  ...params,
4133
4133
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
4134
4134
  }));
@@ -4141,11 +4141,11 @@ const unionProcessor = (schema, ctx, json, params) => {
4141
4141
  };
4142
4142
  const intersectionProcessor = (schema, ctx, json, params) => {
4143
4143
  const def = schema._zod.def;
4144
- const a = process(def.left, ctx, {
4144
+ const a = process$1(def.left, ctx, {
4145
4145
  ...params,
4146
4146
  path: [...params.path, "allOf", 0],
4147
4147
  });
4148
- const b = process(def.right, ctx, {
4148
+ const b = process$1(def.right, ctx, {
4149
4149
  ...params,
4150
4150
  path: [...params.path, "allOf", 1],
4151
4151
  });
@@ -4158,7 +4158,7 @@ const intersectionProcessor = (schema, ctx, json, params) => {
4158
4158
  };
4159
4159
  const nullableProcessor = (schema, ctx, json, params) => {
4160
4160
  const def = schema._zod.def;
4161
- const inner = process(def.innerType, ctx, params);
4161
+ const inner = process$1(def.innerType, ctx, params);
4162
4162
  const seen = ctx.seen.get(schema);
4163
4163
  if (ctx.target === "openapi-3.0") {
4164
4164
  seen.ref = def.innerType;
@@ -4170,20 +4170,20 @@ const nullableProcessor = (schema, ctx, json, params) => {
4170
4170
  };
4171
4171
  const nonoptionalProcessor = (schema, ctx, _json, params) => {
4172
4172
  const def = schema._zod.def;
4173
- process(def.innerType, ctx, params);
4173
+ process$1(def.innerType, ctx, params);
4174
4174
  const seen = ctx.seen.get(schema);
4175
4175
  seen.ref = def.innerType;
4176
4176
  };
4177
4177
  const defaultProcessor = (schema, ctx, json, params) => {
4178
4178
  const def = schema._zod.def;
4179
- process(def.innerType, ctx, params);
4179
+ process$1(def.innerType, ctx, params);
4180
4180
  const seen = ctx.seen.get(schema);
4181
4181
  seen.ref = def.innerType;
4182
4182
  json.default = JSON.parse(JSON.stringify(def.defaultValue));
4183
4183
  };
4184
4184
  const prefaultProcessor = (schema, ctx, json, params) => {
4185
4185
  const def = schema._zod.def;
4186
- process(def.innerType, ctx, params);
4186
+ process$1(def.innerType, ctx, params);
4187
4187
  const seen = ctx.seen.get(schema);
4188
4188
  seen.ref = def.innerType;
4189
4189
  if (ctx.io === "input")
@@ -4191,7 +4191,7 @@ const prefaultProcessor = (schema, ctx, json, params) => {
4191
4191
  };
4192
4192
  const catchProcessor = (schema, ctx, json, params) => {
4193
4193
  const def = schema._zod.def;
4194
- process(def.innerType, ctx, params);
4194
+ process$1(def.innerType, ctx, params);
4195
4195
  const seen = ctx.seen.get(schema);
4196
4196
  seen.ref = def.innerType;
4197
4197
  let catchValue;
@@ -4206,20 +4206,20 @@ const catchProcessor = (schema, ctx, json, params) => {
4206
4206
  const pipeProcessor = (schema, ctx, _json, params) => {
4207
4207
  const def = schema._zod.def;
4208
4208
  const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
4209
- process(innerType, ctx, params);
4209
+ process$1(innerType, ctx, params);
4210
4210
  const seen = ctx.seen.get(schema);
4211
4211
  seen.ref = innerType;
4212
4212
  };
4213
4213
  const readonlyProcessor = (schema, ctx, json, params) => {
4214
4214
  const def = schema._zod.def;
4215
- process(def.innerType, ctx, params);
4215
+ process$1(def.innerType, ctx, params);
4216
4216
  const seen = ctx.seen.get(schema);
4217
4217
  seen.ref = def.innerType;
4218
4218
  json.readOnly = true;
4219
4219
  };
4220
4220
  const optionalProcessor = (schema, ctx, _json, params) => {
4221
4221
  const def = schema._zod.def;
4222
- process(def.innerType, ctx, params);
4222
+ process$1(def.innerType, ctx, params);
4223
4223
  const seen = ctx.seen.get(schema);
4224
4224
  seen.ref = def.innerType;
4225
4225
  };
@@ -4961,7 +4961,54 @@ const createSchema = (rule) => {
4961
4961
  }
4962
4962
  };
4963
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
+
4964
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
+ }
4965
5012
  return new Promise((resolve, reject) => {
4966
5013
  const arr = [];
4967
5014
  req.on('data', (chunk) => {
@@ -4970,36 +5017,7 @@ const parseBody = async (req) => {
4970
5017
  req.on('end', () => {
4971
5018
  try {
4972
5019
  const body = Buffer.concat(arr).toString();
4973
- // 获取 Content-Type 头信息
4974
- const contentType = req.headers['content-type'] || '';
4975
- // 处理 application/json
4976
- if (contentType.includes('application/json')) {
4977
- resolve(JSON.parse(body));
4978
- return;
4979
- }
4980
- // 处理 application/x-www-form-urlencoded
4981
- if (contentType.includes('application/x-www-form-urlencoded')) {
4982
- const formData = new URLSearchParams(body);
4983
- const result = {};
4984
- formData.forEach((value, key) => {
4985
- // 尝试将值解析为 JSON,如果失败则保留原始字符串
4986
- try {
4987
- result[key] = JSON.parse(value);
4988
- }
4989
- catch {
4990
- result[key] = value;
4991
- }
4992
- });
4993
- resolve(result);
4994
- return;
4995
- }
4996
- // 默认尝试 JSON 解析
4997
- try {
4998
- resolve(JSON.parse(body));
4999
- }
5000
- catch {
5001
- resolve({});
5002
- }
5020
+ resolve(resolveBody(body));
5003
5021
  }
5004
5022
  catch (e) {
5005
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,91 @@ 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 | ListenerFun | (Listener$1 | 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
+ type RouterReq<T = {}> = {
448
+ url: string;
449
+ method: string;
450
+ headers: Record<string, string>;
451
+ socket?: {
452
+ remoteAddress?: string;
453
+ remotePort?: number;
454
+ };
455
+ cookies?: Record<string, string>;
456
+ } & T;
457
+ type RouterRes<T = {}> = {
458
+ statusCode: number;
459
+ headersSent: boolean;
460
+ _headers: Record<string, string | string[]>;
461
+ _bodyChunks: any[];
462
+ writableEnded: boolean;
463
+ writeHead: (statusCode: number, headers?: Record<string, string>) => void;
464
+ setHeader: (name: string, value: string | string[]) => void;
465
+ cookie: (name: string, value: string, options?: any) => void;
466
+ write: (chunk: any) => void;
467
+ pipe: (stream: any) => void;
468
+ end: (data?: any) => void;
469
+ } & T;
470
+
385
471
  interface StringifyOptions {
386
472
  /**
387
473
  * 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 +563,6 @@ interface SetCookie {
477
563
  */
478
564
  type SerializeOptions = StringifyOptions & Omit<SetCookie, "name" | "value">;
479
565
 
480
- type Listener = (...args: any[]) => void;
481
566
  type CookieFn = (name: string, value: string, options?: SerializeOptions, end?: boolean) => void;
482
567
  type HandleCtx = {
483
568
  req: IncomingMessage & {
@@ -490,38 +575,19 @@ type HandleCtx = {
490
575
  cookie: CookieFn;
491
576
  };
492
577
  };
493
- type Cors = {
578
+ type Cors$1 = {
494
579
  /**
495
580
  * @default '*''
496
581
  */
497
582
  origin?: string | undefined;
498
583
  };
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 {
584
+ declare class ServerBase implements ServerType {
517
585
  path: string;
518
- private _server;
586
+ _server: any;
519
587
  handle: ServerOpts['handle'];
520
- private _callback;
521
- private cors;
522
- private hasOn;
523
- private httpType;
524
- private options;
588
+ _callback: any;
589
+ cors: Cors$1;
590
+ listeners: Listener$1[];
525
591
  constructor(opts?: ServerOpts);
526
592
  listen(port: number, hostname?: string, backlog?: number, listeningListener?: () => void): void;
527
593
  listen(port: number, hostname?: string, listeningListener?: () => void): void;
@@ -531,23 +597,80 @@ declare class Server {
531
597
  listen(path: string, listeningListener?: () => void): void;
532
598
  listen(handle: any, backlog?: number, listeningListener?: () => void): void;
533
599
  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>;
600
+ /**
601
+ * child class can custom listen method
602
+ * @param args
603
+ */
604
+ customListen(...args: any[]): void;
605
+ get handleServer(): any;
606
+ set handleServer(fn: any);
607
+ get callback(): any;
608
+ get server(): any;
535
609
  setHandle(handle?: any): void;
536
610
  /**
537
611
  * get callback
538
612
  * @returns
539
613
  */
540
614
  createCallback(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
541
- get handleServer(): any;
542
- set handleServer(fn: any);
615
+ on(listener: OnListener): void;
616
+ onWebSocket({ ws, message, pathname, token, id }: {
617
+ ws: any;
618
+ message: any;
619
+ pathname: any;
620
+ token: any;
621
+ id: any;
622
+ }): Promise<void>;
623
+ }
624
+
625
+ type WsServerBaseOpts = {
626
+ wss?: WebSocketServer | null;
627
+ path?: string;
628
+ };
629
+ type ListenerFn = (message: {
630
+ data: Record<string, any>;
631
+ ws: WebSocket;
632
+ end: (data: any) => any;
633
+ }) => Promise<any>;
634
+ type Listener<T = 'router' | 'chat' | 'ai'> = {
635
+ type: T;
636
+ path?: string;
637
+ listener: ListenerFn;
638
+ };
639
+ declare class WsServerBase {
640
+ wss: WebSocketServer | null;
641
+ listeners: Listener[];
642
+ listening: boolean;
643
+ server: ServerType;
644
+ constructor(opts: WsServerBaseOpts);
645
+ listen(): void;
646
+ }
647
+ declare class WsServer extends WsServerBase {
648
+ constructor(server: ServerType);
649
+ listen(): void;
650
+ }
651
+
652
+ type Cors = {
543
653
  /**
544
- * 兜底监听,当除开 `/api/router` 之外的请求,框架只监听一个api,所以有其他的请求都执行其他的监听
545
- * @description 主要是为了兼容其他的监听
546
- * @param listener
654
+ * @default '*''
547
655
  */
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>;
656
+ origin?: string | undefined;
657
+ };
658
+ type ServerNodeOpts = ServerOpts<{
659
+ httpType?: 'http' | 'https' | 'http2';
660
+ httpsKey?: string;
661
+ httpsCert?: string;
662
+ }>;
663
+ declare class ServerNode extends ServerBase implements ServerType {
664
+ _server: http$1.Server | https.Server | http2.Http2SecureServer;
665
+ _callback: any;
666
+ cors: Cors;
667
+ private httpType;
668
+ listeners: Listener$1[];
669
+ private options;
670
+ io: WsServer | undefined;
671
+ constructor(opts?: ServerNodeOpts);
672
+ customListen(...args: any[]): void;
673
+ 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
674
  }
552
675
 
553
676
  /**
@@ -631,36 +754,6 @@ declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
631
754
 
632
755
  type Schema = z.ZodType<any, any, any>;
633
756
 
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
757
  type RouteObject = {
665
758
  [key: string]: RouteOpts$1;
666
759
  };
@@ -740,17 +833,11 @@ type RouterHandle = (msg: {
740
833
  };
741
834
  type AppOptions<T = {}> = {
742
835
  router?: QueryRouter;
743
- server?: Server;
836
+ server?: ServerType;
744
837
  /** handle msg 关联 */
745
838
  routerHandle?: RouterHandle;
746
839
  routerContext?: RouteContext<T>;
747
- serverOptions?: ServerOpts;
748
- io?: boolean;
749
- ioOpts?: {
750
- routerHandle?: RouterHandle;
751
- routerContext?: RouteContext<T>;
752
- path?: string;
753
- };
840
+ serverOptions?: ServerNodeOpts;
754
841
  };
755
842
  type AppRouteContext<T = {}> = HandleCtx & RouteContext<T> & {
756
843
  app: App<T>;
@@ -761,8 +848,7 @@ type AppRouteContext<T = {}> = HandleCtx & RouteContext<T> & {
761
848
  */
762
849
  declare class App<U = {}> {
763
850
  router: QueryRouter;
764
- server: Server;
765
- io: WsServer;
851
+ server: ServerType;
766
852
  constructor(opts?: AppOptions<U>);
767
853
  listen(port: number, hostname?: string, backlog?: number, listeningListener?: () => void): void;
768
854
  listen(port: number, hostname?: string, listeningListener?: () => void): void;
@@ -825,5 +911,5 @@ declare class App<U = {}> {
825
911
  onServerRequest(fn: (req: IncomingMessage$1, res: ServerResponse$1) => void): void;
826
912
  }
827
913
 
828
- export { App, Connect, CustomError, Mini, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, Server, createSchema, define, handleServer, util };
829
- export type { RouteArray, RouteContext, RouteMiddleware, RouteObject, RouteOpts, Rule, Run, Schema };
914
+ export { App, Connect, CustomError, Mini, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, define, handleServer, util };
915
+ export type { RouteArray, RouteContext, RouteMiddleware, RouteObject, RouteOpts, RouterReq, RouterRes, Rule, Run, Schema };