@jmealo/fastify-uws 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +7 -7
- package/dist/websocket-server.js +4 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./request.cjs"),c=require("./response.cjs"),r=require("./server.cjs"),e=require("./websocket-server.cjs"),u=require("./plugin-sse.cjs"),S=require("./plugin-websocket.cjs"),n=(t,s)=>new r.Server(t,s);exports.Request=o.Request;exports.Response=c.Response;exports.Server=r.Server;exports.WebSocket=e.WebSocket;exports.WebSocketServer=e.WebSocketServer;exports.WebSocketStream=e.WebSocketStream;exports.sse=u.default;exports.websocket=S.default;exports.serverFactory=n;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ContextConfigDefault, FastifyBaseLogger, FastifyInstance,
|
|
1
|
+
import { ContextConfigDefault, FastifyBaseLogger, FastifyInstance, FastifyReply, FastifyRequest, FastifySchema, FastifyServerFactory, FastifyTypeProvider, FastifyTypeProviderDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestGenericInterface } from 'fastify';
|
|
2
2
|
import { SSEContext } from './plugin-sse';
|
|
3
|
-
import { Server } from './server';
|
|
4
3
|
import { Request } from './request';
|
|
5
4
|
import { Response } from './response';
|
|
5
|
+
import { Server } from './server';
|
|
6
6
|
import { WebSocket as UwsWebSocket, WebSocketServer, WebSocketStream } from './websocket-server';
|
|
7
7
|
export type UwsServer = RawServerDefault & Server;
|
|
8
8
|
export type UwsRequest = Request;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Server as o } from "./server.js";
|
|
2
1
|
import { Request as p } from "./request.js";
|
|
3
2
|
import { Response as c } from "./response.js";
|
|
3
|
+
import { Server as o } from "./server.js";
|
|
4
4
|
import { WebSocket as S, WebSocketServer as b, WebSocketStream as k } from "./websocket-server.js";
|
|
5
5
|
import { default as u } from "./plugin-sse.js";
|
|
6
6
|
import { default as W } from "./plugin-websocket.js";
|
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("uWebSockets.js"),E=require("node:dns/promises"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("uWebSockets.js"),E=require("node:dns/promises"),g=require("node:events"),S=require("node:fs"),y=require("node:http"),L=require("node:os"),R=require("node:path"),q=require("ipaddr.js"),u=require("./errors.cjs"),w=require("./http-socket.cjs"),D=require("./request.cjs"),H=require("./response.cjs"),e=require("./symbols.cjs");function T(t,s,r){if(t!=null){if(Array.isArray(t)){if(t.length===0)return;if(t.length>1)throw new Error(`fastify-uws: multiple ${s} values are not supported by uWebSockets.js`);t=t[0]}if(typeof t=="string")return t;if(Buffer.isBuffer(t)){const i=R.join(L.tmpdir(),`fastify-uws-${s}-${process.pid}-${Date.now()}.pem`);return S.writeFileSync(i,t,{mode:384}),r.push(i),i}}}function C(t){if(t.https){const s=[],r=T(t.https.key,"key",s),i=T(t.https.cert,"cert",s),o=T(t.https.ca,"ca",s),c={};return r&&(c.key_file_name=r),i&&(c.cert_file_name=i),o&&(c.ca_file_name=o),t.https.passphrase&&(c.passphrase=t.https.passphrase),{app:k.SSLApp(c),tempFiles:s}}return{app:k.App(),tempFiles:[]}}const v=new Map(y.METHODS.map(t=>[t.toLowerCase(),t])),h={};class F extends g.EventEmitter{[e.kHandler];timeout=0;drainTimeout;maxHeadersCount=0;maxRequestsPerSocket=0;headersTimeout=0;keepAliveTimeout=0;requestTimeout=0;[e.kHttps];[e.kWs];[e.kAddress]=null;[e.kListenSocket]=null;[e.kApp];[e.kClosed]=!1;[e.kListenAll]=!1;[e.kListening]=!1;[e.kTempFiles];constructor(s,r={}){super();const{http2:i=!1,https:o=null,connectionTimeout:c=0,drainTimeout:a}=r;this[e.kHandler]=s,this.timeout=c,this.drainTimeout=a,this[e.kHttps]=o,this[e.kWs]=null;const{app:l,tempFiles:f}=C({https:o});this[e.kApp]=l,this[e.kTempFiles]=f}get encrypted(){return!!this[e.kHttps]}get listening(){return!!this[e.kListening]}setTimeout(s,r){return this.timeout=s,r&&this.once("timeout",r),this}address(){return this[e.kAddress]}listen(s,r){s?.signal&&s.signal.addEventListener("abort",()=>{this.close()},{once:!0}),this[e.kListen](s).then(()=>{this[e.kListening]=!0,r?.(),this.emit("listening")}).catch(i=>{this[e.kAddress]=null,process.nextTick(()=>this.emit("error",i))})}closeIdleConnections(){}closeAllConnections(){if(this[e.kWs])for(const s of this[e.kWs].connections)s.close()}close(s=()=>{}){if(this[e.kClosed])return s();const r=this[e.kAddress]?.port;r!==void 0&&h[r]===this&&delete h[r],this[e.kAddress]=null,this[e.kListening]=!1,this[e.kClosed]=!0,this[e.kListenSocket]&&(k.us_listen_socket_close(this[e.kListenSocket]),this[e.kListenSocket]=null),this.closeAllConnections();for(const i of this[e.kTempFiles])try{S.unlinkSync(i)}catch{}this[e.kTempFiles]=[],process.nextTick(()=>{this.emit("close"),s()})}ref(){}unref(){}async[e.kListen]({port:s,host:r}){if(this[e.kClosed])throw new u.ERR_SERVER_DESTROYED;if(s!=null&&Number.isNaN(Number(s)))throw new u.ERR_SOCKET_BAD_PORT(s);let i=s==null?0:Number(s);const o=await E.lookup(r);if(this[e.kAddress]={address:o.address,family:o.family===6?"IPv6":"IPv4",port:i},this[e.kAddress].address.startsWith("["))throw new u.ERR_ENOTFOUND(this[e.kAddress].address);const a=q.parse(this[e.kAddress].address).toNormalizedString(),l=this[e.kApp],f=(m,p)=>{const d=v.get(p.getMethod()),n=new w.HTTPSocket(this,m,d==="GET"||d==="HEAD");if(!d){n[e.kClientError]=!0,this.emit("clientError",new u.ERR_INVALID_METHOD,n);return}const A=new D.Request(p,n,d),_=new H.Response(n);A.headers.upgrade&&this.emit("upgrade",A,n),this[e.kHandler](A,_)};return l.any("/*",f),i!==0&&h[i]&&(this[e.kWs]=h[i][e.kWs]),this[e.kWs]&&this[e.kWs].addServer(this),new Promise((m,p)=>{const d=n=>{if(!n)return p(new u.ERR_ADDRINUSE(this[e.kAddress].address,i));this[e.kListenSocket]=n,i=this[e.kAddress].port=k.us_socket_local_port(n),h[i]||(h[i]=this),m()};this[e.kListenAll]=r==="localhost",this[e.kListenAll]?l.listen(i,d):l.listen(a,i,d)})}}exports.Server=F;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { default as uws } from 'uWebSockets.js';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
2
3
|
import { ServerOptions } from 'node:https';
|
|
3
4
|
import { AddressInfo } from 'node:net';
|
|
4
|
-
import { EventEmitter } from 'node:events';
|
|
5
5
|
import { FastifyServerFactoryHandler, FastifyServerOptions } from 'fastify';
|
|
6
6
|
import { kAddress, kApp, kClosed, kHandler, kHttps, kListen, kListenAll, kListening, kListenSocket, kTempFiles, kWs } from './symbols';
|
|
7
7
|
import { WebSocketServer } from './websocket-server';
|
package/dist/server.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import E from "uWebSockets.js";
|
|
2
2
|
import H from "node:dns/promises";
|
|
3
|
+
import { EventEmitter as O } from "node:events";
|
|
3
4
|
import N from "node:fs";
|
|
4
|
-
import { METHODS as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { EventEmitter as I } from "node:events";
|
|
5
|
+
import { METHODS as v } from "node:http";
|
|
6
|
+
import F from "node:os";
|
|
7
|
+
import I from "node:path";
|
|
8
8
|
import x from "ipaddr.js";
|
|
9
9
|
import { ERR_SERVER_DESTROYED as M, ERR_SOCKET_BAD_PORT as q, ERR_ENOTFOUND as B, ERR_INVALID_METHOD as $, ERR_ADDRINUSE as b } from "./errors.js";
|
|
10
10
|
import { HTTPSocket as P } from "./http-socket.js";
|
|
@@ -21,7 +21,7 @@ function D(e, t, i) {
|
|
|
21
21
|
}
|
|
22
22
|
if (typeof e == "string") return e;
|
|
23
23
|
if (Buffer.isBuffer(e)) {
|
|
24
|
-
const s =
|
|
24
|
+
const s = I.join(F.tmpdir(), `fastify-uws-${t}-${process.pid}-${Date.now()}.pem`);
|
|
25
25
|
return N.writeFileSync(s, e, { mode: 384 }), i.push(s), s;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -45,8 +45,8 @@ function U(e) {
|
|
|
45
45
|
}
|
|
46
46
|
return { app: E.App(), tempFiles: [] };
|
|
47
47
|
}
|
|
48
|
-
const z = new Map(
|
|
49
|
-
class nt extends
|
|
48
|
+
const z = new Map(v.map((e) => [e.toLowerCase(), e])), f = {};
|
|
49
|
+
class nt extends O {
|
|
50
50
|
[y];
|
|
51
51
|
timeout = 0;
|
|
52
52
|
drainTimeout;
|
package/dist/websocket-server.js
CHANGED
|
@@ -124,7 +124,10 @@ class H extends l {
|
|
|
124
124
|
i.ws("/*", {
|
|
125
125
|
upgrade: (n, s, c) => {
|
|
126
126
|
const a = s.getMethod().toUpperCase(), u = new y(e, n, a === "GET" || a === "HEAD"), f = new B(s, u, a), b = new S(u);
|
|
127
|
-
f[w] = c, e.emit("upgrade", f, u), r(
|
|
127
|
+
f[w] = c, e.emit("upgrade", f, u), r(
|
|
128
|
+
f,
|
|
129
|
+
b
|
|
130
|
+
);
|
|
128
131
|
},
|
|
129
132
|
open: (n) => {
|
|
130
133
|
this.connections.add(n), n.handler(n), this.emit("open", n);
|