@trpc/client
Advanced tools
Comparing version 11.0.0-rc.806 to 11.0.0-rc.807
{ | ||
"bundleSize": 75585, | ||
"bundleOrigSize": 94308, | ||
"bundleSize": 75612, | ||
"bundleOrigSize": 94335, | ||
"bundleReduction": 19.85, | ||
@@ -8,4 +8,4 @@ "modules": [ | ||
"id": "/src/links/wsLink/wsClient/wsClient.ts", | ||
"size": 12353, | ||
"origSize": 12459, | ||
"size": 12067, | ||
"origSize": 12199, | ||
"renderedExports": [ | ||
@@ -18,4 +18,4 @@ "WsClient" | ||
], | ||
"percent": 16.34, | ||
"reduction": 0.85 | ||
"percent": 15.96, | ||
"reduction": 1.08 | ||
}, | ||
@@ -35,2 +35,17 @@ { | ||
{ | ||
"id": "/src/links/wsLink/wsClient/wsConnection.ts", | ||
"size": 6174, | ||
"origSize": 6492, | ||
"renderedExports": [ | ||
"WsConnection", | ||
"backwardCompatibility" | ||
], | ||
"removedExports": [], | ||
"dependents": [ | ||
"/src/links/wsLink/wsClient/wsClient.ts" | ||
], | ||
"percent": 8.17, | ||
"reduction": 4.9 | ||
}, | ||
{ | ||
"id": "/src/links/httpBatchStreamLink.ts", | ||
@@ -48,17 +63,2 @@ "size": 6017, | ||
{ | ||
"id": "/src/links/wsLink/wsClient/wsConnection.ts", | ||
"size": 5861, | ||
"origSize": 6205, | ||
"renderedExports": [ | ||
"WsConnection", | ||
"backwardCompatibility" | ||
], | ||
"removedExports": [], | ||
"dependents": [ | ||
"/src/links/wsLink/wsClient/wsClient.ts" | ||
], | ||
"percent": 7.75, | ||
"reduction": 5.54 | ||
}, | ||
{ | ||
"id": "/src/links/loggerLink.ts", | ||
@@ -148,3 +148,3 @@ "size": 5596, | ||
"dependents": [], | ||
"percent": 4.36, | ||
"percent": 4.35, | ||
"reduction": 12.56 | ||
@@ -411,12 +411,2 @@ }, | ||
{ | ||
"id": "/src/index.ts", | ||
"size": 0, | ||
"origSize": 540, | ||
"renderedExports": [], | ||
"removedExports": [], | ||
"dependents": [], | ||
"percent": 0, | ||
"reduction": 100 | ||
}, | ||
{ | ||
"id": "/src/unstable-internals.ts", | ||
@@ -434,2 +424,12 @@ "size": 0, | ||
"reduction": 100 | ||
}, | ||
{ | ||
"id": "/src/index.ts", | ||
"size": 0, | ||
"origSize": 540, | ||
"renderedExports": [], | ||
"removedExports": [], | ||
"dependents": [], | ||
"percent": 0, | ||
"reduction": 100 | ||
} | ||
@@ -436,0 +436,0 @@ ], |
@@ -23,3 +23,2 @@ import type { AnyTRPCRouter } from '@trpc/server'; | ||
private readonly callbacks; | ||
private readonly connectionParams; | ||
private readonly lazyMode; | ||
@@ -26,0 +25,0 @@ constructor(opts: WebSocketClientOptions); |
@@ -136,2 +136,5 @@ 'use strict'; | ||
await this.activeConnection.open(); | ||
if (this.requestManager.hasPendingRequests()) { | ||
this.send(this.requestManager.getPendingRequests().map(({ message })=>message)); | ||
} | ||
} | ||
@@ -162,5 +165,2 @@ this.reconnecting = null; | ||
} | ||
if (this.connectionParams) { | ||
ws.send(await utils.buildConnectionMessage(this.connectionParams)); | ||
} | ||
this.callbacks.onOpen?.(); | ||
@@ -172,6 +172,2 @@ this.connectionState.next({ | ||
}); | ||
const messages = this.requestManager.getPendingRequests().map(({ message })=>message); | ||
if (messages.length) { | ||
ws.send(JSON.stringify(messages)); | ||
} | ||
}).catch((error)=>{ | ||
@@ -279,3 +275,2 @@ ws.close(3000); | ||
_define_property(this, "callbacks", void 0); | ||
_define_property(this, "connectionParams", void 0); | ||
_define_property(this, "lazyMode", void 0); | ||
@@ -293,3 +288,2 @@ /** | ||
}; | ||
this.connectionParams = opts.connectionParams; | ||
const lazyOptions = { | ||
@@ -296,0 +290,0 @@ ...options.lazyDefaults, |
@@ -88,3 +88,3 @@ 'use strict'; | ||
*/ isOpen() { | ||
return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN; | ||
return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN && !this.openPromise; | ||
} | ||
@@ -100,16 +100,23 @@ /** | ||
const wsPromise = utils.prepareUrl(this.urlOptions).then((url)=>new this.WebSocketPonyfill(url)); | ||
this.openPromise = wsPromise.then(asyncWsOpen); | ||
this.ws = await wsPromise; | ||
// Setup ping listener | ||
this.ws.addEventListener('message', function({ data }) { | ||
if (data === 'PING') { | ||
this.send('PONG'); | ||
this.openPromise = wsPromise.then(async (ws)=>{ | ||
this.ws = ws; | ||
// Setup ping listener | ||
ws.addEventListener('message', function({ data }) { | ||
if (data === 'PING') { | ||
this.send('PONG'); | ||
} | ||
}); | ||
if (this.keepAliveOpts.enabled) { | ||
setupPingInterval(ws, this.keepAliveOpts); | ||
} | ||
ws.addEventListener('close', ()=>{ | ||
if (this.ws === ws) { | ||
this.ws = null; | ||
} | ||
}); | ||
await asyncWsOpen(ws); | ||
if (this.urlOptions.connectionParams) { | ||
ws.send(await utils.buildConnectionMessage(this.urlOptions.connectionParams)); | ||
} | ||
}); | ||
if (this.keepAliveOpts.enabled) { | ||
setupPingInterval(this.ws, this.keepAliveOpts); | ||
} | ||
this.ws.addEventListener('close', ()=>{ | ||
this.ws = null; | ||
}); | ||
try { | ||
@@ -116,0 +123,0 @@ await this.openPromise; |
{ | ||
"name": "@trpc/client", | ||
"version": "11.0.0-rc.806+c16467cd1", | ||
"version": "11.0.0-rc.807+be14f29e3", | ||
"description": "The tRPC client library", | ||
@@ -80,7 +80,7 @@ "author": "KATT", | ||
"peerDependencies": { | ||
"@trpc/server": "11.0.0-rc.806+c16467cd1", | ||
"@trpc/server": "11.0.0-rc.807+be14f29e3", | ||
"typescript": ">=5.7.2" | ||
}, | ||
"devDependencies": { | ||
"@trpc/server": "11.0.0-rc.806+c16467cd1", | ||
"@trpc/server": "11.0.0-rc.807+be14f29e3", | ||
"@types/isomorphic-fetch": "^0.0.39", | ||
@@ -104,3 +104,3 @@ "@types/node": "^22.13.5", | ||
], | ||
"gitHead": "c16467cd1b5156dfa8a3ad4acace14f3306c66be" | ||
"gitHead": "be14f29e3f0667a2670f89e2e9e6d017797502d8" | ||
} |
@@ -23,7 +23,3 @@ import type { AnyTRPCRouter } from '@trpc/server'; | ||
import { RequestManager } from './requestManager'; | ||
import { | ||
buildConnectionMessage, | ||
ResettableTimeout, | ||
TRPCWebSocketClosedError, | ||
} from './utils'; | ||
import { ResettableTimeout, TRPCWebSocketClosedError } from './utils'; | ||
import { backwardCompatibility, WsConnection } from './wsConnection'; | ||
@@ -52,3 +48,2 @@ | ||
>; | ||
private readonly connectionParams: WebSocketClientOptions['connectionParams']; | ||
private readonly lazyMode: boolean; | ||
@@ -63,3 +58,2 @@ | ||
}; | ||
this.connectionParams = opts.connectionParams; | ||
@@ -268,2 +262,10 @@ const lazyOptions = { | ||
await this.activeConnection.open(); | ||
if (this.requestManager.hasPendingRequests()) { | ||
this.send( | ||
this.requestManager | ||
.getPendingRequests() | ||
.map(({ message }) => message), | ||
); | ||
} | ||
} | ||
@@ -304,6 +306,2 @@ this.reconnecting = null; | ||
if (this.connectionParams) { | ||
ws.send(await buildConnectionMessage(this.connectionParams)); | ||
} | ||
this.callbacks.onOpen?.(); | ||
@@ -316,9 +314,2 @@ | ||
}); | ||
const messages = this.requestManager | ||
.getPendingRequests() | ||
.map(({ message }) => message); | ||
if (messages.length) { | ||
ws.send(JSON.stringify(messages)); | ||
} | ||
}).catch((error) => { | ||
@@ -325,0 +316,0 @@ ws.close(3000); |
import { behaviorSubject } from '@trpc/server/observable'; | ||
import type { UrlOptionsWithConnectionParams } from '../../internals/urlWithConnectionParams'; | ||
import { prepareUrl, withResolvers } from './utils'; | ||
import { buildConnectionMessage, prepareUrl, withResolvers } from './utils'; | ||
@@ -132,3 +132,7 @@ /** | ||
public isOpen(): this is { ws: WebSocket } { | ||
return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN; | ||
return ( | ||
!!this.ws && | ||
this.ws.readyState === this.WebSocketPonyfill.OPEN && | ||
!this.openPromise | ||
); | ||
} | ||
@@ -164,18 +168,27 @@ | ||
); | ||
this.openPromise = wsPromise.then(asyncWsOpen); | ||
this.ws = await wsPromise; | ||
this.openPromise = wsPromise.then(async (ws) => { | ||
this.ws = ws; | ||
// Setup ping listener | ||
this.ws.addEventListener('message', function ({ data }) { | ||
if (data === 'PING') { | ||
this.send('PONG'); | ||
// Setup ping listener | ||
ws.addEventListener('message', function ({ data }) { | ||
if (data === 'PING') { | ||
this.send('PONG'); | ||
} | ||
}); | ||
if (this.keepAliveOpts.enabled) { | ||
setupPingInterval(ws, this.keepAliveOpts); | ||
} | ||
}); | ||
if (this.keepAliveOpts.enabled) { | ||
setupPingInterval(this.ws, this.keepAliveOpts); | ||
} | ||
ws.addEventListener('close', () => { | ||
if (this.ws === ws) { | ||
this.ws = null; | ||
} | ||
}); | ||
this.ws.addEventListener('close', () => { | ||
this.ws = null; | ||
await asyncWsOpen(ws); | ||
if (this.urlOptions.connectionParams) { | ||
ws.send(await buildConnectionMessage(this.urlOptions.connectionParams)); | ||
} | ||
}); | ||
@@ -182,0 +195,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
357178
9274