@trpc/client 11.0.0-alpha-tmp.234 → 11.0.0-alpha-tmp-v11-trpc-sveltekit.191
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/README.md +4 -4
- package/dist/TRPCClientError.d.ts +3 -2
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/bundle-analysis.json +65 -92
- package/dist/createTRPCClient.d.ts +5 -5
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCUntypedClient.d.ts +3 -2
- package/dist/createTRPCUntypedClient.d.ts.map +1 -1
- package/dist/getFetch.d.ts +1 -1
- package/dist/getFetch.d.ts.map +1 -1
- package/dist/{httpBatchLink-a1f60db9.mjs → httpBatchLink-0ee76b31.mjs} +2 -2
- package/dist/{httpBatchLink-4653e4a1.js → httpBatchLink-6c1c898e.js} +2 -2
- package/dist/{httpBatchLink-f7c51d58.js → httpBatchLink-bc1c3273.js} +2 -2
- package/dist/index.js +1 -2
- package/dist/index.mjs +2 -3
- package/dist/internals/TRPCUntypedClient.d.ts +6 -6
- package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
- package/dist/internals/dataLoader.d.ts +1 -1
- package/dist/internals/dataLoader.d.ts.map +1 -1
- package/dist/internals/getAbortController.d.ts +2 -2
- package/dist/internals/getAbortController.d.ts.map +1 -1
- package/dist/links/HTTPBatchLinkOptions.d.ts +3 -3
- package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts +1 -1
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +2 -3
- package/dist/links/httpBatchLink.mjs +2 -3
- package/dist/links/httpBatchStreamLink.d.ts +2 -2
- package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
- package/dist/links/httpFormDataLink.d.ts.map +1 -1
- package/dist/links/httpLink.d.ts +4 -4
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +3 -4
- package/dist/links/httpLink.mjs +3 -4
- package/dist/links/internals/createChain.d.ts +2 -2
- package/dist/links/internals/createChain.d.ts.map +1 -1
- package/dist/links/internals/createHTTPBatchLink.d.ts +4 -4
- package/dist/links/internals/createHTTPBatchLink.d.ts.map +1 -1
- package/dist/links/internals/dedupeLink.d.ts +2 -2
- package/dist/links/internals/dedupeLink.d.ts.map +1 -1
- package/dist/links/internals/getTextDecoder.d.ts +1 -1
- package/dist/links/internals/getTextDecoder.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.d.ts +5 -5
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/internals/parseJSONStream.d.ts +4 -4
- package/dist/links/internals/parseJSONStream.d.ts.map +1 -1
- package/dist/links/internals/retryLink.d.ts +2 -2
- package/dist/links/internals/retryLink.d.ts.map +1 -1
- 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/splitLink.d.ts +2 -2
- package/dist/links/splitLink.d.ts.map +1 -1
- package/dist/links/types.d.ts +5 -5
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts +5 -5
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +3 -4
- package/dist/links/wsLink.mjs +3 -4
- package/package.json +4 -10
- package/src/TRPCClientError.ts +3 -5
- package/src/createTRPCClient.ts +8 -11
- package/src/createTRPCUntypedClient.ts +3 -5
- package/src/getFetch.ts +1 -1
- package/src/internals/TRPCUntypedClient.ts +7 -8
- package/src/internals/dataLoader.ts +1 -1
- package/src/internals/getAbortController.ts +2 -2
- package/src/links/HTTPBatchLinkOptions.ts +3 -3
- package/src/links/httpBatchLink.ts +5 -7
- package/src/links/httpBatchStreamLink.ts +6 -8
- package/src/links/httpFormDataLink.ts +2 -1
- package/src/links/httpLink.ts +12 -7
- package/src/links/internals/createChain.ts +6 -2
- package/src/links/internals/createHTTPBatchLink.ts +15 -11
- package/src/links/internals/dedupeLink.ts +4 -3
- package/src/links/internals/getTextDecoder.ts +1 -1
- package/src/links/internals/httpUtils.ts +9 -5
- package/src/links/internals/parseJSONStream.ts +6 -11
- package/src/links/internals/retryLink.ts +4 -3
- package/src/links/loggerLink.ts +4 -4
- package/src/links/splitLink.ts +2 -2
- package/src/links/types.ts +5 -5
- package/src/links/wsLink.ts +8 -7
- package/dist/shared/index.d.ts +0 -2
- package/dist/shared/index.d.ts.map +0 -1
- package/dist/shared/index.js +0 -10
- package/dist/shared/index.mjs +0 -2
- package/dist/shared/transformResult.d.ts +0 -36
- package/dist/shared/transformResult.d.ts.map +0 -1
- package/dist/transformResult-150436c9.js +0 -57
- package/dist/transformResult-c388d1ca.js +0 -57
- package/dist/transformResult-e5b21a85.mjs +0 -55
- package/shared/index.d.ts +0 -1
- package/shared/index.js +0 -1
- package/src/shared/index.ts +0 -1
- package/src/shared/transformResult.ts +0 -78
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
AnyRouter,
|
|
3
3
|
CombinedDataTransformer,
|
|
4
4
|
DataTransformerOptions,
|
|
5
5
|
DefaultDataTransformer,
|
|
6
6
|
} from '@trpc/core';
|
|
7
|
-
import {
|
|
7
|
+
import type {
|
|
8
8
|
inferObservableValue,
|
|
9
|
-
observableToPromise,
|
|
10
|
-
share,
|
|
11
9
|
Unsubscribable,
|
|
12
10
|
} from '@trpc/core/observable';
|
|
11
|
+
import { observableToPromise, share } from '@trpc/core/observable';
|
|
13
12
|
import { createChain } from '../links/internals/createChain';
|
|
14
|
-
import {
|
|
13
|
+
import type {
|
|
15
14
|
OperationContext,
|
|
16
15
|
OperationLink,
|
|
17
16
|
TRPCClientRuntime,
|
|
@@ -26,7 +25,7 @@ type CreateTRPCClientBaseOptions<TRouter extends AnyRouter> =
|
|
|
26
25
|
* Data transformer
|
|
27
26
|
*
|
|
28
27
|
* You must use the same transformer on the backend and frontend
|
|
29
|
-
* @link https://trpc.io/docs/data-transformers
|
|
28
|
+
* @link https://trpc.io/docs/v11/data-transformers
|
|
30
29
|
**/
|
|
31
30
|
transformer?: 'You must set a transformer on the backend router';
|
|
32
31
|
}
|
|
@@ -36,7 +35,7 @@ type CreateTRPCClientBaseOptions<TRouter extends AnyRouter> =
|
|
|
36
35
|
* Data transformer
|
|
37
36
|
*
|
|
38
37
|
* You must use the same transformer on the backend and frontend
|
|
39
|
-
* @link https://trpc.io/docs/data-transformers
|
|
38
|
+
* @link https://trpc.io/docs/v11/data-transformers
|
|
40
39
|
**/
|
|
41
40
|
transformer: TRouter['_def']['_config']['transformer'] extends CombinedDataTransformer
|
|
42
41
|
? DataTransformerOptions
|
|
@@ -47,7 +46,7 @@ type CreateTRPCClientBaseOptions<TRouter extends AnyRouter> =
|
|
|
47
46
|
* Data transformer
|
|
48
47
|
*
|
|
49
48
|
* You must use the same transformer on the backend and frontend
|
|
50
|
-
* @link https://trpc.io/docs/data-transformers
|
|
49
|
+
* @link https://trpc.io/docs/v11/data-transformers
|
|
51
50
|
**/
|
|
52
51
|
transformer?: CombinedDataTransformer;
|
|
53
52
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Maybe } from '@trpc/core';
|
|
2
|
-
import { AbortControllerEsque } from './types';
|
|
1
|
+
import type { Maybe } from '@trpc/core';
|
|
2
|
+
import type { AbortControllerEsque } from './types';
|
|
3
3
|
|
|
4
4
|
export function getAbortController(
|
|
5
5
|
customAbortControllerImpl: Maybe<AbortControllerEsque>,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NonEmptyArray } from '../internals/types';
|
|
2
|
-
import { HTTPLinkBaseOptions } from './internals/httpUtils';
|
|
3
|
-
import { HTTPHeaders, Operation } from './types';
|
|
1
|
+
import type { NonEmptyArray } from '../internals/types';
|
|
2
|
+
import type { HTTPLinkBaseOptions } from './internals/httpUtils';
|
|
3
|
+
import type { HTTPHeaders, Operation } from './types';
|
|
4
4
|
|
|
5
5
|
export interface HTTPBatchLinkOptions extends HTTPLinkBaseOptions {
|
|
6
6
|
maxURLLength?: number;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { NonEmptyArray } from '../internals/types';
|
|
2
|
-
import { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
RequesterFn,
|
|
6
|
-
} from './internals/createHTTPBatchLink';
|
|
1
|
+
import type { NonEmptyArray } from '../internals/types';
|
|
2
|
+
import type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
|
|
3
|
+
import type { RequesterFn } from './internals/createHTTPBatchLink';
|
|
4
|
+
import { createHTTPBatchLink } from './internals/createHTTPBatchLink';
|
|
7
5
|
import { jsonHttpRequester } from './internals/httpUtils';
|
|
8
|
-
import { Operation } from './types';
|
|
6
|
+
import type { Operation } from './types';
|
|
9
7
|
|
|
10
8
|
const batchRequester: RequesterFn<HTTPBatchLinkOptions> = (requesterOpts) => {
|
|
11
9
|
return (batchOps) => {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { NonEmptyArray } from '../internals/types';
|
|
2
|
-
import { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
RequesterFn,
|
|
6
|
-
} from './internals/createHTTPBatchLink';
|
|
1
|
+
import type { NonEmptyArray } from '../internals/types';
|
|
2
|
+
import type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
|
|
3
|
+
import type { RequesterFn } from './internals/createHTTPBatchLink';
|
|
4
|
+
import { createHTTPBatchLink } from './internals/createHTTPBatchLink';
|
|
7
5
|
import { getTextDecoder } from './internals/getTextDecoder';
|
|
8
6
|
import { streamingJsonHttpRequester } from './internals/parseJSONStream';
|
|
9
|
-
import { TextDecoderEsque } from './internals/streamingUtils';
|
|
10
|
-
import { Operation } from './types';
|
|
7
|
+
import type { TextDecoderEsque } from './internals/streamingUtils';
|
|
8
|
+
import type { Operation } from './types';
|
|
11
9
|
|
|
12
10
|
export interface HTTPBatchStreamLinkOptions extends HTTPBatchLinkOptions {
|
|
13
11
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { httpLinkFactory } from './httpLink';
|
|
2
|
-
import {
|
|
2
|
+
import type { Requester } from './internals/httpUtils';
|
|
3
|
+
import { httpRequest } from './internals/httpUtils';
|
|
3
4
|
|
|
4
5
|
const formDataRequester: Requester = (opts) => {
|
|
5
6
|
if (opts.type !== 'mutation') {
|
package/src/links/httpLink.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { AnyRouter } from '@trpc/core';
|
|
1
|
+
import type { AnyRouter } from '@trpc/core';
|
|
2
|
+
import { transformResult } from '@trpc/core';
|
|
2
3
|
import { observable } from '@trpc/core/observable';
|
|
3
|
-
import { transformResult } from '../shared/transformResult';
|
|
4
4
|
import { TRPCClientError } from '../TRPCClientError';
|
|
5
|
-
import {
|
|
5
|
+
import type {
|
|
6
6
|
HTTPLinkBaseOptions,
|
|
7
7
|
HTTPResult,
|
|
8
|
-
jsonHttpRequester,
|
|
9
8
|
Requester,
|
|
9
|
+
} from './internals/httpUtils';
|
|
10
|
+
import {
|
|
11
|
+
jsonHttpRequester,
|
|
10
12
|
resolveHTTPLinkOptions,
|
|
11
13
|
} from './internals/httpUtils';
|
|
12
|
-
import { HTTPHeaders, Operation, TRPCLink } from './types';
|
|
14
|
+
import type { HTTPHeaders, Operation, TRPCLink } from './types';
|
|
13
15
|
|
|
14
16
|
export interface HTTPLinkOptions extends HTTPLinkBaseOptions {
|
|
15
17
|
/**
|
|
@@ -53,7 +55,10 @@ export function httpLinkFactory(factoryOpts: { requester: Requester }) {
|
|
|
53
55
|
promise
|
|
54
56
|
.then((res) => {
|
|
55
57
|
meta = res.meta;
|
|
56
|
-
const transformed = transformResult(
|
|
58
|
+
const transformed = transformResult(
|
|
59
|
+
res.json,
|
|
60
|
+
runtime.transformer,
|
|
61
|
+
);
|
|
57
62
|
|
|
58
63
|
if (!transformed.ok) {
|
|
59
64
|
observer.error(
|
|
@@ -81,6 +86,6 @@ export function httpLinkFactory(factoryOpts: { requester: Requester }) {
|
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
/**
|
|
84
|
-
* @
|
|
89
|
+
* @link https://trpc.io/docs/v11/client/links/httpLink
|
|
85
90
|
*/
|
|
86
91
|
export const httpLink = httpLinkFactory({ requester: jsonHttpRequester });
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { AnyRouter } from '@trpc/core';
|
|
1
|
+
import type { AnyRouter } from '@trpc/core';
|
|
2
2
|
import { observable } from '@trpc/core/observable';
|
|
3
|
-
import {
|
|
3
|
+
import type {
|
|
4
|
+
Operation,
|
|
5
|
+
OperationLink,
|
|
6
|
+
OperationResultObservable,
|
|
7
|
+
} from '../types';
|
|
4
8
|
|
|
5
9
|
/** @internal */
|
|
6
10
|
export function createChain<
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { AnyRouter, ProcedureType } from '@trpc/core';
|
|
1
|
+
import type { AnyRouter, ProcedureType } from '@trpc/core';
|
|
2
|
+
import { transformResult } from '@trpc/core';
|
|
2
3
|
import { observable } from '@trpc/core/observable';
|
|
3
4
|
import { dataLoader } from '../../internals/dataLoader';
|
|
4
|
-
import { transformResult } from '../../shared/transformResult';
|
|
5
5
|
import { TRPCClientError } from '../../TRPCClientError';
|
|
6
|
-
import { HTTPBatchLinkOptions } from '../HTTPBatchLinkOptions';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from './httpUtils';
|
|
6
|
+
import type { HTTPBatchLinkOptions } from '../HTTPBatchLinkOptions';
|
|
7
|
+
import type {
|
|
8
|
+
CancelFn,
|
|
9
|
+
Operation,
|
|
10
|
+
TRPCClientRuntime,
|
|
11
|
+
TRPCLink,
|
|
12
|
+
} from '../types';
|
|
13
|
+
import type { HTTPResult, ResolvedHTTPLinkOptions } from './httpUtils';
|
|
14
|
+
import { getUrl, resolveHTTPLinkOptions } from './httpUtils';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* @internal
|
|
@@ -91,7 +92,10 @@ export function createHTTPBatchLink<TOptions extends HTTPBatchLinkOptions>(
|
|
|
91
92
|
promise
|
|
92
93
|
.then((res) => {
|
|
93
94
|
_res = res;
|
|
94
|
-
const transformed = transformResult(
|
|
95
|
+
const transformed = transformResult(
|
|
96
|
+
res.json,
|
|
97
|
+
runtime.transformer,
|
|
98
|
+
);
|
|
95
99
|
|
|
96
100
|
if (!transformed.ok) {
|
|
97
101
|
observer.error(
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* istanbul ignore file -- @preserve */
|
|
2
2
|
// We're not actually exporting this link
|
|
3
|
-
import { AnyRouter } from '@trpc/core';
|
|
4
|
-
import { Observable
|
|
5
|
-
import {
|
|
3
|
+
import type { AnyRouter } from '@trpc/core';
|
|
4
|
+
import type { Observable } from '@trpc/core/observable';
|
|
5
|
+
import { observable, share } from '@trpc/core/observable';
|
|
6
|
+
import type { TRPCLink } from '../types';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @internal used for testing
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ProcedureType } from '@trpc/core';
|
|
2
|
-
import { TRPCResponse } from '@trpc/core/rpc';
|
|
1
|
+
import type { ProcedureType } from '@trpc/core';
|
|
2
|
+
import type { TRPCResponse } from '@trpc/core/rpc';
|
|
3
3
|
import { getFetch } from '../../getFetch';
|
|
4
4
|
import { getAbortController } from '../../internals/getAbortController';
|
|
5
|
-
import {
|
|
5
|
+
import type {
|
|
6
6
|
AbortControllerEsque,
|
|
7
7
|
AbortControllerInstanceEsque,
|
|
8
8
|
FetchEsque,
|
|
@@ -10,8 +10,12 @@ import {
|
|
|
10
10
|
ResponseEsque,
|
|
11
11
|
} from '../../internals/types';
|
|
12
12
|
import { TRPCClientError } from '../../TRPCClientError';
|
|
13
|
-
import { TextDecoderEsque } from '../internals/streamingUtils';
|
|
14
|
-
import {
|
|
13
|
+
import type { TextDecoderEsque } from '../internals/streamingUtils';
|
|
14
|
+
import type {
|
|
15
|
+
HTTPHeaders,
|
|
16
|
+
PromiseAndCancel,
|
|
17
|
+
TRPCClientRuntime,
|
|
18
|
+
} from '../types';
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* @internal
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
// Stream parsing adapted from https://www.loginradius.com/blog/engineering/guest-post/http-streaming-with-nodejs-and-fetch-api/
|
|
2
|
-
import { TRPCResponse } from '@trpc/core/rpc';
|
|
3
|
-
import { WebReadableStreamEsque } from '../../internals/types';
|
|
4
|
-
import { HTTPHeaders } from '../types';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getUrl,
|
|
9
|
-
HTTPBaseRequestOptions,
|
|
10
|
-
HTTPResult,
|
|
11
|
-
} from './httpUtils';
|
|
12
|
-
import { TextDecoderEsque } from './streamingUtils';
|
|
2
|
+
import type { TRPCResponse } from '@trpc/core/rpc';
|
|
3
|
+
import type { WebReadableStreamEsque } from '../../internals/types';
|
|
4
|
+
import type { HTTPHeaders } from '../types';
|
|
5
|
+
import type { HTTPBaseRequestOptions, HTTPResult } from './httpUtils';
|
|
6
|
+
import { fetchHTTPResponse, getBody, getUrl } from './httpUtils';
|
|
7
|
+
import type { TextDecoderEsque } from './streamingUtils';
|
|
13
8
|
|
|
14
9
|
/**
|
|
15
10
|
* @internal
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* istanbul ignore file -- @preserve */
|
|
2
2
|
// We're not actually exporting this link
|
|
3
|
-
import { AnyRouter } from '@trpc/core';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import type { AnyRouter } from '@trpc/core';
|
|
4
|
+
import type { Unsubscribable } from '@trpc/core/observable';
|
|
5
|
+
import { observable } from '@trpc/core/observable';
|
|
6
|
+
import type { TRPCLink } from '../types';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @internal used for testing
|
package/src/links/loggerLink.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
// Using triple-slash directive makes sure that it will be available,
|
|
6
6
|
// even if end-user `tsconfig.json` omits it in the `lib` array.
|
|
7
7
|
|
|
8
|
-
import { AnyRouter } from '@trpc/core';
|
|
8
|
+
import type { AnyRouter } from '@trpc/core';
|
|
9
9
|
import { observable, tap } from '@trpc/core/observable';
|
|
10
|
-
import { TRPCClientError } from '../TRPCClientError';
|
|
11
|
-
import { Operation, OperationResultEnvelope, TRPCLink } from './types';
|
|
10
|
+
import type { TRPCClientError } from '../TRPCClientError';
|
|
11
|
+
import type { Operation, OperationResultEnvelope, TRPCLink } from './types';
|
|
12
12
|
|
|
13
13
|
type ConsoleEsque = {
|
|
14
14
|
log: (...args: any[]) => void;
|
|
@@ -196,7 +196,7 @@ const defaultLogger =
|
|
|
196
196
|
};
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
* @
|
|
199
|
+
* @link https://trpc.io/docs/v11/client/links/loggerLink
|
|
200
200
|
*/
|
|
201
201
|
export function loggerLink<TRouter extends AnyRouter = AnyRouter>(
|
|
202
202
|
opts: LoggerLinkOptions<TRouter> = {},
|
package/src/links/splitLink.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AnyRouter } from '@trpc/core';
|
|
1
|
+
import type { AnyRouter } from '@trpc/core';
|
|
2
2
|
import { observable } from '@trpc/core/observable';
|
|
3
3
|
import { createChain } from './internals/createChain';
|
|
4
|
-
import { Operation, TRPCLink } from './types';
|
|
4
|
+
import type { Operation, TRPCLink } from './types';
|
|
5
5
|
|
|
6
6
|
function asArray<TType>(value: TType | TType[]) {
|
|
7
7
|
return Array.isArray(value) ? value : [value];
|
package/src/links/types.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
AnyRouter,
|
|
3
3
|
CombinedDataTransformer,
|
|
4
4
|
DataTransformer,
|
|
5
5
|
} from '@trpc/core';
|
|
6
|
-
import { Observable, Observer } from '@trpc/core/observable';
|
|
7
|
-
import { TRPCResultMessage, TRPCSuccessResponse } from '@trpc/core/rpc';
|
|
8
|
-
import { ResponseEsque } from '../internals/types';
|
|
9
|
-
import { TRPCClientError } from '../TRPCClientError';
|
|
6
|
+
import type { Observable, Observer } from '@trpc/core/observable';
|
|
7
|
+
import type { TRPCResultMessage, TRPCSuccessResponse } from '@trpc/core/rpc';
|
|
8
|
+
import type { ResponseEsque } from '../internals/types';
|
|
9
|
+
import type { TRPCClientError } from '../TRPCClientError';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @internal
|
package/src/links/wsLink.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
AnyRouter,
|
|
3
3
|
inferRouterError,
|
|
4
4
|
MaybePromise,
|
|
5
5
|
ProcedureType,
|
|
6
6
|
} from '@trpc/core';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { transformResult } from '@trpc/core';
|
|
8
|
+
import type { Observer, UnsubscribeFn } from '@trpc/core/observable';
|
|
9
|
+
import { observable } from '@trpc/core/observable';
|
|
10
|
+
import type {
|
|
9
11
|
TRPCClientIncomingMessage,
|
|
10
12
|
TRPCClientIncomingRequest,
|
|
11
13
|
TRPCClientOutgoingMessage,
|
|
12
14
|
TRPCRequestMessage,
|
|
13
15
|
TRPCResponseMessage,
|
|
14
16
|
} from '@trpc/core/rpc';
|
|
15
|
-
import { transformResult } from '../shared/transformResult';
|
|
16
17
|
import { TRPCClientError } from '../TRPCClientError';
|
|
17
|
-
import { Operation, TRPCLink } from './types';
|
|
18
|
+
import type { Operation, TRPCLink } from './types';
|
|
18
19
|
|
|
19
20
|
const run = <TResult>(fn: () => TResult): TResult => fn();
|
|
20
21
|
|
|
@@ -442,7 +443,7 @@ class TRPCWebSocketClosedError extends Error {
|
|
|
442
443
|
}
|
|
443
444
|
|
|
444
445
|
/**
|
|
445
|
-
* @
|
|
446
|
+
* @link https://trpc.io/docs/v11/client/links/wsLink
|
|
446
447
|
*/
|
|
447
448
|
export function wsLink<TRouter extends AnyRouter>(
|
|
448
449
|
opts: WebSocketLinkOptions,
|
|
@@ -466,7 +467,7 @@ export function wsLink<TRouter extends AnyRouter>(
|
|
|
466
467
|
observer.complete();
|
|
467
468
|
},
|
|
468
469
|
next(message) {
|
|
469
|
-
const transformed = transformResult(message, runtime);
|
|
470
|
+
const transformed = transformResult(message, runtime.transformer);
|
|
470
471
|
|
|
471
472
|
if (!transformed.ok) {
|
|
472
473
|
observer.error(TRPCClientError.from(transformed.error));
|
package/dist/shared/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
package/dist/shared/index.js
DELETED
package/dist/shared/index.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { type AnyRouter, type inferRouterError } from '@trpc/core';
|
|
2
|
-
import type { TRPCResponse, TRPCResponseMessage } from '@trpc/core/rpc';
|
|
3
|
-
import type { TRPCClientRuntime } from '../links';
|
|
4
|
-
/** @internal */
|
|
5
|
-
declare function transformResultInner<TRouter extends AnyRouter, TOutput>(response: TRPCResponse<TOutput, inferRouterError<TRouter>> | TRPCResponseMessage<TOutput, inferRouterError<TRouter>>, runtime: TRPCClientRuntime): {
|
|
6
|
-
readonly ok: false;
|
|
7
|
-
readonly error: {
|
|
8
|
-
readonly error: inferRouterError<TRouter>;
|
|
9
|
-
readonly id?: import("@trpc/core/rpc").JSONRPC2.RequestId | undefined;
|
|
10
|
-
readonly jsonrpc?: "2.0" | undefined;
|
|
11
|
-
} | {
|
|
12
|
-
readonly error: inferRouterError<TRouter>;
|
|
13
|
-
readonly id: string | number | null;
|
|
14
|
-
readonly jsonrpc?: "2.0" | undefined;
|
|
15
|
-
};
|
|
16
|
-
readonly result?: undefined;
|
|
17
|
-
} | {
|
|
18
|
-
readonly ok: true;
|
|
19
|
-
readonly result: {
|
|
20
|
-
type: "started";
|
|
21
|
-
data?: undefined;
|
|
22
|
-
} | {
|
|
23
|
-
type: "stopped";
|
|
24
|
-
data?: undefined;
|
|
25
|
-
} | (import("@trpc/core/rpc").TRPCResult<TOutput> & {
|
|
26
|
-
type: "data";
|
|
27
|
-
});
|
|
28
|
-
readonly error?: undefined;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Transforms and validates that the result is a valid TRPCResponse
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
export declare function transformResult<TRouter extends AnyRouter, TOutput>(response: TRPCResponse<TOutput, inferRouterError<TRouter>> | TRPCResponseMessage<TOutput, inferRouterError<TRouter>>, runtime: TRPCClientRuntime): ReturnType<typeof transformResultInner>;
|
|
35
|
-
export {};
|
|
36
|
-
//# sourceMappingURL=transformResult.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformResult.d.ts","sourceRoot":"","sources":["../../src/shared/transformResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EAEpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAKlD,gBAAgB;AAChB,iBAAS,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAC9D,QAAQ,EACJ,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAChD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAC3D,OAAO,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;EAuB3B;AAQD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAChE,QAAQ,EACJ,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAChD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAC3D,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAqBzC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@trpc/core');
|
|
4
|
-
|
|
5
|
-
// FIXME:
|
|
6
|
-
// - the generics here are probably unnecessary
|
|
7
|
-
// - the RPC-spec could probably be simplified to combine HTTP + WS
|
|
8
|
-
/** @internal */ function transformResultInner(response, runtime) {
|
|
9
|
-
if ('error' in response) {
|
|
10
|
-
const error = runtime.transformer.deserialize(response.error);
|
|
11
|
-
return {
|
|
12
|
-
ok: false,
|
|
13
|
-
error: {
|
|
14
|
-
...response,
|
|
15
|
-
error
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
const result = {
|
|
20
|
-
...response.result,
|
|
21
|
-
...(!response.result.type || response.result.type === 'data') && {
|
|
22
|
-
type: 'data',
|
|
23
|
-
data: runtime.transformer.deserialize(response.result.data)
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
return {
|
|
27
|
-
ok: true,
|
|
28
|
-
result
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
class TransformResultError extends Error {
|
|
32
|
-
constructor(){
|
|
33
|
-
super('Unable to transform response from server');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Transforms and validates that the result is a valid TRPCResponse
|
|
38
|
-
* @internal
|
|
39
|
-
*/ function transformResult(response, runtime) {
|
|
40
|
-
let result;
|
|
41
|
-
try {
|
|
42
|
-
// Use the data transformers on the JSON-response
|
|
43
|
-
result = transformResultInner(response, runtime);
|
|
44
|
-
} catch (err) {
|
|
45
|
-
throw new TransformResultError();
|
|
46
|
-
}
|
|
47
|
-
// check that output of the transformers is a valid TRPCResponse
|
|
48
|
-
if (!result.ok && (!core.isObject(result.error.error) || typeof result.error.error['code'] !== 'number')) {
|
|
49
|
-
throw new TransformResultError();
|
|
50
|
-
}
|
|
51
|
-
if (result.ok && !core.isObject(result.result)) {
|
|
52
|
-
throw new TransformResultError();
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
exports.transformResult = transformResult;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { isObject } from '@trpc/core';
|
|
2
|
-
|
|
3
|
-
// FIXME:
|
|
4
|
-
// - the generics here are probably unnecessary
|
|
5
|
-
// - the RPC-spec could probably be simplified to combine HTTP + WS
|
|
6
|
-
/** @internal */
|
|
7
|
-
function transformResultInner(response, runtime) {
|
|
8
|
-
if ('error' in response) {
|
|
9
|
-
const error = runtime.transformer.deserialize(response.error);
|
|
10
|
-
return {
|
|
11
|
-
ok: false,
|
|
12
|
-
error: {
|
|
13
|
-
...response,
|
|
14
|
-
error,
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const result = {
|
|
19
|
-
...response.result,
|
|
20
|
-
...((!response.result.type || response.result.type === 'data') && {
|
|
21
|
-
type: 'data',
|
|
22
|
-
data: runtime.transformer.deserialize(response.result.data),
|
|
23
|
-
}),
|
|
24
|
-
};
|
|
25
|
-
return { ok: true, result };
|
|
26
|
-
}
|
|
27
|
-
class TransformResultError extends Error {
|
|
28
|
-
constructor() {
|
|
29
|
-
super('Unable to transform response from server');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Transforms and validates that the result is a valid TRPCResponse
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
function transformResult(response, runtime) {
|
|
37
|
-
let result;
|
|
38
|
-
try {
|
|
39
|
-
// Use the data transformers on the JSON-response
|
|
40
|
-
result = transformResultInner(response, runtime);
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
throw new TransformResultError();
|
|
44
|
-
}
|
|
45
|
-
// check that output of the transformers is a valid TRPCResponse
|
|
46
|
-
if (!result.ok &&
|
|
47
|
-
(!isObject(result.error.error) ||
|
|
48
|
-
typeof result.error.error['code'] !== 'number')) {
|
|
49
|
-
throw new TransformResultError();
|
|
50
|
-
}
|
|
51
|
-
if (result.ok && !isObject(result.result)) {
|
|
52
|
-
throw new TransformResultError();
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { transformResult as t };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { isObject } from '@trpc/core';
|
|
2
|
-
|
|
3
|
-
// FIXME:
|
|
4
|
-
// - the generics here are probably unnecessary
|
|
5
|
-
// - the RPC-spec could probably be simplified to combine HTTP + WS
|
|
6
|
-
/** @internal */ function transformResultInner(response, runtime) {
|
|
7
|
-
if ('error' in response) {
|
|
8
|
-
const error = runtime.transformer.deserialize(response.error);
|
|
9
|
-
return {
|
|
10
|
-
ok: false,
|
|
11
|
-
error: {
|
|
12
|
-
...response,
|
|
13
|
-
error
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const result = {
|
|
18
|
-
...response.result,
|
|
19
|
-
...(!response.result.type || response.result.type === 'data') && {
|
|
20
|
-
type: 'data',
|
|
21
|
-
data: runtime.transformer.deserialize(response.result.data)
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
ok: true,
|
|
26
|
-
result
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
class TransformResultError extends Error {
|
|
30
|
-
constructor(){
|
|
31
|
-
super('Unable to transform response from server');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Transforms and validates that the result is a valid TRPCResponse
|
|
36
|
-
* @internal
|
|
37
|
-
*/ function transformResult(response, runtime) {
|
|
38
|
-
let result;
|
|
39
|
-
try {
|
|
40
|
-
// Use the data transformers on the JSON-response
|
|
41
|
-
result = transformResultInner(response, runtime);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
throw new TransformResultError();
|
|
44
|
-
}
|
|
45
|
-
// check that output of the transformers is a valid TRPCResponse
|
|
46
|
-
if (!result.ok && (!isObject(result.error.error) || typeof result.error.error['code'] !== 'number')) {
|
|
47
|
-
throw new TransformResultError();
|
|
48
|
-
}
|
|
49
|
-
if (result.ok && !isObject(result.result)) {
|
|
50
|
-
throw new TransformResultError();
|
|
51
|
-
}
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { transformResult as t };
|
package/shared/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../dist/shared';
|
package/shared/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../dist/shared');
|
package/src/shared/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './transformResult';
|