@trpc/client 10.0.0-alpha.33 → 10.0.0-alpha.36

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,5 +1,5 @@
1
1
  import type { AnyRouter } from '@trpc/server';
2
2
  import { TRPCClient as Client, CreateTRPCClientOptions } from './internals/TRPCClient';
3
- export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): Client<TRouter> & (TRouter["_def"]["record"] extends infer T ? { [Key in keyof T]: TRouter["_def"]["record"][Key] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"] extends infer T_1 ? { [Key_1 in keyof T_1]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"] extends infer T_2 ? { [Key_2 in keyof T_2]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"] extends infer T_3 ? { [Key_3 in keyof T_3]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"] extends infer T_4 ? { [Key_4 in keyof T_4]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"] extends infer T_5 ? { [Key_5 in keyof T_5]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"] extends infer T_6 ? { [Key_6 in keyof T_6]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"] extends infer T_7 ? { [Key_7 in keyof T_7]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"] extends infer T_8 ? { [Key_8 in keyof T_8]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"] extends infer T_9 ? { [Key_9 in keyof T_9]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9]["_def"]["record"] extends infer T_10 ? { [Key_10 in keyof T_10]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9]["_def"]["record"][Key_10] extends AnyRouter ? any : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9]["_def"]["record"][Key_10]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]; } : never : TRouter["_def"]["record"][Key]; } : never);
3
+ export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): Client<TRouter>;
4
4
  export type { TRPCRequestOptions, CreateTRPCClientOptions, TRPCClient, } from './internals/TRPCClient';
5
5
  //# sourceMappingURL=createTRPCClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EACL,UAAU,IAAI,MAAM,EACpB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,0zLAIvC;AAID,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,GACX,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,UAAU,IAAI,MAAM,EACpB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,mBAIvC;AAID,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,GACX,MAAM,wBAAwB,CAAC"}
@@ -1,8 +1,10 @@
1
1
  import type { AnyRouter } from '@trpc/server';
2
2
  import { TRPCClient as Client } from './internals/TRPCClient';
3
- declare type FlattenRouter<TRouter extends AnyRouter> = {
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare type FlattenRouter<TRouter extends AnyRouter> = {
4
7
  [Key in keyof TRouter['_def']['record']]: TRouter['_def']['record'][Key] extends AnyRouter ? FlattenRouter<TRouter['_def']['record'][Key]> : TRouter['_def']['record'][Key];
5
8
  };
6
- export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): Client<TRouter> & FlattenRouter<TRouter>;
7
- export {};
9
+ export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): FlattenRouter<TRouter>;
8
10
  //# sourceMappingURL=createTRPCClientProxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE9D,aAAK,aAAa,CAAC,OAAO,SAAS,SAAS,IAAI;KAC7C,GAAG,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,SAAS,SAAS,GACtF,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,GAC7C,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC;CACnC,CAAC;AAyCF,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,4CAGxB"}
1
+ {"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;GAEG;AACH,oBAAY,aAAa,CAAC,OAAO,SAAS,SAAS,IAAI;KACpD,GAAG,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,SAAS,SAAS,GACtF,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,GAC7C,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC;CACnC,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,0BAYxB"}
package/dist/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
6
5
  var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
7
6
  var _createClass = require('@babel/runtime/helpers/createClass');
8
7
  var observable = require('@trpc/server/observable');
@@ -16,64 +15,18 @@ require('@babel/runtime/helpers/inherits');
16
15
  require('@babel/runtime/helpers/possibleConstructorReturn');
17
16
  require('@babel/runtime/helpers/getPrototypeOf');
18
17
  require('@babel/runtime/helpers/wrapNativeSuper');
18
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
19
+ var shared = require('@trpc/server/shared');
19
20
  var links_httpLink = require('./links/httpLink.js');
20
21
  var links_loggerLink = require('./links/loggerLink.js');
21
22
  require('./httpUtils-a0169eef.js');
22
23
 
23
24
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
24
25
 
25
- var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
26
26
  var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
27
27
  var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
