Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@trpc/server

Package Overview
Dependencies
Maintainers
3
Versions
1072
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trpc/server - npm Package Compare versions

Comparing version 11.0.0-rc.530 to 11.0.0-rc.531

64

dist/adapters/ws.js

@@ -284,3 +284,13 @@ 'use strict';

}
client.on('message', async (message)=>{
client.on('message', async (rawData)=>{
const msgStr = rawData.toString();
if (msgStr === 'PONG') {
return;
}
if (msgStr === 'PING') {
if (!opts.dangerouslyDisablePong) {
client.send('PONG');
}
return;
}
if (ctxPromise === unsetContextPromiseSymbol) {

@@ -291,3 +301,3 @@ // If the ctxPromise wasn't created immediately, we're expecting the first message to be a TRPCConnectionParamsMessage

try {
msg = JSON.parse(message.toString());
msg = JSON.parse(msgStr);
if (!utils.isObject(msg)) {

@@ -309,10 +319,3 @@ throw new Error('Message was not an object');

try {
const str = message.toString();
if (str === 'PING') {
if (!opts.dangerouslyDisablePong) {
client.send('PONG');
}
return;
}
const msgJSON = JSON.parse(str);
const msgJSON = JSON.parse(msgStr);
const msgs = Array.isArray(msgJSON) ? msgJSON : [

@@ -370,23 +373,26 @@ msgJSON

*/ function handleKeepAlive(client, pingMs = 30000, pongWaitMs = 5000) {
let heartbeatTimeout;
const heartbeatInterval = setInterval(()=>{
if (client.readyState !== WEBSOCKET_OPEN) {
return;
}
// First we send a ping message and wait for a pong
client.ping();
// We set a timeout to close the connection if the pong is not received
heartbeatTimeout = setTimeout(()=>{
client.terminate();
clearInterval(heartbeatInterval);
}, pongWaitMs);
}, pingMs).unref();
// When we receive a pong message, we clear the timeout
client.on('pong', ()=>{
heartbeatTimeout && clearTimeout(heartbeatTimeout);
});
// If the connection is closed, we clear the interval
let timeout = undefined;
let ping = undefined;
const schedulePing = ()=>{
const scheduleTimeout = ()=>{
timeout = setTimeout(()=>{
client.terminate();
}, pongWaitMs);
};
ping = setTimeout(()=>{
client.send('PING');
scheduleTimeout();
}, pingMs);
};
const onMessage = ()=>{
clearTimeout(ping);
clearTimeout(timeout);
schedulePing();
};
client.on('message', onMessage);
client.on('close', ()=>{
clearInterval(heartbeatInterval);
clearTimeout(ping);
clearTimeout(timeout);
});
schedulePing();
}

@@ -393,0 +399,0 @@ function applyWSSHandler(opts) {

{
"bundleSize": 136257,
"bundleOrigSize": 186007,
"bundleReduction": 26.75,
"bundleSize": 136151,
"bundleOrigSize": 185917,
"bundleReduction": 26.77,
"modules": [

@@ -17,3 +17,3 @@ {

],
"percent": 13.15,
"percent": 13.16,
"reduction": 0

@@ -35,3 +35,3 @@ },

],
"percent": 12.89,
"percent": 12.9,
"reduction": 4.31

@@ -41,4 +41,4 @@ },

"id": "/src/adapters/ws.ts",
"size": 16392,
"origSize": 15346,
"size": 16286,
"origSize": 15256,
"renderedExports": [

@@ -53,3 +53,3 @@ "getWSConnectionHandler",

],
"percent": 12.03,
"percent": 11.96,
"reduction": 0

@@ -69,3 +69,3 @@ },

],
"percent": 5.64,
"percent": 5.65,
"reduction": 0

@@ -88,3 +88,3 @@ },

],
"percent": 4.71,
"percent": 4.72,
"reduction": 40.18

@@ -121,3 +121,3 @@ },

],
"percent": 4.25,
"percent": 4.26,
"reduction": 63.05

@@ -170,3 +170,3 @@ },

],
"percent": 2.36,
"percent": 2.37,
"reduction": 22.57

@@ -221,3 +221,3 @@ },

],
"percent": 2.01,
"percent": 2.02,
"reduction": 45.94

@@ -236,3 +236,3 @@ },

],
"percent": 1.98,
"percent": 1.99,
"reduction": 40.91

@@ -287,3 +287,3 @@ },

],
"percent": 1.65,
"percent": 1.66,
"reduction": 2.17

@@ -317,3 +317,3 @@ },

],
"percent": 1.5,
"percent": 1.51,
"reduction": 5.79

@@ -451,5 +451,5 @@ },

"/src/unstable-core-do-not-import/router.ts",
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
"/src/unstable-core-do-not-import/http/contentType.ts",
"/src/unstable-core-do-not-import/procedureBuilder.ts",
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
"/src/unstable-core-do-not-import/stream/jsonl.ts",

