@trpc/client 10.0.0-alpha.44 → 10.0.0-alpha.47
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/TRPCClientError.d.ts +6 -5
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/httpUtils-44781613.mjs +76 -0
- package/dist/httpUtils-801112a6.js +79 -0
- package/dist/index.js +226 -337
- package/dist/index.mjs +228 -333
- package/dist/internals/TRPCClient.d.ts +3 -1
- package/dist/internals/TRPCClient.d.ts.map +1 -1
- package/dist/internals/dataLoader.d.ts.map +1 -1
- package/dist/internals/fetchHelpers.d.ts.map +1 -1
- package/dist/internals/retryDelay.d.ts.map +1 -1
- package/dist/links/dedupeLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +182 -304
- package/dist/links/httpBatchLink.mjs +182 -304
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +30 -53
- package/dist/links/httpLink.mjs +30 -53
- package/dist/links/index.d.ts.map +1 -1
- package/dist/links/internals/createChain.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/internals/transformResult.d.ts.map +1 -1
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +89 -94
- package/dist/links/loggerLink.mjs +89 -89
- package/dist/links/retryLink.d.ts.map +1 -1
- package/dist/links/splitLink.d.ts.map +1 -1
- package/dist/links/splitLink.js +1 -1
- package/dist/links/splitLink.mjs +1 -1
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +248 -379
- package/dist/links/wsLink.mjs +248 -368
- package/dist/splitLink-695ae288.js +48 -0
- package/dist/splitLink-ad44a55d.mjs +45 -0
- package/dist/transformResult-106791d7.mjs +62 -0
- package/dist/transformResult-e15ccdf6.js +65 -0
- package/links/httpBatchLink/index.d.ts +1 -1
- package/links/httpBatchLink/index.js +1 -1
- package/links/httpLink/index.d.ts +1 -1
- package/links/httpLink/index.js +1 -1
- package/links/loggerLink/index.d.ts +1 -1
- package/links/loggerLink/index.js +1 -1
- package/links/splitLink/index.d.ts +1 -1
- package/links/splitLink/index.js +1 -1
- package/links/wsLink/index.d.ts +1 -1
- package/links/wsLink/index.js +1 -1
- package/package.json +7 -11
- package/src/TRPCClientError.ts +13 -7
- package/src/internals/TRPCClient.ts +10 -9
- package/src/links/wsLink.ts +1 -1
- package/dist/httpUtils-089853f6.mjs +0 -99
- package/dist/httpUtils-a0169eef.js +0 -106
- package/dist/index.ts.js +0 -1
- package/dist/links/httpBatchLink.ts.js +0 -1
- package/dist/links/httpLink.ts.js +0 -1
- package/dist/links/loggerLink.ts.js +0 -1
- package/dist/links/splitLink.ts.js +0 -1
- package/dist/links/wsLink.ts.js +0 -1
- package/dist/splitLink-0202cd7b.mjs +0 -54
- package/dist/splitLink-23c5ce5c.js +0 -57
- package/dist/transformResult-06bec648.mjs +0 -108
- package/dist/transformResult-3ccc74ea.js +0 -122
package/dist/index.js
CHANGED
|
@@ -2,386 +2,275 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
6
|
-
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
7
5
|
var observable = require('@trpc/server/observable');
|
|
8
|
-
var transformResult = require('./transformResult-
|
|
6
|
+
var transformResult = require('./transformResult-e15ccdf6.js');
|
|
9
7
|
var links_httpBatchLink = require('./links/httpBatchLink.js');
|
|
10
|
-
require('
|
|
11
|
-
require('@babel/runtime/helpers/slicedToArray');
|
|
12
|
-
var links_splitLink = require('./splitLink-23c5ce5c.js');
|
|
13
|
-
require('@babel/runtime/helpers/assertThisInitialized');
|
|
14
|
-
require('@babel/runtime/helpers/inherits');
|
|
15
|
-
require('@babel/runtime/helpers/possibleConstructorReturn');
|
|
16
|
-
require('@babel/runtime/helpers/getPrototypeOf');
|
|
17
|
-
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
18
|
-
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
8
|
+
var links_splitLink = require('./splitLink-695ae288.js');
|
|
19
9
|
var shared = require('@trpc/server/shared');
|
|
20
10
|
var links_httpLink = require('./links/httpLink.js');
|
|
21
11
|
var links_loggerLink = require('./links/loggerLink.js');
|
|
22
12
|
var links_wsLink = require('./links/wsLink.js');
|
|
23
|
-
require('./httpUtils-
|
|
24
|
-
|
|
25
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
26
|
-
|
|
27
|
-
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
28
|
-
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
29
|
-
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
13
|
+
require('./httpUtils-801112a6.js');
|
|
30
14
|
|
|
31
15
|
function getWindow() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return global;
|
|
16
|
+
if (typeof window !== 'undefined') {
|
|
17
|
+
return window;
|
|
18
|
+
}
|
|
19
|
+
return global;
|
|
37
20
|
}
|
|
38
21
|
function getAbortController(ac) {
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const win = getWindow();
|
|
23
|
+
return ac || win.AbortController || null;
|
|
41
24
|
}
|
|
42
25
|
|
|
43
26
|
function getFetch(f) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
throw new Error('No fetch implementation found');
|
|
27
|
+
if (f) {
|
|
28
|
+
return f;
|
|
29
|
+
}
|
|
30
|
+
const win = getWindow();
|
|
31
|
+
if (win.fetch) {
|
|
32
|
+
return typeof win.fetch.bind === 'function' ? win.fetch.bind(win) : win.fetch;
|
|
33
|
+
}
|
|
34
|
+
throw new Error('No fetch implementation found');
|
|
55
35
|
}
|
|
56
36
|
|
|
57
37
|
function dedupeLink() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
reset();
|
|
102
|
-
subscription.unsubscribe();
|
|
38
|
+
// initialized config
|
|
39
|
+
return ()=>{
|
|
40
|
+
// initialized in app
|
|
41
|
+
const pending = {};
|
|
42
|
+
return ({ op , next })=>{
|
|
43
|
+
// initialized for request
|
|
44
|
+
if (op.type !== 'query') {
|
|
45
|
+
// pass through
|
|
46
|
+
return next(op);
|
|
47
|
+
}
|
|
48
|
+
const key = JSON.stringify([
|
|
49
|
+
op.path,
|
|
50
|
+
op.input
|
|
51
|
+
]);
|
|
52
|
+
const obs$ = pending[key];
|
|
53
|
+
if (obs$) {
|
|
54
|
+
// console.log('hooking into pending', { op });
|
|
55
|
+
return observable.observable((observer)=>obs$.subscribe(observer));
|
|
56
|
+
}
|
|
57
|
+
const shared$ = observable.observable((observer)=>{
|
|
58
|
+
function reset() {
|
|
59
|
+
delete pending[key];
|
|
60
|
+
}
|
|
61
|
+
const subscription = next(op).subscribe({
|
|
62
|
+
next (v) {
|
|
63
|
+
observer.next(v);
|
|
64
|
+
},
|
|
65
|
+
error (e) {
|
|
66
|
+
reset();
|
|
67
|
+
observer.error(e);
|
|
68
|
+
},
|
|
69
|
+
complete () {
|
|
70
|
+
reset();
|
|
71
|
+
observer.complete();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return ()=>{
|
|
75
|
+
reset();
|
|
76
|
+
subscription.unsubscribe();
|
|
77
|
+
};
|
|
78
|
+
}).pipe(observable.share());
|
|
79
|
+
pending[key] = shared$;
|
|
80
|
+
return shared$;
|
|
103
81
|
};
|
|
104
|
-
}).pipe(observable.share());
|
|
105
|
-
pending[key] = shared$;
|
|
106
|
-
return shared$;
|
|
107
82
|
};
|
|
108
|
-
};
|
|
109
83
|
}
|
|
110
84
|
|
|
111
85
|
function retryLink(opts) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
attempt();
|
|
162
|
-
return function () {
|
|
163
|
-
var _next$2;
|
|
164
|
-
|
|
165
|
-
isDone = true;
|
|
166
|
-
(_next$2 = next$) === null || _next$2 === void 0 ? void 0 : _next$2.unsubscribe();
|
|
86
|
+
// initialized config
|
|
87
|
+
return ()=>{
|
|
88
|
+
// initialized in app
|
|
89
|
+
return ({ op , next })=>{
|
|
90
|
+
// initialized for request
|
|
91
|
+
return observable.observable((observer)=>{
|
|
92
|
+
let next$ = null;
|
|
93
|
+
let attempts = 0;
|
|
94
|
+
let isDone = false;
|
|
95
|
+
function attempt() {
|
|
96
|
+
attempts++;
|
|
97
|
+
next$?.unsubscribe();
|
|
98
|
+
next$ = next(op).subscribe({
|
|
99
|
+
error (error) {
|
|
100
|
+
if (attempts >= opts.attempts) {
|
|
101
|
+
observer.error(error);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
attempt();
|
|
105
|
+
},
|
|
106
|
+
next (result) {
|
|
107
|
+
if ('result' in result.result) {
|
|
108
|
+
isDone = true;
|
|
109
|
+
observer.next(result);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (attempts >= opts.attempts) {
|
|
113
|
+
isDone = true;
|
|
114
|
+
observer.next(result);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
attempt();
|
|
118
|
+
},
|
|
119
|
+
complete () {
|
|
120
|
+
if (isDone) {
|
|
121
|
+
observer.complete();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
attempt();
|
|
127
|
+
return ()=>{
|
|
128
|
+
isDone = true;
|
|
129
|
+
next$?.unsubscribe();
|
|
130
|
+
};
|
|
131
|
+
});
|
|
167
132
|
};
|
|
168
|
-
});
|
|
169
133
|
};
|
|
170
|
-
};
|
|
171
134
|
}
|
|
172
135
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return ++idCounter;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
var TRPCClient = /*#__PURE__*/function () {
|
|
180
|
-
function TRPCClient(opts) {
|
|
181
|
-
var _this = this;
|
|
182
|
-
|
|
183
|
-
_classCallCheck__default["default"](this, TRPCClient);
|
|
184
|
-
|
|
185
|
-
this.links = void 0;
|
|
186
|
-
this.runtime = void 0;
|
|
187
|
-
|
|
188
|
-
var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
|
|
189
|
-
|
|
190
|
-
var AC = getAbortController(opts === null || opts === void 0 ? void 0 : opts.AbortController);
|
|
191
|
-
|
|
192
|
-
function getHeadersFn() {
|
|
193
|
-
if (opts.headers) {
|
|
194
|
-
var headers = opts.headers;
|
|
195
|
-
return typeof headers === 'function' ? headers : function () {
|
|
196
|
-
return headers;
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return function () {
|
|
201
|
-
return {};
|
|
202
|
-
};
|
|
136
|
+
class TRPCClient {
|
|
137
|
+
getRequestId() {
|
|
138
|
+
return ++this.requestId;
|
|
203
139
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.runtime = {
|
|
217
|
-
AbortController: AC,
|
|
218
|
-
fetch: _fetch,
|
|
219
|
-
headers: getHeadersFn(),
|
|
220
|
-
transformer: transformer
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
if ('links' in opts) {
|
|
224
|
-
this.links = opts.links.map(function (link) {
|
|
225
|
-
return link(_this.runtime);
|
|
226
|
-
});
|
|
227
|
-
} else {
|
|
228
|
-
this.links = [links_httpBatchLink.httpBatchLink({
|
|
229
|
-
url: opts.url
|
|
230
|
-
})(this.runtime)];
|
|
140
|
+
$request({ type , input , path , context ={} }) {
|
|
141
|
+
const chain$ = links_splitLink.createChain({
|
|
142
|
+
links: this.links,
|
|
143
|
+
op: {
|
|
144
|
+
id: this.getRequestId(),
|
|
145
|
+
type,
|
|
146
|
+
path,
|
|
147
|
+
input,
|
|
148
|
+
context
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return chain$.pipe(observable.share());
|
|
231
152
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
op: {
|
|
245
|
-
id: getRequestId(),
|
|
246
|
-
type: type,
|
|
247
|
-
path: path,
|
|
248
|
-
input: input,
|
|
249
|
-
context: context
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
return chain$.pipe(observable.share());
|
|
153
|
+
requestAsPromise(opts) {
|
|
154
|
+
const req$ = this.$request(opts);
|
|
155
|
+
const { promise , abort } = observable.observableToPromise(req$);
|
|
156
|
+
const cancellablePromise = new Promise((resolve, reject)=>{
|
|
157
|
+
promise.then((envelope)=>{
|
|
158
|
+
resolve(envelope.result.data);
|
|
159
|
+
}).catch((err)=>{
|
|
160
|
+
reject(transformResult.TRPCClientError.from(err));
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
cancellablePromise.cancel = abort;
|
|
164
|
+
return cancellablePromise;
|
|
253
165
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
abort = _observableToPromise.abort;
|
|
262
|
-
|
|
263
|
-
var cancellablePromise = new Promise(function (resolve, reject) {
|
|
264
|
-
promise.then(function (envelope) {
|
|
265
|
-
resolve(envelope.result.data);
|
|
266
|
-
}).catch(function (err) {
|
|
267
|
-
reject(transformResult.TRPCClientError.from(err));
|
|
166
|
+
query(path, ...args) {
|
|
167
|
+
const context = args[1]?.context;
|
|
168
|
+
return this.requestAsPromise({
|
|
169
|
+
type: 'query',
|
|
170
|
+
path,
|
|
171
|
+
input: args[0],
|
|
172
|
+
context
|
|
268
173
|
});
|
|
269
|
-
});
|
|
270
|
-
cancellablePromise.cancel = abort;
|
|
271
|
-
return cancellablePromise;
|
|
272
174
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
var context = (_args$ = args[1]) === null || _args$ === void 0 ? void 0 : _args$.requestContext;
|
|
283
|
-
return this.requestAsPromise({
|
|
284
|
-
type: 'query',
|
|
285
|
-
path: path,
|
|
286
|
-
input: args[0],
|
|
287
|
-
context: context
|
|
288
|
-
});
|
|
175
|
+
mutation(path, ...args) {
|
|
176
|
+
const context = args[1]?.context;
|
|
177
|
+
return this.requestAsPromise({
|
|
178
|
+
type: 'mutation',
|
|
179
|
+
path,
|
|
180
|
+
input: args[0],
|
|
181
|
+
context
|
|
182
|
+
});
|
|
289
183
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
184
|
+
subscription(path, input, opts) {
|
|
185
|
+
const observable$ = this.$request({
|
|
186
|
+
type: 'subscription',
|
|
187
|
+
path,
|
|
188
|
+
input,
|
|
189
|
+
context: opts?.context
|
|
190
|
+
});
|
|
191
|
+
return observable$.subscribe({
|
|
192
|
+
next (envelope) {
|
|
193
|
+
if (envelope.result.type === 'started') {
|
|
194
|
+
opts.onStarted?.();
|
|
195
|
+
} else if (envelope.result.type === 'stopped') {
|
|
196
|
+
opts.onStopped?.();
|
|
197
|
+
} else {
|
|
198
|
+
opts.onData?.(envelope.result.data);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
error (err) {
|
|
202
|
+
opts.onError?.(err);
|
|
203
|
+
},
|
|
204
|
+
complete () {
|
|
205
|
+
opts.onComplete?.();
|
|
206
|
+
}
|
|
207
|
+
});
|
|
306
208
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
(_opts$onComplete = opts.onComplete) === null || _opts$onComplete === void 0 ? void 0 : _opts$onComplete.call(opts);
|
|
209
|
+
constructor(opts){
|
|
210
|
+
const _fetch = getFetch(opts?.fetch);
|
|
211
|
+
const AC = getAbortController(opts?.AbortController);
|
|
212
|
+
this.requestId = 0;
|
|
213
|
+
function getHeadersFn() {
|
|
214
|
+
if (opts.headers) {
|
|
215
|
+
const headers = opts.headers;
|
|
216
|
+
return typeof headers === 'function' ? headers : ()=>headers;
|
|
217
|
+
}
|
|
218
|
+
return ()=>({});
|
|
219
|
+
}
|
|
220
|
+
const transformer = opts.transformer ? 'input' in opts.transformer ? {
|
|
221
|
+
serialize: opts.transformer.input.serialize,
|
|
222
|
+
deserialize: opts.transformer.output.deserialize
|
|
223
|
+
} : opts.transformer : {
|
|
224
|
+
serialize: (data)=>data,
|
|
225
|
+
deserialize: (data)=>data
|
|
226
|
+
};
|
|
227
|
+
this.runtime = {
|
|
228
|
+
AbortController: AC,
|
|
229
|
+
fetch: _fetch,
|
|
230
|
+
headers: getHeadersFn(),
|
|
231
|
+
transformer
|
|
232
|
+
};
|
|
233
|
+
if ('links' in opts) {
|
|
234
|
+
this.links = opts.links.map((link)=>link(this.runtime));
|
|
235
|
+
} else {
|
|
236
|
+
this.links = [
|
|
237
|
+
links_httpBatchLink.httpBatchLink({
|
|
238
|
+
url: opts.url
|
|
239
|
+
})(this.runtime),
|
|
240
|
+
];
|
|
341
241
|
}
|
|
342
|
-
});
|
|
343
242
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return TRPCClient;
|
|
347
|
-
}();
|
|
243
|
+
}
|
|
348
244
|
|
|
349
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
350
245
|
function createTRPCClient(opts) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
246
|
+
const client = new TRPCClient(opts);
|
|
247
|
+
return client;
|
|
248
|
+
}
|
|
354
249
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
250
|
+
const clientCallTypeMap = {
|
|
251
|
+
query: 'query',
|
|
252
|
+
mutate: 'mutation',
|
|
253
|
+
subscribe: 'subscription'
|
|
359
254
|
};
|
|
360
255
|
/**
|
|
361
256
|
* @deprecated use createTRPCProxyClient instead
|
|
362
257
|
* @internal
|
|
363
|
-
*/
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
var clientCallType = pathCopy.pop();
|
|
375
|
-
var procedureType = clientCallTypeMap[clientCallType];
|
|
376
|
-
var fullPath = pathCopy.join('.');
|
|
377
|
-
return (_ref2 = client)[procedureType].apply(_ref2, [fullPath].concat(_toConsumableArray__default["default"](args)));
|
|
378
|
-
});
|
|
379
|
-
return proxy;
|
|
258
|
+
*/ function createTRPCClientProxy(client) {
|
|
259
|
+
const proxy = shared.createProxy(({ path , args })=>{
|
|
260
|
+
const pathCopy = [
|
|
261
|
+
...path
|
|
262
|
+
];
|
|
263
|
+
const clientCallType = pathCopy.pop();
|
|
264
|
+
const procedureType = clientCallTypeMap[clientCallType];
|
|
265
|
+
const fullPath = pathCopy.join('.');
|
|
266
|
+
return client[procedureType](fullPath, ...args);
|
|
267
|
+
});
|
|
268
|
+
return proxy;
|
|
380
269
|
}
|
|
381
270
|
function createTRPCProxyClient(opts) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
271
|
+
const client = createTRPCClient(opts);
|
|
272
|
+
const proxy = createTRPCClientProxy(client);
|
|
273
|
+
return proxy;
|
|
385
274
|
}
|
|
386
275
|
|
|
387
276
|
exports.TRPCClientError = transformResult.TRPCClientError;
|