28
28
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
29
-
30
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
31
-
32
- /* eslint-disable @typescript-eslint/no-explicit-any */
33
- function makeProxy(client) {
34
- for (var _len = arguments.length, path = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
35
- path[_key - 1] = arguments[_key];
36
- }
37
-
38
- var proxy = new Proxy(function () {// noop
39
- }, {
40
- get: function get(_obj, name) {
41
- if (name in client && !path.length) {
42
- return client[name];
43
- }
44
-
45
- if (typeof name === 'string') {
46
- return makeProxy.apply(void 0, [client].concat(path, [name]));
47
- }
48
-
49
- return client;
50
- },
51
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
52
- apply: function apply(_1, _2, args) {
53
- var _ref;
54
-
55
- var pathCopy = [].concat(path);
56
- var type = pathCopy.pop();
57
-
58
- if (type === 'mutate') {
59
- type = 'mutation';
60
- }
61
-
62
- var fullPath = pathCopy.join('.');
63
-
64
- if (type.startsWith('use')) {
65
- throw new Error("Invalid hook call");
66
- }
67
-
68
- return (_ref = client)[type].apply(_ref, [fullPath].concat(_toConsumableArray__default["default"](args)));
69
- }
70
- });
71
- return proxy;
72
- }
73
-
74
- function createTRPCClientProxy(client) {
75
- return makeProxy(client);
76
- }
29
+ var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
77
30
 