@@ -555,3 +555,3 @@ "/src/unstable-core-do-not-import/stream/sse.ts"

],
"percent": 0.58,
"percent": 0.59,
"reduction": 44.65

@@ -766,11 +766,8 @@ },

{
"id": "/src/unstable-core-do-not-import.ts",
"id": "/src/rpc.ts",
"size": 0,
"origSize": 2306,
"origSize": 36,
"renderedExports": [],
"removedExports": [],
"dependents": [
"/src/adapters/ws.ts",
"/src/adapters/next-app-dir/nextAppDirCaller.ts"
],
"dependents": [],
"percent": 0,

@@ -780,8 +777,11 @@ "reduction": 100

{
"id": "/src/rpc.ts",
"id": "/src/unstable-core-do-not-import.ts",
"size": 0,
"origSize": 36,
"origSize": 2306,
"renderedExports": [],
"removedExports": [],
"dependents": [],
"dependents": [
"/src/adapters/ws.ts",
"/src/adapters/next-app-dir/nextAppDirCaller.ts"
],
"percent": 0,

@@ -833,12 +833,2 @@ "reduction": 100

{
"id": "/src/adapters/fetch/index.ts",
"size": 0,
"origSize": 64,
"renderedExports": [],
"removedExports": [],
"dependents": [],
"percent": 0,
"reduction": 100
},
{
"id": "/src/adapters/node-http/index.ts",

@@ -857,2 +847,12 @@ "size": 0,

"reduction": 100
},
{
"id": "/src/adapters/fetch/index.ts",
"size": 0,
"origSize": 64,
"renderedExports": [],
"removedExports": [],
"dependents": [],
"percent": 0,
"reduction": 100
}

@@ -859,0 +859,0 @@ ],

{
"name": "@trpc/server",
"version": "11.0.0-rc.530+d1e8f33f6",
"version": "11.0.0-rc.531+42d5af1b1",
"description": "The tRPC server library",

@@ -152,3 +152,3 @@ "author": "KATT",

],
"gitHead": "d1e8f33f6bc6104003f4a0d4030c6cf306e6dec2"
"gitHead": "42d5af1b189a1b80b1f128deb81550b1ddc6eeb6"
}

@@ -391,3 +391,13 @@ import type { IncomingMessage } from 'http';

}
client.on('message', async (message) => {
client.on('message', async (rawData) => {
const msgStr = rawData.toString();
if (msgStr === 'PONG') {
return;
}
if (msgStr === 'PING') {
if (!opts.dangerouslyDisablePong) {
client.send('PONG');
}
return;
}
if (ctxPromise === unsetContextPromiseSymbol) {

@@ -398,3 +408,3 @@ // If the ctxPromise wasn't created immediately, we're expecting the first message to be a TRPCConnectionParamsMessage

try {
msg = JSON.parse(message.toString()) as TRPCConnectionParamsMessage;
msg = JSON.parse(msgStr) as TRPCConnectionParamsMessage;

@@ -419,11 +429,3 @@ if (!isObject(msg)) {

try {
const str = message.toString();
if (str === 'PING') {
if (!opts.dangerouslyDisablePong) {
client.send('PONG');
}
return;
}
const msgJSON: unknown = JSON.parse(str);
const msgJSON: unknown = JSON.parse(msgStr);
const msgs: unknown[] = Array.isArray(msgJSON) ? msgJSON : [msgJSON];

@@ -491,23 +493,33 @@ const promises = msgs

) {
let heartbeatTimeout: NodeJS.Timeout | undefined;
const heartbeatInterval = setInterval(() => {
if (client.readyState !== WEBSOCKET_OPEN) {
return;
}
// First we send a ping message and wait for a pong
client.ping();
// We set a timeout to close the connection if the pong is not received
heartbeatTimeout = setTimeout(() => {
client.terminate();
clearInterval(heartbeatInterval);
}, pongWaitMs);
}, pingMs).unref();
// When we receive a pong message, we clear the timeout
client.on('pong', () => {
heartbeatTimeout && clearTimeout(heartbeatTimeout);
});
// If the connection is closed, we clear the interval
let timeout: NodeJS.Timeout | undefined = undefined;
let ping: NodeJS.Timeout | undefined = undefined;
const schedulePing = () => {
const scheduleTimeout = () => {
timeout = setTimeout(() => {
client.terminate();
}, pongWaitMs);
};
ping = setTimeout(() => {
client.send('PING');
scheduleTimeout();
}, pingMs);
};
const onMessage = () => {
clearTimeout(ping);
clearTimeout(timeout);
schedulePing();
};
client.on('message', onMessage);
client.on('close', () => {
clearInterval(heartbeatInterval);
clearTimeout(ping);
clearTimeout(timeout);
});
schedulePing();
}

@@ -514,0 +526,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc