Socket
Socket
Sign inDemoInstall

@trpc/client

Package Overview
Dependencies
Maintainers
3
Versions
1030
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trpc/client - npm Package Compare versions

Comparing version 11.0.0-alpha-tmp-subscription-connection-state.488 to 11.0.0-alpha-tmp-subscription-connection-state.489

66

dist/bundle-analysis.json
{
"bundleSize": 57187,
"bundleOrigSize": 76762,
"bundleReduction": 25.5,
"bundleSize": 58110,
"bundleOrigSize": 77569,
"bundleReduction": 25.09,
"modules": [
{
"id": "/src/links/wsLink.ts",
"size": 16030,
"origSize": 17050,
"size": 16780,
"origSize": 17626,
"renderedExports": [

@@ -16,28 +16,28 @@ "createWSClient",

"dependents": [],
"percent": 28.03,
"reduction": 5.98
"percent": 28.88,
"reduction": 4.8
},
{
"id": "/src/links/httpBatchStreamLink.ts",
"size": 5861,
"origSize": 6074,
"id": "/src/links/httpSubscriptionLink.ts",
"size": 5925,
"origSize": 5715,
"renderedExports": [
"unstable_httpBatchStreamLink"
"unstable_httpSubscriptionLink"
],
"removedExports": [],
"dependents": [],
"percent": 10.25,
"reduction": 3.51
"percent": 10.2,
"reduction": 0
},
{
"id": "/src/links/httpSubscriptionLink.ts",
"size": 5752,
"origSize": 5484,
"id": "/src/links/httpBatchStreamLink.ts",
"size": 5861,
"origSize": 6074,
"renderedExports": [
"unstable_httpSubscriptionLink"
"unstable_httpBatchStreamLink"
],
"removedExports": [],
"dependents": [],
"percent": 10.06,
"reduction": 0
"percent": 10.09,
"reduction": 3.51
},

@@ -53,3 +53,3 @@ {

"dependents": [],
"percent": 9.54,
"percent": 9.39,
"reduction": 18.48

@@ -78,3 +78,3 @@ },

],
"percent": 7.81,
"percent": 7.68,
"reduction": 32.82

@@ -94,3 +94,3 @@ },

],
"percent": 7.14,
"percent": 7.03,
"reduction": 5.64

@@ -107,3 +107,3 @@ },

"dependents": [],
"percent": 6.86,
"percent": 6.75,
"reduction": 4.69

@@ -120,3 +120,3 @@ },

"dependents": [],
"percent": 5.57,
"percent": 5.48,
"reduction": 14.15

@@ -136,3 +136,3 @@ },

],
"percent": 3.99,
"percent": 3.93,
"reduction": 47.25

@@ -157,3 +157,3 @@ },

],
"percent": 3.39,
"percent": 3.34,
"reduction": 45.43

@@ -175,3 +175,3 @@ },

],
"percent": 2.08,
"percent": 2.04,
"reduction": 73.19

@@ -191,3 +191,3 @@ },

],
"percent": 1.21,
"percent": 1.19,
"reduction": 32.75

@@ -204,3 +204,3 @@ },

"dependents": [],
"percent": 1.07,
"percent": 1.05,
"reduction": 44.95

@@ -219,3 +219,3 @@ },

],
"percent": 0.99,
"percent": 0.97,
"reduction": 66.75

@@ -235,3 +235,3 @@ },

],
"percent": 0.75,
"percent": 0.74,
"reduction": 33.54

@@ -252,3 +252,3 @@ },

],
"percent": 0.58,
"percent": 0.57,
"reduction": 15.17

@@ -268,3 +268,3 @@ },

],
"percent": 0.28,
"percent": 0.27,
"reduction": 81.71

@@ -271,0 +271,0 @@ },

@@ -95,4 +95,8 @@ 'use strict';

