@trpc/client 10.0.0-alpha.30 → 10.0.0-alpha.31

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,9 +1,5 @@
1
1
  import type { AnyRouter } from '@trpc/server';
2
2
  import { TRPCClient as Client, CreateTRPCClientOptions } from './internals/TRPCClient';
3
- export declare type EnsureRecord<T> = T extends Record<string, any> ? T : Record<string, never>;
4
- declare type FlattenRouter<TRouter extends AnyRouter> = {
5
- [Key in keyof TRouter['_def']['procedures']]: TRouter['_def']['procedures'][Key] extends AnyRouter ? FlattenRouter<TRouter['_def']['procedures'][Key]> : TRouter['_def']['procedures'][Key];
6
- };
7
- export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): Client<TRouter> & FlattenRouter<TRouter>;
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);
8
4
  export type { TRPCRequestOptions, CreateTRPCClientOptions, TRPCClient, } from './internals/TRPCClient';
9
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;AAC9C,OAAO,EACL,UAAU,IAAI,MAAM,EACpB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAEhC,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACvD,CAAC,GACD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE1B,aAAK,aAAa,CAAC,OAAO,SAAS,SAAS,IAAI;KAC7C,GAAG,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,SAAS,SAAS,GAC9F,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,GACjD,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC;CACvC,CAAC;AAyCF,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,4CAKvC;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;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"}
@@ -0,0 +1,8 @@
1
+ import type { AnyRouter } from '@trpc/server';
2
+ import { TRPCClient as Client } from './internals/TRPCClient';
3
+ declare type FlattenRouter<TRouter extends AnyRouter> = {
4
+ [Key in keyof TRouter['_def']['record']]: TRouter['_def']['record'][Key] extends AnyRouter ? FlattenRouter<TRouter['_def']['record'][Key]> : TRouter['_def']['record'][Key];
5
+ };
6
+ export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): Client<TRouter> & FlattenRouter<TRouter>;
7
+ export {};
8
+ //# sourceMappingURL=createTRPCClientProxy.d.ts.map
@@ -0,0 +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"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './createTRPCClient';
2
+ export * from './createTRPCClientProxy';
2
3
  export * from './getFetch';
3
4
  export * from './TRPCClientError';
4
5
  export * from './links';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,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,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -27,6 +27,54 @@ var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallChec
27
27
  var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
