@trpc/client 10.28.0 → 10.28.2

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.
Files changed (57) hide show
  1. package/dist/TRPCClientError.d.ts +25 -25
  2. package/dist/TRPCClientError.d.ts.map +1 -1
  3. package/dist/createTRPCClient.d.ts +19 -19
  4. package/dist/createTRPCClient.d.ts.map +1 -1
  5. package/dist/createTRPCClientProxy.d.ts +38 -38
  6. package/dist/createTRPCClientProxy.d.ts.map +1 -1
  7. package/dist/createTRPCUntypedClient.d.ts +4 -4
  8. package/dist/getFetch.d.ts +2 -2
  9. package/dist/{httpUtils-1a07b2e6.js → httpUtils-00c8b54e.js} +125 -125
  10. package/dist/index.d.ts +6 -6
  11. package/dist/index.js +2 -2
  12. package/dist/index.mjs +2 -2
  13. package/dist/internals/TRPCUntypedClient.d.ts +61 -61
  14. package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
  15. package/dist/internals/dataLoader.d.ts +17 -17
  16. package/dist/internals/dataLoader.d.ts.map +1 -1
  17. package/dist/internals/getAbortController.d.ts +3 -3
  18. package/dist/internals/retryDelay.d.ts +1 -1
  19. package/dist/internals/types.d.ts +75 -102
  20. package/dist/internals/types.d.ts.map +1 -1
  21. package/dist/links/dedupeLink.d.ts +3 -3
  22. package/dist/links/httpBatchLink.d.ts +15 -15
  23. package/dist/links/httpBatchLink.d.ts.map +1 -1
  24. package/dist/links/httpFormDataLink.d.ts +1 -1
  25. package/dist/links/httpLink.d.ts +16 -16
  26. package/dist/links/httpLink.d.ts.map +1 -1
  27. package/dist/links/index.d.ts +7 -7
  28. package/dist/links/internals/createChain.d.ts +7 -7
  29. package/dist/links/internals/httpUtils.d.ts +59 -59
  30. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  31. package/dist/links/internals/isObject.d.ts +1 -1
  32. package/dist/links/loggerLink.d.ts +39 -39
  33. package/dist/links/loggerLink.d.ts.map +1 -1
  34. package/dist/links/retryLink.d.ts +5 -5
  35. package/dist/links/splitLink.d.ts +13 -13
  36. package/dist/links/types.d.ts +69 -69
  37. package/dist/links/types.d.ts.map +1 -1
  38. package/dist/links/wsLink.d.ts +28 -28
  39. package/dist/links/wsLink.d.ts.map +1 -1
  40. package/dist/shared/index.d.ts +1 -1
  41. package/dist/shared/transformResult.d.ts +33 -33
  42. package/dist/shared/transformResult.d.ts.map +1 -1
  43. package/dist/{splitLink-aebd28df.js → splitLink-0df96fdc.js} +34 -34
  44. package/dist/{transformResult-fc4863b8.js → transformResult-ae8e970c.js} +80 -80
  45. package/package.json +6 -6
  46. package/src/TRPCClientError.ts +1 -1
  47. package/src/createTRPCClient.ts +1 -1
  48. package/src/createTRPCClientProxy.ts +1 -1
  49. package/src/internals/TRPCUntypedClient.ts +2 -2
  50. package/src/internals/types.ts +0 -39
  51. package/src/links/httpBatchLink.ts +2 -2
  52. package/src/links/httpFormDataLink.ts +1 -1
  53. package/src/links/httpLink.ts +2 -2
  54. package/src/links/retryLink.ts +1 -1
  55. package/src/links/types.ts +1 -1
  56. package/src/links/wsLink.ts +3 -3
  57. package/src/shared/transformResult.ts +1 -1