for await (const chunk of iterable){
// if the `sse({})`-helper is used, we always have an `id` field
const data = 'id' in chunk ? chunk : chunk.data;
if (!chunk.ok) {
continue;
}
const chunkData = chunk.data;
// if the `tracked()`-helper is used, we always have an `id` field
const data = 'id' in chunkData ? chunkData : chunkData.data;
observer.next({

@@ -99,0 +103,0 @@ result: {

@@ -50,3 +50,7 @@ import type { Observer, UnsubscribeFn } from '@trpc/server/observable';

close: () => void;
request: (op: Operation, callbacks: WSCallbackObserver<AnyRouter, unknown>) => UnsubscribeFn;
request: (opts: {
op: Operation;
callbacks: WSCallbackObserver<AnyRouter, unknown>;
lastEventId: string | undefined;
}) => UnsubscribeFn;
readonly connection: ({

@@ -53,0 +57,0 @@ id: number;

@@ -103,3 +103,7 @@ 'use strict';

}
request(req.op, req.callbacks);
request({
op: req.op,
callbacks: req.callbacks,
lastEventId: req.lastEventId
});
}

@@ -221,2 +225,5 @@ const startLazyDisconnectTimer = ()=>{

}
if ('result' in data && data.result.type === 'data' && typeof data.result.id === 'string') {
req.lastEventId = data.result.id;
}
if ('result' in data && data.result.type === 'stopped' && activeConnection === self) {

@@ -274,3 +281,4 @@ req.callbacks.complete();

}
function request(op, callbacks) {
function request(opts) {
const { op , callbacks , lastEventId } = opts;
const { type , input , path , id } = op;

@@ -282,3 +290,4 @@ const envelope = {

input,
path
path,
lastEventId
}

@@ -290,3 +299,4 @@ };

callbacks,
op
op,
lastEventId
};

@@ -354,65 +364,69 @@ // enqueue message

const unsub = client.request({
type,
path,
input,
id,
context,
signal: null
}, {
error (err) {
observer.next({
result: {
type: 'state',
state: 'error',
data: err
},
context: context
});
observer.error(err);
unsub();
op: {
type,
path,
input,
id,
context,
signal: null
},
complete () {
observer.complete();
observer.next({
result: {
type: 'state',
state: 'idle'
},
context: context
});
},
next (message) {
if ('result' in message && types.isConnectionStateMessage(message.result)) {
message.result;
callbacks: {
error (err) {
observer.next({
result: message.result,
result: {
type: 'state',
state: 'error',
data: err
},
context: context
});
return;
}
if (!('id' in message)) return;
const transformed = unstableCoreDoNotImport.transformResult(message, transformer$1.output);
if (!transformed.ok) {
const error = TRPCClientError.TRPCClientError.from(transformed.error);
observer.error(err);
unsub();
},
complete () {
observer.complete();
observer.next({
result: {
type: 'state',
state: 'error',
data: error
state: 'idle'
},
context: context
});
observer.error(TRPCClientError.TRPCClientError.from(error));
return;
},
next (message) {
if ('result' in message && types.isConnectionStateMessage(message.result)) {
message.result;
observer.next({
result: message.result,
context: context
});
return;
}
if (!('id' in message)) return;
const transformed = unstableCoreDoNotImport.transformResult(message, transformer$1.output);
if (!transformed.ok) {
const error = TRPCClientError.TRPCClientError.from(transformed.error);
observer.next({
result: {
type: 'state',
state: 'error',
data: error
},
context: context
});
observer.error(TRPCClientError.TRPCClientError.from(error));
return;
}
observer.next({
result: transformed.result,
context: context
});
if (op.type !== 'subscription') {
// if it isn't a subscription we don't care about next response
unsub();
observer.complete();
}
}
observer.next({
result: transformed.result,
context: context
});
if (op.type !== 'subscription') {
// if it isn't a subscription we don't care about next response
unsub();
observer.complete();
}
}
},
lastEventId: undefined
});

@@ -419,0 +433,0 @@ return ()=>{

{
"name": "@trpc/client",
"version": "11.0.0-alpha-tmp-subscription-connection-state.488+70f6f6f44",
"version": "11.0.0-alpha-tmp-subscription-connection-state.489+04c141d1b",
"description": "The tRPC client library",

@@ -79,9 +79,9 @@ "author": "KATT",

"peerDependencies": {
"@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.488+70f6f6f44"
"@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.489+04c141d1b"
},
"devDependencies": {
"@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.488+70f6f6f44",
"@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.489+04c141d1b",
"@types/isomorphic-fetch": "^0.0.39",
"@types/node": "^20.10.0",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"isomorphic-fetch": "^3.0.0",

@@ -100,3 +100,3 @@ "node-fetch": "^3.3.0",

],
"gitHead": "70f6f6f44439bcb258420096517570e8369b3d69"
"gitHead": "04c141d1b4bb50631826aa956a874ba1d363f492"
}

@@ -6,3 +6,2 @@ import { observable } from '@trpc/server/observable';

InferrableClientTypes,
SSEMessage,
} from '@trpc/server/unstable-core-do-not-import';

@@ -138,3 +137,6 @@ import {

const iterable = sseStreamConsumer<Partial<SSEMessage>>({
const iterable = sseStreamConsumer<{
id?: string;
data?: unknown;
}>({
from: eventSource,

@@ -145,4 +147,10 @@ deserialize: transformer.output.deserialize,

for await (const chunk of iterable) {
// if the `sse({})`-helper is used, we always have an `id` field
const data = 'id' in chunk ? chunk : chunk.data;
if (!chunk.ok) {
// TODO: handle in https://github.com/trpc/trpc/issues/5871
continue;
}
const chunkData = chunk.data;
// if the `tracked()`-helper is used, we always have an `id` field
const data = 'id' in chunkData ? chunkData : chunkData.data;
observer.next({

@@ -149,0 +157,0 @@ result: {

@@ -110,3 +110,3 @@ import type { Observer, UnsubscribeFn } from '@trpc/server/observable';

type TCallbacks = WSCallbackObserver<AnyRouter, unknown>;
type TRequest = {
type WsRequest = {
/**

@@ -119,4 +119,8 @@ * Reference to the WebSocket instance this request was made to

op: Operation;
/**
* The last event id that the client has received
*/
lastEventId: string | undefined;
};
const pendingRequests: Record<number | string, TRequest> =
const pendingRequests: Record<number | string, WsRequest> =
Object.create(null);

@@ -219,7 +223,11 @@ let connectAttempt = 0;

}
function resumeSubscriptionOnReconnect(req: TRequest) {
function resumeSubscriptionOnReconnect(req: WsRequest) {
if (outgoing.some((r) => r.id === req.op.id)) {
return;
}
request(req.op, req.callbacks);
request({
op: req.op,
callbacks: req.callbacks,
lastEventId: req.lastEventId,
});
}

@@ -364,2 +372,9 @@

'result' in data &&
data.result.type === 'data' &&
typeof data.result.id === 'string'
) {
req.lastEventId = data.result.id;
}
if (
'result' in data &&
data.result.type === 'stopped' &&

@@ -428,3 +443,8 @@ activeConnection === self

function request(op: Operation, callbacks: TCallbacks): UnsubscribeFn {
function request(opts: {
op: Operation;
callbacks: TCallbacks;
lastEventId: string | undefined;
}): UnsubscribeFn {
const { op, callbacks, lastEventId } = opts;
const { type, input, path, id } = op;

@@ -437,4 +457,6 @@ const envelope: TRPCRequestMessage = {

path,
lastEventId,
},
};
pendingRequests[id] = {

@@ -445,2 +467,3 @@ connection: null,

op,
lastEventId,
};

@@ -528,5 +551,5 @@

const unsub = client.request(
{ type, path, input, id, context, signal: null },
{
const unsub = client.request({
op: { type, path, input, id, context, signal: null },
callbacks: {
error(err) {

@@ -604,3 +627,4 @@ observer.next({

},
);
lastEventId: undefined,
});
return () => {

@@ -607,0 +631,0 @@ unsub();

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

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