78
31
  function getWindow() {
79
32
  if (typeof window !== 'undefined') {
@@ -459,9 +412,30 @@ var TRPCClient = /*#__PURE__*/function () {
459
412
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
460
413
  function createTRPCClient(opts) {
461
414
  var client = new TRPCClient(opts);
462
- return createTRPCClientProxy(client);
415
+ return client;
463
416
  } // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
464
417
 
418
+ function createTRPCClientProxy(client) {
419
+ var proxy = shared.createProxy(function (_ref) {
420
+ var _ref2;
421
+
422
+ var path = _ref.path,
423
+ args = _ref.args;
424
+
425
+ var pathCopy = _toConsumableArray__default["default"](path);
426
+
427
+ var type = pathCopy.pop();
428
+
429
+ if (type === 'mutate') {
430
+ type = 'mutation';
431
+ }
432
+
433
+ var fullPath = pathCopy.join('.');
434
+ return (_ref2 = client)[type].apply(_ref2, [fullPath].concat(_toConsumableArray__default["default"](args)));
435
+ });
436
+ return proxy;
437
+ }
438
+
465
439
  exports.TRPCClientError = links_wsLink.TRPCClientError;
466
440
  exports.createWSClient = links_wsLink.createWSClient;
467
441
  exports.wsLink = links_wsLink.wsLink;
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
1
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
3
2
  import _createClass from '@babel/runtime/helpers/createClass';
4
3
  import { observable, share, observableToPromise } from '@trpc/server/observable';
@@ -15,58 +14,12 @@ import '@babel/runtime/helpers/inherits';
15
14
  import '@babel/runtime/helpers/possibleConstructorReturn';
16
15
  import '@babel/runtime/helpers/getPrototypeOf';
17
16
  import '@babel/runtime/helpers/wrapNativeSuper';
17
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
18
+ import { createProxy } from '@trpc/server/shared';
18
19
  export { httpLink } from './links/httpLink.mjs';
19
20
  export { loggerLink } from './links/loggerLink.mjs';
20
21
  import './httpUtils-089853f6.mjs';
21
22
 
22
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
23
-
24
- /* eslint-disable @typescript-eslint/no-explicit-any */
25
- function makeProxy(client) {
26
- for (var _len = arguments.length, path = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
27
- path[_key - 1] = arguments[_key];
28
- }
29
-
30
- var proxy = new Proxy(function () {// noop
31
- }, {
32
- get: function get(_obj, name) {
33
- if (name in client && !path.length) {
34
- return client[name];
35
- }
36
-
37
- if (typeof name === 'string') {
38
- return makeProxy.apply(void 0, [client].concat(path, [name]));
39
- }
40
-
41
- return client;
42
- },
43
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
- apply: function apply(_1, _2, args) {
45
- var _ref;
46
-
47
- var pathCopy = [].concat(path);
48
- var type = pathCopy.pop();
49
-
50
- if (type === 'mutate') {
51
- type = 'mutation';
52
- }
53
-
54
- var fullPath = pathCopy.join('.');
55
-
56
- if (type.startsWith('use')) {
57
- throw new Error("Invalid hook call");
58
- }
59
-
60
- return (_ref = client)[type].apply(_ref, [fullPath].concat(_toConsumableArray(args)));
61
- }
62
- });
63
- return proxy;
64
- }
65
-
66
- function createTRPCClientProxy(client) {
67
- return makeProxy(client);
68
- }
69
-
70
23
  function getWindow() {
71
24
  if (typeof window !== 'undefined') {
72
25
  return window;
@@ -451,7 +404,28 @@ var TRPCClient = /*#__PURE__*/function () {
451
404
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
452
405
  function createTRPCClient(opts) {
453
406
  var client = new TRPCClient(opts);
454
- return createTRPCClientProxy(client);
407
+ return client;
455
408
  } // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
456
409
 
410
+ function createTRPCClientProxy(client) {
411
+ var proxy = createProxy(function (_ref) {
412
+ var _ref2;
413
+
414
+ var path = _ref.path,
415
+ args = _ref.args;
416
+
417
+ var pathCopy = _toConsumableArray(path);
418
+
419
+ var type = pathCopy.pop();
420
+
421
+ if (type === 'mutate') {
422
+ type = 'mutation';
423
+ }
424
+
425
+ var fullPath = pathCopy.join('.');
426
+ return (_ref2 = client)[type].apply(_ref2, [fullPath].concat(_toConsumableArray(args)));
427
+ });
428
+ return proxy;
429
+ }
430
+
457
431
  export { createTRPCClient, createTRPCClientProxy, dedupeLink, getFetch, retryLink };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "10.0.0-alpha.33",
3
+ "version": "10.0.0-alpha.36",
4
4
  "description": "tRPC Client lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -67,13 +67,13 @@
67
67
  "@babel/runtime": "^7.9.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "@trpc/server": "10.0.0-alpha.33"
70
+ "@trpc/server": "10.0.0-alpha.36"
71
71
  },
72
72
  "devDependencies": {
73
- "@trpc/server": "10.0.0-alpha.33"
73
+ "@trpc/server": "10.0.0-alpha.36"
74
74
  },
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  },
78
- "gitHead": "c8c29ee70a7a5c3c6a319da0b43dc8fb4e89ab0d"
78
+ "gitHead": "c45c7bddde215ec057b2695a5b458cac67451cf3"
79
79
  }
@@ -2,7 +2,6 @@
2
2
 
3
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
4
  import type { AnyRouter } from '@trpc/server';
5
- import { createTRPCClientProxy } from './createTRPCClientProxy';
6
5
  import {
7
6
  TRPCClient as Client,
8
7
  CreateTRPCClientOptions,
@@ -12,7 +11,7 @@ export function createTRPCClient<TRouter extends AnyRouter>(
12
11
  opts: CreateTRPCClientOptions<TRouter>,
13
12
  ) {
14
13
  const client = new Client<TRouter>(opts);
15
- return createTRPCClientProxy(client);
14
+ return client;
16
15
  }
17
16
 
18
17
  // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
@@ -2,55 +2,29 @@
2
2
 
3
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
4
  import type { AnyRouter } from '@trpc/server';
5
+ import { createProxy } from '@trpc/server/shared';
5
6
  import { TRPCClient as Client } from './internals/TRPCClient';
6
7
 
7
- type FlattenRouter<TRouter extends AnyRouter> = {
8
+ /**
9
+ * @internal
10
+ */
11
+ export type FlattenRouter<TRouter extends AnyRouter> = {
8
12
  [Key in keyof TRouter['_def']['record']]: TRouter['_def']['record'][Key] extends AnyRouter
9
13
  ? FlattenRouter<TRouter['_def']['record'][Key]>
10
14
  : TRouter['_def']['record'][Key];
11
15
  };
12
16
 
13
- function makeProxy<TRouter extends AnyRouter>(
14
- client: Client<TRouter>,
15
- ...path: string[]
16
- ) {
17
- const proxy: any = new Proxy(
18
- function () {
19
- // noop
20
- },
21
- {
22
- get(_obj, name) {
23
- if (name in client && !path.length) {
24
- return client[name as keyof typeof client];
25
- }
26
- if (typeof name === 'string') {
27
- return makeProxy(client, ...path, name);
28
- }
29
-
30
- return client;
31
- },
32
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
- apply(_1, _2, args) {
34
- const pathCopy = [...path];
35
- let type = pathCopy.pop()!;
36
- if (type === 'mutate') {
37
- type = 'mutation';
38
- }
39
- const fullPath = pathCopy.join('.');
40
-
41
- if (type.startsWith('use')) {
42
- throw new Error(`Invalid hook call`);
43
- }
44
-
45
- return (client as any)[type](fullPath, ...args);
46
- },
47
- },
48
- );
49
-
50
- return proxy as typeof client & FlattenRouter<TRouter>;
51
- }
52
17
  export function createTRPCClientProxy<TRouter extends AnyRouter>(
53
18
  client: Client<TRouter>,
54
19
  ) {
55
- return makeProxy(client);
20
+ const proxy = createProxy(({ path, args }) => {
21
+ const pathCopy = [...path];
22
+ let type = pathCopy.pop()!;
23
+ if (type === 'mutate') {
24
+ type = 'mutation';
25
+ }
26
+ const fullPath = pathCopy.join('.');
27
+ return (client as any)[type](fullPath, ...args);
28
+ });
29
+ return proxy as FlattenRouter<TRouter>;
56
30
  }