@@ -1,87 +1,87 @@
1
- class TRPCClientError extends Error {
2
- constructor(message, opts) {
3
- const cause = opts?.cause;
4
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
- // @ts-ignore https://github.com/tc39/proposal-error-cause
6
- super(message, { cause });
7
- this.meta = opts?.meta;
8
- this.cause = cause;
9
- this.shape = opts?.result?.error;
10
- this.data = opts?.result?.error.data;
11
- this.name = 'TRPCClientError';
12
- Object.setPrototypeOf(this, TRPCClientError.prototype);
13
- }
14
- static from(cause, opts = {}) {
15
- if (!(cause instanceof Error)) {
16
- return new TRPCClientError(cause.error.message ?? '', {
17
- ...opts,
18
- cause: undefined,
19
- result: cause,
20
- });
21
- }
22
- if (cause.name === 'TRPCClientError') {
23
- return cause;
24
- }
25
- return new TRPCClientError(cause.message, {
26
- ...opts,
27
- cause,
28
- result: null,
29
- });
30
- }
1
+ class TRPCClientError extends Error {
2
+ constructor(message, opts) {
3
+ const cause = opts?.cause;
4
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
+ // @ts-ignore https://github.com/tc39/proposal-error-cause
6
+ super(message, { cause });
7
+ this.meta = opts?.meta;
8
+ this.cause = cause;
9
+ this.shape = opts?.result?.error;
10
+ this.data = opts?.result?.error.data;
11
+ this.name = 'TRPCClientError';
12
+ Object.setPrototypeOf(this, TRPCClientError.prototype);
13
+ }
14
+ static from(cause, opts = {}) {
15
+ if (!(cause instanceof Error)) {
16
+ return new TRPCClientError(cause.error.message ?? '', {
17
+ ...opts,
18
+ cause: undefined,
19
+ result: cause,
20
+ });
21
+ }
22
+ if (cause.name === 'TRPCClientError') {
23
+ return cause;
24
+ }
25
+ return new TRPCClientError(cause.message, {
26
+ ...opts,
27
+ cause,
28
+ result: null,
29
+ });
30
+ }
31
31
  }
32
32
 
33
- function isObject(value) {
34
- // check that value is object
35
- return !!value && !Array.isArray(value) && typeof value === 'object';
33
+ function isObject(value) {
34
+ // check that value is object
35
+ return !!value && !Array.isArray(value) && typeof value === 'object';
36
36
  }
37
37
 
38
- // FIXME:
39
- // - the generics here are probably unnecessary
40
- // - the RPC-spec could probably be simplified to combine HTTP + WS
41
- /** @internal */
42
- function transformResultInner(response, runtime) {
43
- if ('error' in response) {
44
- const error = runtime.transformer.deserialize(response.error);
45
- return {
46
- ok: false,
47
- error: {
48
- ...response,
49
- error,
50
- },
51
- };
52
- }
53
- const result = {
54
- ...response.result,
55
- ...((!response.result.type || response.result.type === 'data') && {
56
- type: 'data',
57
- data: runtime.transformer.deserialize(response.result.data),
58
- }),
59
- };
60
- return { ok: true, result };
61
- }
62
- /**
63
- * Transforms and validates that the result is a valid TRPCResponse
64
- * @internal
65
- */
66
- function transformResult(response, runtime) {
67
- let result;
68
- try {
69
- // Use the data transformers on the JSON-response
70
- result = transformResultInner(response, runtime);
71
- }
72
- catch (err) {
73
- throw new TRPCClientError('Unable to transform response from server');
74
- }
75
- // check that output of the transformers is a valid TRPCResponse
76
- if (!result.ok &&
77
- (!isObject(result.error.error) ||
78
- typeof result.error.error.code !== 'number')) {
79
- throw new TRPCClientError('Badly formatted response from server');
80
- }
81
- if (result.ok && !isObject(result.result)) {
82
- throw new TRPCClientError('Badly formatted response from server');
83
- }
84
- return result;
38
+ // FIXME:
39
+ // - the generics here are probably unnecessary
40
+ // - the RPC-spec could probably be simplified to combine HTTP + WS
41
+ /** @internal */
42
+ function transformResultInner(response, runtime) {
43
+ if ('error' in response) {
44
+ const error = runtime.transformer.deserialize(response.error);
45
+ return {
46
+ ok: false,
47
+ error: {
48
+ ...response,
49
+ error,
50
+ },
51
+ };
52
+ }
53
+ const result = {
54
+ ...response.result,
55
+ ...((!response.result.type || response.result.type === 'data') && {
56
+ type: 'data',
57
+ data: runtime.transformer.deserialize(response.result.data),
58
+ }),
59
+ };
60
+ return { ok: true, result };
61
+ }
62
+ /**
63
+ * Transforms and validates that the result is a valid TRPCResponse
64
+ * @internal
65
+ */
66
+ function transformResult(response, runtime) {
67
+ let result;
68
+ try {
69
+ // Use the data transformers on the JSON-response
70
+ result = transformResultInner(response, runtime);
71
+ }
72
+ catch (err) {
73
+ throw new TRPCClientError('Unable to transform response from server');
74
+ }
75
+ // check that output of the transformers is a valid TRPCResponse
76
+ if (!result.ok &&
77
+ (!isObject(result.error.error) ||
78
+ typeof result.error.error.code !== 'number')) {
79
+ throw new TRPCClientError('Badly formatted response from server');
80
+ }
81
+ if (result.ok && !isObject(result.result)) {
82
+ throw new TRPCClientError('Badly formatted response from server');
83
+ }
84
+ return result;
85
85
  }
86
86
 
87
87
  export { TRPCClientError as T, transformResult as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "10.28.0",
3
+ "version": "10.28.2",
4
4
  "description": "The tRPC client library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -76,15 +76,15 @@
76
76
  "!**/*.test.*"
77
77
  ],
78
78
  "peerDependencies": {
79
- "@trpc/server": "10.28.0"
79
+ "@trpc/server": "10.28.2"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@testing-library/dom": "^9.0.0",
83
- "@trpc/server": "10.28.0",
83
+ "@trpc/server": "10.28.2",
84
84
  "@types/isomorphic-fetch": "^0.0.36",
85
- "@types/node": "^18.7.20",
85
+ "@types/node": "^18.16.16",
86
86
  "eslint": "^8.40.0",
87
- "expect-type": "^0.15.0",
87
+ "expect-type": "^0.16.0",
88
88
  "isomorphic-fetch": "^3.0.0",
89
89
  "node-fetch": "^3.3.0",
90
90
  "rollup": "^2.79.1",
@@ -98,5 +98,5 @@
98
98
  "funding": [
99
99
  "https://trpc.io/sponsor"
100
100
  ],
101
- "gitHead": "7aadb24ce0bc20ae27f32bd80891ef6da5885e5e"
101
+ "gitHead": "055c27724a3163ee9fde633f92f30756caf7690b"
102
102
  }
@@ -2,8 +2,8 @@ import {
2
2
  AnyProcedure,
3
3
  AnyRouter,
4
4
  DefaultErrorShape,
5
- Maybe,
6
5
  inferRouterError,
6
+ Maybe,
7
7
  } from '@trpc/server';
8
8
  import { TRPCErrorResponse, TRPCErrorShape } from '@trpc/server/rpc';
9
9
 
@@ -6,7 +6,6 @@ import type {
6
6
  } from '@trpc/server';
7
7
  import { Unsubscribable } from '@trpc/server/observable';
8
8
  import { inferTransformedProcedureOutput } from '@trpc/server/shared';
9
- import { TRPCClientError } from './TRPCClientError';
10
9
  import {
11
10
  CreateTRPCClientOptions,
12
11
  TRPCRequestOptions,
@@ -14,6 +13,7 @@ import {
14
13
  TRPCUntypedClient,
15
14
  } from './internals/TRPCUntypedClient';
16
15
  import { TRPCClientRuntime } from './links';
16
+ import { TRPCClientError } from './TRPCClientError';
17
17
 
18
18
  /**
19
19
  * @deprecated
@@ -17,7 +17,6 @@ import {
17
17
  inferTransformedProcedureOutput,
18
18
  inferTransformedSubscriptionOutput,
19
19
  } from '@trpc/server/shared';
20
- import { TRPCClientError } from './TRPCClientError';
21
20
  import { TRPCClient } from './createTRPCClient';
22
21
  import { CreateTRPCClientOptions } from './createTRPCUntypedClient';
23
22
  import {
@@ -25,6 +24,7 @@ import {
25
24
  TRPCUntypedClient,
26
25
  UntypedClientProperties,
27
26
  } from './internals/TRPCUntypedClient';
27
+ import { TRPCClientError } from './TRPCClientError';
28
28
 
29
29
  /** @public */
30
30
  export type inferRouterProxyClient<TRouter extends AnyRouter> =
@@ -6,12 +6,11 @@ import {
6
6
  DefaultDataTransformer,
7
7
  } from '@trpc/server';
8
8
  import {
9
- Unsubscribable,
10
9
  inferObservableValue,
11
10
  observableToPromise,
12
11
  share,
12
+ Unsubscribable,
13
13
  } from '@trpc/server/observable';
14
- import { TRPCClientError } from '../TRPCClientError';
15
14
  import { createChain } from '../links/internals/createChain';
16
15
  import {
17
16
  OperationContext,
@@ -19,6 +18,7 @@ import {
19
18
  TRPCClientRuntime,
20
19
  TRPCLink,
21
20
  } from '../links/types';
21
+ import { TRPCClientError } from '../TRPCClientError';
22
22
 
23
23
  type CreateTRPCClientBaseOptions<TRouter extends AnyRouter> =
24
24
  TRouter['_def']['_config']['transformer'] extends DefaultDataTransformer
@@ -43,33 +43,6 @@ export interface NodeFetchRequestInitEsque {
43
43
  body?: string;
44
44
  }
45
45
 
46
- /**
47
- * A subset of the standard Headers properties needed by tRPC internally.
48
- * @see Headers from lib.dom.d.ts
49
- * @remarks
50
- * If you need a property that you know exists but doesn't exist on this
51
- * interface, go ahead and add it.
52
- */
53
- export interface HeadersEsque {
54
- append(name: string, value: string): void;
55
- delete(name: string): void;
56
- get(name: string): string | null;
57
- has(name: string): boolean;
58
- set(name: string, value: string): void;
59
- forEach(
60
- callbackfn: (value: string, key: string) => void,
61
- thisArg?: any,
62
- ): void;
63
- }
64
-
65
- export type ResponseType =
66
- | 'basic'
67
- | 'cors'
68
- | 'default'
69
- | 'error'
70
- | 'opaque'
71
- | 'opaqueredirect';
72
-
73
46
  /**
74
47
  * A subset of the standard RequestInit properties needed by tRPC internally.
75
48
  * @see RequestInit from lib.dom.d.ts
@@ -102,20 +75,8 @@ export interface RequestInitEsque {
102
75
  /**
103
76
  * A subset of the standard Response properties needed by tRPC internally.
104
77
  * @see Response from lib.dom.d.ts
105
- * @remarks
106
- * If you need a property that you know exists but doesn't exist on this
107
- * interface, go ahead and add it.
108
78
  */
109
79
  export interface ResponseEsque {
110
- readonly headers: HeadersEsque;
111
- readonly ok: boolean;
112
- readonly redirected: boolean;
113
- readonly status: number;
114
- readonly statusText: string;
115
- readonly type: ResponseType;
116
- readonly url: string;
117
- clone(): ResponseEsque;
118
-
119
80
  /**
120
81
  * @remarks
121
82
  * The built-in Response::json() method returns Promise<any>, but
@@ -1,13 +1,13 @@
1
1
  import { AnyRouter, ProcedureType } from '@trpc/server';
2
2
  import { observable } from '@trpc/server/observable';
3
- import { TRPCClientError } from '../TRPCClientError';
4
3
  import { dataLoader } from '../internals/dataLoader';
5
4
  import { NonEmptyArray } from '../internals/types';
6
5
  import { transformResult } from '../shared/transformResult';
6
+ import { TRPCClientError } from '../TRPCClientError';
7
7
  import {
8
+ getUrl,
8
9
  HTTPLinkBaseOptions,
9
10
  HTTPResult,
10
- getUrl,
11
11
  jsonHttpRequester,
12
12
  resolveHTTPLinkOptions,
13
13
  } from './internals/httpUtils';
@@ -1,5 +1,5 @@
1
1
  import { httpLinkFactory } from './httpLink';
2
- import { GetBody, Requester, httpRequest } from './internals/httpUtils';
2
+ import { GetBody, httpRequest, Requester } from './internals/httpUtils';
3
3
 
4
4
  const getBody: GetBody = (opts) => {
5
5
  if (!('input' in opts)) {
@@ -1,11 +1,11 @@
1
1
  import { AnyRouter } from '@trpc/server';
2
2
  import { observable } from '@trpc/server/observable';
3
- import { TRPCClientError } from '../TRPCClientError';
4
3
  import { transformResult } from '../shared/transformResult';
4
+ import { TRPCClientError } from '../TRPCClientError';
5
5
  import {
6
6
  HTTPLinkBaseOptions,
7
- Requester,
8
7
  jsonHttpRequester,
8
+ Requester,
9
9
  resolveHTTPLinkOptions,
10
10
  } from './internals/httpUtils';
11
11
  import { HTTPHeaders, Operation, TRPCLink } from './types';
@@ -1,7 +1,7 @@
1
1
  /* istanbul ignore file -- @preserve */
2
2
  // We're not actually exporting this link
3
3
  import { AnyRouter } from '@trpc/server';
4
- import { Unsubscribable, observable } from '@trpc/server/observable';
4
+ import { observable, Unsubscribable } from '@trpc/server/observable';
5
5
  import { TRPCLink } from './types';
6
6
 
7
7
  export function retryLink<TRouter extends AnyRouter = AnyRouter>(opts: {
@@ -5,8 +5,8 @@ import {
5
5
  } from '@trpc/server';
6
6
  import { Observable, Observer } from '@trpc/server/observable';
7
7
  import { TRPCResultMessage, TRPCSuccessResponse } from '@trpc/server/rpc';
8
- import { TRPCClientError } from '../TRPCClientError';
9
8
  import { ResponseEsque } from '../internals/types';
9
+ import { TRPCClientError } from '../TRPCClientError';
10
10
 
11
11
  /**
12
12
  * @internal
@@ -1,5 +1,5 @@
1
- import { AnyRouter, ProcedureType, inferRouterError } from '@trpc/server';
2
- import { Observer, UnsubscribeFn, observable } from '@trpc/server/observable';
1
+ import { AnyRouter, inferRouterError, ProcedureType } from '@trpc/server';
2
+ import { observable, Observer, UnsubscribeFn } from '@trpc/server/observable';
3
3
  import {
4
4
  TRPCClientIncomingMessage,
5
5
  TRPCClientIncomingRequest,
@@ -7,9 +7,9 @@ import {
7
7
  TRPCRequestMessage,
8
8
  TRPCResponseMessage,
9
9
  } from '@trpc/server/rpc';
10
- import { TRPCClientError } from '../TRPCClientError';
11
10
  import { retryDelay } from '../internals/retryDelay';
12
11
  import { transformResult } from '../shared/transformResult';
12
+ import { TRPCClientError } from '../TRPCClientError';
13
13
  import { Operation, TRPCLink } from './types';
14
14
 
15
15
  type WSCallbackResult<TRouter extends AnyRouter, TOutput> = TRPCResponseMessage<
@@ -4,9 +4,9 @@ import type {
4
4
  TRPCResponseMessage,
5
5
  TRPCResultMessage,
6
6
  } from '@trpc/server/rpc';
7
- import { TRPCClientError } from '../TRPCClientError';
8
7
  import type { TRPCClientRuntime } from '../links';
9
8
  import { isObject } from '../links/internals/isObject';
9
+ import { TRPCClientError } from '../TRPCClientError';
10
10
 
11
11
  // FIXME:
12
12
  // - the generics here are probably unnecessary