@trpc/client
Advanced tools
Comparing version 11.0.0-rc.528 to 11.0.0-rc.530
{ | ||
"bundleSize": 52387, | ||
"bundleOrigSize": 69892, | ||
"bundleReduction": 25.05, | ||
"bundleSize": 54079, | ||
"bundleOrigSize": 71745, | ||
"bundleReduction": 24.62, | ||
"modules": [ | ||
{ | ||
"id": "/src/links/wsLink.ts", | ||
"size": 13436, | ||
"origSize": 15060, | ||
"size": 15128, | ||
"origSize": 16913, | ||
"renderedExports": [ | ||
@@ -16,4 +16,4 @@ "createWSClient", | ||
"dependents": [], | ||
"percent": 25.65, | ||
"reduction": 10.78 | ||
"percent": 27.97, | ||
"reduction": 10.55 | ||
}, | ||
@@ -29,3 +29,3 @@ { | ||
"dependents": [], | ||
"percent": 11.19, | ||
"percent": 10.84, | ||
"reduction": 3.51 | ||
@@ -42,3 +42,3 @@ }, | ||
"dependents": [], | ||
"percent": 10.42, | ||
"percent": 10.09, | ||
"reduction": 18.48 | ||
@@ -62,8 +62,8 @@ }, | ||
"dependents": [ | ||
"/src/links/httpBatchLink.ts", | ||
"/src/links/httpLink.ts", | ||
"/src/links/httpBatchLink.ts", | ||
"/src/links/httpBatchStreamLink.ts", | ||
"/src/links/httpSubscriptionLink.ts" | ||
], | ||
"percent": 8.52, | ||
"percent": 8.26, | ||
"reduction": 32.82 | ||
@@ -83,3 +83,3 @@ }, | ||
], | ||
"percent": 7.8, | ||
"percent": 7.55, | ||
"reduction": 5.64 | ||
@@ -96,3 +96,3 @@ }, | ||
"dependents": [], | ||
"percent": 7.49, | ||
"percent": 7.26, | ||
"reduction": 4.69 | ||
@@ -109,3 +109,3 @@ }, | ||
"dependents": [], | ||
"percent": 7.26, | ||
"percent": 7.04, | ||
"reduction": 9.86 | ||
@@ -122,3 +122,3 @@ }, | ||
"dependents": [], | ||
"percent": 6.08, | ||
"percent": 5.89, | ||
"reduction": 14.15 | ||
@@ -138,3 +138,3 @@ }, | ||
], | ||
"percent": 4.13, | ||
"percent": 4, | ||
"reduction": 47.6 | ||
@@ -152,4 +152,4 @@ }, | ||
"/src/index.ts", | ||
"/src/links/httpBatchLink.ts", | ||
"/src/links/httpLink.ts", | ||
"/src/links/httpBatchLink.ts", | ||
"/src/links/wsLink.ts", | ||
@@ -160,3 +160,3 @@ "/src/links/httpBatchStreamLink.ts", | ||
], | ||
"percent": 3.7, | ||
"percent": 3.59, | ||
"reduction": 45.43 | ||
@@ -178,3 +178,3 @@ }, | ||
], | ||
"percent": 2.27, | ||
"percent": 2.19, | ||
"reduction": 73.19 | ||
@@ -194,3 +194,3 @@ }, | ||
], | ||
"percent": 1.32, | ||
"percent": 1.28, | ||
"reduction": 32.75 | ||
@@ -207,3 +207,3 @@ }, | ||
"dependents": [], | ||
"percent": 1.16, | ||
"percent": 1.13, | ||
"reduction": 44.95 | ||
@@ -222,3 +222,3 @@ }, | ||
], | ||
"percent": 1.08, | ||
"percent": 1.04, | ||
"reduction": 66.75 | ||
@@ -238,3 +238,3 @@ }, | ||
], | ||
"percent": 0.82, | ||
"percent": 0.79, | ||
"reduction": 33.54 | ||
@@ -253,3 +253,3 @@ }, | ||
"dependents": [], | ||
"percent": 0.63, | ||
"percent": 0.61, | ||
"reduction": 15.17 | ||
@@ -269,3 +269,3 @@ }, | ||
], | ||
"percent": 0.3, | ||
"percent": 0.29, | ||
"reduction": 81.71 | ||
@@ -284,3 +284,3 @@ }, | ||
], | ||
"percent": 0.19, | ||
"percent": 0.18, | ||
"reduction": 82.58 | ||
@@ -287,0 +287,0 @@ }, |
@@ -49,2 +49,21 @@ import type { Observer, UnsubscribeFn } from '@trpc/server/observable'; | ||
}; | ||
/** | ||
* Send ping messages to the server and kill the connection if no pong message is returned | ||
*/ | ||
keepAlive?: { | ||
/** | ||
* @default false | ||
*/ | ||
enabled: boolean; | ||
/** | ||
* Send a ping message every this many milliseconds | ||
* @default 5_000 | ||
*/ | ||
intervalMs?: number; | ||
/** | ||
* Close the WebSocket after this many milliseconds if the server does not respond | ||
* @default 1_000 | ||
*/ | ||
pongTimeoutMs?: number; | ||
}; | ||
} | ||
@@ -51,0 +70,0 @@ export declare function createWSClient(opts: WebSocketClientOptions): { |
@@ -123,2 +123,4 @@ 'use strict'; | ||
function createConnection() { | ||
let pingTimeout; | ||
let pongTimeout; | ||
const self = { | ||
@@ -130,2 +132,4 @@ id: ++connectionIndex, | ||
const onCloseOrError = ()=>{ | ||
clearTimeout(pingTimeout); | ||
clearTimeout(pongTimeout); | ||
if (self.state === 'closed') { | ||
@@ -154,2 +158,11 @@ return; | ||
}; | ||
const onClose = (code)=>{ | ||
const wasOpen = self.state === 'open'; | ||
onCloseOrError(); | ||
if (wasOpen) { | ||
opts.onClose?.({ | ||
code | ||
}); | ||
} | ||
}; | ||
const onError = (evt)=>{ | ||
@@ -171,2 +184,34 @@ onCloseOrError(); | ||
ws.addEventListener('open', ()=>{ | ||
async function sendConnectionParams() { | ||
if (!opts.connectionParams) { | ||
return; | ||
} | ||
const connectMsg = { | ||
method: 'connectionParams', | ||
data: await urlWithConnectionParams.resultOf(opts.connectionParams) | ||
}; | ||
ws.send(JSON.stringify(connectMsg)); | ||
} | ||
function handleKeepAlive() { | ||
if (!opts.keepAlive?.enabled) { | ||
return; | ||
} | ||
const { pongTimeoutMs =1000 , intervalMs =5000 } = opts.keepAlive; | ||
function sendPing() { | ||
ws.send('PING'); | ||
pongTimeout = setTimeout(()=>{ | ||
ws.close(3001); | ||
onClose(3001); | ||
}, pongTimeoutMs); | ||
const onMessage = (msg)=>{ | ||
if (msg.data === 'PONG') { | ||
clearTimeout(pongTimeout); | ||
pingTimeout = setTimeout(sendPing, intervalMs); | ||
} | ||
ws.removeEventListener('message', onMessage); | ||
}; | ||
ws.addEventListener('message', onMessage); | ||
} | ||
pingTimeout = setTimeout(sendPing, intervalMs); | ||
} | ||
run(async ()=>{ | ||
@@ -176,9 +221,4 @@ /* istanbul ignore next -- @preserve */ if (activeConnection?.ws !== ws) { | ||
} | ||
if (opts.connectionParams) { | ||
const connectMsg = { | ||
method: 'connectionParams', | ||
data: await urlWithConnectionParams.resultOf(opts.connectionParams) | ||
}; | ||
ws.send(JSON.stringify(connectMsg)); | ||
} | ||
await sendConnectionParams(); | ||
handleKeepAlive(); | ||
connectAttempt = 0; | ||
@@ -232,2 +272,5 @@ self.state = 'open'; | ||
ws.addEventListener('message', ({ data })=>{ | ||
if (data === 'PONG') { | ||
return; | ||
} | ||
startLazyDisconnectTimer(); | ||
@@ -234,0 +277,0 @@ const msg = JSON.parse(data); |
{ | ||
"name": "@trpc/client", | ||
"version": "11.0.0-rc.528+32e6b1285", | ||
"version": "11.0.0-rc.530+d1e8f33f6", | ||
"description": "The tRPC client library", | ||
@@ -79,6 +79,6 @@ "author": "KATT", | ||
"peerDependencies": { | ||
"@trpc/server": "11.0.0-rc.528+32e6b1285" | ||
"@trpc/server": "11.0.0-rc.530+d1e8f33f6" | ||
}, | ||
"devDependencies": { | ||
"@trpc/server": "11.0.0-rc.528+32e6b1285", | ||
"@trpc/server": "11.0.0-rc.530+d1e8f33f6", | ||
"@types/isomorphic-fetch": "^0.0.39", | ||
@@ -100,3 +100,3 @@ "@types/node": "^20.10.0", | ||
], | ||
"gitHead": "32e6b1285dd844776d323ae23fbea638312d676e" | ||
"gitHead": "d1e8f33f6bc6104003f4a0d4030c6cf306e6dec2" | ||
} |
@@ -77,2 +77,21 @@ import type { Observer, UnsubscribeFn } from '@trpc/server/observable'; | ||
}; | ||
/** | ||
* Send ping messages to the server and kill the connection if no pong message is returned | ||
*/ | ||
keepAlive?: { | ||
/** | ||
* @default false | ||
*/ | ||
enabled: boolean; | ||
/** | ||
* Send a ping message every this many milliseconds | ||
* @default 5_000 | ||
*/ | ||
intervalMs?: number; | ||
/** | ||
* Close the WebSocket after this many milliseconds if the server does not respond | ||
* @default 1_000 | ||
*/ | ||
pongTimeoutMs?: number; | ||
}; | ||
} | ||
@@ -248,2 +267,4 @@ | ||
function createConnection(): Connection { | ||
let pingTimeout: ReturnType<typeof setTimeout> | undefined; | ||
let pongTimeout: ReturnType<typeof setTimeout> | undefined; | ||
const self: Connection = { | ||
@@ -257,2 +278,5 @@ id: ++connectionIndex, | ||
const onCloseOrError = () => { | ||
clearTimeout(pingTimeout); | ||
clearTimeout(pongTimeout); | ||
if (self.state === 'closed') { | ||
@@ -289,2 +313,11 @@ return; | ||
const onClose = (code: number) => { | ||
const wasOpen = self.state === 'open'; | ||
onCloseOrError(); | ||
if (wasOpen) { | ||
opts.onClose?.({ code }); | ||
} | ||
}; | ||
const onError = (evt?: Event) => { | ||
@@ -309,2 +342,37 @@ onCloseOrError(); | ||
ws.addEventListener('open', () => { | ||
async function sendConnectionParams() { | ||
if (!opts.connectionParams) { | ||
return; | ||
} | ||
const connectMsg: TRPCConnectionParamsMessage = { | ||
method: 'connectionParams', | ||
data: await resultOf(opts.connectionParams), | ||
}; | ||
ws.send(JSON.stringify(connectMsg)); | ||
} | ||
function handleKeepAlive() { | ||
if (!opts.keepAlive?.enabled) { | ||
return; | ||
} | ||
const { pongTimeoutMs = 1_000, intervalMs = 5_000 } = opts.keepAlive; | ||
function sendPing() { | ||
ws.send('PING'); | ||
pongTimeout = setTimeout(() => { | ||
ws.close(3001); | ||
onClose(3001); | ||
}, pongTimeoutMs); | ||
const onMessage = (msg: MessageEvent) => { | ||
if (msg.data === 'PONG') { | ||
clearTimeout(pongTimeout); | ||
pingTimeout = setTimeout(sendPing, intervalMs); | ||
} | ||
ws.removeEventListener('message', onMessage); | ||
}; | ||
ws.addEventListener('message', onMessage); | ||
} | ||
pingTimeout = setTimeout(sendPing, intervalMs); | ||
} | ||
run(async () => { | ||
@@ -315,11 +383,7 @@ /* istanbul ignore next -- @preserve */ | ||
} | ||
if (opts.connectionParams) { | ||
const connectMsg: TRPCConnectionParamsMessage = { | ||
method: 'connectionParams', | ||
data: await resultOf(opts.connectionParams), | ||
}; | ||
ws.send(JSON.stringify(connectMsg)); | ||
} | ||
await sendConnectionParams(); | ||
handleKeepAlive(); | ||
connectAttempt = 0; | ||
@@ -387,3 +451,7 @@ self.state = 'open'; | ||
}; | ||
ws.addEventListener('message', ({ data }) => { | ||
if (data === 'PONG') { | ||
return; | ||
} | ||
startLazyDisconnectTimer(); | ||
@@ -406,2 +474,3 @@ | ||
const wasOpen = self.state === 'open'; | ||
onCloseOrError(); | ||
@@ -408,0 +477,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
263097
6901