@trpc/client 10.6.0 → 10.8.0

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.
@@ -1,8 +1,20 @@
1
- import type { AnyRouter } from '@trpc/server';
2
- import { TRPCClient as Client, CreateTRPCClientOptions } from './internals/TRPCClient';
1
+ import type { AnyRouter, inferProcedureInput, inferProcedureOutput, inferSubscriptionOutput } from '@trpc/server';
2
+ import { Unsubscribable } from '@trpc/server/observable';
3
+ import { inferTransformedProcedureOutput } from '@trpc/server/shared';
4
+ import { TRPCClientError } from './TRPCClientError';
5
+ import { CreateTRPCClientOptions, TRPCRequestOptions, TRPCSubscriptionObserver } from './internals/TRPCUntypedClient';
6
+ import { TRPCClientRuntime } from './links';
7
+ /**
8
+ * @deprecated
9
+ */
10
+ export interface TRPCClient<TRouter extends AnyRouter> {
11
+ readonly runtime: TRPCClientRuntime;
12
+ query<TQueries extends TRouter['_def']['queries'], TPath extends string & keyof TQueries, TInput extends inferProcedureInput<TQueries[TPath]>>(path: TPath, input?: TInput, opts?: TRPCRequestOptions): Promise<inferProcedureOutput<TQueries[TPath]>>;
13
+ mutation<TMutations extends TRouter['_def']['mutations'], TPath extends string & keyof TMutations, TInput extends inferProcedureInput<TMutations[TPath]>>(path: TPath, input?: TInput, opts?: TRPCRequestOptions): Promise<inferTransformedProcedureOutput<TMutations[TPath]>>;
14
+ subscription<TSubscriptions extends TRouter['_def']['subscriptions'], TPath extends string & keyof TSubscriptions, TOutput extends inferSubscriptionOutput<TRouter, TPath>, TInput extends inferProcedureInput<TSubscriptions[TPath]>>(path: TPath, input: TInput, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<TOutput, TRPCClientError<TRouter>>>): Unsubscribable;
15
+ }
3
16
  /**
4
17
  * @deprecated use `createTRPCProxyClient` instead
5
18
  */
6
- export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): Client<TRouter>;
7
- export type { CreateTRPCClientOptions, TRPCClient, TRPCRequestOptions, } from './internals/TRPCClient';
19
+ export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): TRPCClient<TRouter>;
8
20
  //# sourceMappingURL=createTRPCClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,UAAU,IAAI,MAAM,EACpB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAGhC;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,mBAavC;AAID,YAAY,EACV,uBAAuB,EACvB,UAAU,EACV,kBAAkB,GACnB,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,wBAAwB,EAEzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,OAAO,SAAS,SAAS;IACnD,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,KAAK,CACH,QAAQ,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAC3C,KAAK,SAAS,MAAM,GAAG,MAAM,QAAQ,EACrC,MAAM,SAAS,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAEnD,IAAI,EAAE,KAAK,EACX,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAElD,QAAQ,CACN,UAAU,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,EAC/C,KAAK,SAAS,MAAM,GAAG,MAAM,UAAU,EACvC,MAAM,SAAS,mBAAmB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAErD,IAAI,EAAE,KAAK,EACX,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,+BAA+B,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/D,YAAY,CACV,cAAc,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,EACvD,KAAK,SAAS,MAAM,GAAG,MAAM,cAAc,EAE3C,OAAO,SAAS,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,EACvD,MAAM,SAAS,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAEzD,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,kBAAkB,GACtB,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,GACrE,cAAc,CAAC;CACnB;AACD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,uBAIvC"}
