insite-ws 2.2.3 → 2.3.1
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/bun.lock +1082 -0
- package/dist/client/WS.d.ts +40 -25
- package/dist/client/WS.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +4 -4
- package/dist/client/node/global.d.ts +5 -0
- package/dist/client/node/global.d.ts.map +1 -0
- package/dist/client/node/index.d.ts +3 -0
- package/dist/client/node/index.d.ts.map +1 -0
- package/dist/client/node/index.js +2 -0
- package/dist/client/node/index.js.map +7 -0
- package/dist/client/types.d.ts +19 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/common.d.ts +18 -5
- package/dist/common.d.ts.map +1 -1
- package/dist/server/WSServer.d.ts +17 -8
- package/dist/server/WSServer.d.ts.map +1 -1
- package/dist/server/WSServerClient.d.ts +22 -16
- package/dist/server/WSServerClient.d.ts.map +1 -1
- package/dist/server/common.d.ts +2 -0
- package/dist/server/common.d.ts.map +1 -0
- package/dist/server/index.js +1 -5
- package/dist/server/index.js.map +4 -4
- package/dist/server/symbols.d.ts +5 -1
- package/dist/server/symbols.d.ts.map +1 -1
- package/dist/server/types.d.ts +2 -1
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +39 -38
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type http from "node:http";
|
|
2
2
|
import type https from "node:https";
|
|
3
3
|
import { WebSocketServer } from "ws";
|
|
4
|
+
import { isQuietSymbol, requestListenersSymbol } from "./symbols";
|
|
4
5
|
import { WSServerClient } from "./WSServerClient";
|
|
5
6
|
import type { Options, RequestListener } from "./types";
|
|
6
7
|
export declare class WSServer<WSSC extends WSServerClient = WSServerClient> extends WebSocketServer<typeof WSServerClient> {
|
|
7
8
|
#private;
|
|
8
9
|
constructor(options: Options<WSSC>);
|
|
9
|
-
on(event: "connection", callback: (this:
|
|
10
|
-
on(event: "error", callback: (this:
|
|
11
|
-
on(event: "headers", callback: (this:
|
|
12
|
-
on(event: "close" | "listening", callback: (this:
|
|
13
|
-
on(event: "client-connect", listener: (this:
|
|
14
|
-
on(event: "client-error", listener: (this:
|
|
15
|
-
on(event: `client-${string}`, listener: (this:
|
|
16
|
-
on(event: string | symbol, listener: (this:
|
|
10
|
+
on(event: "connection", callback: (this: this, socket: WSSC, request: http.IncomingMessage) => void): this;
|
|
11
|
+
on(event: "error", callback: (this: this, error: Error) => void): this;
|
|
12
|
+
on(event: "headers", callback: (this: this, headers: string[], request: http.IncomingMessage) => void): this;
|
|
13
|
+
on(event: "close" | "listening", callback: (this: this) => void): this;
|
|
14
|
+
on(event: "client-connect", listener: (this: this, wscc: WSSC, request: http.IncomingMessage) => void): this;
|
|
15
|
+
on(event: "client-error", listener: (this: this, wscc: WSSC, error: Error | undefined) => void): this;
|
|
16
|
+
on(event: `client-${string}`, listener: (this: this, wscc: WSSC, ...args: any[]) => void): this;
|
|
17
|
+
on(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;
|
|
17
18
|
readonly isWebSocketServer = true;
|
|
18
19
|
readonly isWebSocketServerClient = false;
|
|
19
20
|
readonly isWebSocket = false;
|
|
@@ -22,9 +23,17 @@ export declare class WSServer<WSSC extends WSServerClient = WSServerClient> exte
|
|
|
22
23
|
get protocol(): string;
|
|
23
24
|
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | https.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
24
25
|
get isS(): boolean;
|
|
26
|
+
[isQuietSymbol]: boolean;
|
|
27
|
+
[requestListenersSymbol]: Map<string, RequestListener<WSSC>>;
|
|
25
28
|
addRequestListener(kind: string, listener: RequestListener<WSSC>): this;
|
|
29
|
+
/**
|
|
30
|
+
* Alias for `addRequestListener()`
|
|
31
|
+
*/
|
|
26
32
|
onRequest: (kind: string, listener: RequestListener<WSSC>) => this;
|
|
27
33
|
removeRequestListener(kind: string): this;
|
|
34
|
+
/**
|
|
35
|
+
* Alias for `removeRequestListener()`
|
|
36
|
+
*/
|
|
28
37
|
offRequest: (kind: string) => this;
|
|
29
38
|
static makeProps<SWSSC extends WSServerClient>({ ssl }: Options<SWSSC>): http.ServerOptions | https.ServerOptions;
|
|
30
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WSServer.d.ts","sourceRoot":"","sources":["../../src/server/WSServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"WSServer.d.ts","sourceRoot":"","sources":["../../src/server/WSServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAOrC,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAMxD,qBAAa,QAAQ,CAAC,IAAI,SAAS,cAAc,GAAG,cAAc,CAAE,SAAQ,eAAe,CAAC,OAAO,cAAc,CAAC;;gBACrG,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC;IA2ClC,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,eAAe,KAAK,IAAI,GAAG,IAAI;IAC1G,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,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AC,qCAA4C;IAEpE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC;IAMhE;;OAEG;IACH,SAAS,SATgB,MAAM,YAAY,eAAe,CAAC,IAAI,CAAC,UAS5B;IAEpC,qBAAqB,CAAC,IAAI,EAAE,MAAM;IAMlC;;OAEG;IACH,UAAU,SATkB,MAAM,UASM;IA4BxC,MAAM,CAAC,SAAS,CAAC,KAAK,SAAS,cAAc,EAAE,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa;CAMjH"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { ClientRequest, IncomingMessage } from "node:http";
|
|
2
2
|
import { RawData, WebSocket } from "ws";
|
|
3
|
-
import { defibSymbol, heartbeatIntervalSymbol,
|
|
3
|
+
import { defibSymbol, heartbeatIntervalSymbol, heartbeatTimeoutSymbol, heartbeatTsSymbol, requestCounterSymbol } from "./symbols";
|
|
4
4
|
import { WSServer } from "./WSServer";
|
|
5
|
-
export declare class WSServerClient
|
|
6
|
-
on(event: "close", listener: (this:
|
|
7
|
-
on(event: "error", listener: (this:
|
|
8
|
-
on(event: "upgrade", listener: (this:
|
|
9
|
-
on(event: "message", listener: (this:
|
|
10
|
-
on(event: "open", listener: (this:
|
|
11
|
-
on(event: "
|
|
12
|
-
on(event:
|
|
13
|
-
on(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this;
|
|
5
|
+
export declare class WSServerClient extends WebSocket {
|
|
6
|
+
on(event: "close", listener: (this: this, code: number, reason: Buffer) => void): this;
|
|
7
|
+
on(event: "error", listener: (this: this, error: Error) => void): this;
|
|
8
|
+
on(event: "upgrade", listener: (this: this, request: IncomingMessage) => void): this;
|
|
9
|
+
on(event: "message", listener: (this: this, data: RawData, isBinary: boolean) => void): this;
|
|
10
|
+
on(event: "open", listener: (this: this) => void): this;
|
|
11
|
+
on(event: "unexpected-response", listener: (this: this, request: ClientRequest, response: IncomingMessage) => void): this;
|
|
12
|
+
on(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;
|
|
14
13
|
get isConnecting(): boolean;
|
|
15
14
|
get isOpen(): boolean;
|
|
16
15
|
get isClosing(): boolean;
|
|
@@ -18,16 +17,23 @@ export declare class WSServerClient<WSSC extends WSServerClient = any> extends W
|
|
|
18
17
|
readonly isWebSocketServerClient = true;
|
|
19
18
|
readonly isWebSocketServer = false;
|
|
20
19
|
readonly isWebSocket = false;
|
|
21
|
-
wss: WSServer<
|
|
20
|
+
wss: WSServer<this>;
|
|
22
21
|
userAgent: string;
|
|
23
22
|
remoteAddress: string;
|
|
24
|
-
[
|
|
23
|
+
[heartbeatTimeoutSymbol]?: ReturnType<typeof setTimeout>;
|
|
24
|
+
[defibSymbol](): void;
|
|
25
25
|
latency: number;
|
|
26
|
-
[
|
|
26
|
+
[heartbeatTsSymbol]?: number;
|
|
27
27
|
[heartbeatIntervalSymbol]: NodeJS.Timeout;
|
|
28
28
|
sendMessage(...args: unknown[]): void;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
static makeHeartbeatInterval(this: WSServerClient
|
|
29
|
+
[requestCounterSymbol]: number;
|
|
30
|
+
sendRequest(...args: unknown[]): this | Promise<unknown>;
|
|
31
|
+
static makeHeartbeatInterval(this: WSServerClient): NodeJS.Timeout;
|
|
32
|
+
static extend(this: WSServerClient): void;
|
|
33
|
+
static handleConnect(this: WSServerClient): void;
|
|
34
|
+
static handleMessage(this: WSServerClient, data: RawData): void;
|
|
35
|
+
static handleRequest(this: WSServerClient, id: number, kind: string, ...rest: unknown[]): Promise<void>;
|
|
36
|
+
static handleError(this: WSServerClient, error: Error | Event | undefined): void;
|
|
37
|
+
static handleClose(this: WSServerClient, code: number, reason: Buffer): void;
|
|
32
38
|
}
|
|
33
39
|
//# sourceMappingURL=WSServerClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WSServerClient.d.ts","sourceRoot":"","sources":["../../src/server/WSServerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"WSServerClient.d.ts","sourceRoot":"","sources":["../../src/server/WSServerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAQxC,OAAO,EACN,WAAW,EACX,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EAEjB,oBAAoB,EAEpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMtC,qBAAa,cAAe,SAAQ,SAAS;IAC5C,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IACtF,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI;IACtE,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,KAAK,IAAI,GAAG,IAAI;IACpF,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAC5F,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,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EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE;IA4B7F,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS;IAezE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAqBrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/server/common.ts"],"names":[],"mappings":""}
|
package/dist/server/index.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import{WebSocketServer as
|
|
2
|
-
`).map(n=>`${o}${n}`).join(`
|
|
3
|
-
`)}function P(t){return!!t&&typeof t=="object"&&"errorResponse"in t&&!!t.errorResponse&&typeof t.errorResponse=="object"&&"errInfo"in t.errorResponse}function R(t){return P(t)&&t.errorResponse.errmsg==="Document failed validation"&&(t.message=`${t.errorResponse.errmsg}
|
|
4
|
-
${k(`failingDocumentId: ${t.errorResponse.errInfo?.failingDocumentId}
|
|
5
|
-
schemaRulesNotSatisfied: ${JSON.stringify(t.errorResponse.errInfo?.details?.schemaRulesNotSatisfied,null," ")}`," ")}`),t}function E(t,e,r,o,n=!0){return Array.isArray(t)&&(t=t.length),typeof o!="string"&&(n=o??!0,o=r),(n?`${t}\xA0`:"")+E.raw(t,e,r,o)}E.raw=(t,e,r,o=r)=>{t=Math.abs(t);let n=t%10,s=t%100;return n===1&&s!==11?e:n>=2&&n<=4&&!(s>=12&&s<=15)?r:o};function M(t="",e=""){return`${t}${Date.now().toString(36)}${Math.round(Math.random()*Number.MAX_SAFE_INTEGER).toString(36)}${e}`}import{createServer as N,getRemoteAddress as A,resolveSSL as L,showServerListeningMessage as T}from"insite-common/backend";var m={request:"~r-q",response:"~r-s"};var y=Symbol("heartbeatInterval"),d=Symbol("defib"),h=Symbol("pingTs");import{WebSocket as B}from"ws";var l=class t extends B{on(e,r){return super.on(e,r)}get isConnecting(){return this.readyState===this.CONNECTING}get isOpen(){return this.readyState===this.OPEN}get isClosing(){return this.readyState===this.CLOSING}get isClosed(){return this.readyState===this.CLOSED}isWebSocketServerClient=!0;isWebSocketServer=!1;isWebSocket=!1;wss;userAgent="";remoteAddress="";[d]=t.makeDefib.call(this);latency=0;[h];[y]=t.makeHeartbeatInterval.call(this);sendMessage(...e){return this.send(JSON.stringify(e))}sendRequest(...e){let r=M(),o=`message:${m.response}-${r}`;return typeof e.at(-1)=="function"?(this.once(o,e.splice(-1,1)[0]),this.sendMessage(m.request,r,...e),this):new Promise((n,s)=>{this.once(o,(i,f)=>{if(i){let{message:c,...S}=i;s(Object.assign(new Error(c),S))}else n(f)}),this.sendMessage(m.request,r,...e)})}static makeDefib(){return O(()=>this.terminate(),65e3)}static makeHeartbeatInterval(){return setInterval(()=>{this[h]=Date.now(),this.send("")},5e3)}};var j=class t extends D{constructor(e){let{ssl:r,port:o,server:n=N(t.makeProps(e)),...s}=e;super({WebSocket:l,...s,server:n}),this.server=n,e.server?new Promise(i=>void(n.listening?i():n.on("listening",i))).then(()=>T(this)):this.server.listen(typeof o=="string"?Number.parseInt(o):o??(this.isS?443:80),()=>T(this)),this.on("connection",this.#o),this.on(`client-message:${m.request}`,this.#r),this.on("error",i=>console.error(`${this.icon}\u2757\uFE0F WS Server:`,i)),this.on("close",()=>console.error(`${this.icon}\u2757\uFE0F WS Server closed`))}on(e,r){return super.on(e,r)}isWebSocketServer=!0;isWebSocketServerClient=!1;isWebSocket=!1;icon="\u{1F50C}";name="WS";get protocol(){return`ws${this.isS?"s":""}`}server;get isS(){return"setSecureContext"in this.server}#e=new Map;addRequestListener(e,r){return this.#e.set(e,r),this}onRequest=this.addRequestListener;removeRequestListener(e){return this.#e.delete(e),this}offRequest=this.removeRequestListener;#r=async(e,r,o,...n)=>{let s=this.#e.get(o),i,f=null;if(s)try{i=await s.call(this,e,...n)}catch(c){if(process.env.NODE_ENV==="development"&&R(c),c instanceof Error){let{message:S,...b}=c;f={message:S,...b}}process.env.NODE_ENV==="development"&&console.error(`${this.icon}\u2757\uFE0F WS Server request "${o}" (${r}):`,c)}else f={message:`Unknown request kind "${o}"`};e.sendMessage(`${m.response}-${r}`,f,i)};#o(e,r){if(!(e instanceof l)){Object.defineProperties(e,{isConnecting:{get:Object.getOwnPropertyDescriptor(l.prototype,"isConnecting").get},isOpen:{get:Object.getOwnPropertyDescriptor(l.prototype,"isOpen").get},isClosing:{get:Object.getOwnPropertyDescriptor(l.prototype,"isClosing").get},isClosed:{get:Object.getOwnPropertyDescriptor(l.prototype,"isClosed").get}});let{terminate:o}=e;Object.assign(e,{isWebSocketServerClient:!0,isWebSocketServer:!1,isWebSocket:!1,[d]:l.makeDefib.call(e),latency:0,[y]:l.makeHeartbeatInterval.call(e),sendMessage:l.prototype.sendMessage,sendRequest:l.prototype.sendRequest,terminate(){try{o.call(e)}catch(n){console.error(n)}}})}Object.assign(e,{wss:this,userAgent:r.headers["user-agent"]??"",remoteAddress:A(r)}),e[d](),e.on("message",o=>this.#n(e,o)),e.on("error",o=>this.#t(e,o)),e.on("close",(...o)=>this.#s(e,...o)),this.emit("client-connect",e,r),process.env.NODE_ENV==="development"&&console.info(`${this.icon} WS Server:`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m","connected")}#n(e,r){let o=r.toString();if(e[d](),o)try{let[n,...s]=JSON.parse(o);e.emit(`message:${n}`,...s),this.emit("client-message",e,n,...s),this.emit(`client-message:${n}`,e,...s)}catch(n){this.#t(e,n)}else e[h]&&(e.latency=Date.now()-e[h],delete e[h])}#t(e,r){r instanceof Event&&(r=void 0),console.error(`${this.icon}\u2757\uFE0F WS Server client`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m:`:"\x1B[3manonymous\x1B[0m:",r),this.emit("client-error",e,r)}#s(e,r,o){if(process.env.NODE_ENV==="development"){let n=o.toString();console.info(`${this.icon} WS Server:`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m",`disconnected ${r?`with code ${r}`:""} ${r&&n?"and ":""}${n?`reason "${n}"`:""}`)}e[d].clear(),clearInterval(e[y]),this.emit("client-close",e),this.emit("client-closed",e)}static makeProps({ssl:e}){return{...L(e)}}};export{j as WSServer,l as WSServerClient};
|
|
1
|
+
import{WebSocketServer as N}from"ws";import{createServer as x,getRemoteAddress as w,resolveSSL as k,showServerListeningMessage as O}from"insite-common/backend";var o=Symbol("isQuiet"),c=Symbol("requestListeners"),v=Symbol("heartbeatInterval"),p=Symbol("heartbeatTimeout"),S=Symbol("defib"),m=Symbol("heartbeatTs"),u=Symbol("requestCounter");import{WebSocket as T}from"ws";import{handleMongoError as W}from"@nesvet/n";var y=Number.MAX_SAFE_INTEGER/2,b={NORMAL:1e3,PROTOCOL_ERROR:1002,ABNORMAL:1006,NO_HEARTBEAT:3e3,OFFLINE:3001,MANUAL:3500,REOPEN:4e3},A=[b.PROTOCOL_ERROR,b.MANUAL,b.REOPEN],d={REQUEST:"~r-q",RESPONSE:"~r-s"};var h=class r extends T{on(e,t){return super.on(e,t)}get isConnecting(){return this.readyState===this.CONNECTING}get isOpen(){return this.readyState===this.OPEN}get isClosing(){return this.readyState===this.CLOSING}get isClosed(){return this.readyState===this.CLOSED}isWebSocketServerClient=!0;isWebSocketServer=!1;isWebSocket=!1;wss;userAgent="";remoteAddress="";[p];[S](){clearTimeout(this[p]),this[p]=setTimeout(()=>this.terminate(),35e3)}latency=0;[m];[v]=r.makeHeartbeatInterval.call(this);sendMessage(...e){return this.send(JSON.stringify(e))}[u]=0;sendRequest(...e){let t=this[u]++;this[u]>=y&&(this[u]=0);let s=`message:${d.RESPONSE}-${t}`;return typeof e.at(-1)=="function"?(this.once(s,e.splice(-1,1)[0]),this.sendMessage(d.REQUEST,t,...e),this):new Promise((i,l)=>{this.once(s,(a,n)=>{if(a){let{message:g,...E}=a;l(Object.assign(new Error(g),E))}else i(n)}),this.sendMessage(d.REQUEST,t,...e)})}static makeHeartbeatInterval(){return setInterval(()=>{this[m]=Date.now(),this.send("")},5e3)}static extend(){Object.defineProperties(this,{isConnecting:{get:Object.getOwnPropertyDescriptor(r.prototype,"isConnecting").get},isOpen:{get:Object.getOwnPropertyDescriptor(r.prototype,"isOpen").get},isClosing:{get:Object.getOwnPropertyDescriptor(r.prototype,"isClosing").get},isClosed:{get:Object.getOwnPropertyDescriptor(r.prototype,"isClosed").get}});let{terminate:e}=this;Object.assign(this,{isWebSocketServerClient:!0,isWebSocketServer:!1,isWebSocket:!1,[S]:r.prototype[S],latency:0,[v]:r.makeHeartbeatInterval.call(this),sendMessage:r.prototype.sendMessage,sendRequest:r.prototype.sendRequest,terminate(){try{e.call(this)}catch(t){console.error(t)}}})}static handleConnect(){this.on("message",r.handleMessage),this.on("error",r.handleError),this.on("close",r.handleClose),this[S]()}static handleMessage(e){let t=e.toString();if(this[S](),t)if(t==="?")this.send("!");else try{let[s,...i]=JSON.parse(t);switch(s){case d.REQUEST:r.handleRequest.call(this,...i);break;default:this.emit(`message:${s}`,...i),this.wss.emit("client-message",this,s,...i),this.wss.emit(`client-message:${s}`,this,...i)}}catch(s){r.handleError.call(this,s)}else this[m]&&(this.latency=Date.now()-this[m],this[m]=void 0)}static async handleRequest(e,t,...s){let i=this.wss[c].get(t),l,a=null;if(i)try{l=await i.call(this.wss,this,...s)}catch(n){if(process.env.NODE_ENV==="development"&&W(n),n instanceof Error){let{message:g,...E}=n;a={message:g,...E}}process.env.NODE_ENV==="development"&&!this.wss[o]&&console.error(`${this.wss.icon}\u2757\uFE0F WS Server request "${t}" (${e}):`,n)}else a={message:`Unknown request kind "${t}"`};this.sendMessage(`${d.RESPONSE}-${e}`,a,l)}static handleError(e){e instanceof Event&&(e=void 0),this.wss[o]||console.error(`${this.wss.icon}\u2757\uFE0F WS Server client`,"user"in this?`\x1B[1m${this.user.email}\x1B[0m:`:"\x1B[3manonymous\x1B[0m:",e),this.wss.emit("client-error",this,e)}static handleClose(e,t){if(process.env.NODE_ENV==="development"){let s=t.toString();this.wss[o]||console.info(`${this.wss.icon} WS Server:`,"user"in this?`\x1B[1m${this.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m",`disconnected ${e?`with code ${e}`:""} ${e&&s?"and ":""}${s?`reason "${s}"`:""}`)}clearTimeout(this[p]),clearInterval(this[v]),this.wss.emit("client-close",this),this.wss.emit("client-closed",this)}};var R=class r extends N{constructor(e){let{ssl:t,port:s,server:i=x(r.makeProps(e)),quiet:l=!1,...a}=e;super({WebSocket:h,...a,server:i}),this.server=i,e.server?new Promise(n=>void(i.listening?n():i.on("listening",n))).then(()=>O(this)):this.server.listen(typeof s=="string"?Number.parseInt(s):s??(this.isS?443:80),()=>O(this)),this[o]=l,this.on("connection",this.#e),this[o]||(this.on("error",n=>console.error(`${this.icon}\u2757\uFE0F WS Server:`,n)),this.on("close",()=>console.error(`${this.icon}\u2757\uFE0F WS Server closed`)))}on(e,t){return super.on(e,t)}isWebSocketServer=!0;isWebSocketServerClient=!1;isWebSocket=!1;icon="\u{1F50C}";name="WS";get protocol(){return`ws${this.isS?"s":""}`}server;get isS(){return"setSecureContext"in this.server}[o];[c]=new Map;addRequestListener(e,t){return this[c].set(e,t),this}onRequest=this.addRequestListener;removeRequestListener(e){return this[c].delete(e),this}offRequest=this.removeRequestListener;#e(e,t){e instanceof h||h.extend.call(e),Object.assign(e,{wss:this,userAgent:t.headers["user-agent"]??"",remoteAddress:w(t)}),h.handleConnect.call(e),this.emit("client-connect",e,t),process.env.NODE_ENV==="development"&&!this[o]&&console.info(`${this.icon} WS Server:`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m","connected")}static makeProps({ssl:e}){return{...k(e)}}};export{R as WSServer,h as WSServerClient};
|
|
6
2
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/server/WSServer.ts", "
|
|
4
|
-
"sourcesContent": ["import type http from \"node:http\";\nimport type https from \"node:https\";\nimport { WebSocketServer, type RawData, type WebSocket } from \"ws\";\nimport { handleMongoError } from \"@nesvet/n\";\nimport {\n\tcreateServer,\n\tgetRemoteAddress,\n\tresolveSSL,\n\tshowServerListeningMessage\n} from \"insite-common/backend\";\nimport { requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { WSServerClient } from \"./WSServerClient\";\nimport type { Options, RequestListener } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServer<WSSC extends WSServerClient = WSServerClient> extends WebSocketServer<typeof WSServerClient> {\n\tconstructor(options: Options<WSSC>) {\n\t\tconst {\n\t\t\tssl: _,\n\t\t\tport,\n\t\t\tserver = createServer(WSServer.makeProps(options)),\n\t\t\t...wssOptions\n\t\t} = options;\n\t\t\n\t\tsuper({\n\t\t\tWebSocket: WSServerClient<WSSC>,\n\t\t\t...wssOptions,\n\t\t\tserver\n\t\t});\n\t\t\n\t\tthis.server = server;\n\t\t\n\t\tif (options.server)\n\t\t\tnew Promise<void>(resolve => void (\n\t\t\t\tserver.listening ?\n\t\t\t\t\tresolve() :\n\t\t\t\t\tserver.on(\"listening\", resolve)\n\t\t\t)).then(() => showServerListeningMessage(this));\n\t\telse\n\t\t\tthis.server.listen(\n\t\t\t\ttypeof port == \"string\" ?\n\t\t\t\t\tNumber.parseInt(port) :\n\t\t\t\t\tport ?? (this.isS ? 443 : 80),\n\t\t\t\t() => showServerListeningMessage(this)\n\t\t\t);\n\t\t\n\t\tthis.on(\"connection\", this.#handleConnection);\n\t\t\n\t\tthis.on(`client-message:${requestHeaders.request}`, this.#handleRequest);\n\t\t\n\t\tthis.on(\"error\", (error: Error) => console.error(`${this.icon}\u2757\uFE0F WS Server:`, error));\n\t\t\n\t\tthis.on(\"close\", () => console.error(`${this.icon}\u2757\uFE0F WS Server closed`));\n\t\t\n\t}\n\t\n\ton(event: \"connection\", callback: (this: WSServer<WSSC>, socket: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"error\", callback: (this: WSServer<WSSC>, error: Error) => void): this;\n\ton(event: \"headers\", callback: (this: WSServer<WSSC>, headers: string[], request: http.IncomingMessage) => void): this;\n\ton(event: \"close\" | \"listening\", callback: (this: WSServer<WSSC>) => void): this;\n\t\n\ton(event: \"client-connect\", listener: (this: WSServer<WSSC>, wscc: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"client-error\", listener: (this: WSServer<WSSC>, wscc: WSSC, error: Error | undefined) => void): this;\n\ton(event: `client-${string}`, listener: (this: WSServer<WSSC>, wscc: WSSC, ...args: any[]) => void): this;\n\t\n\ton(event: string | symbol, listener: (this: WSServer<WSSC>, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: WSServer<WSSC>, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as unknown as (this: WebSocketServer, ...args: any[]) => void);\n\t}\n\t\n\treadonly isWebSocketServer = true;\n\treadonly isWebSocketServerClient = false;\n\treadonly isWebSocket = false;\n\t\n\ticon = \"\uD83D\uDD0C\";\n\tname = \"WS\";\n\tget protocol() {\n\t\treturn `ws${this.isS ? \"s\" : \"\"}`;\n\t}\n\t\n\tserver;\n\t\n\tget isS() {\n\t\treturn \"setSecureContext\" in this.server;\n\t}\n\t\n\t#requestListeners = new Map<string, RequestListener<WSSC>>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener<WSSC>) {\n\t\tthis.#requestListeners.set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\n\t\n\tonRequest = this.addRequestListener;\n\t\n\tremoveRequestListener(kind: string) {\n\t\tthis.#requestListeners.delete(kind);\n\t\t\n\t\treturn this;\n\t}\n\t\n\toffRequest = this.removeRequestListener;\n\t\n\t#handleRequest = async (wssc: WSSC, id: string, kind: string, ...rest: unknown[]) => {\n\t\tconst listener = this.#requestListeners.get(kind);\n\t\t\n\t\tlet result;\n\t\tlet requestError = null;\n\t\t\n\t\tif (listener)\n\t\t\ttry {\n\t\t\t\tresult = await listener.call(this, wssc, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\t\thandleMongoError(error);\n\t\t\t\t\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\trequestError = { message, ...restProps };\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\t\tconsole.error(`${this.icon}\u2757\uFE0F WS Server request \"${kind}\" (${id}):`, error);\n\t\t\t}\n\t\telse\n\t\t\trequestError = { message: `Unknown request kind \"${kind}\"` };\n\t\t\n\t\twssc.sendMessage(`${requestHeaders.response}-${id}`, requestError, result);\n\t\t\n\t};\n\t\n\t#handleConnection(wssc: WSSC, request: http.IncomingMessage) {\n\t\tif (!(wssc instanceof WSServerClient)) { /* Compatibility with Bun */\n\t\t\tObject.defineProperties(wssc, {\n\t\t\t\tisConnecting: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isConnecting\")!.get\n\t\t\t\t},\n\t\t\t\tisOpen: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isOpen\")!.get\n\t\t\t\t},\n\t\t\t\tisClosing: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosing\")!.get\n\t\t\t\t},\n\t\t\t\tisClosed: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosed\")!.get\n\t\t\t\t}\n\t\t\t});\n\t\t\t\n\t\t\tconst { terminate } = wssc as WebSocket;\n\t\t\t\n\t\t\tObject.assign(wssc, {\n\t\t\t\tisWebSocketServerClient: true,\n\t\t\t\tisWebSocketServer: false,\n\t\t\t\tisWebSocket: false,\n\t\t\t\t[defibSymbol]: WSServerClient.makeDefib.call(wssc),\n\t\t\t\tlatency: 0,\n\t\t\t\t[heartbeatIntervalSymbol]: WSServerClient.makeHeartbeatInterval.call(wssc),\n\t\t\t\tsendMessage: WSServerClient.prototype.sendMessage,\n\t\t\t\tsendRequest: WSServerClient.prototype.sendRequest,\n\t\t\t\tterminate() { /* Workaround Bun's WebSocket#terminate bug */\n\t\t\t\t\t\n\t\t\t\t\ttry {\n\t\t\t\t\t\tterminate.call(wssc);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error(error);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\t\n\t\tObject.assign(wssc, {\n\t\t\twss: this,\n\t\t\tuserAgent: request.headers[\"user-agent\"] ?? \"\",\n\t\t\tremoteAddress: getRemoteAddress(request)\n\t\t});\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\twssc.on(\"message\", data => this.#handleClientMessage(wssc, data));\n\t\twssc.on(\"error\", error => this.#handleClientError(wssc, error));\n\t\twssc.on(\"close\", (...args) => this.#handleClientClose(wssc, ...args));\n\t\t\n\t\tthis.emit(\"client-connect\", wssc, request);\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\"connected\"\n\t\t\t);\n\t\t\n\t\t\n\t}\n\t\n\t\n\t#handleClientMessage(wssc: WSSC, data: RawData) {\n\t\tconst message = data.toString();\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\tif (message)\n\t\t\ttry {\n\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\n\t\t\t\twssc.emit(`message:${kind}`, ...rest);\n\t\t\t\tthis.emit(\"client-message\", wssc, kind, ...rest);\n\t\t\t\tthis.emit(`client-message:${kind}`, wssc, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tthis.#handleClientError(wssc, error as Error);\n\t\t\t}\n\t\telse if (wssc[pingTsSymbol]) {\n\t\t\twssc.latency = Date.now() - wssc[pingTsSymbol];\n\t\t\tdelete wssc[pingTsSymbol];\n\t\t}\n\t\t\n\t}\n\t\n\t#handleClientError(wssc: WSSC, error: Error | Event | undefined) {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tconsole.error(\n\t\t\t`${this.icon}\u2757\uFE0F WS Server client`,\n\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m:` : \"\\x1B[3manonymous\\x1B[0m:\",\n\t\t\terror\n\t\t);\n\t\t\n\t\tthis.emit(\"client-error\", wssc, error);\n\t\t\n\t}\n\t\n\t#handleClientClose(wssc: WSSC, code: number, reason: Buffer) {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst reasonString = reason.toString();\n\t\t\t\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t`disconnected ${code ? `with code ${code}` : \"\"} ${code && reasonString ? \"and \" : \"\"}${reasonString ? `reason \"${reasonString}\"` : \"\"}`\n\t\t\t);\n\t\t}\n\t\t\n\t\twssc[defibSymbol].clear();\n\t\tclearInterval(wssc[heartbeatIntervalSymbol]);\n\t\t\n\t\tthis.emit(\"client-close\", wssc);\n\t\tthis.emit(\"client-closed\", wssc);\n\t\t\n\t}\n\t\n\t\n\tstatic makeProps<SWSSC extends WSServerClient>({ ssl }: Options<SWSSC>): http.ServerOptions | https.ServerOptions {\n\t\treturn {\n\t\t\t...resolveSSL(ssl)\n\t\t};\n\t}\n\t\n}\n", "export function noop() { /**/ }\n", "import { noop } from \"./noop.js\";\n\n\ntype Callback<Result> = (...args: unknown[]) => Result;\ntype FunctionOrBoolean = (() => unknown) | boolean;\ntype Options = { leading?: FunctionOrBoolean; maxWait?: number; trailing?: FunctionOrBoolean };\ntype NumberOrUndefined = number | undefined;\n\ntype DebouncedFunction<Result> = {\n\t(this: unknown, ..._args: unknown[]): Promise<Result>;\n};\n\nexport type Debounced<Result> = {\n\tcallback: Callback<Result>;\n\tpromise: {\n\t\tisResolved: boolean;\n\t} & Promise<unknown>;\n\tresolve: (value: Result) => void;\n\trun(): Promise<Result>;\n\tclear(shouldRun?: boolean): Promise<void>;\n} & DebouncedFunction<Result>;\n\n\nexport function debounce<Result>(callback: Callback<Result>, limit = 0, options: Options = {}) {\n\tlet { leading = false, trailing = true } = options;\n\tconst { maxWait = Infinity } = options;\n\t\n\tlet timeout: NumberOrUndefined;\n\tlet maxWaitTimeout: NumberOrUndefined;\n\tlet end: NumberOrUndefined;\n\tlet context: unknown;\n\tlet args: unknown[];\n\tlet initial: FunctionOrBoolean;\n\tlet final: FunctionOrBoolean;\n\tlet result: Result;\n\t\n\tconst expired = async () => {\n\t\t\n\t\tconst n = Date.now();\n\t\t\n\t\tif (n >= end!) {\n\t\t\ttimeout = undefined;\n\t\t\tend = undefined;\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\tif (typeof final == \"function\")\n\t\t\t\tawait final();\n\t\t\tdebounced.resolve(result);\n\t\t\tdebounced.promise.isResolved = true;\n\t\t\tinitial = leading;\n\t\t} else {\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = setTimeout(expired, end! - n);\n\t\t}\n\t\t\n\t};\n\t\n\tconst maxWaitExpired = Number.isFinite(maxWait) ? () => {\n\t\t\n\t\tif (final === run)\n\t\t\tfinal = false;\n\t\trun();\n\t\tmaxWaitTimeout = setTimeout(maxWaitExpired as TimerHandler, maxWait);\n\t\t\n\t} : null;\n\t\n\tasync function run() {\n\t\treturn (result = await callback.apply(context, args));\n\t}\n\t\n\tif (leading && typeof leading == \"boolean\")\n\t\tleading = run;\n\tinitial = leading;\n\t\n\tif (trailing && typeof trailing == \"boolean\")\n\t\ttrailing = run;\n\tfinal = trailing;\n\t\n\tconst debounced: Debounced<Result> = Object.assign(function (..._args) {\n\t\targs = _args;\n\t\tcontext = this;// eslint-disable-line no-invalid-this\n\t\t\n\t\tend = Date.now() + limit;\n\t\tfinal = trailing;\n\t\t\n\t\tif (debounced.promise.isResolved)\n\t\t\tdebounced.promise = Object.assign(new Promise(resolve => {\n\t\t\t\tdebounced.resolve = resolve;\n\t\t\t\t\n\t\t\t\tif (typeof initial == \"function\") {\n\t\t\t\t\tinitial();\n\t\t\t\t\tinitial = false;\n\t\t\t\t\tif (final === run)\n\t\t\t\t\t\tfinal = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (!timeout) {\n\t\t\t\t\ttimeout = setTimeout(expired, limit);\n\t\t\t\t\tif (maxWaitExpired)\n\t\t\t\t\t\tmaxWaitTimeout = setTimeout(maxWaitExpired, maxWait);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}), {\n\t\t\t\tisResolved: false\n\t\t\t});\n\t\t\n\t\treturn debounced.promise;\n\t} as DebouncedFunction<Result>, {\n\t\tcallback,\n\t\tpromise: Object.assign(Promise.resolve(), {\n\t\t\tisResolved: true\n\t\t}),\n\t\tresolve: noop,\n\t\trun,\n\t\tclear: async (shouldRun?: boolean) => {\n\t\t\t\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = undefined;\n\t\t\t\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\t\n\t\t\tdebounced.promise.isResolved = true;\n\t\t\tdebounced.resolve(shouldRun ? await run() : result);\n\t\t\t\n\t\t}\n\t});\n\t\n\treturn debounced;\n}\n\n\ndebounce.noop = Object.assign(() => { /**/ }, {\n\tcallback: noop,\n\tpromise: Object.assign(Promise.resolve(), {\n\t\tisResolved: true\n\t}),\n\tresolve: noop,\n\trun: noop,\n\tclear: noop\n}) as unknown as Debounced<void>;\n\n\nexport function throttle<Result>(callback: Callback<Result>, limit?: number, options?: Options) {\n\treturn debounce(callback, limit, {\n\t\tmaxWait: limit,\n\t\tleading: true,\n\t\ttrailing: true,\n\t\t...options\n\t});\n}\n", "export function indent(string: string, indentation: string = \"\\t\", times: number = 1): string {\n\tif (!string)\n\t\treturn string;\n\t\n\tconst prefix = indentation.repeat(times);\n\t\n\treturn string.split(\"\\n\").map(line => `${prefix}${line}`).join(\"\\n\");\n}\n", "import { indent } from \"./indent.js\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\ntype MongoServerError = {\n\terrorResponse: {\n\t\terrmsg: string;\n\t\terrInfo?: {\n\t\t\t[key: string]: any;\n\t\t};\n\t};\n\t[key: string]: any;\n};\n\nfunction isMongoServerError(error: unknown): error is MongoServerError {\n\treturn (\n\t\t!!error &&\n\t\ttypeof error == \"object\" &&\n\t\t\"errorResponse\" in error &&\n\t\t!!error.errorResponse &&\n\t\ttypeof error.errorResponse == \"object\" &&\n\t\t\"errInfo\" in error.errorResponse\n\t);\n}\n\nexport function handleMongoError<E extends MongoServerError>(error: E): E;\nexport function handleMongoError(error: any): any;\nexport function handleMongoError(error: any) {\n\tif (isMongoServerError(error) && error.errorResponse.errmsg === \"Document failed validation\")\n\t\terror.message = `${error.errorResponse.errmsg}\\n${indent(`failingDocumentId: ${error.errorResponse.errInfo?.failingDocumentId}\\nschemaRulesNotSatisfied: ${JSON.stringify(error.errorResponse.errInfo?.details?.schemaRulesNotSatisfied, null, \" \")}`, \" \")}`;\n\t\n\treturn error;\n}\n", "export function howmuch(number: [] | number, one: string, two: string, five: boolean | string, shouldPrintNumber = true) {\n\tif (Array.isArray(number))\n\t\tnumber = number.length;\n\t\n\tif (typeof five != \"string\") {\n\t\tshouldPrintNumber = five ?? true;\n\t\tfive = two;\n\t}\n\t\n\t\n\treturn (shouldPrintNumber ? `${number}\u00A0` : \"\") + howmuch.raw(number, one, two, five);\n}\n\nhowmuch.raw = (number: number, one: string, two: string, five = two) => {\n\tnumber = Math.abs(number);\n\tconst u = number % 10;\n\tconst d = number % 100;\n\t\n\treturn (\n\t\t(u === 1 && d !== 11) ?\n\t\t\tone :\n\t\t\t((u >= 2 && u <= 4) && !(d >= 12 && d <= 15)) ?\n\t\t\t\ttwo :\n\t\t\t\tfive\n\t);\n};\n", "export function uid(prefix: string | undefined = \"\", postfix: string | undefined = \"\") {\n\treturn `${prefix}${Date.now().toString(36)}${Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36)}${postfix}`;\n}\n", "export const heartbeatInterval = 5_000;\nexport const heartbeatGap = 60_000;\n\nexport const requestHeaders = {\n\trequest: \"~r-q\",\n\tresponse: \"~r-s\"\n};\n", "export const heartbeatIntervalSymbol = Symbol(\"heartbeatInterval\");\nexport const defibSymbol = Symbol(\"defib\");\nexport const pingTsSymbol = Symbol(\"pingTs\");\n", "import { ClientRequest, IncomingMessage } from \"node:http\";\nimport { RawData, WebSocket } from \"ws\";\nimport { debounce, uid } from \"@nesvet/n\";\nimport { heartbeatGap, heartbeatInterval, requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { WSServer } from \"./WSServer\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServerClient<WSSC extends WSServerClient = any> extends WebSocket {\n\ton(event: \"close\", listener: (this: WSSC, code: number, reason: Buffer) => void): this;\n\ton(event: \"error\", listener: (this: WSSC, error: Error) => void): this;\n\ton(event: \"upgrade\", listener: (this: WSSC, request: IncomingMessage) => void): this;\n\ton(event: \"message\", listener: (this: WSSC, data: RawData, isBinary: boolean) => void): this;\n\ton(event: \"open\", listener: (this: WSSC) => void): this;\n\ton(event: \"ping\" | \"pong\", listener: (this: WSSC, data: Buffer) => void): this;\n\ton(event: \"unexpected-response\", listener: (this: WSSC, request: ClientRequest, response: IncomingMessage) => void): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocket, ...args: any[]) => void);\n\t}\n\t\n\tget isConnecting() {\n\t\treturn this.readyState === this.CONNECTING;\n\t}\n\t\n\tget isOpen() {\n\t\treturn this.readyState === this.OPEN;\n\t}\n\t\n\tget isClosing() {\n\t\treturn this.readyState === this.CLOSING;\n\t}\n\t\n\tget isClosed() {\n\t\treturn this.readyState === this.CLOSED;\n\t}\n\t\n\treadonly isWebSocketServerClient = true;\n\treadonly isWebSocketServer = false;\n\treadonly isWebSocket = false;\n\t\n\twss!: WSServer<WSSC>;\n\t\n\tuserAgent = \"\";\n\t\n\tremoteAddress = \"\";\n\t\n\t[defibSymbol] = WSServerClient.makeDefib.call(this);\n\t\n\tlatency = 0;\n\t\n\t[pingTsSymbol]?: number;\n\t\n\t[heartbeatIntervalSymbol] = WSServerClient.makeHeartbeatInterval.call(this);\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = uid();\n\t\tconst eventName = `message:${requestHeaders.response}-${id}`;\n\t\t\n\t\tif (typeof args.at(-1) == \"function\") {\n\t\t\tthis.once(eventName, args.splice(-1, 1)[0] as () => void);\n\t\t\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t\treturn this;\n\t\t}\n\t\t\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t\n\t\t\tthis.once(eventName, (error, result) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\treject(Object.assign(new Error(message), restProps));\n\t\t\t\t} else\n\t\t\t\t\tresolve(result);\n\t\t\t\t\n\t\t\t});\n\t\t\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t\n\tstatic makeDefib(this: WSServerClient<any>) {\n\t\treturn debounce(() => this.terminate(), heartbeatInterval + heartbeatGap);\n\t}\n\t\n\tstatic makeHeartbeatInterval(this: WSServerClient<any>) {\n\t\treturn setInterval(() => {\n\t\t\t\n\t\t\tthis[pingTsSymbol] = Date.now();\n\t\t\tthis.send(\"\");\n\t\t\t\n\t\t}, heartbeatInterval);\n\t}\n\t\n}\n"],
|
|
5
|
-
"mappings": "AAEA,OAAS,mBAAAA,
|
|
6
|
-
"names": ["WebSocketServer", "
|
|
3
|
+
"sources": ["../../src/server/WSServer.ts", "../../src/server/symbols.ts", "../../src/server/WSServerClient.ts", "../../src/common.ts"],
|
|
4
|
+
"sourcesContent": ["import type http from \"node:http\";\nimport type https from \"node:https\";\nimport { WebSocketServer } from \"ws\";\nimport {\n\tcreateServer,\n\tgetRemoteAddress,\n\tresolveSSL,\n\tshowServerListeningMessage\n} from \"insite-common/backend\";\nimport { isQuietSymbol, requestListenersSymbol } from \"./symbols\";\nimport { WSServerClient } from \"./WSServerClient\";\nimport type { Options, RequestListener } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServer<WSSC extends WSServerClient = WSServerClient> extends WebSocketServer<typeof WSServerClient> {\n\tconstructor(options: Options<WSSC>) {\n\t\tconst {\n\t\t\tssl: _,\n\t\t\tport,\n\t\t\tserver = createServer(WSServer.makeProps(options)),\n\t\t\tquiet = false,\n\t\t\t...wssOptions\n\t\t} = options;\n\t\t\n\t\tsuper({\n\t\t\tWebSocket: WSServerClient,\n\t\t\t...wssOptions,\n\t\t\tserver\n\t\t});\n\t\t\n\t\tthis.server = server;\n\t\t\n\t\tif (options.server)\n\t\t\tvoid new Promise<void>(resolve => void (\n\t\t\t\tserver.listening ?\n\t\t\t\t\tresolve() :\n\t\t\t\t\tserver.on(\"listening\", resolve)\n\t\t\t)).then(() => showServerListeningMessage(this));\n\t\telse\n\t\t\tthis.server.listen(\n\t\t\t\ttypeof port == \"string\" ?\n\t\t\t\t\tNumber.parseInt(port) :\n\t\t\t\t\tport ?? (this.isS ? 443 : 80),\n\t\t\t\t() => showServerListeningMessage(this)\n\t\t\t);\n\t\t\n\t\tthis[isQuietSymbol] = quiet;\n\t\t\n\t\tthis.on(\"connection\", this.#handleConnection);\n\t\t\n\t\tif (!this[isQuietSymbol]) {\n\t\t\tthis.on(\"error\", (error: Error) => console.error(`${this.icon}\u2757\uFE0F WS Server:`, error));\n\t\t\t\n\t\t\tthis.on(\"close\", () => console.error(`${this.icon}\u2757\uFE0F WS Server closed`));\n\t\t}\n\t\t\n\t}\n\t\n\ton(event: \"connection\", callback: (this: this, socket: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"error\", callback: (this: this, error: Error) => void): this;\n\ton(event: \"headers\", callback: (this: this, headers: string[], request: http.IncomingMessage) => void): this;\n\ton(event: \"close\" | \"listening\", callback: (this: this) => void): this;\n\t\n\ton(event: \"client-connect\", listener: (this: this, wscc: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"client-error\", listener: (this: this, wscc: WSSC, error: Error | undefined) => void): this;\n\ton(event: `client-${string}`, listener: (this: this, wscc: WSSC, ...args: any[]) => void): this;\n\t\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocketServer, ...args: any[]) => void);\n\t}\n\t\n\treadonly isWebSocketServer = true;\n\treadonly isWebSocketServerClient = false;\n\treadonly isWebSocket = false;\n\t\n\ticon = \"\uD83D\uDD0C\";\n\tname = \"WS\";\n\tget protocol() {\n\t\treturn `ws${this.isS ? \"s\" : \"\"}`;\n\t}\n\t\n\tserver;\n\t\n\tget isS() {\n\t\treturn \"setSecureContext\" in this.server;\n\t}\n\t\n\t[isQuietSymbol]: boolean;\n\t\n\t[requestListenersSymbol] = new Map<string, RequestListener<WSSC>>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener<WSSC>) {\n\t\tthis[requestListenersSymbol].set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t * Alias for `addRequestListener()`\n\t */\n\tonRequest = this.addRequestListener;\n\t\n\tremoveRequestListener(kind: string) {\n\t\tthis[requestListenersSymbol].delete(kind);\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t * Alias for `removeRequestListener()`\n\t */\n\toffRequest = this.removeRequestListener;\n\t\n\t#handleConnection(wssc: WSSC, request: http.IncomingMessage) {\n\t\t\n\t\t/* Compatibility with Bun */\n\t\tif (!(wssc instanceof WSServerClient))\n\t\t\tWSServerClient.extend.call(wssc);\n\t\t\n\t\tObject.assign(wssc, {\n\t\t\twss: this,\n\t\t\tuserAgent: request.headers[\"user-agent\"] ?? \"\",\n\t\t\tremoteAddress: getRemoteAddress(request)\n\t\t});\n\t\t\n\t\tWSServerClient.handleConnect.call(wssc);\n\t\t\n\t\tthis.emit(\"client-connect\", wssc, request);\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\" && !this[isQuietSymbol])\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\"connected\"\n\t\t\t);\n\t\t\n\t}\n\t\n\t\n\tstatic makeProps<SWSSC extends WSServerClient>({ ssl }: Options<SWSSC>): http.ServerOptions | https.ServerOptions {\n\t\treturn {\n\t\t\t...resolveSSL(ssl)\n\t\t};\n\t}\n\t\n}\n", "export const isQuietSymbol = Symbol(\"isQuiet\");\nexport const requestListenersSymbol = Symbol(\"requestListeners\");\nexport const heartbeatIntervalSymbol = Symbol(\"heartbeatInterval\");\nexport const heartbeatTimeoutSymbol = Symbol(\"heartbeatTimeout\");\nexport const defibSymbol = Symbol(\"defib\");\nexport const heartbeatTsSymbol = Symbol(\"heartbeatTs\");\nexport const requestCounterSymbol = Symbol(\"requestCounter\");\n", "import { ClientRequest, IncomingMessage } from \"node:http\";\nimport { RawData, WebSocket } from \"ws\";\nimport { handleMongoError } from \"@nesvet/n\";\nimport {\n\tHEARTBEAT_GAP,\n\tHEARTBEAT_INTERVAL,\n\tREQUEST_COUNTER_LIMIT,\n\tREQUEST_HEADERS\n} from \"../common\";\nimport {\n\tdefibSymbol,\n\theartbeatIntervalSymbol,\n\theartbeatTimeoutSymbol,\n\theartbeatTsSymbol,\n\tisQuietSymbol,\n\trequestCounterSymbol,\n\trequestListenersSymbol\n} from \"./symbols\";\nimport { WSServer } from \"./WSServer\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServerClient extends WebSocket {\n\ton(event: \"close\", listener: (this: this, code: number, reason: Buffer) => void): this;\n\ton(event: \"error\", listener: (this: this, error: Error) => void): this;\n\ton(event: \"upgrade\", listener: (this: this, request: IncomingMessage) => void): this;\n\ton(event: \"message\", listener: (this: this, data: RawData, isBinary: boolean) => void): this;\n\ton(event: \"open\", listener: (this: this) => void): this;\n\ton(event: \"unexpected-response\", listener: (this: this, request: ClientRequest, response: IncomingMessage) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocket, ...args: any[]) => void);\n\t}\n\t\n\tget isConnecting() {\n\t\treturn this.readyState === this.CONNECTING;\n\t}\n\t\n\tget isOpen() {\n\t\treturn this.readyState === this.OPEN;\n\t}\n\t\n\tget isClosing() {\n\t\treturn this.readyState === this.CLOSING;\n\t}\n\t\n\tget isClosed() {\n\t\treturn this.readyState === this.CLOSED;\n\t}\n\t\n\treadonly isWebSocketServerClient = true;\n\treadonly isWebSocketServer = false;\n\treadonly isWebSocket = false;\n\t\n\twss!: WSServer<this>;\n\t\n\tuserAgent = \"\";\n\t\n\tremoteAddress = \"\";\n\t\n\t[heartbeatTimeoutSymbol]?: ReturnType<typeof setTimeout>;\n\t\n\t[defibSymbol]() {\n\t\t\n\t\tclearTimeout(this[heartbeatTimeoutSymbol]);\n\t\t\n\t\tthis[heartbeatTimeoutSymbol] = setTimeout(\n\t\t\t() => this.terminate(),\n\t\t\tHEARTBEAT_INTERVAL + HEARTBEAT_GAP\n\t\t);\n\t\t\n\t}\n\t\n\tlatency = 0;\n\t\n\t[heartbeatTsSymbol]?: number;\n\t\n\t[heartbeatIntervalSymbol] = WSServerClient.makeHeartbeatInterval.call(this);\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\t[requestCounterSymbol]: number = 0;\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = this[requestCounterSymbol]++;\n\t\t\n\t\tif (this[requestCounterSymbol] >= REQUEST_COUNTER_LIMIT)\n\t\t\tthis[requestCounterSymbol] = 0;\n\t\t\n\t\tconst eventName = `message:${REQUEST_HEADERS.RESPONSE}-${id}`;\n\t\t\n\t\tif (typeof args.at(-1) == \"function\") {\n\t\t\tthis.once(eventName, args.splice(-1, 1)[0] as () => void);\n\t\t\t\n\t\t\tthis.sendMessage(REQUEST_HEADERS.REQUEST, id, ...args);\n\t\t\t\n\t\t\treturn this;\n\t\t}\n\t\t\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t\n\t\t\tthis.once(eventName, (error, result) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\treject(Object.assign(new Error(message), restProps) as Error);\n\t\t\t\t} else\n\t\t\t\t\tresolve(result);\n\t\t\t\t\n\t\t\t});\n\t\t\t\n\t\t\tthis.sendMessage(REQUEST_HEADERS.REQUEST, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t\n\tstatic makeHeartbeatInterval(this: WSServerClient) {\n\t\treturn setInterval(() => {\n\t\t\t\n\t\t\tthis[heartbeatTsSymbol] = Date.now();\n\t\t\t\n\t\t\tthis.send(\"\");\n\t\t\t\n\t\t}, HEARTBEAT_INTERVAL);\n\t}\n\t\n\t/* Compatibility with Bun */\n\tstatic extend(this: WSServerClient) {\n\t\t\n\t\tObject.defineProperties(this, {\n\t\t\tisConnecting: {\n\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isConnecting\")!.get\n\t\t\t},\n\t\t\tisOpen: {\n\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isOpen\")!.get\n\t\t\t},\n\t\t\tisClosing: {\n\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosing\")!.get\n\t\t\t},\n\t\t\tisClosed: {\n\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosed\")!.get\n\t\t\t}\n\t\t});\n\t\t\n\t\tconst { terminate } = this;\n\t\t\n\t\tObject.assign(this, {\n\t\t\tisWebSocketServerClient: true,\n\t\t\tisWebSocketServer: false,\n\t\t\tisWebSocket: false,\n\t\t\t[defibSymbol]: WSServerClient.prototype[defibSymbol],\n\t\t\tlatency: 0,\n\t\t\t[heartbeatIntervalSymbol]: WSServerClient.makeHeartbeatInterval.call(this),\n\t\t\tsendMessage: WSServerClient.prototype.sendMessage,\n\t\t\tsendRequest: WSServerClient.prototype.sendRequest,\n\t\t\tterminate() { /* Workaround Bun's WebSocket#terminate bug */\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tterminate.call(this);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t});\n\t\t\n\t}\n\t\n\tstatic handleConnect(this: WSServerClient) {\n\t\t\n\t\tthis.on(\"message\", WSServerClient.handleMessage);\n\t\tthis.on(\"error\", WSServerClient.handleError);\n\t\tthis.on(\"close\", WSServerClient.handleClose);\n\t\t\n\t\tthis[defibSymbol]();\n\t\t\n\t}\n\t\n\tstatic handleMessage(this: WSServerClient, data: RawData) {\n\t\tconst message = data.toString();// eslint-disable-line @typescript-eslint/no-base-to-string\n\t\t\n\t\tthis[defibSymbol]();\n\t\t\n\t\tif (message)\n\t\t\tif (message === \"?\")\n\t\t\t\tthis.send(\"!\");\n\t\t\telse\n\t\t\t\ttry {\n\t\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\t\n\t\t\t\t\tswitch (kind) {\n\t\t\t\t\t\tcase REQUEST_HEADERS.REQUEST:\n\t\t\t\t\t\t\tvoid WSServerClient.handleRequest.call(this, ...rest as [ id: number, kind: string, ...rest: unknown[] ]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthis.emit(`message:${kind}`, ...rest);\n\t\t\t\t\t\t\tthis.wss.emit(\"client-message\", this, kind, ...rest);\n\t\t\t\t\t\t\tthis.wss.emit(`client-message:${kind}`, this, ...rest);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tWSServerClient.handleError.call(this, error as Error);\n\t\t\t\t}\n\t\telse if (this[heartbeatTsSymbol]) {\n\t\t\tthis.latency = Date.now() - this[heartbeatTsSymbol];\n\t\t\tthis[heartbeatTsSymbol] = undefined;\n\t\t}\n\t\t\n\t}\n\t\n\tstatic async handleRequest(this: WSServerClient, id: number, kind: string, ...rest: unknown[]) {\n\t\tconst listener = this.wss[requestListenersSymbol].get(kind);\n\t\t\n\t\tlet result;\n\t\tlet requestError = null;\n\t\t\n\t\tif (listener)\n\t\t\ttry {\n\t\t\t\tresult = await listener.call(this.wss, this, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\t\thandleMongoError(error);\n\t\t\t\t\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\trequestError = { message, ...restProps };\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (process.env.NODE_ENV === \"development\" && !this.wss[isQuietSymbol])\n\t\t\t\t\tconsole.error(`${this.wss.icon}\u2757\uFE0F WS Server request \"${kind}\" (${id}):`, error);\n\t\t\t}\n\t\telse\n\t\t\trequestError = { message: `Unknown request kind \"${kind}\"` };\n\t\t\n\t\tthis.sendMessage(`${REQUEST_HEADERS.RESPONSE}-${id}`, requestError, result);\n\t\t\n\t}\n\t\n\tstatic handleError(this: WSServerClient, error: Error | Event | undefined) {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tif (!this.wss[isQuietSymbol])\n\t\t\tconsole.error(\n\t\t\t\t`${this.wss.icon}\u2757\uFE0F WS Server client`,\n\t\t\t\t\"user\" in this ? `\\x1B[1m${(this.user as { email: string }).email}\\x1B[0m:` : \"\\x1B[3manonymous\\x1B[0m:\",\n\t\t\t\terror\n\t\t\t);\n\t\t\n\t\tthis.wss.emit(\"client-error\", this, error);\n\t\t\n\t}\n\t\n\tstatic handleClose(this: WSServerClient, code: number, reason: Buffer) {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst reasonString = reason.toString();\n\t\t\t\n\t\t\tif (!this.wss[isQuietSymbol])\n\t\t\t\tconsole.info(\n\t\t\t\t\t`${this.wss.icon} WS Server:`,\n\t\t\t\t\t\"user\" in this ? `\\x1B[1m${(this.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\t`disconnected ${code ? `with code ${code}` : \"\"} ${code && reasonString ? \"and \" : \"\"}${reasonString ? `reason \"${reasonString}\"` : \"\"}`\n\t\t\t\t);\n\t\t}\n\t\t\n\t\tclearTimeout(this[heartbeatTimeoutSymbol]);\n\t\tclearInterval(this[heartbeatIntervalSymbol]);\n\t\t\n\t\tthis.wss.emit(\"client-close\", this);\n\t\tthis.wss.emit(\"client-closed\", this);\n\t\t\n\t}\n\t\n}\n", "export const HEARTBEAT_INTERVAL = 5_000;\nexport const HEARTBEAT_GAP = 30_000;\nexport const RESPONSIVENESS_TIMEOUT = 1000;\nexport const OFFLINE_TIMEOUT = 5000;\nexport const REQUEST_COUNTER_LIMIT = Number.MAX_SAFE_INTEGER / 2;\n\nexport const CODES = {\n\tNORMAL: 1000,\n\tPROTOCOL_ERROR: 1002,\n\tABNORMAL: 1006,\n\tNO_HEARTBEAT: 3000,\n\tOFFLINE: 3001,\n\tMANUAL: 3500,\n\tREOPEN: 4000\n} as const;\n\nexport const NON_RECONNECTABLE_CODES = [\n\tCODES.PROTOCOL_ERROR,\n\tCODES.MANUAL,\n\tCODES.REOPEN\n];\n\nexport const REQUEST_HEADERS = {\n\tREQUEST: \"~r-q\",\n\tRESPONSE: \"~r-s\"\n};\n"],
|
|
5
|
+
"mappings": "AAEA,OAAS,mBAAAA,MAAuB,KAChC,OACC,gBAAAC,EACA,oBAAAC,EACA,cAAAC,EACA,8BAAAC,MACM,wBCRA,IAAMC,EAAgB,OAAO,SAAS,EAChCC,EAAyB,OAAO,kBAAkB,EAClDC,EAA0B,OAAO,mBAAmB,EACpDC,EAAyB,OAAO,kBAAkB,EAClDC,EAAc,OAAO,OAAO,EAC5BC,EAAoB,OAAO,aAAa,EACxCC,EAAuB,OAAO,gBAAgB,ECL3D,OAAkB,aAAAC,MAAiB,KACnC,OAAS,oBAAAC,MAAwB,YCE1B,IAAMC,EAAwB,OAAO,iBAAmB,EAElDC,EAAQ,CACpB,OAAQ,IACR,eAAgB,KAChB,SAAU,KACV,aAAc,IACd,QAAS,KACT,OAAQ,KACR,OAAQ,GACT,EAEaC,EAA0B,CACtCD,EAAM,eACNA,EAAM,OACNA,EAAM,MACP,EAEaE,EAAkB,CAC9B,QAAS,OACT,SAAU,MACX,EDDO,IAAMC,EAAN,MAAMC,UAAuBC,CAAU,CAQ7C,GAAGC,EAAwBC,EAAsD,CAChF,OAAO,MAAM,GAAGD,EAAOC,CAAqD,CAC7E,CAEA,IAAI,cAAe,CAClB,OAAO,KAAK,aAAe,KAAK,UACjC,CAEA,IAAI,QAAS,CACZ,OAAO,KAAK,aAAe,KAAK,IACjC,CAEA,IAAI,WAAY,CACf,OAAO,KAAK,aAAe,KAAK,OACjC,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essage", "isQuietSymbol", "requestListenersSymbol", "heartbeatIntervalSymbol", "heartbeatTimeoutSymbol", "defibSymbol", "heartbeatTsSymbol", "requestCounterSymbol", "WebSocket", "handleMongoError", "REQUEST_COUNTER_LIMIT", "CODES", "NON_RECONNECTABLE_CODES", "REQUEST_HEADERS", "WSServerClient", "_WSServerClient", "WebSocket", "event", "listener", "heartbeatTimeoutSymbol", "defibSymbol", "heartbeatTsSymbol", "heartbeatIntervalSymbol", "args", "requestCounterSymbol", "id", "REQUEST_COUNTER_LIMIT", "eventName", "REQUEST_HEADERS", "resolve", "reject", "error", "result", "message", "restProps", "terminate", "data", "kind", "rest", "requestListenersSymbol", "requestError", "handleMongoError", "isQuietSymbol", "code", "reason", "reasonString", "WSServer", "_WSServer", "WebSocketServer", "options", "_", "port", "server", "createServer", "quiet", "wssOptions", "WSServerClient", "resolve", "showServerListeningMessage", "isQuietSymbol", "#handleConnection", "error", "event", "listener", "requestListenersSymbol", "kind", "wssc", "request", "getRemoteAddress", "ssl", "resolveSSL"]
|
|
7
7
|
}
|
package/dist/server/symbols.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export declare const isQuietSymbol: unique symbol;
|
|
2
|
+
export declare const requestListenersSymbol: unique symbol;
|
|
1
3
|
export declare const heartbeatIntervalSymbol: unique symbol;
|
|
4
|
+
export declare const heartbeatTimeoutSymbol: unique symbol;
|
|
2
5
|
export declare const defibSymbol: unique symbol;
|
|
3
|
-
export declare const
|
|
6
|
+
export declare const heartbeatTsSymbol: unique symbol;
|
|
7
|
+
export declare const requestCounterSymbol: unique symbol;
|
|
4
8
|
//# sourceMappingURL=symbols.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../../src/server/symbols.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,eAA8B,CAAC;AACnE,eAAO,MAAM,WAAW,eAAkB,CAAC;AAC3C,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../../src/server/symbols.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,eAAoB,CAAC;AAC/C,eAAO,MAAM,sBAAsB,eAA6B,CAAC;AACjE,eAAO,MAAM,uBAAuB,eAA8B,CAAC;AACnE,eAAO,MAAM,sBAAsB,eAA6B,CAAC;AACjE,eAAO,MAAM,WAAW,eAAkB,CAAC;AAC3C,eAAO,MAAM,iBAAiB,eAAwB,CAAC;AACvD,eAAO,MAAM,oBAAoB,eAA2B,CAAC"}
|
package/dist/server/types.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ export type Options<WSSC extends WSServerClient> = Omit<ServerOptions<typeof WSS
|
|
|
9
9
|
WebSocket?: typeof WSServerClient & {
|
|
10
10
|
new (...args: any[]): WSSC;
|
|
11
11
|
};
|
|
12
|
+
quiet?: boolean;
|
|
12
13
|
};
|
|
13
|
-
export type RequestListener<WSSC extends WSServerClient> = (wscc: WSSC, ...args: any[]) =>
|
|
14
|
+
export type RequestListener<WSSC extends WSServerClient> = (wscc: WSSC, ...args: any[]) => any;
|
|
14
15
|
export type CompatibleListener = () => void;
|
|
15
16
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMvD,MAAM,MAAM,OAAO,CAAC,IAAI,SAAS,cAAc,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,cAAc,CAAC,EAAE,MAAM,CAAC,GAAG;IACvG,GAAG,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;QACtB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACrB,CAAC;IACF,IAAI,CAAC,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|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
2
|
+
"name": "insite-ws",
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"description": "inSite WebSockets",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./server": "./dist/server/index.js",
|
|
8
|
+
"./client": "./dist/client/index.js",
|
|
9
|
+
"./client/node": "./dist/client/node/index.js"
|
|
10
|
+
},
|
|
11
|
+
"packageManager": "bun@1.2.13",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
+
"build": "bun .conveyer.js",
|
|
15
|
+
"postbuild": "tsc -p ."
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/nesvet/insite-ws.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"insite",
|
|
23
|
+
"ws",
|
|
24
|
+
"websockets"
|
|
25
|
+
],
|
|
26
|
+
"author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@nesvet/n": "^1.2.0",
|
|
30
|
+
"eventemitter3": "^5.0.1",
|
|
31
|
+
"insite-common": "^2.3.0",
|
|
32
|
+
"ws": "^8.18.2"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@nesvet/conveyer": "^2.5.2",
|
|
36
|
+
"@nesvet/eslint-config": "^2.1.1",
|
|
37
|
+
"@types/node": "^22.15.18",
|
|
38
|
+
"@types/ws": "^8.18.1",
|
|
39
|
+
"typescript": "^5.8.3"
|
|
40
|
+
}
|
|
40
41
|
}
|