@trpc/client 10.0.0-alpha.30 → 10.0.0-alpha.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createTRPCClient.d.ts +1 -5
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClientProxy.d.ts +8 -0
- package/dist/createTRPCClientProxy.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -44
- package/dist/index.mjs +52 -45
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +14 -80
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +14 -80
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +14 -76
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +9 -76
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +9 -76
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +9 -72
- package/package.json +4 -4
- package/src/createTRPCClient.ts +2 -51
- package/src/createTRPCClientProxy.ts +56 -0
- package/src/index.ts +1 -0
|
@@ -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
|
|
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;
|
|
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
package/dist/index.d.ts.map
CHANGED
|
@@ -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
|
-
|
|
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);
|
|
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
|
-
|
|
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);
|
|
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 };
|
|
@@ -2,23 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
|
-
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
|
-
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
8
|
-
require('@babel/runtime/helpers/classCallCheck');
|
|
9
|
-
require('@babel/runtime/helpers/createClass');
|
|
10
5
|
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
11
|
-
var transformRPCResponse = require('../../../dist/transformRPCResponse-
|
|
6
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-0ad3cc9f.cjs.dev.js');
|
|
12
7
|
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
8
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
9
|
+
require('@babel/runtime/helpers/classCallCheck');
|
|
10
|
+
require('@babel/runtime/helpers/createClass');
|
|
13
11
|
require('@babel/runtime/helpers/assertThisInitialized');
|
|
14
12
|
require('@babel/runtime/helpers/inherits');
|
|
15
13
|
require('@babel/runtime/helpers/createSuper');
|
|
16
14
|
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
17
15
|
|
|
18
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
-
|
|
20
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
21
|
-
|
|
22
16
|
/**
|
|
23
17
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
24
18
|
* Less configuration, no caching, and allows you to cancel requests
|
|
@@ -130,65 +124,12 @@ function httpBatchLink(opts) {
|
|
|
130
124
|
|
|
131
125
|
return function (runtime) {
|
|
132
126
|
// initialized in app
|
|
133
|
-
var getHeaders = /*#__PURE__*/function () {
|
|
134
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(arg1) {
|
|
135
|
-
var val;
|
|
136
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
137
|
-
while (1) {
|
|
138
|
-
switch (_context.prev = _context.next) {
|
|
139
|
-
case 0:
|
|
140
|
-
val = opts.headers;
|
|
141
|
-
_context.t0 = _objectSpread;
|
|
142
|
-
_context.t1 = _objectSpread;
|
|
143
|
-
_context.t2 = {};
|
|
144
|
-
_context.next = 6;
|
|
145
|
-
return runtime.headers();
|
|
146
|
-
|
|
147
|
-
case 6:
|
|
148
|
-
_context.t3 = _context.sent;
|
|
149
|
-
_context.t4 = (0, _context.t1)(_context.t2, _context.t3);
|
|
150
|
-
|
|
151
|
-
if (!(typeof val === 'function')) {
|
|
152
|
-
_context.next = 14;
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
_context.next = 11;
|
|
157
|
-
return val(arg1);
|
|
158
|
-
|
|
159
|
-
case 11:
|
|
160
|
-
_context.t5 = _context.sent;
|
|
161
|
-
_context.next = 15;
|
|
162
|
-
break;
|
|
163
|
-
|
|
164
|
-
case 14:
|
|
165
|
-
_context.t5 = val;
|
|
166
|
-
|
|
167
|
-
case 15:
|
|
168
|
-
_context.t6 = _context.t5;
|
|
169
|
-
return _context.abrupt("return", (0, _context.t0)(_context.t4, _context.t6));
|
|
170
|
-
|
|
171
|
-
case 17:
|
|
172
|
-
case "end":
|
|
173
|
-
return _context.stop();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}, _callee);
|
|
177
|
-
}));
|
|
178
|
-
|
|
179
|
-
return function getHeaders(_x) {
|
|
180
|
-
return _ref.apply(this, arguments);
|
|
181
|
-
};
|
|
182
|
-
}();
|
|
183
|
-
|
|
184
127
|
var fetcher = function fetcher(type) {
|
|
185
|
-
return function (
|
|
186
|
-
var
|
|
187
|
-
|
|
188
|
-
var path = pairs.map(function (op) {
|
|
128
|
+
return function (keyInputPairs) {
|
|
129
|
+
var path = keyInputPairs.map(function (op) {
|
|
189
130
|
return op.path;
|
|
190
131
|
}).join(',');
|
|
191
|
-
var inputs =
|
|
132
|
+
var inputs = keyInputPairs.map(function (op) {
|
|
192
133
|
return op.input;
|
|
193
134
|
});
|
|
194
135
|
|
|
@@ -196,15 +137,8 @@ function httpBatchLink(opts) {
|
|
|
196
137
|
url: url,
|
|
197
138
|
inputs: inputs,
|
|
198
139
|
path: path,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
AbortController: transformRPCResponse.getAbortController((_opts$AbortController = opts.AbortController) !== null && _opts$AbortController !== void 0 ? _opts$AbortController : runtime.AbortController),
|
|
202
|
-
headers: function headers() {
|
|
203
|
-
return getHeaders({
|
|
204
|
-
operations: pairs
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
transformer: runtime.transformer
|
|
140
|
+
runtime: runtime,
|
|
141
|
+
type: type
|
|
208
142
|
}),
|
|
209
143
|
promise = _httpRequest.promise,
|
|
210
144
|
cancel = _httpRequest.cancel;
|
|
@@ -212,7 +146,7 @@ function httpBatchLink(opts) {
|
|
|
212
146
|
return {
|
|
213
147
|
promise: promise.then(function (res) {
|
|
214
148
|
if (!Array.isArray(res)) {
|
|
215
|
-
return
|
|
149
|
+
return keyInputPairs.map(function () {
|
|
216
150
|
return res;
|
|
217
151
|
});
|
|
218
152
|
}
|
|
@@ -238,10 +172,10 @@ function httpBatchLink(opts) {
|
|
|
238
172
|
subscription: subscription,
|
|
239
173
|
mutation: mutation
|
|
240
174
|
};
|
|
241
|
-
return function (
|
|
242
|
-
var op =
|
|
243
|
-
prev =
|
|
244
|
-
onDestroy =
|
|
175
|
+
return function (_ref) {
|
|
176
|
+
var op = _ref.op,
|
|
177
|
+
prev = _ref.prev,
|
|
178
|
+
onDestroy = _ref.onDestroy;
|
|
245
179
|
var loader = loaders[op.type];
|
|
246
180
|
|
|
247
181
|
var _loader$load = loader.load(op),
|
|
@@ -2,23 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
|
-
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
|
-
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
8
|
-
require('@babel/runtime/helpers/classCallCheck');
|
|
9
|
-
require('@babel/runtime/helpers/createClass');
|
|
10
5
|
var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
|
|
11
|
-
var transformRPCResponse = require('../../../dist/transformRPCResponse-
|
|
6
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-e6daeb02.cjs.prod.js');
|
|
12
7
|
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
8
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
9
|
+
require('@babel/runtime/helpers/classCallCheck');
|
|
10
|
+
require('@babel/runtime/helpers/createClass');
|
|
13
11
|
require('@babel/runtime/helpers/assertThisInitialized');
|
|
14
12
|
require('@babel/runtime/helpers/inherits');
|
|
15
13
|
require('@babel/runtime/helpers/createSuper');
|
|
16
14
|
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
17
15
|
|
|
18
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
-
|
|
20
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
21
|
-
|
|
22
16
|
/**
|
|
23
17
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
24
18
|
* Less configuration, no caching, and allows you to cancel requests
|
|
@@ -130,65 +124,12 @@ function httpBatchLink(opts) {
|
|
|
130
124
|
|
|
131
125
|
return function (runtime) {
|
|
132
126
|
// initialized in app
|
|
133
|
-
var getHeaders = /*#__PURE__*/function () {
|
|
134
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(arg1) {
|
|
135
|
-
var val;
|
|
136
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
137
|
-
while (1) {
|
|
138
|
-
switch (_context.prev = _context.next) {
|
|
139
|
-
case 0:
|
|
140
|
-
val = opts.headers;
|
|
141
|
-
_context.t0 = _objectSpread;
|
|
142
|
-
_context.t1 = _objectSpread;
|
|
143
|
-
_context.t2 = {};
|
|
144
|
-
_context.next = 6;
|
|
145
|
-
return runtime.headers();
|
|
146
|
-
|
|
147
|
-
case 6:
|
|
148
|
-
_context.t3 = _context.sent;
|
|
149
|
-
_context.t4 = (0, _context.t1)(_context.t2, _context.t3);
|
|
150
|
-
|
|
151
|
-
if (!(typeof val === 'function')) {
|
|
152
|
-
_context.next = 14;
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
_context.next = 11;
|
|
157
|
-
return val(arg1);
|
|
158
|
-
|
|
159
|
-
case 11:
|
|
160
|
-
_context.t5 = _context.sent;
|
|
161
|
-
_context.next = 15;
|
|
162
|
-
break;
|
|
163
|
-
|
|
164
|
-
case 14:
|
|
165
|
-
_context.t5 = val;
|
|
166
|
-
|
|
167
|
-
case 15:
|
|
168
|
-
_context.t6 = _context.t5;
|
|
169
|
-
return _context.abrupt("return", (0, _context.t0)(_context.t4, _context.t6));
|
|
170
|
-
|
|
171
|
-
case 17:
|
|
172
|
-
case "end":
|
|
173
|
-
return _context.stop();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}, _callee);
|
|
177
|
-
}));
|
|
178
|
-
|
|
179
|
-
return function getHeaders(_x) {
|
|
180
|
-
return _ref.apply(this, arguments);
|
|
181
|
-
};
|
|
182
|
-
}();
|
|
183
|
-
|
|
184
127
|
var fetcher = function fetcher(type) {
|
|
185
|
-
return function (
|
|
186
|
-
var
|
|
187
|
-
|
|
188
|
-
var path = pairs.map(function (op) {
|
|
128
|
+
return function (keyInputPairs) {
|
|
129
|
+
var path = keyInputPairs.map(function (op) {
|
|
189
130
|
return op.path;
|
|
190
131
|
}).join(',');
|
|
191
|
-
var inputs =
|
|
132
|
+
var inputs = keyInputPairs.map(function (op) {
|
|
192
133
|
return op.input;
|
|
193
134
|
});
|
|
194
135
|
|
|
@@ -196,15 +137,8 @@ function httpBatchLink(opts) {
|
|
|
196
137
|
url: url,
|
|
197
138
|
inputs: inputs,
|
|
198
139
|
path: path,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
AbortController: transformRPCResponse.getAbortController((_opts$AbortController = opts.AbortController) !== null && _opts$AbortController !== void 0 ? _opts$AbortController : runtime.AbortController),
|
|
202
|
-
headers: function headers() {
|
|
203
|
-
return getHeaders({
|
|
204
|
-
operations: pairs
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
transformer: runtime.transformer
|
|
140
|
+
runtime: runtime,
|
|
141
|
+
type: type
|
|
208
142
|
}),
|
|
209
143
|
promise = _httpRequest.promise,
|
|
210
144
|
cancel = _httpRequest.cancel;
|
|
@@ -212,7 +146,7 @@ function httpBatchLink(opts) {
|
|
|
212
146
|
return {
|
|
213
147
|
promise: promise.then(function (res) {
|
|
214
148
|
if (!Array.isArray(res)) {
|
|
215
|
-
return
|
|
149
|
+
return keyInputPairs.map(function () {
|
|
216
150
|
return res;
|
|
217
151
|
});
|
|
218
152
|
}
|
|
@@ -238,10 +172,10 @@ function httpBatchLink(opts) {
|
|
|
238
172
|
subscription: subscription,
|
|
239
173
|
mutation: mutation
|
|
240
174
|
};
|
|
241
|
-
return function (
|
|
242
|
-
var op =
|
|
243
|
-
prev =
|
|
244
|
-
onDestroy =
|
|
175
|
+
return function (_ref) {
|
|
176
|
+
var op = _ref.op,
|
|
177
|
+
prev = _ref.prev,
|
|
178
|
+
onDestroy = _ref.onDestroy;
|
|
245
179
|
var loader = loaders[op.type];
|
|
246
180
|
|
|
247
181
|
var _loader$load = loader.load(op),
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
2
|
-
import _asyncToGenerator from '@babel/runtime/helpers/esm/asyncToGenerator';
|
|
3
|
-
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
4
|
-
import '@babel/runtime/helpers/classCallCheck';
|
|
5
|
-
import '@babel/runtime/helpers/createClass';
|
|
6
1
|
import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
|
|
7
|
-
import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest
|
|
2
|
+
import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest } from '../../../dist/transformRPCResponse-3700ef8b.esm.js';
|
|
8
3
|
import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
|
|
4
|
+
import '@babel/runtime/helpers/objectSpread2';
|
|
5
|
+
import '@babel/runtime/helpers/classCallCheck';
|
|
6
|
+
import '@babel/runtime/helpers/createClass';
|
|
9
7
|
import '@babel/runtime/helpers/assertThisInitialized';
|
|
10
8
|
import '@babel/runtime/helpers/inherits';
|
|
11
9
|
import '@babel/runtime/helpers/createSuper';
|
|
@@ -122,65 +120,12 @@ function httpBatchLink(opts) {
|
|
|
122
120
|
|
|
123
121
|
return function (runtime) {
|
|
124
122
|
// initialized in app
|
|
125
|
-
var getHeaders = /*#__PURE__*/function () {
|
|
126
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(arg1) {
|
|
127
|
-
var val;
|
|
128
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
129
|
-
while (1) {
|
|
130
|
-
switch (_context.prev = _context.next) {
|
|
131
|
-
case 0:
|
|
132
|
-
val = opts.headers;
|
|
133
|
-
_context.t0 = _objectSpread;
|
|
134
|
-
_context.t1 = _objectSpread;
|
|
135
|
-
_context.t2 = {};
|
|
136
|
-
_context.next = 6;
|
|
137
|
-
return runtime.headers();
|
|
138
|
-
|
|
139
|
-
case 6:
|
|
140
|
-
_context.t3 = _context.sent;
|
|
141
|
-
_context.t4 = (0, _context.t1)(_context.t2, _context.t3);
|
|
142
|
-
|
|
143
|
-
if (!(typeof val === 'function')) {
|
|
144
|
-
_context.next = 14;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
_context.next = 11;
|
|
149
|
-
return val(arg1);
|
|
150
|
-
|
|
151
|
-
case 11:
|
|
152
|
-
_context.t5 = _context.sent;
|
|
153
|
-
_context.next = 15;
|
|
154
|
-
break;
|
|
155
|
-
|
|
156
|
-
case 14:
|
|
157
|
-
_context.t5 = val;
|
|
158
|
-
|
|
159
|
-
case 15:
|
|
160
|
-
_context.t6 = _context.t5;
|
|
161
|
-
return _context.abrupt("return", (0, _context.t0)(_context.t4, _context.t6));
|
|
162
|
-
|
|
163
|
-
case 17:
|
|
164
|
-
case "end":
|
|
165
|
-
return _context.stop();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}, _callee);
|
|
169
|
-
}));
|
|
170
|
-
|
|
171
|
-
return function getHeaders(_x) {
|
|
172
|
-
return _ref.apply(this, arguments);
|
|
173
|
-
};
|
|
174
|
-
}();
|
|
175
|
-
|
|
176
123
|
var fetcher = function fetcher(type) {
|
|
177
|
-
return function (
|
|
178
|
-
var
|
|
179
|
-
|
|
180
|
-
var path = pairs.map(function (op) {
|
|
124
|
+
return function (keyInputPairs) {
|
|
125
|
+
var path = keyInputPairs.map(function (op) {
|
|
181
126
|
return op.path;
|
|
182
127
|
}).join(',');
|
|
183
|
-
var inputs =
|
|
128
|
+
var inputs = keyInputPairs.map(function (op) {
|
|
184
129
|
return op.input;
|
|
185
130
|
});
|
|
186
131
|
|
|
@@ -188,15 +133,8 @@ function httpBatchLink(opts) {
|
|
|
188
133
|
url: url,
|
|
189
134
|
inputs: inputs,
|
|
190
135
|
path: path,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
AbortController: getAbortController((_opts$AbortController = opts.AbortController) !== null && _opts$AbortController !== void 0 ? _opts$AbortController : runtime.AbortController),
|
|
194
|
-
headers: function headers() {
|
|
195
|
-
return getHeaders({
|
|
196
|
-
operations: pairs
|
|
197
|
-
});
|
|
198
|
-
},
|
|
199
|
-
transformer: runtime.transformer
|
|
136
|
+
runtime: runtime,
|
|
137
|
+
type: type
|
|
200
138
|
}),
|
|
201
139
|
promise = _httpRequest.promise,
|
|
202
140
|
cancel = _httpRequest.cancel;
|
|
@@ -204,7 +142,7 @@ function httpBatchLink(opts) {
|
|
|
204
142
|
return {
|
|
205
143
|
promise: promise.then(function (res) {
|
|
206
144
|
if (!Array.isArray(res)) {
|
|
207
|
-
return
|
|
145
|
+
return keyInputPairs.map(function () {
|
|
208
146
|
return res;
|
|
209
147
|
});
|
|
210
148
|
}
|
|
@@ -230,10 +168,10 @@ function httpBatchLink(opts) {
|
|
|
230
168
|
subscription: subscription,
|
|
231
169
|
mutation: mutation
|
|
232
170
|
};
|
|
233
|
-
return function (
|
|
234
|
-
var op =
|
|
235
|
-
prev =
|
|
236
|
-
onDestroy =
|
|
171
|
+
return function (_ref) {
|
|
172
|
+
var op = _ref.op,
|
|
173
|
+
prev = _ref.prev,
|
|
174
|
+
onDestroy = _ref.onDestroy;
|
|
237
175
|
var loader = loaders[op.type];
|
|
238
176
|
|
|
239
177
|
var _loader$load = loader.load(op),
|
|
@@ -2,102 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
5
|
+
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
6
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-0ad3cc9f.cjs.dev.js');
|
|
7
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
8
8
|
require('@babel/runtime/helpers/classCallCheck');
|
|
9
9
|
require('@babel/runtime/helpers/createClass');
|
|
10
|
-
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
11
|
-
var transformRPCResponse = require('../../../dist/transformRPCResponse-c6cc4677.cjs.dev.js');
|
|
12
|
-
require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
13
10
|
require('@babel/runtime/helpers/assertThisInitialized');
|
|
14
11
|
require('@babel/runtime/helpers/inherits');
|
|
15
12
|
require('@babel/runtime/helpers/createSuper');
|
|
16
13
|
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
17
14
|
|
|
18
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
-
|
|
20
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
21
|
-
|
|
22
15
|
function httpLink(opts) {
|
|
23
16
|
var url = opts.url; // initialized config
|
|
24
17
|
|
|
25
18
|
return function (runtime) {
|
|
26
19
|
// initialized in app
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
while (1) {
|
|
32
|
-
switch (_context.prev = _context.next) {
|
|
33
|
-
case 0:
|
|
34
|
-
val = opts.headers;
|
|
35
|
-
_context.t0 = _objectSpread;
|
|
36
|
-
_context.t1 = _objectSpread;
|
|
37
|
-
_context.t2 = {};
|
|
38
|
-
_context.next = 6;
|
|
39
|
-
return runtime.headers();
|
|
40
|
-
|
|
41
|
-
case 6:
|
|
42
|
-
_context.t3 = _context.sent;
|
|
43
|
-
_context.t4 = (0, _context.t1)(_context.t2, _context.t3);
|
|
44
|
-
|
|
45
|
-
if (!(typeof val === 'function')) {
|
|
46
|
-
_context.next = 14;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
_context.next = 11;
|
|
51
|
-
return val(arg1);
|
|
52
|
-
|
|
53
|
-
case 11:
|
|
54
|
-
_context.t5 = _context.sent;
|
|
55
|
-
_context.next = 15;
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
case 14:
|
|
59
|
-
_context.t5 = val;
|
|
60
|
-
|
|
61
|
-
case 15:
|
|
62
|
-
_context.t6 = _context.t5;
|
|
63
|
-
return _context.abrupt("return", (0, _context.t0)(_context.t4, _context.t6));
|
|
64
|
-
|
|
65
|
-
case 17:
|
|
66
|
-
case "end":
|
|
67
|
-
return _context.stop();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}, _callee);
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
return function getHeaders(_x) {
|
|
74
|
-
return _ref.apply(this, arguments);
|
|
75
|
-
};
|
|
76
|
-
}();
|
|
77
|
-
|
|
78
|
-
return function (_ref2) {
|
|
79
|
-
var _opts$fetch, _opts$AbortController;
|
|
80
|
-
|
|
81
|
-
var op = _ref2.op,
|
|
82
|
-
prev = _ref2.prev,
|
|
83
|
-
onDestroy = _ref2.onDestroy;
|
|
20
|
+
return function (_ref) {
|
|
21
|
+
var op = _ref.op,
|
|
22
|
+
prev = _ref.prev,
|
|
23
|
+
onDestroy = _ref.onDestroy;
|
|
84
24
|
var path = op.path,
|
|
85
25
|
input = op.input,
|
|
86
26
|
type = op.type;
|
|
87
27
|
|
|
88
28
|
var _httpRequest = transformRPCResponse.httpRequest({
|
|
29
|
+
runtime: runtime,
|
|
89
30
|
type: type,
|
|
90
31
|
input: input,
|
|
91
32
|
url: url,
|
|
92
|
-
path: path
|
|
93
|
-
transformer: runtime.transformer,
|
|
94
|
-
fetch: transformRPCResponse.getFetch((_opts$fetch = opts.fetch) !== null && _opts$fetch !== void 0 ? _opts$fetch : runtime.fetch),
|
|
95
|
-
AbortController: transformRPCResponse.getAbortController((_opts$AbortController = opts.AbortController) !== null && _opts$AbortController !== void 0 ? _opts$AbortController : runtime.AbortController),
|
|
96
|
-
headers: function headers() {
|
|
97
|
-
return getHeaders({
|
|
98
|
-
op: op
|
|
99
|
-
});
|
|
100
|
-
}
|
|
33
|
+
path: path
|
|
101
34
|
}),
|
|
102
35
|
promise = _httpRequest.promise,
|
|
103
36
|
cancel = _httpRequest.cancel;
|
|
@@ -2,102 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
5
|
+
var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
|
|
6
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-e6daeb02.cjs.prod.js');
|
|
7
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
8
8
|
require('@babel/runtime/helpers/classCallCheck');
|
|
9
9
|
require('@babel/runtime/helpers/createClass');
|
|
10
|
-
var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
|
|
11
|
-
var transformRPCResponse = require('../../../dist/transformRPCResponse-2b5b4bba.cjs.prod.js');
|
|
12
|
-
require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
13
10
|
require('@babel/runtime/helpers/assertThisInitialized');
|
|
14
11
|
require('@babel/runtime/helpers/inherits');
|
|
15
12
|
require('@babel/runtime/helpers/createSuper');
|
|
16
13
|
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
17
14
|
|
|
18
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
-
|
|
20
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
21
|
-
|
|
22
15
|
function httpLink(opts) {
|
|
23
16
|
var url = opts.url; // initialized config
|
|
24
17
|
|
|
25
18
|
return function (runtime) {
|
|
26
19
|
// initialized in app
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
while (1) {
|
|
32
|
-
switch (_context.prev = _context.next) {
|
|
33
|
-
case 0:
|
|
34
|
-
val = opts.headers;
|
|
35
|
-
_context.t0 = _objectSpread;
|
|
36
|
-
_context.t1 = _objectSpread;
|
|
37
|
-
_context.t2 = {};
|
|
38
|
-
_context.next = 6;
|
|
39
|
-
return runtime.headers();
|
|
40
|
-
|
|
41
|
-
case 6:
|
|
42
|
-
_context.t3 = _context.sent;
|
|
43
|
-
_context.t4 = (0, _context.t1)(_context.t2, _context.t3);
|
|
44
|
-
|
|
45
|
-
if (!(typeof val === 'function')) {
|
|
46
|
-
_context.next = 14;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
_context.next = 11;
|
|
51
|
-
return val(arg1);
|
|
52
|
-
|
|
53
|
-
case 11:
|
|
54
|
-
_context.t5 = _context.sent;
|
|
55
|
-
_context.next = 15;
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
case 14:
|
|
59
|
-
_context.t5 = val;
|
|
60
|
-
|
|
61
|
-
case 15:
|
|
62
|
-
_context.t6 = _context.t5;
|
|
63
|
-
return _context.abrupt("return", (0, _context.t0)(_context.t4, _context.t6));
|
|
64
|
-
|
|
65
|
-
case 17:
|
|
66
|
-
case "end":
|
|
67
|
-
return _context.stop();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}, _callee);
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
return function getHeaders(_x) {
|
|
74
|
-
return _ref.apply(this, arguments);
|
|
75
|
-
};
|
|
76
|
-
}();
|
|
77
|
-
|
|
78
|
-
return function (_ref2) {
|
|
79
|
-
var _opts$fetch, _opts$AbortController;
|
|
80
|
-
|
|
81
|
-
var op = _ref2.op,
|
|
82
|
-
prev = _ref2.prev,
|
|
83
|
-
onDestroy = _ref2.onDestroy;
|
|
20
|
+
return function (_ref) {
|
|
21
|
+
var op = _ref.op,
|
|
22
|
+
prev = _ref.prev,
|
|
23
|
+
onDestroy = _ref.onDestroy;
|
|
84
24
|
var path = op.path,
|
|
85
25
|
input = op.input,
|
|
86
26
|
type = op.type;
|
|
87
27
|
|
|
88
28
|
var _httpRequest = transformRPCResponse.httpRequest({
|
|
29
|
+
runtime: runtime,
|
|
89
30
|
type: type,
|
|
90
31
|
input: input,
|
|
91
32
|
url: url,
|
|
92
|
-
path: path
|
|
93
|
-
transformer: runtime.transformer,
|
|
94
|
-
fetch: transformRPCResponse.getFetch((_opts$fetch = opts.fetch) !== null && _opts$fetch !== void 0 ? _opts$fetch : runtime.fetch),
|
|
95
|
-
AbortController: transformRPCResponse.getAbortController((_opts$AbortController = opts.AbortController) !== null && _opts$AbortController !== void 0 ? _opts$AbortController : runtime.AbortController),
|
|
96
|
-
headers: function headers() {
|
|
97
|
-
return getHeaders({
|
|
98
|
-
op: op
|
|
99
|
-
});
|
|
100
|
-
}
|
|
33
|
+
path: path
|
|
101
34
|
}),
|
|
102
35
|
promise = _httpRequest.promise,
|
|
103
36
|
cancel = _httpRequest.cancel;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
|
|
2
|
+
import { h as httpRequest, T as TRPCAbortError, t as transformRPCResponse } from '../../../dist/transformRPCResponse-3700ef8b.esm.js';
|
|
3
|
+
import '@babel/runtime/helpers/objectSpread2';
|
|
4
4
|
import '@babel/runtime/helpers/classCallCheck';
|
|
5
5
|
import '@babel/runtime/helpers/createClass';
|
|
6
|
-
import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
|
|
7
|
-
import { h as httpRequest, g as getFetch, a as getAbortController, T as TRPCAbortError, t as transformRPCResponse } from '../../../dist/transformRPCResponse-648d57f1.esm.js';
|
|
8
|
-
import '@babel/runtime/helpers/createForOfIteratorHelper';
|
|
9
6
|
import '@babel/runtime/helpers/assertThisInitialized';
|
|
10
7
|
import '@babel/runtime/helpers/inherits';
|
|
11
8
|
import '@babel/runtime/helpers/createSuper';
|
|
@@ -16,80 +13,20 @@ function httpLink(opts) {
|
|
|
16
13
|
|
|
17
14
|
return function (runtime) {
|
|
18
15
|
// initialized in app
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
while (1) {
|
|
24
|
-
switch (_context.prev = _context.next) {
|
|
25
|
-
case 0:
|
|
26
|
-
val = opts.headers;
|
|
27
|
-
_context.t0 = _objectSpread;
|
|
28
|
-
_context.t1 = _objectSpread;
|
|
29
|
-
_context.t2 = {};
|
|
30
|
-
_context.next = 6;
|
|
31
|
-
return runtime.headers();
|
|
32
|
-
|
|
33
|
-
case 6:
|
|
34
|
-
_context.t3 = _context.sent;
|
|
35
|
-
_context.t4 = (0, _context.t1)(_context.t2, _context.t3);
|
|
36
|
-
|
|
37
|
-
if (!(typeof val === 'function')) {
|
|
38
|
-
_context.next = 14;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
_context.next = 11;
|
|
43
|
-
return val(arg1);
|
|
44
|
-
|
|
45
|
-
case 11:
|
|
46
|
-
_context.t5 = _context.sent;
|
|
47
|
-
_context.next = 15;
|
|
48
|
-
break;
|
|
49
|
-
|
|
50
|
-
case 14:
|
|
51
|
-
_context.t5 = val;
|
|
52
|
-
|
|
53
|
-
case 15:
|
|
54
|
-
_context.t6 = _context.t5;
|
|
55
|
-
return _context.abrupt("return", (0, _context.t0)(_context.t4, _context.t6));
|
|
56
|
-
|
|
57
|
-
case 17:
|
|
58
|
-
case "end":
|
|
59
|
-
return _context.stop();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}, _callee);
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
return function getHeaders(_x) {
|
|
66
|
-
return _ref.apply(this, arguments);
|
|
67
|
-
};
|
|
68
|
-
}();
|
|
69
|
-
|
|
70
|
-
return function (_ref2) {
|
|
71
|
-
var _opts$fetch, _opts$AbortController;
|
|
72
|
-
|
|
73
|
-
var op = _ref2.op,
|
|
74
|
-
prev = _ref2.prev,
|
|
75
|
-
onDestroy = _ref2.onDestroy;
|
|
16
|
+
return function (_ref) {
|
|
17
|
+
var op = _ref.op,
|
|
18
|
+
prev = _ref.prev,
|
|
19
|
+
onDestroy = _ref.onDestroy;
|
|
76
20
|
var path = op.path,
|
|
77
21
|
input = op.input,
|
|
78
22
|
type = op.type;
|
|
79
23
|
|
|
80
24
|
var _httpRequest = httpRequest({
|
|
25
|
+
runtime: runtime,
|
|
81
26
|
type: type,
|
|
82
27
|
input: input,
|
|
83
28
|
url: url,
|
|
84
|
-
path: path
|
|
85
|
-
transformer: runtime.transformer,
|
|
86
|
-
fetch: getFetch((_opts$fetch = opts.fetch) !== null && _opts$fetch !== void 0 ? _opts$fetch : runtime.fetch),
|
|
87
|
-
AbortController: getAbortController((_opts$AbortController = opts.AbortController) !== null && _opts$AbortController !== void 0 ? _opts$AbortController : runtime.AbortController),
|
|
88
|
-
headers: function headers() {
|
|
89
|
-
return getHeaders({
|
|
90
|
-
op: op
|
|
91
|
-
});
|
|
92
|
-
}
|
|
29
|
+
path: path
|
|
93
30
|
}),
|
|
94
31
|
promise = _httpRequest.promise,
|
|
95
32
|
cancel = _httpRequest.cancel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.33",
|
|
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.
|
|
70
|
+
"@trpc/server": "10.0.0-alpha.33"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@trpc/server": "10.0.0-alpha.
|
|
73
|
+
"@trpc/server": "10.0.0-alpha.33"
|
|
74
74
|
},
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "c8c29ee70a7a5c3c6a319da0b43dc8fb4e89ab0d"
|
|
79
79
|
}
|
package/src/createTRPCClient.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|