28
28
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
29
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
+ }
77
+
30
78
  function getWindow() {
31
79
  if (typeof window !== 'undefined') {
32
80
  return window;
@@ -408,51 +456,10 @@ var TRPCClient = /*#__PURE__*/function () {
408
456
  return TRPCClient;
409
457
  }();
410
458
 
411
- function makeProxy(client) {
412
- for (var _len = arguments.length, path = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
413
- path[_key - 1] = arguments[_key];
414
- }
415
-
416
- var proxy = new Proxy(function () {// noop
417
- }, {
418
- get: function get(_obj, name) {
419
- if (name in client && !path.length) {
420
- return client[name];
421
- }
422
-
423
- if (typeof name === 'string') {
424
- return makeProxy.apply(void 0, [client].concat(path, [name]));
425
- }
426
-
427
- return client;
428
- },
429
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
430
- apply: function apply(_1, _2, args) {
431
- var _ref;
432
-
433
- var pathCopy = [].concat(path);
434
- var type = pathCopy.pop();
435
-
436
- if (type === 'mutate') {
437
- type = 'mutation';
438
- }
439
-
440
- var fullPath = pathCopy.join('.');
441
-
442
- if (type.startsWith('use')) {
443
- throw new Error("Invalid hook call");
444
- }
445
-
446
- return (_ref = client)[type].apply(_ref, [fullPath].concat(_toConsumableArray__default["default"](args)));
447
- }
448
- });
449
- return proxy;
450
- }
451
-
459
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
452
460
  function createTRPCClient(opts) {
453
- var client = new TRPCClient(opts); // Here we need to wrap the client in a Proxy to be able to call deep objects and translate them to `client.query`-calls
454
-
455
- return makeProxy(client);
461
+ var client = new TRPCClient(opts);
462
+ return createTRPCClientProxy(client);
456
463
  } // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
457
464
 
458
465
  exports.TRPCClientError = links_wsLink.TRPCClientError;
@@ -463,6 +470,7 @@ exports.splitLink = links_splitLink.splitLink;
463
470
  exports.httpLink = links_httpLink.httpLink;
464
471
  exports.loggerLink = links_loggerLink.loggerLink;
465
472
  exports.createTRPCClient = createTRPCClient;
473
+ exports.createTRPCClientProxy = createTRPCClientProxy;
466
474
  exports.dedupeLink = dedupeLink;
467
475
  exports.getFetch = getFetch;
468
476
  exports.retryLink = retryLink;
package/dist/index.mjs CHANGED
@@ -19,6 +19,54 @@ export { httpLink } from './links/httpLink.mjs';
19
19
  export { loggerLink } from './links/loggerLink.mjs';
20
20
  import './httpUtils-089853f6.mjs';
21
21
 
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
+
22
70
  function getWindow() {
23
71
  if (typeof window !== 'undefined') {
24
72
  return window;
@@ -400,51 +448,10 @@ var TRPCClient = /*#__PURE__*/function () {
400
448
  return TRPCClient;
401
449
  }();
402
450
 
403
- function makeProxy(client) {
404
- for (var _len = arguments.length, path = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
405
- path[_key - 1] = arguments[_key];
406
- }
407
-
408
- var proxy = new Proxy(function () {// noop
409
- }, {
410
- get: function get(_obj, name) {
411
- if (name in client && !path.length) {
412
- return client[name];
413
- }
414
-
415
- if (typeof name === 'string') {
416
- return makeProxy.apply(void 0, [client].concat(path, [name]));
417
- }
418
-
419
- return client;
420
- },
421
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
422
- apply: function apply(_1, _2, args) {
423
- var _ref;
424
-
425
- var pathCopy = [].concat(path);
426
- var type = pathCopy.pop();
427
-
428
- if (type === 'mutate') {
429
- type = 'mutation';
430
- }
431
-
432
- var fullPath = pathCopy.join('.');
433
-
434
- if (type.startsWith('use')) {
435
- throw new Error("Invalid hook call");
436
- }
437
-
438
- return (_ref = client)[type].apply(_ref, [fullPath].concat(_toConsumableArray(args)));
439
- }
440
- });
441
- return proxy;
442
- }
443
-
451
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
444
452
  function createTRPCClient(opts) {
445
- var client = new TRPCClient(opts); // Here we need to wrap the client in a Proxy to be able to call deep objects and translate them to `client.query`-calls
446
-
447
- return makeProxy(client);
453
+ var client = new TRPCClient(opts);
454
+ return createTRPCClientProxy(client);
448
455
  } // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
449
456
 
450
- export { createTRPCClient, dedupeLink, getFetch, retryLink };
457
+ 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.30",
3
+ "version": "10.0.0-alpha.31",
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.30"
70
+ "@trpc/server": "10.0.0-alpha.31"
71
71
  },
72
72
  "devDependencies": {
73
- "@trpc/server": "10.0.0-alpha.30"
73
+ "@trpc/server": "10.0.0-alpha.31"
74
74
  },
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  },
78
- "gitHead": "31e28de6c0469b28a6f39378f931f35e469f17f4"
78
+ "gitHead": "c5ec72d9866dcb1e2df1ec881a6e4bb18362c7b6"
79
79
  }
@@ -2,66 +2,17 @@
2
2
 
3
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
4
  import type { AnyRouter } from '@trpc/server';
5
+ import { createTRPCClientProxy } from './createTRPCClientProxy';
5
6
  import {
6
7
  TRPCClient as Client,
7
8
  CreateTRPCClientOptions,
8
9
  } from './internals/TRPCClient';
9
10
 
10
- export type EnsureRecord<T> = T extends Record<string, any>
11
- ? T
12
- : Record<string, never>;
13
-
14
- type FlattenRouter<TRouter extends AnyRouter> = {
15
- [Key in keyof TRouter['_def']['procedures']]: TRouter['_def']['procedures'][Key] extends AnyRouter
16
- ? FlattenRouter<TRouter['_def']['procedures'][Key]>
17
- : TRouter['_def']['procedures'][Key];
18
- };
19
-
20
- function makeProxy<TRouter extends AnyRouter>(
21
- client: Client<TRouter>,
22
- ...path: string[]
23
- ) {
24
- const proxy: any = new Proxy(
25
- function () {
26
- // noop
27
- },
28
- {
29
- get(_obj, name) {
30
- if (name in client && !path.length) {
31
- return client[name as keyof typeof client];
32
- }
33
- if (typeof name === 'string') {
34
- return makeProxy(client, ...path, name);
35
- }
36
-
37
- return client;
38
- },
39
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
- apply(_1, _2, args) {
41
- const pathCopy = [...path];
42
- let type = pathCopy.pop()!;
43
- if (type === 'mutate') {
44
- type = 'mutation';
45
- }
46
- const fullPath = pathCopy.join('.');
47
-
48
- if (type.startsWith('use')) {
49
- throw new Error(`Invalid hook call`);
50
- }
51
-
52
- return (client as any)[type](fullPath, ...args);
53
- },
54
- },
55
- );
56
-
57
- return proxy as typeof client & FlattenRouter<TRouter>;
58
- }
59
11
  export function createTRPCClient<TRouter extends AnyRouter>(
60
12
  opts: CreateTRPCClientOptions<TRouter>,
61
13
  ) {
62
14
  const client = new Client<TRouter>(opts);
63
- // Here we need to wrap the client in a Proxy to be able to call deep objects and translate them to `client.query`-calls
64
- return makeProxy(client);
15
+ return createTRPCClientProxy(client);
65
16
  }
66
17
 
67
18
  // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
@@ -0,0 +1,56 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ import type { AnyRouter } from '@trpc/server';
5
+ import { TRPCClient as Client } from './internals/TRPCClient';
6
+
7
+ type FlattenRouter<TRouter extends AnyRouter> = {
8
+ [Key in keyof TRouter['_def']['record']]: TRouter['_def']['record'][Key] extends AnyRouter
9
+ ? FlattenRouter<TRouter['_def']['record'][Key]>
10
+ : TRouter['_def']['record'][Key];
11
+ };
12
+
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
+ export function createTRPCClientProxy<TRouter extends AnyRouter>(
53
+ client: Client<TRouter>,
54
+ ) {
55
+ return makeProxy(client);
56
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './createTRPCClient';
2
+ export * from './createTRPCClientProxy';
2
3
  export * from './getFetch';
3
4
  export * from './TRPCClientError';
4
5
  export * from './links';