@@ -2,8 +2,9 @@ import type { AnyMutationProcedure, AnyProcedure, AnyQueryProcedure, AnyRouter,
2
2
  import type { Unsubscribable } from '@trpc/server/observable';
3
3
  import { inferTransformedProcedureOutput, inferTransformedSubscriptionOutput } from '@trpc/server/shared';
4
4
  import { TRPCClientError } from './TRPCClientError';
5
- import { CreateTRPCClientOptions } from './createTRPCClient';
6
- import { TRPCClient, TRPCSubscriptionObserver } from './internals/TRPCClient';
5
+ import { TRPCClient } from './createTRPCClient';
6
+ import { CreateTRPCClientOptions } from './createTRPCUntypedClient';
7
+ import { TRPCSubscriptionObserver } from './internals/TRPCUntypedClient';
7
8
  export declare type inferRouterProxyClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<TRouter['_def']['record'], TRouter>;
8
9
  declare type Resolver<TProcedure extends AnyProcedure> = (...args: ProcedureArgs<TProcedure['_def']>) => Promise<inferTransformedProcedureOutput<TProcedure>>;
9
10
  declare type SubscriptionResolver<TProcedure extends AnyProcedure, TRouter extends AnyRouter> = (...args: [
@@ -1 +1 @@
1
- {"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,wBAAwB,EACxB,aAAa,EACb,qBAAqB,EAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAGL,+BAA+B,EAC/B,kCAAkC,EACnC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAE9E,oBAAY,sBAAsB,CAAC,OAAO,SAAS,SAAS,IAC1D,wBAAwB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;AAE/D,aAAK,QAAQ,CAAC,UAAU,SAAS,YAAY,IAAI,C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qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,gEAoB5B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,gEAKvC"}
@@ -0,0 +1,5 @@
1
+ import { AnyRouter } from '@trpc/server';
2
+ import { CreateTRPCClientOptions, TRPCUntypedClient } from './internals/TRPCUntypedClient';
3
+ export declare function createTRPCUntypedClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): TRPCUntypedClient<AnyRouter>;
4
+ export type { CreateTRPCClientOptions, TRPCRequestOptions, TRPCUntypedClient, } from './internals/TRPCUntypedClient';
5
+ //# sourceMappingURL=createTRPCUntypedClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTRPCUntypedClient.d.ts","sourceRoot":"","sources":["../src/createTRPCUntypedClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAEvC,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,gCAIvC;AAED,YAAY,EACV,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,+BAA+B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './createTRPCUntypedClient';
1
2
  export * from './createTRPCClient';
2
3
  export * from './createTRPCClientProxy';
3
4
  export * from './getFetch';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -5,14 +5,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var observable = require('@trpc/server/observable');
6
6
  var transformResult = require('./transformResult-e7a1e69e.js');
7
7
  var links_splitLink = require('./splitLink-f29e84be.js');
8
- var links_httpBatchLink = require('./links/httpBatchLink.js');
9
8
  var shared = require('@trpc/server/shared');
10
9
  var httpUtils = require('./httpUtils-277fd63a.js');
10
+ var links_httpBatchLink = require('./links/httpBatchLink.js');
11
11
  var links_httpLink = require('./links/httpLink.js');
12
12
  var links_loggerLink = require('./links/loggerLink.js');
13
13
  var links_wsLink = require('./links/wsLink.js');
14
14
 
15
- class TRPCClient {
15
+ class TRPCUntypedClient {
16
16
  $request({ type , input , path , context ={} }) {
17
17
  const chain$ = links_splitLink.createChain({
18
18
  links: this.links,
@@ -43,7 +43,7 @@ class TRPCClient {
43
43
  return this.requestAsPromise({
44
44
  type: 'query',
45
45
  path,
46
- input: input,
46
+ input,
47
47
  context: opts?.context,
48
48
  signal: opts?.signal
49
49
  });
@@ -52,7 +52,7 @@ class TRPCClient {
52
52
  return this.requestAsPromise({
53
53
  type: 'mutation',
54
54
  path,
55
- input: input,
55
+ input,
56
56
  context: opts?.context,
57
57
  signal: opts?.signal
58
58
  });
@@ -85,15 +85,16 @@ class TRPCClient {
85
85
  constructor(opts){
86
86
  this.requestId = 0;
87
87
  function getTransformer() {
88
- if (!opts.transformer) return {
88
+ const transformer = opts.transformer;
89
+ if (!transformer) return {
89
90
  serialize: (data)=>data,
90
91
  deserialize: (data)=>data
91
92
  };
92
- if ('input' in opts.transformer) return {
93
- serialize: opts.transformer.input.serialize,
94
- deserialize: opts.transformer.output.deserialize
93
+ if ('input' in transformer) return {
94
+ serialize: transformer.input.serialize,
95
+ deserialize: transformer.output.deserialize
95
96
  };
96
- return opts.transformer;
97
+ return transformer;
97
98
  }
98
99
  this.runtime = {
99
100
  transformer: getTransformer()
@@ -103,21 +104,15 @@ class TRPCClient {
103
104
  }
104
105
  }
105
106
 
107
+ function createTRPCUntypedClient(opts) {
108
+ const client = new TRPCUntypedClient(opts);
109
+ return client;
110
+ }
111
+
106
112
  /**
107
113
  * @deprecated use `createTRPCProxyClient` instead
108
114
  */ function createTRPCClient(opts) {
109
- const getLinks = ()=>{
110
- if ('links' in opts) {
111
- return opts.links;
112
- }
113
- return [
114
- links_httpBatchLink.httpBatchLink(opts)
115
- ];
116
- };
117
- const client = new TRPCClient({
118
- transformer: opts.transformer,
119
- links: getLinks()
120
- });
115
+ const client = new TRPCUntypedClient(opts);
121
116
  return client;
122
117
  }
123
118
 
@@ -147,15 +142,15 @@ const clientCallTypeMap = {
147
142
  });
148
143
  }
149
144
  function createTRPCProxyClient(opts) {
150
- const client = new TRPCClient(opts);
145
+ const client = new TRPCUntypedClient(opts);
151
146
  const proxy = createTRPCClientProxy(client);
152
147
  return proxy;
153
148
  }
154
149
 
155
150
  exports.TRPCClientError = transformResult.TRPCClientError;
156
151
  exports.splitLink = links_splitLink.splitLink;
157
- exports.httpBatchLink = links_httpBatchLink.httpBatchLink;
158
152
  exports.getFetch = httpUtils.getFetch;
153
+ exports.httpBatchLink = links_httpBatchLink.httpBatchLink;
159
154
  exports.httpLink = links_httpLink.httpLink;
160
155
  exports.loggerLink = links_loggerLink.loggerLink;
161
156
  exports.createWSClient = links_wsLink.createWSClient;
@@ -163,3 +158,4 @@ exports.wsLink = links_wsLink.wsLink;
163
158
  exports.createTRPCClient = createTRPCClient;
164
159
  exports.createTRPCClientProxy = createTRPCClientProxy;
165
160
  exports.createTRPCProxyClient = createTRPCProxyClient;
161
+ exports.createTRPCUntypedClient = createTRPCUntypedClient;
package/dist/index.mjs CHANGED
@@ -3,15 +3,14 @@ import { T as TRPCClientError } from './transformResult-6fb67924.mjs';
3
3
  export { T as TRPCClientError } from './transformResult-6fb67924.mjs';
4
4
  import { c as createChain } from './splitLink-4c75f7be.mjs';
5
5
  export { s as splitLink } from './splitLink-4c75f7be.mjs';
6
- import { httpBatchLink } from './links/httpBatchLink.mjs';
7
- export { httpBatchLink } from './links/httpBatchLink.mjs';
8
6
  import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
9
7
  export { g as getFetch } from './httpUtils-939364d7.mjs';
8
+ export { httpBatchLink } from './links/httpBatchLink.mjs';
10
9
  export { httpLink } from './links/httpLink.mjs';
11
10
  export { loggerLink } from './links/loggerLink.mjs';
12
11
  export { createWSClient, wsLink } from './links/wsLink.mjs';
13
12
 
14
- class TRPCClient {
13
+ class TRPCUntypedClient {
15
14
  $request({ type , input , path , context ={} }) {
16
15
  const chain$ = createChain({
17
16
  links: this.links,
@@ -42,7 +41,7 @@ class TRPCClient {
42
41
  return this.requestAsPromise({
43
42
  type: 'query',
44
43
  path,
45
- input: input,
44
+ input,
46
45
  context: opts?.context,
47
46
  signal: opts?.signal
48
47
  });
@@ -51,7 +50,7 @@ class TRPCClient {
51
50
  return this.requestAsPromise({
52
51
  type: 'mutation',
53
52
  path,
54
- input: input,
53
+ input,
55
54
  context: opts?.context,
56
55
  signal: opts?.signal
57
56
  });
@@ -84,15 +83,16 @@ class TRPCClient {
84
83
  constructor(opts){
85
84
  this.requestId = 0;
86
85
  function getTransformer() {
87
- if (!opts.transformer) return {
86
+ const transformer = opts.transformer;
87
+ if (!transformer) return {
88
88
  serialize: (data)=>data,
89
89
  deserialize: (data)=>data
90
90
  };
91
- if ('input' in opts.transformer) return {
92
- serialize: opts.transformer.input.serialize,
93
- deserialize: opts.transformer.output.deserialize
91
+ if ('input' in transformer) return {
92
+ serialize: transformer.input.serialize,
93
+ deserialize: transformer.output.deserialize
94
94
  };
95
- return opts.transformer;
95
+ return transformer;
96
96
  }
97
97
  this.runtime = {
98
98
  transformer: getTransformer()
@@ -102,21 +102,15 @@ class TRPCClient {
102
102
  }
103
103
  }
104
104
 
105
+ function createTRPCUntypedClient(opts) {
106
+ const client = new TRPCUntypedClient(opts);
107
+ return client;
108
+ }
109
+
105
110
  /**
106
111
  * @deprecated use `createTRPCProxyClient` instead
107
112
  */ function createTRPCClient(opts) {
108
- const getLinks = ()=>{
109
- if ('links' in opts) {
110
- return opts.links;
111
- }
112
- return [
113
- httpBatchLink(opts)
114
- ];
115
- };
116
- const client = new TRPCClient({
117
- transformer: opts.transformer,
118
- links: getLinks()
119
- });
113
+ const client = new TRPCUntypedClient(opts);
120
114
  return client;
121
115
  }
122
116
 
@@ -146,9 +140,9 @@ const clientCallTypeMap = {
146
140
  });
147
141
  }
148
142
  function createTRPCProxyClient(opts) {
149
- const client = new TRPCClient(opts);
143
+ const client = new TRPCUntypedClient(opts);
150
144
  const proxy = createTRPCClientProxy(client);
151
145
  return proxy;
152
146
  }
153
147
 
154
- export { createTRPCClient, createTRPCClientProxy, createTRPCProxyClient };
148
+ export { createTRPCClient, createTRPCClientProxy, createTRPCProxyClient, createTRPCUntypedClient };
@@ -0,0 +1,60 @@
1
+ import { AnyRouter, ClientDataTransformerOptions, CombinedDataTransformer, DataTransformerOptions, DefaultDataTransformer } from '@trpc/server';
2
+ import { Unsubscribable } from '@trpc/server/observable';
3
+ import { TRPCClientError } from '../TRPCClientError';
4
+ import { OperationContext, TRPCClientRuntime, TRPCLink } from '../links/types';
5
+ declare type CreateTRPCClientBaseOptions<TRouter extends AnyRouter> = TRouter['_def']['_config']['transformer'] extends DefaultDataTransformer ? {
6
+ /**
7
+ * Data transformer
8
+ *
9
+ * You must use the same transformer on the backend and frontend
10
+ * @link https://trpc.io/docs/data-transformers
11
+ **/
12
+ transformer?: 'You must set a transformer on the backend router';
13
+ } : TRouter['_def']['_config']['transformer'] extends DataTransformerOptions ? {
14
+ /**
15
+ * Data transformer
16
+ *
17
+ * You must use the same transformer on the backend and frontend
18
+ * @link https://trpc.io/docs/data-transformers
19
+ **/
20
+ transformer: TRouter['_def']['_config']['transformer'] extends CombinedDataTransformer ? DataTransformerOptions : TRouter['_def']['_config']['transformer'];
21
+ } : {
22
+ /**
23
+ * Data transformer
24
+ *
25
+ * You must use the same transformer on the backend and frontend
26
+ * @link https://trpc.io/docs/data-transformers
27
+ **/
28
+ transformer?: ClientDataTransformerOptions;
29
+ };
30
+ export interface TRPCRequestOptions {
31
+ /**
32
+ * Pass additional context to links
33
+ */
34
+ context?: OperationContext;
35
+ signal?: AbortSignal;
36
+ }
37
+ export interface TRPCSubscriptionObserver<TValue, TError> {
38
+ onStarted: () => void;
39
+ onData: (value: TValue) => void;
40
+ onError: (err: TError) => void;
41
+ onStopped: () => void;
42
+ onComplete: () => void;
43
+ }
44
+ /** @internal */
45
+ export declare type CreateTRPCClientOptions<TRouter extends AnyRouter> = CreateTRPCClientBaseOptions<TRouter> & {
46
+ links: TRPCLink<TRouter>[];
47
+ };
48
+ export declare class TRPCUntypedClient<TRouter extends AnyRouter> {
49
+ private readonly links;
50
+ readonly runtime: TRPCClientRuntime;
51
+ private requestId;
52
+ constructor(opts: CreateTRPCClientOptions<TRouter>);
53
+ private $request;
54
+ private requestAsPromise;
55
+ query(path: string, input?: unknown, opts?: TRPCRequestOptions): Promise<unknown>;
56
+ mutation(path: string, input?: unknown, opts?: TRPCRequestOptions): Promise<unknown>;
57
+ subscription(path: string, input: unknown, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<unknown, TRPCClientError<AnyRouter>>>): Unsubscribable;
58
+ }
59
+ export {};
60
+ //# sourceMappingURL=TRPCUntypedClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TRPCUntypedClient.d.ts","sourceRoot":"","sources":["../../src/internals/TRPCUntypedClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,4BAA4B,EAC5B,uBAAuB,EAEvB,sBA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SAAS,IACzD,2BAA2B,CAAC,OAAO,CAAC,GAAG;IACrC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;CAC5B,CAAC;AAEN,qBAAa,iBAAiB,CAAC,OAAO,SAAS,SAAS;IACtD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IACnD,SAAgB,OAAO,EAAE,iBAAiB,CAAC;IAC3C,OAAO,CAAC,SAAS,CAAS;gBAEd,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC;IA4BlD,OAAO,CAAC,QAAQ;IAuBhB,OAAO,CAAC,gBAAgB;IAyBjB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,kBAAkB;IAS9D,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,kBAAkB;IASjE,YAAY,CACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,kBAAkB,GACtB,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,GACvE,cAAc;CAyBlB"}
@@ -191,7 +191,7 @@ function createWSClient(opts) {
191
191
  delete pendingRequests[id];
192
192
  outgoing = outgoing.filter((msg)=>msg.id !== id);
193
193
  callbacks?.complete?.();
194
- if (activeConnection.readyState === WebSocket.OPEN && op.type === 'subscription') {
194
+ if (activeConnection.readyState === WebSocketImpl.OPEN && op.type === 'subscription') {
195
195
  outgoing.push({
196
196
  id,
197
197
  method: 'subscription.stop'
@@ -187,7 +187,7 @@ function createWSClient(opts) {
187
187
  delete pendingRequests[id];
188
188
  outgoing = outgoing.filter((msg)=>msg.id !== id);
189
189
  callbacks?.complete?.();
190
- if (activeConnection.readyState === WebSocket.OPEN && op.type === 'subscription') {
190
+ if (activeConnection.readyState === WebSocketImpl.OPEN && op.type === 'subscription') {
191
191
  outgoing.push({
192
192
  id,
193
193
  method: 'subscription.stop'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "10.6.0",
3
+ "version": "10.8.0",
4
4
  "description": "tRPC Client lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -25,6 +25,7 @@
25
25
  "build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
26
26
  "dev": "pnpm build --watch",
27
27
  "codegen:entrypoints": "tsx entrypoints.script.ts",
28
+ "lint": "eslint --ext \".js,.ts,.tsx\" --ignore-path ../../.gitignore --report-unused-disable-directives src",
28
29
  "ts-watch": "tsc --project tsconfig.watch.json"
29
30
  },
30
31
  "exports": {
@@ -66,17 +67,18 @@
66
67
  "links"
67
68
  ],
68
69
  "peerDependencies": {
69
- "@trpc/server": "10.6.0"
70
+ "@trpc/server": "10.8.0"
70
71
  },
71
72
  "devDependencies": {
72
73
  "@testing-library/dom": "^8.18.1",
73
- "@trpc/server": "10.6.0",
74
+ "@trpc/server": "10.8.0",
74
75
  "@types/node": "^18.7.20",
76
+ "eslint": "^8.30.0",
75
77
  "rollup": "^2.79.1",
76
78
  "tsx": "^3.9.0"
77
79
  },
78
80
  "publishConfig": {
79
81
  "access": "public"
80
82
  },
81
- "gitHead": "96bf1570091557de433533d4cab5f37cb256de1c"
83
+ "gitHead": "f5b4d4f398b2880725f472a2208e822e0f6ecb87"
82
84
  }
@@ -1,33 +1,64 @@
1
- import type { AnyRouter } from '@trpc/server';
1
+ import type {
2
+ AnyRouter,
3
+ inferProcedureInput,
4
+ inferProcedureOutput,
5
+ inferSubscriptionOutput,
6
+ } from '@trpc/server';
7
+ import { Unsubscribable } from '@trpc/server/observable';
8
+ import { inferTransformedProcedureOutput } from '@trpc/server/shared';
9
+ import { TRPCClientError } from './TRPCClientError';
2
10
  import {
3
- TRPCClient as Client,
4
11
  CreateTRPCClientOptions,
5
- } from './internals/TRPCClient';
6
- import { httpBatchLink } from './links';
12
+ TRPCRequestOptions,
13
+ TRPCSubscriptionObserver,
14
+ TRPCUntypedClient,
15
+ } from './internals/TRPCUntypedClient';
16
+ import { TRPCClientRuntime } from './links';
17
+
18
+ /**
19
+ * @deprecated
20
+ */
21
+ export interface TRPCClient<TRouter extends AnyRouter> {
22
+ readonly runtime: TRPCClientRuntime;
23
+ query<
24
+ TQueries extends TRouter['_def']['queries'],
25
+ TPath extends string & keyof TQueries,
26
+ TInput extends inferProcedureInput<TQueries[TPath]>,
27
+ >(
28
+ path: TPath,
29
+ input?: TInput,
30
+ opts?: TRPCRequestOptions,
31
+ ): Promise<inferProcedureOutput<TQueries[TPath]>>;
32
+
33
+ mutation<
34
+ TMutations extends TRouter['_def']['mutations'],
35
+ TPath extends string & keyof TMutations,
36
+ TInput extends inferProcedureInput<TMutations[TPath]>,
37
+ >(
38
+ path: TPath,
39
+ input?: TInput,
40
+ opts?: TRPCRequestOptions,
41
+ ): Promise<inferTransformedProcedureOutput<TMutations[TPath]>>;
7
42
 
43
+ subscription<
44
+ TSubscriptions extends TRouter['_def']['subscriptions'],
45
+ TPath extends string & keyof TSubscriptions,
46
+ // TODO - this should probably be updated to use inferTransformedProcedureOutput but this is only hit for legacy clients
47
+ TOutput extends inferSubscriptionOutput<TRouter, TPath>,
48
+ TInput extends inferProcedureInput<TSubscriptions[TPath]>,
49
+ >(
50
+ path: TPath,
51
+ input: TInput,
52
+ opts: TRPCRequestOptions &
53
+ Partial<TRPCSubscriptionObserver<TOutput, TRPCClientError<TRouter>>>,
54
+ ): Unsubscribable;
55
+ }
8
56
  /**
9
57
  * @deprecated use `createTRPCProxyClient` instead
10
58
  */
11
59
  export function createTRPCClient<TRouter extends AnyRouter>(
12
60
  opts: CreateTRPCClientOptions<TRouter>,
13
61
  ) {
14
- const getLinks = () => {
15
- if ('links' in opts) {
16
- return opts.links;
17
- }
18
- return [httpBatchLink(opts)];
19
- };
20
- const client = new Client<TRouter>({
21
- transformer: opts.transformer,
22
- links: getLinks(),
23
- });
24
- return client;
62
+ const client = new TRPCUntypedClient(opts);
63
+ return client as TRPCClient<TRouter>;
25
64
  }
26
-
27
- // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
28
-
29
- export type {
30
- CreateTRPCClientOptions,
31
- TRPCClient,
32
- TRPCRequestOptions,
33
- } from './internals/TRPCClient';
@@ -1,6 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
-
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
2
  import type {
5
3
  AnyMutationProcedure,
6
4
  AnyProcedure,
@@ -19,8 +17,12 @@ import {
19
17
  inferTransformedSubscriptionOutput,
20
18
  } from '@trpc/server/shared';
21
19
  import { TRPCClientError } from './TRPCClientError';
22
- import { CreateTRPCClientOptions } from './createTRPCClient';
23
- import { TRPCClient, TRPCSubscriptionObserver } from './internals/TRPCClient';
20
+ import { TRPCClient } from './createTRPCClient';
21
+ import { CreateTRPCClientOptions } from './createTRPCUntypedClient';
22
+ import {
23
+ TRPCSubscriptionObserver,
24
+ TRPCUntypedClient,
25
+ } from './internals/TRPCUntypedClient';
24
26
 
25
27
  export type inferRouterProxyClient<TRouter extends AnyRouter> =
26
28
  DecoratedProcedureRecord<TRouter['_def']['record'], TRouter>;
@@ -121,7 +123,7 @@ export function createTRPCClientProxy<TRouter extends AnyRouter>(
121
123
  export function createTRPCProxyClient<TRouter extends AnyRouter>(
122
124
  opts: CreateTRPCClientOptions<TRouter>,
123
125
  ) {
124
- const client = new TRPCClient<TRouter>(opts);
125
- const proxy = createTRPCClientProxy(client);
126
+ const client = new TRPCUntypedClient(opts);
127
+ const proxy = createTRPCClientProxy(client as TRPCClient<TRouter>);
126
128
  return proxy;
127
129
  }
@@ -0,0 +1,18 @@
1
+ import { AnyRouter } from '@trpc/server';
2
+ import {
3
+ CreateTRPCClientOptions,
4
+ TRPCUntypedClient,
5
+ } from './internals/TRPCUntypedClient';
6
+
7
+ export function createTRPCUntypedClient<TRouter extends AnyRouter>(
8
+ opts: CreateTRPCClientOptions<TRouter>,
9
+ ) {
10
+ const client = new TRPCUntypedClient(opts);
11
+ return client;
12
+ }
13
+
14
+ export type {
15
+ CreateTRPCClientOptions,
16
+ TRPCRequestOptions,
17
+ TRPCUntypedClient,
18
+ } from './internals/TRPCUntypedClient';
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './createTRPCUntypedClient';
1
2
  export * from './createTRPCClient';
2
3
  export * from './createTRPCClientProxy';
3
4
  export * from './getFetch';
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  AnyRouter,
3
3
  ClientDataTransformerOptions,
4
+ CombinedDataTransformer,
4
5
  DataTransformer,
5
- inferProcedureInput,
6
- inferProcedureOutput,
7
- inferSubscriptionOutput,
6
+ DataTransformerOptions,
7
+ DefaultDataTransformer,
8
8
  } from '@trpc/server';
9
9
  import {
10
10
  Unsubscribable,
@@ -12,7 +12,6 @@ import {
12
12
  observableToPromise,
13
13
  share,
14
14
  } from '@trpc/server/observable';
15
- import { inferTransformedProcedureOutput } from '@trpc/server/shared';
16
15
  import { TRPCClientError } from '../TRPCClientError';
17
16
  import { createChain } from '../links/internals/createChain';
18
17
  import {
@@ -22,13 +21,38 @@ import {
22
21
  TRPCLink,
23
22
  } from '../links/types';
24
23
 
25
- interface CreateTRPCClientBaseOptions {
26
- /**
27
- * Data transformer
28
- * @link https://trpc.io/docs/data-transformers
29
- **/
30
- transformer?: ClientDataTransformerOptions;
31
- }
24
+ type CreateTRPCClientBaseOptions<TRouter extends AnyRouter> =
25
+ TRouter['_def']['_config']['transformer'] extends DefaultDataTransformer
26
+ ? {
27
+ /**
28
+ * Data transformer
29
+ *
30
+ * You must use the same transformer on the backend and frontend
31
+ * @link https://trpc.io/docs/data-transformers
32
+ **/
33
+ transformer?: 'You must set a transformer on the backend router';
34
+ }
35
+ : TRouter['_def']['_config']['transformer'] extends DataTransformerOptions
36
+ ? {
37
+ /**
38
+ * Data transformer
39
+ *
40
+ * You must use the same transformer on the backend and frontend
41
+ * @link https://trpc.io/docs/data-transformers
42
+ **/
43
+ transformer: TRouter['_def']['_config']['transformer'] extends CombinedDataTransformer
44
+ ? DataTransformerOptions
45
+ : TRouter['_def']['_config']['transformer'];
46
+ }
47
+ : {
48
+ /**
49
+ * Data transformer
50
+ *
51
+ * You must use the same transformer on the backend and frontend
52
+ * @link https://trpc.io/docs/data-transformers
53
+ **/
54
+ transformer?: ClientDataTransformerOptions;
55
+ };
32
56
 
33
57
  type TRPCType = 'subscription' | 'query' | 'mutation';
34
58
  export interface TRPCRequestOptions {
@@ -49,12 +73,12 @@ export interface TRPCSubscriptionObserver<TValue, TError> {
49
73
 
50
74
  /** @internal */
51
75
  export type CreateTRPCClientOptions<TRouter extends AnyRouter> =
52
- | CreateTRPCClientBaseOptions & {
76
+ | CreateTRPCClientBaseOptions<TRouter> & {
53
77
  links: TRPCLink<TRouter>[];
54
78
  };
55
79
 
56
- export class TRPCClient<TRouter extends AnyRouter> {
57
- private readonly links: OperationLink<TRouter>[];
80
+ export class TRPCUntypedClient<TRouter extends AnyRouter> {
81
+ private readonly links: OperationLink<AnyRouter>[];
58
82
  public readonly runtime: TRPCClientRuntime;
59
83
  private requestId: number;
60
84
 
@@ -62,17 +86,21 @@ export class TRPCClient<TRouter extends AnyRouter> {
62
86
  this.requestId = 0;
63
87
 
64
88
  function getTransformer(): DataTransformer {
65
- if (!opts.transformer)
89
+ const transformer = opts.transformer as
90
+ | ClientDataTransformerOptions
91
+ | undefined;
92
+ if (!transformer)
66
93
  return {
67
94
  serialize: (data) => data,
68
95
  deserialize: (data) => data,
69
96
  };
70
- if ('input' in opts.transformer)
97
+
98
+ if ('input' in transformer)
71
99
  return {
72
- serialize: opts.transformer.input.serialize,
73
- deserialize: opts.transformer.output.deserialize,
100
+ serialize: transformer.input.serialize,
101
+ deserialize: transformer.output.deserialize,
74
102
  };
75
- return opts.transformer;
103
+ return transformer;
76
104
  }
77
105
 
78
106
  this.runtime = {
@@ -93,7 +121,7 @@ export class TRPCClient<TRouter extends AnyRouter> {
93
121
  path: string;
94
122
  context?: OperationContext;
95
123
  }) {
96
- const chain$ = createChain<TRouter, TInput, TOutput>({
124
+ const chain$ = createChain<AnyRouter, TInput, TOutput>({
97
125
  links: this.links as OperationLink<any, any, any>[],
98
126
  op: {
99
127
  id: ++this.requestId,
@@ -130,47 +158,31 @@ export class TRPCClient<TRouter extends AnyRouter> {
130
158
 
131
159
  return abortablePromise;
132
160
  }
133
- public query<
134
- TQueries extends TRouter['_def']['queries'],
135
- TPath extends string & keyof TQueries,
136
- TInput extends inferProcedureInput<TQueries[TPath]>,
137
- >(path: TPath, input?: TInput, opts?: TRPCRequestOptions) {
138
- type TOutput = inferProcedureOutput<TQueries[TPath]>;
139
- return this.requestAsPromise<TInput, TOutput>({
161
+ public query(path: string, input?: unknown, opts?: TRPCRequestOptions) {
162
+ return this.requestAsPromise<unknown, unknown>({
140
163
  type: 'query',
141
164
  path,
142
- input: input as TInput,
165
+ input,
143
166
  context: opts?.context,
144
167
  signal: opts?.signal,
145
168
  });
146
169
  }
147
- public mutation<
148
- TMutations extends TRouter['_def']['mutations'],
149
- TPath extends string & keyof TMutations,
150
- TInput extends inferProcedureInput<TMutations[TPath]>,
151
- >(path: TPath, input?: TInput, opts?: TRPCRequestOptions) {
152
- type TOutput = inferTransformedProcedureOutput<TMutations[TPath]>;
153
- return this.requestAsPromise<TInput, TOutput>({
170
+ public mutation(path: string, input?: unknown, opts?: TRPCRequestOptions) {
171
+ return this.requestAsPromise<unknown, unknown>({
154
172
  type: 'mutation',
155
173
  path,
156
- input: input as TInput,
174
+ input,
157
175
  context: opts?.context,
158
176
  signal: opts?.signal,
159
177
  });
160
178
  }
161
- public subscription<
162
- TSubscriptions extends TRouter['_def']['subscriptions'],
163
- TPath extends string & keyof TSubscriptions,
164
- // TODO - this should probably be updated to use inferTransformedProcedureOutput but this is only hit for legacy clients
165
- TOutput extends inferSubscriptionOutput<TRouter, TPath>,
166
- TInput extends inferProcedureInput<TSubscriptions[TPath]>,
167
- >(
168
- path: TPath,
169
- input: TInput,
179
+ public subscription(
180
+ path: string,
181
+ input: unknown,
170
182
  opts: TRPCRequestOptions &
171
- Partial<TRPCSubscriptionObserver<TOutput, TRPCClientError<TRouter>>>,
183
+ Partial<TRPCSubscriptionObserver<unknown, TRPCClientError<AnyRouter>>>,
172
184
  ): Unsubscribable {
173
- const observable$ = this.$request<TInput, TOutput>({
185
+ const observable$ = this.$request({
174
186
  type: 'subscription',
175
187
  path,
176
188
  input,
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
1
  import { observable } from '@trpc/server/observable';
3
2
  import { splitLink } from '../';
4
3
  import { OperationLink, TRPCLink } from '../';
@@ -265,7 +265,7 @@ export function createWSClient(opts: WebSocketClientOptions) {
265
265
 
266
266
  callbacks?.complete?.();
267
267
  if (
268
- activeConnection.readyState === WebSocket.OPEN &&
268
+ activeConnection.readyState === WebSocketImpl.OPEN &&
269
269
  op.type === 'subscription'
270
270
  ) {
271
271
  outgoing.push({
@@ -1,43 +0,0 @@
1
- import { AnyRouter, ClientDataTransformerOptions, inferProcedureInput, inferProcedureOutput, inferSubscriptionOutput } from '@trpc/server';
2
- import { Unsubscribable } from '@trpc/server/observable';
3
- import { inferTransformedProcedureOutput } from '@trpc/server/shared';
4
- import { TRPCClientError } from '../TRPCClientError';
5
- import { OperationContext, TRPCClientRuntime, TRPCLink } from '../links/types';
6
- interface CreateTRPCClientBaseOptions {
7
- /**
8
- * Data transformer
9
- * @link https://trpc.io/docs/data-transformers
10
- **/
11
- transformer?: ClientDataTransformerOptions;
12
- }
13
- export interface TRPCRequestOptions {
14
- /**
15
- * Pass additional context to links
16
- */
17
- context?: OperationContext;
18
- signal?: AbortSignal;
19
- }
20
- export interface TRPCSubscriptionObserver<TValue, TError> {
21
- onStarted: () => void;
22
- onData: (value: TValue) => void;
23
- onError: (err: TError) => void;
24
- onStopped: () => void;
25
- onComplete: () => void;
26
- }
27
- /** @internal */
28
- export declare type CreateTRPCClientOptions<TRouter extends AnyRouter> = CreateTRPCClientBaseOptions & {
29
- links: TRPCLink<TRouter>[];
30
- };
31
- export declare class TRPCClient<TRouter extends AnyRouter> {
32
- private readonly links;
33
- readonly runtime: TRPCClientRuntime;
34
- private requestId;
35
- constructor(opts: CreateTRPCClientOptions<TRouter>);
36
- private $request;
37
- private requestAsPromise;
38
- query<TQueries extends TRouter['_def']['queries'], TPath extends string & keyof TQueries, TInput extends inferProcedureInput<TQueries[TPath]>>(path: TPath, input?: TInput, opts?: TRPCRequestOptions): Promise<inferProcedureOutput<TQueries[TPath]>>;
39
- mutation<TMutations extends TRouter['_def']['mutations'], TPath extends string & keyof TMutations, TInput extends inferProcedureInput<TMutations[TPath]>>(path: TPath, input?: TInput, opts?: TRPCRequestOptions): Promise<inferTransformedProcedureOutput<TMutations[TPath]>>;
40
- subscription<TSubscriptions extends TRouter['_def']['subscriptions'], TPath extends string & keyof TSubscriptions, TOutput extends inferSubscriptionOutput<TRouter, TPath>, TInput extends inferProcedureInput<TSubscriptions[TPath]>>(path: TPath, input: TInput, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<TOutput, TRPCClientError<TRouter>>>): Unsubscribable;
41
- }
42
- export {};
43
- //# sourceMappingURL=TRPCClient.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TRPCClient.d.ts","sourceRoot":"","sources":["../../src/internals/TRPCClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,4BAA4B,EAE5B,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EAIf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD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