@trpc/client 11.0.0-rc.592 → 11.0.0-rc.599
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/TRPCClientError.d.ts +1 -1
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/bundle-analysis.json +61 -49
- package/dist/index.js +2 -0
- package/dist/index.mjs +1 -0
- package/dist/internals/TRPCUntypedClient.d.ts +3 -3
- package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
- package/dist/internals/TRPCUntypedClient.js +24 -8
- package/dist/internals/TRPCUntypedClient.mjs +24 -8
- package/dist/links/httpSubscriptionLink.d.ts +10 -9
- package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
- package/dist/links/httpSubscriptionLink.js +64 -2
- package/dist/links/httpSubscriptionLink.mjs +65 -3
- package/dist/links/internals/retryLink.d.ts +26 -6
- package/dist/links/internals/retryLink.d.ts.map +1 -1
- package/dist/links/internals/retryLink.js +43 -0
- package/dist/links/internals/retryLink.mjs +41 -0
- package/dist/links/internals/subscriptions.d.ts +20 -0
- package/dist/links/internals/subscriptions.d.ts.map +1 -0
- package/dist/links/internals/urlWithConnectionParams.d.ts +2 -1
- package/dist/links/internals/urlWithConnectionParams.d.ts.map +1 -1
- package/dist/links/internals/urlWithConnectionParams.js +3 -2
- package/dist/links/internals/urlWithConnectionParams.mjs +3 -2
- package/dist/links/loggerLink.d.ts +4 -4
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +1 -1
- package/dist/links/loggerLink.mjs +1 -1
- package/dist/links/types.d.ts +5 -4
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts +24 -1
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +125 -54
- package/dist/links/wsLink.mjs +126 -55
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/unstable-internals.d.ts +1 -0
- package/dist/unstable-internals.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/TRPCClientError.ts +1 -1
- package/src/internals/TRPCUntypedClient.ts +23 -10
- package/src/links/httpSubscriptionLink.ts +94 -20
- package/src/links/internals/retryLink.ts +42 -24
- package/src/links/internals/subscriptions.ts +26 -0
- package/src/links/internals/urlWithConnectionParams.ts +8 -2
- package/src/links/loggerLink.ts +16 -6
- package/src/links/types.ts +12 -4
- package/src/links/wsLink.ts +163 -56
- package/src/links.ts +1 -1
- package/src/unstable-internals.ts +1 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { observable } from '@trpc/server/observable';
|
|
1
|
+
import { observable, behaviorSubject } from '@trpc/server/observable';
|
|
2
|
+
import { TRPC_ERROR_CODES_BY_KEY } from '@trpc/server/rpc';
|
|
2
3
|
import { sseStreamConsumer, run } from '@trpc/server/unstable-core-do-not-import';
|
|
3
4
|
import { raceAbortSignals } from '../internals/signals.mjs';
|
|
4
5
|
import { TRPCClientError } from '../TRPCClientError.mjs';
|
|
@@ -15,6 +16,15 @@ async function urlWithConnectionParams(opts) {
|
|
|
15
16
|
}
|
|
16
17
|
return url;
|
|
17
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* tRPC error codes that are considered retryable
|
|
21
|
+
* With out of the box SSE, the client will reconnect when these errors are encountered
|
|
22
|
+
*/ const codes5xx = [
|
|
23
|
+
TRPC_ERROR_CODES_BY_KEY.BAD_GATEWAY,
|
|
24
|
+
TRPC_ERROR_CODES_BY_KEY.SERVICE_UNAVAILABLE,
|
|
25
|
+
TRPC_ERROR_CODES_BY_KEY.GATEWAY_TIMEOUT,
|
|
26
|
+
TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR
|
|
27
|
+
];
|
|
18
28
|
/**
|
|
19
29
|
* @see https://trpc.io/docs/client/links/httpSubscriptionLink
|
|
20
30
|
*/ function unstable_httpSubscriptionLink(opts) {
|
|
@@ -37,10 +47,24 @@ async function urlWithConnectionParams(opts) {
|
|
|
37
47
|
type,
|
|
38
48
|
signal: null
|
|
39
49
|
}),
|
|
40
|
-
init: ()=>resultOf(opts.eventSourceOptions
|
|
50
|
+
init: ()=>resultOf(opts.eventSourceOptions, {
|
|
51
|
+
op
|
|
52
|
+
}),
|
|
41
53
|
signal,
|
|
42
54
|
deserialize: transformer.output.deserialize,
|
|
43
|
-
|
|
55
|
+
EventSource: opts.EventSource ?? globalThis.EventSource
|
|
56
|
+
});
|
|
57
|
+
const connectionState = behaviorSubject({
|
|
58
|
+
type: 'state',
|
|
59
|
+
state: 'connecting',
|
|
60
|
+
error: null
|
|
61
|
+
});
|
|
62
|
+
const connectionSub = connectionState.subscribe({
|
|
63
|
+
next (state) {
|
|
64
|
+
observer.next({
|
|
65
|
+
result: state
|
|
66
|
+
});
|
|
67
|
+
}
|
|
44
68
|
});
|
|
45
69
|
run(async ()=>{
|
|
46
70
|
for await (const chunk of eventSourceStream){
|
|
@@ -68,6 +92,43 @@ async function urlWithConnectionParams(opts) {
|
|
|
68
92
|
eventSource: chunk.eventSource
|
|
69
93
|
}
|
|
70
94
|
});
|
|
95
|
+
connectionState.next({
|
|
96
|
+
type: 'state',
|
|
97
|
+
state: 'pending',
|
|
98
|
+
error: null
|
|
99
|
+
});
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 'serialized-error':
|
|
103
|
+
{
|
|
104
|
+
const error = TRPCClientError.from({
|
|
105
|
+
error: chunk.error
|
|
106
|
+
});
|
|
107
|
+
if (codes5xx.includes(chunk.error.code)) {
|
|
108
|
+
//
|
|
109
|
+
connectionState.next({
|
|
110
|
+
type: 'state',
|
|
111
|
+
state: 'connecting',
|
|
112
|
+
error
|
|
113
|
+
});
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
//
|
|
117
|
+
// non-retryable error, cancel the subscription
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
case 'connecting':
|
|
121
|
+
{
|
|
122
|
+
const lastState = connectionState.get();
|
|
123
|
+
const error1 = chunk.event && TRPCClientError.from(chunk.event);
|
|
124
|
+
if (!error1 && lastState.state === 'connecting') {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
connectionState.next({
|
|
128
|
+
type: 'state',
|
|
129
|
+
state: 'connecting',
|
|
130
|
+
error: error1
|
|
131
|
+
});
|
|
71
132
|
break;
|
|
72
133
|
}
|
|
73
134
|
}
|
|
@@ -84,6 +145,7 @@ async function urlWithConnectionParams(opts) {
|
|
|
84
145
|
return ()=>{
|
|
85
146
|
observer.complete();
|
|
86
147
|
ac.abort();
|
|
148
|
+
connectionSub.unsubscribe();
|
|
87
149
|
};
|
|
88
150
|
});
|
|
89
151
|
};
|
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { InferrableClientTypes } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
+
import type { TRPCClientError } from '../../TRPCClientError';
|
|
3
|
+
import type { Operation, TRPCLink } from '../types';
|
|
4
|
+
interface RetryLinkOptions<TInferrable extends InferrableClientTypes> {
|
|
5
|
+
/**
|
|
6
|
+
* The retry function
|
|
7
|
+
*/
|
|
8
|
+
retry: (opts: RetryFnOptions<TInferrable>) => boolean;
|
|
9
|
+
}
|
|
10
|
+
interface RetryFnOptions<TInferrable extends InferrableClientTypes> {
|
|
11
|
+
/**
|
|
12
|
+
* The operation that failed
|
|
13
|
+
*/
|
|
14
|
+
op: Operation;
|
|
15
|
+
/**
|
|
16
|
+
* The error that occurred
|
|
17
|
+
*/
|
|
18
|
+
error: TRPCClientError<TInferrable>;
|
|
19
|
+
/**
|
|
20
|
+
* The number of attempts that have been made (including the first call)
|
|
21
|
+
*/
|
|
22
|
+
attempts: number;
|
|
23
|
+
}
|
|
3
24
|
/**
|
|
4
|
-
* @
|
|
25
|
+
* @see https://trpc.io/docs/v11/client/links/retryLink
|
|
5
26
|
*/
|
|
6
|
-
export declare function retryLink<
|
|
7
|
-
|
|
8
|
-
}): TRPCLink<TRouter>;
|
|
27
|
+
export declare function retryLink<TInferrable extends InferrableClientTypes>(opts: RetryLinkOptions<TInferrable>): TRPCLink<TInferrable>;
|
|
28
|
+
export {};
|
|
9
29
|
//# sourceMappingURL=retryLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryLink.d.ts","sourceRoot":"","sources":["../../../src/links/internals/retryLink.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"retryLink.d.ts","sourceRoot":"","sources":["../../../src/links/internals/retryLink.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpD,UAAU,gBAAgB,CAAC,WAAW,SAAS,qBAAqB;IAClE;;OAEG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,WAAW,CAAC,KAAK,OAAO,CAAC;CACvD;AAED,UAAU,cAAc,CAAC,WAAW,SAAS,qBAAqB;IAChE;;OAEG;IACH,EAAE,EAAE,SAAS,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC;IACpC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,WAAW,SAAS,qBAAqB,EACjE,IAAI,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAClC,QAAQ,CAAC,WAAW,CAAC,CAmCvB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var observable = require('@trpc/server/observable');
|
|
4
|
+
|
|
5
|
+
/* istanbul ignore file -- @preserve */ // We're not actually exporting this link
|
|
6
|
+
/**
|
|
7
|
+
* @see https://trpc.io/docs/v11/client/links/retryLink
|
|
8
|
+
*/ function retryLink(opts) {
|
|
9
|
+
// initialized config
|
|
10
|
+
return ()=>{
|
|
11
|
+
// initialized in app
|
|
12
|
+
return ({ op , next })=>{
|
|
13
|
+
// initialized for request
|
|
14
|
+
return observable.observable((observer)=>{
|
|
15
|
+
let next$;
|
|
16
|
+
attempt(1);
|
|
17
|
+
function attempt(attempts) {
|
|
18
|
+
next$ = next(op).subscribe({
|
|
19
|
+
error (error) {
|
|
20
|
+
const shouldRetry = opts.retry({
|
|
21
|
+
op,
|
|
22
|
+
attempts,
|
|
23
|
+
error
|
|
24
|
+
});
|
|
25
|
+
shouldRetry ? attempt(attempts + 1) : observer.error(error);
|
|
26
|
+
},
|
|
27
|
+
next (result) {
|
|
28
|
+
observer.next(result);
|
|
29
|
+
},
|
|
30
|
+
complete () {
|
|
31
|
+
observer.complete();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return ()=>{
|
|
36
|
+
next$.unsubscribe();
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.retryLink = retryLink;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { observable } from '@trpc/server/observable';
|
|
2
|
+
|
|
3
|
+
/* istanbul ignore file -- @preserve */ // We're not actually exporting this link
|
|
4
|
+
/**
|
|
5
|
+
* @see https://trpc.io/docs/v11/client/links/retryLink
|
|
6
|
+
*/ function retryLink(opts) {
|
|
7
|
+
// initialized config
|
|
8
|
+
return ()=>{
|
|
9
|
+
// initialized in app
|
|
10
|
+
return ({ op , next })=>{
|
|
11
|
+
// initialized for request
|
|
12
|
+
return observable((observer)=>{
|
|
13
|
+
let next$;
|
|
14
|
+
attempt(1);
|
|
15
|
+
function attempt(attempts) {
|
|
16
|
+
next$ = next(op).subscribe({
|
|
17
|
+
error (error) {
|
|
18
|
+
const shouldRetry = opts.retry({
|
|
19
|
+
op,
|
|
20
|
+
attempts,
|
|
21
|
+
error
|
|
22
|
+
});
|
|
23
|
+
shouldRetry ? attempt(attempts + 1) : observer.error(error);
|
|
24
|
+
},
|
|
25
|
+
next (result) {
|
|
26
|
+
observer.next(result);
|
|
27
|
+
},
|
|
28
|
+
complete () {
|
|
29
|
+
observer.complete();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return ()=>{
|
|
34
|
+
next$.unsubscribe();
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { retryLink };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface ConnectionStateBase<TError> {
|
|
2
|
+
type: 'state';
|
|
3
|
+
data?: never;
|
|
4
|
+
error: TError | null;
|
|
5
|
+
}
|
|
6
|
+
interface ConnectionIdleState<TError> extends ConnectionStateBase<TError> {
|
|
7
|
+
state: 'idle';
|
|
8
|
+
error: null;
|
|
9
|
+
}
|
|
10
|
+
interface ConnectionConnectingState<TError> extends ConnectionStateBase<TError> {
|
|
11
|
+
state: 'connecting';
|
|
12
|
+
error: TError | null;
|
|
13
|
+
}
|
|
14
|
+
interface ConnectionPendingState extends ConnectionStateBase<never> {
|
|
15
|
+
state: 'pending';
|
|
16
|
+
error: null;
|
|
17
|
+
}
|
|
18
|
+
export type TRPCConnectionState<TError> = ConnectionIdleState<TError> | ConnectionConnectingState<TError> | ConnectionPendingState;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=subscriptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../../src/links/internals/subscriptions.ts"],"names":[],"mappings":"AAAA,UAAU,mBAAmB,CAAC,MAAM;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,UAAU,mBAAmB,CAAC,MAAM,CAAE,SAAQ,mBAAmB,CAAC,MAAM,CAAC;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,IAAI,CAAC;CACb;AAED,UAAU,yBAAyB,CAAC,MAAM,CACxC,SAAQ,mBAAmB,CAAC,MAAM,CAAC;IACnC,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,UAAU,sBAAuB,SAAQ,mBAAmB,CAAC,KAAK,CAAC;IACjE,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;CACb;AAED,MAAM,MAAM,mBAAmB,CAAC,MAAM,IAClC,mBAAmB,CAAC,MAAM,CAAC,GAC3B,yBAAyB,CAAC,MAAM,CAAC,GACjC,sBAAsB,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type TRPCRequestInfo } from '@trpc/server/http';
|
|
2
2
|
/**
|
|
3
3
|
* Get the result of a value or function that returns a value
|
|
4
|
+
* It also optionally accepts typesafe arguments for the function
|
|
4
5
|
*/
|
|
5
|
-
export declare const resultOf: <T>(value: T | (() => T)) => T;
|
|
6
|
+
export declare const resultOf: <T, TArgs extends any[]>(value: T | ((...args: TArgs) => T), ...args: TArgs) => T;
|
|
6
7
|
/**
|
|
7
8
|
* A value that can be wrapped in callback
|
|
8
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlWithConnectionParams.d.ts","sourceRoot":"","sources":["../../../src/links/internals/urlWithConnectionParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD
|
|
1
|
+
{"version":3,"file":"urlWithConnectionParams.d.ts","sourceRoot":"","sources":["../../../src/links/internals/urlWithConnectionParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,KAAK,SAAS,GAAG,EAAE,SACtC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,CAAC,CAAC,WACzB,KAAK,KACb,CAIF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5D,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,GAAG,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAE7B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,eAAe,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC;CACzE"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get the result of a value or function that returns a value
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
* It also optionally accepts typesafe arguments for the function
|
|
6
|
+
*/ const resultOf = (value, ...args)=>{
|
|
7
|
+
return typeof value === 'function' ? value(...args) : value;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
exports.resultOf = resultOf;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get the result of a value or function that returns a value
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
* It also optionally accepts typesafe arguments for the function
|
|
4
|
+
*/ const resultOf = (value, ...args)=>{
|
|
5
|
+
return typeof value === 'function' ? value(...args) : value;
|
|
5
6
|
};
|
|
6
7
|
|
|
7
8
|
export { resultOf };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
1
|
+
import type { AnyRouter, InferrableClientTypes } from '@trpc/server/unstable-core-do-not-import';
|
|
2
2
|
import type { TRPCClientError } from '../TRPCClientError';
|
|
3
3
|
import type { Operation, OperationResultEnvelope, TRPCLink } from './types';
|
|
4
4
|
type ConsoleEsque = {
|
|
5
5
|
log: (...args: any[]) => void;
|
|
6
6
|
error: (...args: any[]) => void;
|
|
7
7
|
};
|
|
8
|
-
type EnableFnOptions<TRouter extends
|
|
8
|
+
type EnableFnOptions<TRouter extends InferrableClientTypes> = {
|
|
9
9
|
direction: 'down';
|
|
10
|
-
result: OperationResultEnvelope<unknown
|
|
10
|
+
result: OperationResultEnvelope<unknown, TRPCClientError<TRouter>> | TRPCClientError<TRouter>;
|
|
11
11
|
} | (Operation & {
|
|
12
12
|
direction: 'up';
|
|
13
13
|
});
|
|
@@ -17,7 +17,7 @@ type LoggerLinkFnOptions<TRouter extends AnyRouter> = Operation & ({
|
|
|
17
17
|
* Request result
|
|
18
18
|
*/
|
|
19
19
|
direction: 'down';
|
|
20
|
-
result: OperationResultEnvelope<unknown
|
|
20
|
+
result: OperationResultEnvelope<unknown, TRPCClientError<TRouter>> | TRPCClientError<TRouter>;
|
|
21
21
|
elapsedMs: number;
|
|
22
22
|
} | {
|
|
23
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggerLink.d.ts","sourceRoot":"","sources":["../../src/links/loggerLink.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"loggerLink.d.ts","sourceRoot":"","sources":["../../src/links/loggerLink.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACtB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5E,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,E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AEG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAC9D,IAAI,GAAE,iBAAiB,CAAC,OAAO,CAAM,GACpC,QAAQ,CAAC,OAAO,CAAC,CAkDnB"}
|
package/dist/links/loggerLink.js
CHANGED
|
@@ -117,7 +117,7 @@ const defaultLogger = ({ c =console , colorMode ='css' , withContext })=>(props
|
|
|
117
117
|
input,
|
|
118
118
|
withContext
|
|
119
119
|
});
|
|
120
|
-
const fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.result) ? 'error' : 'log';
|
|
120
|
+
const fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.result && props.result.result.error) ? 'error' : 'log';
|
|
121
121
|
c[fn].apply(null, [
|
|
122
122
|
parts.join(' ')
|
|
123
123
|
].concat(args));
|
|
@@ -115,7 +115,7 @@ const defaultLogger = ({ c =console , colorMode ='css' , withContext })=>(props
|
|
|
115
115
|
input,
|
|
116
116
|
withContext
|
|
117
117
|
});
|
|
118
|
-
const fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.result) ? 'error' : 'log';
|
|
118
|
+
const fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.result && props.result.result.error) ? 'error' : 'log';
|
|
119
119
|
c[fn].apply(null, [
|
|
120
120
|
parts.join(' ')
|
|
121
121
|
].concat(args));
|
package/dist/links/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Observable, Observer } from '@trpc/server/observable';
|
|
|
2
2
|
import type { InferrableClientTypes, Maybe, TRPCResultMessage, TRPCSuccessResponse } from '@trpc/server/unstable-core-do-not-import';
|
|
3
3
|
import type { ResponseEsque } from '../internals/types';
|
|
4
4
|
import type { TRPCClientError } from '../TRPCClientError';
|
|
5
|
+
import type { TRPCConnectionState } from './internals/subscriptions';
|
|
5
6
|
export { isNonJsonSerializable, isFormData, isOctetType, } from './internals/contentTypes';
|
|
6
7
|
/**
|
|
7
8
|
* @internal
|
|
@@ -36,18 +37,18 @@ export interface TRPCClientRuntime {
|
|
|
36
37
|
/**
|
|
37
38
|
* @internal
|
|
38
39
|
*/
|
|
39
|
-
export interface OperationResultEnvelope<TOutput> {
|
|
40
|
-
result: TRPCResultMessage<TOutput>['result'] | TRPCSuccessResponse<TOutput>['result']
|
|
40
|
+
export interface OperationResultEnvelope<TOutput, TError> {
|
|
41
|
+
result: TRPCResultMessage<TOutput>['result'] | TRPCSuccessResponse<TOutput>['result'] | TRPCConnectionState<TError>;
|
|
41
42
|
context?: OperationContext;
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
45
|
* @internal
|
|
45
46
|
*/
|
|
46
|
-
export type OperationResultObservable<TInferrable extends InferrableClientTypes, TOutput> = Observable<OperationResultEnvelope<TOutput
|
|
47
|
+
export type OperationResultObservable<TInferrable extends InferrableClientTypes, TOutput> = Observable<OperationResultEnvelope<TOutput, TRPCClientError<TInferrable>>, TRPCClientError<TInferrable>>;
|
|
47
48
|
/**
|
|
48
49
|
* @internal
|
|
49
50
|
*/
|
|
50
|
-
export type OperationResultObserver<TInferrable extends InferrableClientTypes, TOutput> = Observer<OperationResultEnvelope<TOutput
|
|
51
|
+
export type OperationResultObserver<TInferrable extends InferrableClientTypes, TOutput> = Observer<OperationResultEnvelope<TOutput, TRPCClientError<TInferrable>>, TRPCClientError<TInferrable>>;
|
|
51
52
|
/**
|
|
52
53
|
* @internal
|
|
53
54
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/links/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EACV,qBAAqB,EACrB,KAAK,EACL,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,E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C,CAAC"}
|
package/dist/links/wsLink.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Observer, UnsubscribeFn } from '@trpc/server/observable';
|
|
|
2
2
|
import type { AnyRouter, inferClientTypes, inferRouterError, TRPCResponseMessage } from '@trpc/server/unstable-core-do-not-import';
|
|
3
3
|
import { TRPCClientError } from '../TRPCClientError';
|
|
4
4
|
import type { TransformerOptions } from '../unstable-internals';
|
|
5
|
+
import type { TRPCConnectionState } from './internals/subscriptions';
|
|
5
6
|
import { type UrlOptionsWithConnectionParams } from './internals/urlWithConnectionParams';
|
|
6
7
|
import type { Operation, TRPCLink } from './types';
|
|
7
8
|
type WSCallbackResult<TRouter extends AnyRouter, TOutput> = TRPCResponseMessage<TOutput, inferRouterError<TRouter>>;
|
|
@@ -66,6 +67,12 @@ export interface WebSocketClientOptions extends UrlOptionsWithConnectionParams {
|
|
|
66
67
|
pongTimeoutMs?: number;
|
|
67
68
|
};
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* @see https://trpc.io/docs/v11/client/links/wsLink
|
|
72
|
+
* @deprecated
|
|
73
|
+
* 🙋♂️ **Contributors needed** to continue supporting WebSockets!
|
|
74
|
+
* See https://github.com/trpc/trpc/issues/6109
|
|
75
|
+
*/
|
|
69
76
|
export declare function createWSClient(opts: WebSocketClientOptions): {
|
|
70
77
|
close: () => void;
|
|
71
78
|
request: (opts: {
|
|
@@ -88,14 +95,30 @@ export declare function createWSClient(opts: WebSocketClientOptions): {
|
|
|
88
95
|
/**
|
|
89
96
|
* Reconnect to the WebSocket server
|
|
90
97
|
*/
|
|
91
|
-
reconnect: () => void;
|
|
98
|
+
reconnect: (cause: Error | null) => void;
|
|
99
|
+
connectionState: import("@trpc/server/observable").BehaviorSubject<TRPCConnectionState<TRPCClientError<AnyRouter>>>;
|
|
92
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* @see https://trpc.io/docs/v11/client/links/wsLink
|
|
103
|
+
* @deprecated
|
|
104
|
+
* 🙋♂️ **Contributors needed** to continue supporting WebSockets!
|
|
105
|
+
* See https://github.com/trpc/trpc/issues/6109
|
|
106
|
+
*/
|
|
93
107
|
export type TRPCWebSocketClient = ReturnType<typeof createWSClient>;
|
|
108
|
+
/**
|
|
109
|
+
* @see https://trpc.io/docs/v11/client/links/wsLink
|
|
110
|
+
* @deprecated
|
|
111
|
+
* 🙋♂️ **Contributors needed** to continue supporting WebSockets!
|
|
112
|
+
* See https://github.com/trpc/trpc/issues/6109
|
|
113
|
+
*/
|
|
94
114
|
export type WebSocketLinkOptions<TRouter extends AnyRouter> = {
|
|
95
115
|
client: TRPCWebSocketClient;
|
|
96
116
|
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
97
117
|
/**
|
|
98
118
|
* @see https://trpc.io/docs/v11/client/links/wsLink
|
|
119
|
+
* @deprecated
|
|
120
|
+
* 🙋♂️ **Contributors needed** to continue supporting WebSockets!
|
|
121
|
+
* See https://github.com/trpc/trpc/issues/6109
|
|
99
122
|
*/
|
|
100
123
|
export declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TRouter>): TRPCLink<TRouter>;
|
|
101
124
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsLink.d.ts","sourceRoot":"","sources":["../../src/links/wsLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGvE,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAMhB,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;A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