@trpc/client 10.0.0-alpha.34 → 10.0.0-alpha.37
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/README.md +58 -1
- package/dist/createTRPCClient.d.ts +1 -1
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClientProxy.d.ts +4 -1
- package/dist/createTRPCClientProxy.d.ts.map +1 -1
- package/dist/index.js +30 -55
- package/dist/index.mjs +31 -56
- package/dist/links/dedupeLink.d.ts.map +1 -1
- package/dist/links/internals/createChain.d.ts.map +1 -1
- package/dist/links/splitLink.js +1 -1
- package/dist/links/splitLink.mjs +1 -1
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +2 -1
- package/dist/links/wsLink.mjs +2 -1
- package/dist/{splitLink-62ff9db0.mjs → splitLink-0202cd7b.mjs} +5 -0
- package/dist/{splitLink-8202386e.js → splitLink-23c5ce5c.js} +5 -0
- package/dist/{wsLink-9468a563.mjs → wsLink-11ee4922.mjs} +5 -2
- package/dist/{wsLink-69f5adb8.js → wsLink-807f4ad9.js} +6 -2
- package/package.json +4 -4
- package/src/createTRPCClient.ts +1 -2
- package/src/createTRPCClientProxy.ts +14 -40
- package/src/internals/dataLoader.ts +2 -2
- package/src/links/dedupeLink.ts +3 -2
- package/src/links/internals/createChain.ts +5 -0
- package/src/links/wsLink.ts +1 -2
package/README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://trpc.io/"><img src="../../www/static/img/logo-text.svg" alt="tRPC" height="130"/></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<strong>End-to-end typesafe APIs made easy</strong>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<!-- TODO: replace with new version GIF -->
|
|
11
|
+
<img src="https://storage.googleapis.com/trpc/trpcgif.gif" alt="Demo" />
|
|
12
|
+
</p>
|
|
13
|
+
|
|
1
14
|
# `@trpc/client`
|
|
2
15
|
|
|
3
|
-
|
|
16
|
+
> Communicate with a tRPC server on the client side.
|
|
17
|
+
|
|
18
|
+
## Documentation
|
|
19
|
+
|
|
20
|
+
Full documentation for `@trpc/client` can be found [here](https://trpc.io/docs/vanilla)
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# npm
|
|
26
|
+
npm install @trpc/client
|
|
27
|
+
|
|
28
|
+
# Yarn
|
|
29
|
+
yarn add @trpc/client
|
|
30
|
+
|
|
31
|
+
# pnpm
|
|
32
|
+
pnpm add @trpc/client
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Basic Example
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createTRPCClient, createTRPCClientProxy } from '@trpc/client';
|
|
39
|
+
// Importing the router type from the server file
|
|
40
|
+
import type { AppRouter } from './server';
|
|
41
|
+
|
|
42
|
+
// Initializing the tRPC client
|
|
43
|
+
const client = createTRPCClient<AppRouter>({
|
|
44
|
+
url: 'http://localhost:2022',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Creating a proxy, this allows for cmd+click to the backend function.
|
|
48
|
+
const proxy = createTRPCClientProxy(client);
|
|
49
|
+
|
|
50
|
+
async function main() {
|
|
51
|
+
// Querying the greeting
|
|
52
|
+
const helloResponse = await proxy.greeting.query({
|
|
53
|
+
name: 'world',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log('helloResponse', helloResponse); // Hello world
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
main();
|
|
60
|
+
```
|
|
@@ -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
|
|
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;
|
|
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,7 +1,10 @@
|
|
|
1
1
|
import type { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { TRPCClient as Client } from './internals/TRPCClient';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
3
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>):
|
|
9
|
+
export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): FlattenRouter<TRouter>;
|
|
7
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;
|
|
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,78 +2,31 @@
|
|
|
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');
|
|
9
|
-
var links_wsLink = require('./wsLink-
|
|
8
|
+
var links_wsLink = require('./wsLink-807f4ad9.js');
|
|
10
9
|
var links_httpBatchLink = require('./links/httpBatchLink.js');
|
|
11
10
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
12
11
|
require('@babel/runtime/helpers/slicedToArray');
|
|
13
|
-
var links_splitLink = require('./splitLink-
|
|
12
|
+
var links_splitLink = require('./splitLink-23c5ce5c.js');
|
|
14
13
|
require('@babel/runtime/helpers/assertThisInitialized');
|
|
15
14
|
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') {
|
|
@@ -117,11 +70,12 @@ function dedupeLink() {
|
|
|
117
70
|
}
|
|
118
71
|
|
|
119
72
|
var key = JSON.stringify([op.path, op.input]);
|
|
73
|
+
var obs$ = pending[key];
|
|
120
74
|
|
|
121
|
-
if (
|
|
75
|
+
if (obs$) {
|
|
122
76
|
// console.log('hooking into pending', { op });
|
|
123
77
|
return observable.observable(function (observer) {
|
|
124
|
-
return
|
|
78
|
+
return obs$.subscribe(observer);
|
|
125
79
|
});
|
|
126
80
|
}
|
|
127
81
|
|
|
@@ -459,9 +413,30 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
459
413
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
460
414
|
function createTRPCClient(opts) {
|
|
461
415
|
var client = new TRPCClient(opts);
|
|
462
|
-
return
|
|
416
|
+
return client;
|
|
463
417
|
} // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
|
|
464
418
|
|
|
419
|
+
function createTRPCClientProxy(client) {
|
|
420
|
+
var proxy = shared.createProxy(function (_ref) {
|
|
421
|
+
var _ref2;
|
|
422
|
+
|
|
423
|
+
var path = _ref.path,
|
|
424
|
+
args = _ref.args;
|
|
425
|
+
|
|
426
|
+
var pathCopy = _toConsumableArray__default["default"](path);
|
|
427
|
+
|
|
428
|
+
var type = pathCopy.pop();
|
|
429
|
+
|
|
430
|
+
if (type === 'mutate') {
|
|
431
|
+
type = 'mutation';
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
var fullPath = pathCopy.join('.');
|
|
435
|
+
return (_ref2 = client)[type].apply(_ref2, [fullPath].concat(_toConsumableArray__default["default"](args)));
|
|
436
|
+
});
|
|
437
|
+
return proxy;
|
|
438
|
+
}
|
|
439
|
+
|
|
465
440
|
exports.TRPCClientError = links_wsLink.TRPCClientError;
|
|
466
441
|
exports.createWSClient = links_wsLink.createWSClient;
|
|
467
442
|
exports.wsLink = links_wsLink.wsLink;
|
package/dist/index.mjs
CHANGED
|
@@ -1,72 +1,25 @@
|
|
|
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';
|
|
5
|
-
import { T as TRPCClientError } from './wsLink-
|
|
6
|
-
export { T as TRPCClientError, c as createWSClient, w as wsLink } from './wsLink-
|
|
4
|
+
import { T as TRPCClientError } from './wsLink-11ee4922.mjs';
|
|
5
|
+
export { T as TRPCClientError, c as createWSClient, w as wsLink } from './wsLink-11ee4922.mjs';
|
|
7
6
|
import { httpBatchLink } from './links/httpBatchLink.mjs';
|
|
8
7
|
export { httpBatchLink } from './links/httpBatchLink.mjs';
|
|
9
8
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
10
9
|
import '@babel/runtime/helpers/slicedToArray';
|
|
11
|
-
import { c as createChain } from './splitLink-
|
|
12
|
-
export { s as splitLink } from './splitLink-
|
|
10
|
+
import { c as createChain } from './splitLink-0202cd7b.mjs';
|
|
11
|
+
export { s as splitLink } from './splitLink-0202cd7b.mjs';
|
|
13
12
|
import '@babel/runtime/helpers/assertThisInitialized';
|
|
14
13
|
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;
|
|
@@ -109,11 +62,12 @@ function dedupeLink() {
|
|
|
109
62
|
}
|
|
110
63
|
|
|
111
64
|
var key = JSON.stringify([op.path, op.input]);
|
|
65
|
+
var obs$ = pending[key];
|
|
112
66
|
|
|
113
|
-
if (
|
|
67
|
+
if (obs$) {
|
|
114
68
|
// console.log('hooking into pending', { op });
|
|
115
69
|
return observable(function (observer) {
|
|
116
|
-
return
|
|
70
|
+
return obs$.subscribe(observer);
|
|
117
71
|
});
|
|
118
72
|
}
|
|
119
73
|
|
|
@@ -451,7 +405,28 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
451
405
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
452
406
|
function createTRPCClient(opts) {
|
|
453
407
|
var client = new TRPCClient(opts);
|
|
454
|
-
return
|
|
408
|
+
return client;
|
|
455
409
|
} // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
|
|
456
410
|
|
|
411
|
+
function createTRPCClientProxy(client) {
|
|
412
|
+
var proxy = createProxy(function (_ref) {
|
|
413
|
+
var _ref2;
|
|
414
|
+
|
|
415
|
+
var path = _ref.path,
|
|
416
|
+
args = _ref.args;
|
|
417
|
+
|
|
418
|
+
var pathCopy = _toConsumableArray(path);
|
|
419
|
+
|
|
420
|
+
var type = pathCopy.pop();
|
|
421
|
+
|
|
422
|
+
if (type === 'mutate') {
|
|
423
|
+
type = 'mutation';
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
var fullPath = pathCopy.join('.');
|
|
427
|
+
return (_ref2 = client)[type].apply(_ref2, [fullPath].concat(_toConsumableArray(args)));
|
|
428
|
+
});
|
|
429
|
+
return proxy;
|
|
430
|
+
}
|
|
431
|
+
|
|
457
432
|
export { createTRPCClient, createTRPCClientProxy, dedupeLink, getFetch, retryLink };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedupeLink.d.ts","sourceRoot":"","sources":["../../src/links/dedupeLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,wBAAgB,UAAU,CACxB,OAAO,SAAS,SAAS,GAAG,SAAS,KAClC,QAAQ,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"dedupeLink.d.ts","sourceRoot":"","sources":["../../src/links/dedupeLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,wBAAgB,UAAU,CACxB,OAAO,SAAS,SAAS,GAAG,SAAS,KAClC,QAAQ,CAAC,OAAO,CAAC,CA6CrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createChain.d.ts","sourceRoot":"","sources":["../../../src/links/internals/createChain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAE/E,gBAAgB;AAChB,wBAAgB,WAAW,CACzB,OAAO,SAAS,SAAS,EACzB,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,EACjB,IAAI,EAAE;IACN,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACjD,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CACvB,GAAG,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"createChain.d.ts","sourceRoot":"","sources":["../../../src/links/internals/createChain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAE/E,gBAAgB;AAChB,wBAAgB,WAAW,CACzB,OAAO,SAAS,SAAS,EACzB,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,EACjB,IAAI,EAAE;IACN,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACjD,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CACvB,GAAG,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAuB9C"}
|
package/dist/links/splitLink.js
CHANGED
package/dist/links/splitLink.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '@trpc/server/observable';
|
|
2
|
-
export { s as splitLink } from '../splitLink-
|
|
2
|
+
export { s as splitLink } from '../splitLink-0202cd7b.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsLink.d.ts","sourceRoot":"","sources":["../../src/links/wsLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,aAAa,EAAc,MAAM,yBAAyB,CAAC;AASpE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEvE,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,UAAU,CAAC;CAClC;AACD,wBAAgB,cAAc,CAAC,IAAI,EAAE,sBAAsB;;
|
|
1
|
+
{"version":3,"file":"wsLink.d.ts","sourceRoot":"","sources":["../../src/links/wsLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,aAAa,EAAc,MAAM,yBAAyB,CAAC;AASpE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEvE,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,UAAU,CAAC;CAClC;AACD,wBAAgB,cAAc,CAAC,IAAI,EAAE,sBAAsB;;kBA6LpC,SAAS,6DAA0B,aAAa;;EAgDtE;AACD,oBAAY,mBAAmB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAEpE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAiBD,wBAAgB,MAAM,CAAC,OAAO,SAAS,SAAS,EAC9C,IAAI,EAAE,oBAAoB,GACzB,QAAQ,CAAC,OAAO,CAAC,CAoDnB"}
|
package/dist/links/wsLink.js
CHANGED
|
@@ -9,8 +9,9 @@ require('@babel/runtime/helpers/inherits');
|
|
|
9
9
|
require('@babel/runtime/helpers/possibleConstructorReturn');
|
|
10
10
|
require('@babel/runtime/helpers/getPrototypeOf');
|
|
11
11
|
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
12
|
+
require('@babel/runtime/helpers/slicedToArray');
|
|
12
13
|
require('@trpc/server/observable');
|
|
13
|
-
var links_wsLink = require('../wsLink-
|
|
14
|
+
var links_wsLink = require('../wsLink-807f4ad9.js');
|
|
14
15
|
require('@babel/runtime/helpers/defineProperty');
|
|
15
16
|
|
|
16
17
|
|
package/dist/links/wsLink.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import '@babel/runtime/helpers/inherits';
|
|
|
5
5
|
import '@babel/runtime/helpers/possibleConstructorReturn';
|
|
6
6
|
import '@babel/runtime/helpers/getPrototypeOf';
|
|
7
7
|
import '@babel/runtime/helpers/wrapNativeSuper';
|
|
8
|
+
import '@babel/runtime/helpers/slicedToArray';
|
|
8
9
|
import '@trpc/server/observable';
|
|
9
|
-
export { c as createWSClient, w as wsLink } from '../wsLink-
|
|
10
|
+
export { c as createWSClient, w as wsLink } from '../wsLink-11ee4922.mjs';
|
|
10
11
|
import '@babel/runtime/helpers/defineProperty';
|
|
@@ -7,6 +7,11 @@ function createChain(opts) {
|
|
|
7
7
|
var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
8
8
|
var op = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : opts.op;
|
|
9
9
|
var next = opts.links[index];
|
|
10
|
+
|
|
11
|
+
if (!next) {
|
|
12
|
+
throw new Error('No more links to execute - did you forget to add an ending link?');
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
var subscription = next({
|
|
11
16
|
op: op,
|
|
12
17
|
next: function next(nextOp) {
|
|
@@ -9,6 +9,11 @@ function createChain(opts) {
|
|
|
9
9
|
var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
10
10
|
var op = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : opts.op;
|
|
11
11
|
var next = opts.links[index];
|
|
12
|
+
|
|
13
|
+
if (!next) {
|
|
14
|
+
throw new Error('No more links to execute - did you forget to add an ending link?');
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
var subscription = next({
|
|
13
18
|
op: op,
|
|
14
19
|
next: function next(nextOp) {
|
|
@@ -5,6 +5,7 @@ import _inherits from '@babel/runtime/helpers/inherits';
|
|
|
5
5
|
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
6
6
|
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
7
7
|
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
|
|
8
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
8
9
|
import { observable } from '@trpc/server/observable';
|
|
9
10
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
10
11
|
|
|
@@ -262,10 +263,12 @@ function createWSClient(opts) {
|
|
|
262
263
|
tryReconnect();
|
|
263
264
|
}
|
|
264
265
|
|
|
265
|
-
for (var
|
|
266
|
+
for (var _i2 = 0, _Object$entries = Object.entries(pendingRequests); _i2 < _Object$entries.length; _i2++) {
|
|
266
267
|
var _req$callbacks$error, _req$callbacks2;
|
|
267
268
|
|
|
268
|
-
var
|
|
269
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
|
270
|
+
key = _Object$entries$_i[0],
|
|
271
|
+
req = _Object$entries$_i[1];
|
|
269
272
|
|
|
270
273
|
if (req.ws !== conn) {
|
|
271
274
|
continue;
|
|
@@ -7,6 +7,7 @@ var _inherits = require('@babel/runtime/helpers/inherits');
|
|
|
7
7
|
var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
|
|
8
8
|
var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
|
|
9
9
|
var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
|
|
10
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
10
11
|
var observable = require('@trpc/server/observable');
|
|
11
12
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
12
13
|
|
|
@@ -19,6 +20,7 @@ var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
|
|
|
19
20
|
var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
|
|
20
21
|
var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
|
|
21
22
|
var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper);
|
|
23
|
+
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
22
24
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
23
25
|
|
|
24
26
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -275,10 +277,12 @@ function createWSClient(opts) {
|
|
|
275
277
|
tryReconnect();
|
|
276
278
|
}
|
|
277
279
|
|
|
278
|
-
for (var
|
|
280
|
+
for (var _i2 = 0, _Object$entries = Object.entries(pendingRequests); _i2 < _Object$entries.length; _i2++) {
|
|
279
281
|
var _req$callbacks$error, _req$callbacks2;
|
|
280
282
|
|
|
281
|
-
var
|
|
283
|
+
var _Object$entries$_i = _slicedToArray__default["default"](_Object$entries[_i2], 2),
|
|
284
|
+
key = _Object$entries$_i[0],
|
|
285
|
+
req = _Object$entries$_i[1];
|
|
282
286
|
|
|
283
287
|
if (req.ws !== conn) {
|
|
284
288
|
continue;
|
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.37",
|
|
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.37"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@trpc/server": "10.0.0-alpha.
|
|
73
|
+
"@trpc/server": "10.0.0-alpha.37"
|
|
74
74
|
},
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "da12b6b12f7dc99a54d748f5660a296e9db2d87f"
|
|
79
79
|
}
|
package/src/createTRPCClient.ts
CHANGED
|
@@ -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
|
|
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
|
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
7
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
|
-
|
|
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
|
}
|
|
@@ -112,8 +112,8 @@ export function dataLoader<TKey, TValue>(
|
|
|
112
112
|
promise
|
|
113
113
|
.then((result) => {
|
|
114
114
|
for (let i = 0; i < result.length; i++) {
|
|
115
|
-
const value = result[i]
|
|
116
|
-
const item = batch.items[i]
|
|
115
|
+
const value = result[i]!;
|
|
116
|
+
const item = batch.items[i]!;
|
|
117
117
|
item.resolve(value);
|
|
118
118
|
item.batch = null;
|
|
119
119
|
}
|
package/src/links/dedupeLink.ts
CHANGED
|
@@ -17,9 +17,10 @@ export function dedupeLink<
|
|
|
17
17
|
return next(op);
|
|
18
18
|
}
|
|
19
19
|
const key = JSON.stringify([op.path, op.input]);
|
|
20
|
-
|
|
20
|
+
const obs$ = pending[key];
|
|
21
|
+
if (obs$) {
|
|
21
22
|
// console.log('hooking into pending', { op });
|
|
22
|
-
return observable((observer) =>
|
|
23
|
+
return observable((observer) => obs$.subscribe(observer));
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
const shared$ = observable((observer) => {
|
|
@@ -14,6 +14,11 @@ export function createChain<
|
|
|
14
14
|
return observable((observer) => {
|
|
15
15
|
function execute(index = 0, op = opts.op) {
|
|
16
16
|
const next = opts.links[index];
|
|
17
|
+
if (!next) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
'No more links to execute - did you forget to add an ending link?',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
17
22
|
const subscription = next({
|
|
18
23
|
op,
|
|
19
24
|
next(nextOp) {
|
package/src/links/wsLink.ts
CHANGED
|
@@ -184,8 +184,7 @@ export function createWSClient(opts: WebSocketClientOptions) {
|
|
|
184
184
|
tryReconnect();
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
for (const key
|
|
188
|
-
const req = pendingRequests[key];
|
|
187
|
+
for (const [key, req] of Object.entries(pendingRequests)) {
|
|
189
188
|
if (req.ws !== conn) {
|
|
190
189
|
continue;
|
|
191
190
|
}
|