@trpc/client 10.0.0-alpha.45 → 10.0.0-alpha.48
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 +2 -2
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/createTRPCClient.d.ts +3 -0
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClientProxy.d.ts +1 -1
- package/dist/httpUtils-44781613.mjs +76 -0
- package/dist/httpUtils-801112a6.js +79 -0
- package/dist/index.js +230 -339
- package/dist/index.mjs +232 -335
- 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 +2 -2
- package/src/createTRPCClient.ts +3 -0
- package/src/createTRPCClientProxy.ts +1 -1
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryDelay.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"retryDelay.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/internals/retryDelay.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,iBAAkB,MAAM,WACqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedupeLink.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"dedupeLink.d.ts","sourceRoot":"","sources":["../../../../packages/client/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":"httpBatchLink.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/links/httpBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAIxD,OAAO,EACL,eAAe,EAIhB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,aAAa,CAAC,OAAO,SAAS,SAAS,EACrD,IAAI,EAAE,oBAAoB,GACzB,QAAQ,CAAC,OAAO,CAAC,CA4FnB"}
|
|
@@ -3,332 +3,210 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var observable = require('@trpc/server/observable');
|
|
6
|
-
var transformResult = require('../transformResult-
|
|
7
|
-
var httpUtils = require('../httpUtils-
|
|
8
|
-
require('@babel/runtime/helpers/defineProperty');
|
|
9
|
-
require('@babel/runtime/helpers/classCallCheck');
|
|
10
|
-
require('@babel/runtime/helpers/createClass');
|
|
11
|
-
require('@babel/runtime/helpers/assertThisInitialized');
|
|
12
|
-
require('@babel/runtime/helpers/inherits');
|
|
13
|
-
require('@babel/runtime/helpers/possibleConstructorReturn');
|
|
14
|
-
require('@babel/runtime/helpers/getPrototypeOf');
|
|
15
|
-
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
6
|
+
var transformResult = require('../transformResult-e15ccdf6.js');
|
|
7
|
+
var httpUtils = require('../httpUtils-801112a6.js');
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
-
|
|
21
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
22
|
-
|
|
23
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
24
|
-
|
|
25
|
-
/**
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
|
|
26
10
|
* A function that should never be called unless we messed something up.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
throw new Error('Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new');
|
|
11
|
+
*/ const throwFatalError = ()=>{
|
|
12
|
+
throw new Error('Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new');
|
|
30
13
|
};
|
|
31
14
|
/**
|
|
32
15
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
33
16
|
* Less configuration, no caching, and allows you to cancel requests
|
|
34
17
|
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
dispatchTimer = null;
|
|
45
|
-
pendingItems = null;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
18
|
+
*/ function dataLoader(batchLoader) {
|
|
19
|
+
let pendingItems = null;
|
|
20
|
+
let dispatchTimer = null;
|
|
21
|
+
const destroyTimerAndPendingItems = ()=>{
|
|
22
|
+
clearTimeout(dispatchTimer);
|
|
23
|
+
dispatchTimer = null;
|
|
24
|
+
pendingItems = null;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
48
27
|
* Iterate through the items and split them into groups based on the `batchLoader`'s validate function
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
if (lastGroup.length === 0) {
|
|
84
|
-
item.reject(new Error('Input is too big for a single dispatch'));
|
|
85
|
-
index++;
|
|
86
|
-
continue;
|
|
87
|
-
} // Create new group, next iteration will try to add the item to that
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
groupedItems.push([]);
|
|
28
|
+
*/ function groupItems(items) {
|
|
29
|
+
const groupedItems = [
|
|
30
|
+
[]
|
|
31
|
+
];
|
|
32
|
+
let index = 0;
|
|
33
|
+
while(true){
|
|
34
|
+
const item = items[index];
|
|
35
|
+
if (!item) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const lastGroup = groupedItems[groupedItems.length - 1];
|
|
39
|
+
if (item.aborted) {
|
|
40
|
+
// Item was aborted before it was dispatched
|
|
41
|
+
item.reject(new Error('Aborted'));
|
|
42
|
+
index++;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const isValid = batchLoader.validate(lastGroup.concat(item).map((it)=>it.key));
|
|
46
|
+
if (isValid) {
|
|
47
|
+
lastGroup.push(item);
|
|
48
|
+
index++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (lastGroup.length === 0) {
|
|
52
|
+
item.reject(new Error('Input is too big for a single dispatch'));
|
|
53
|
+
index++;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
// Create new group, next iteration will try to add the item to that
|
|
57
|
+
groupedItems.push([]);
|
|
58
|
+
}
|
|
59
|
+
return groupedItems;
|
|
91
60
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
61
|
+
function dispatch() {
|
|
62
|
+
const groupedItems = groupItems(pendingItems);
|
|
63
|
+
destroyTimerAndPendingItems();
|
|
64
|
+
// Create batches for each group of items
|
|
65
|
+
for (const items of groupedItems){
|
|
66
|
+
if (!items.length) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const batch = {
|
|
70
|
+
items,
|
|
71
|
+
cancel: throwFatalError
|
|
72
|
+
};
|
|
73
|
+
for (const item of items){
|
|
74
|
+
item.batch = batch;
|
|
75
|
+
}
|
|
76
|
+
const { promise , cancel } = batchLoader.fetch(batch.items.map((_item)=>_item.key));
|
|
77
|
+
batch.cancel = cancel;
|
|
78
|
+
promise.then((result)=>{
|
|
79
|
+
for(let i = 0; i < result.length; i++){
|
|
80
|
+
const value = result[i];
|
|
81
|
+
const item = batch.items[i];
|
|
82
|
+
item.resolve(value);
|
|
83
|
+
item.batch = null;
|
|
84
|
+
}
|
|
85
|
+
}).catch((cause)=>{
|
|
86
|
+
for (const item of batch.items){
|
|
87
|
+
item.reject(cause);
|
|
88
|
+
item.batch = null;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
109
91
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
92
|
+
}
|
|
93
|
+
function load(key) {
|
|
94
|
+
const item = {
|
|
95
|
+
aborted: false,
|
|
96
|
+
key,
|
|
97
|
+
batch: null,
|
|
98
|
+
resolve: throwFatalError,
|
|
99
|
+
reject: throwFatalError
|
|
114
100
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
121
|
-
var item = _step2.value;
|
|
122
|
-
item.batch = batch;
|
|
123
|
-
}
|
|
124
|
-
} catch (err) {
|
|
125
|
-
_iterator2.e(err);
|
|
126
|
-
} finally {
|
|
127
|
-
_iterator2.f();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
var _batchLoader$fetch = batchLoader.fetch(batch.items.map(function (_item) {
|
|
131
|
-
return _item.key;
|
|
132
|
-
})),
|
|
133
|
-
promise = _batchLoader$fetch.promise,
|
|
134
|
-
cancel = _batchLoader$fetch.cancel;
|
|
135
|
-
|
|
136
|
-
batch.cancel = cancel;
|
|
137
|
-
promise.then(function (result) {
|
|
138
|
-
for (var i = 0; i < result.length; i++) {
|
|
139
|
-
var _value = result[i];
|
|
140
|
-
var item = batch.items[i];
|
|
141
|
-
item.resolve(_value);
|
|
142
|
-
item.batch = null;
|
|
143
|
-
}
|
|
144
|
-
}).catch(function (cause) {
|
|
145
|
-
var _iterator3 = _createForOfIteratorHelper(batch.items),
|
|
146
|
-
_step3;
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
150
|
-
var item = _step3.value;
|
|
151
|
-
item.reject(cause);
|
|
152
|
-
item.batch = null;
|
|
101
|
+
const promise = new Promise((resolve, reject)=>{
|
|
102
|
+
item.reject = reject;
|
|
103
|
+
item.resolve = resolve;
|
|
104
|
+
if (!pendingItems) {
|
|
105
|
+
pendingItems = [];
|
|
153
106
|
}
|
|
154
|
-
|
|
155
|
-
_iterator3.e(err);
|
|
156
|
-
} finally {
|
|
157
|
-
_iterator3.f();
|
|
158
|
-
}
|
|
107
|
+
pendingItems.push(item);
|
|
159
108
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var item = {
|
|
176
|
-
aborted: false,
|
|
177
|
-
key: key,
|
|
178
|
-
batch: null,
|
|
179
|
-
resolve: throwFatalError,
|
|
180
|
-
reject: throwFatalError
|
|
181
|
-
};
|
|
182
|
-
var promise = new Promise(function (resolve, reject) {
|
|
183
|
-
item.reject = reject;
|
|
184
|
-
item.resolve = resolve;
|
|
185
|
-
|
|
186
|
-
if (!pendingItems) {
|
|
187
|
-
pendingItems = [];
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
pendingItems.push(item);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
if (!dispatchTimer) {
|
|
194
|
-
dispatchTimer = setTimeout(dispatch);
|
|
109
|
+
if (!dispatchTimer) {
|
|
110
|
+
dispatchTimer = setTimeout(dispatch);
|
|
111
|
+
}
|
|
112
|
+
const cancel = ()=>{
|
|
113
|
+
item.aborted = true;
|
|
114
|
+
if (item.batch?.items.every((item)=>item.aborted)) {
|
|
115
|
+
// All items in the batch have been cancelled
|
|
116
|
+
item.batch.cancel();
|
|
117
|
+
item.batch = null;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
promise,
|
|
122
|
+
cancel
|
|
123
|
+
};
|
|
195
124
|
}
|
|
196
|
-
|
|
197
|
-
var cancel = function cancel() {
|
|
198
|
-
var _item$batch;
|
|
199
|
-
|
|
200
|
-
item.aborted = true;
|
|
201
|
-
|
|
202
|
-
if ((_item$batch = item.batch) !== null && _item$batch !== void 0 && _item$batch.items.every(function (item) {
|
|
203
|
-
return item.aborted;
|
|
204
|
-
})) {
|
|
205
|
-
// All items in the batch have been cancelled
|
|
206
|
-
item.batch.cancel();
|
|
207
|
-
item.batch = null;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
125
|
return {
|
|
212
|
-
|
|
213
|
-
cancel: cancel
|
|
126
|
+
load
|
|
214
127
|
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return {
|
|
218
|
-
load: load
|
|
219
|
-
};
|
|
220
128
|
}
|
|
221
129
|
|
|
222
130
|
function httpBatchLink(opts) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
promise: promise.then(function (res) {
|
|
270
|
-
var resJSON = Array.isArray(res.json) ? res.json : batchOps.map(function () {
|
|
271
|
-
return res.json;
|
|
272
|
-
});
|
|
273
|
-
var result = resJSON.map(function (item) {
|
|
274
|
-
return {
|
|
275
|
-
meta: res.meta,
|
|
276
|
-
json: item
|
|
277
|
-
};
|
|
278
|
-
});
|
|
279
|
-
return result;
|
|
280
|
-
}),
|
|
281
|
-
cancel: cancel
|
|
131
|
+
// initialized config
|
|
132
|
+
return (runtime)=>{
|
|
133
|
+
const maxURLLength = opts.maxURLLength || Infinity;
|
|
134
|
+
const batchLoader = (type)=>{
|
|
135
|
+
const validate = (batchOps)=>{
|
|
136
|
+
if (maxURLLength === Infinity) {
|
|
137
|
+
// escape hatch for quick calcs
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
const path = batchOps.map((op)=>op.path).join(',');
|
|
141
|
+
const inputs = batchOps.map((op)=>op.input);
|
|
142
|
+
const url = httpUtils.getUrl({
|
|
143
|
+
url: opts.url,
|
|
144
|
+
runtime,
|
|
145
|
+
type,
|
|
146
|
+
path,
|
|
147
|
+
inputs
|
|
148
|
+
});
|
|
149
|
+
return url.length <= maxURLLength;
|
|
150
|
+
};
|
|
151
|
+
const fetch = (batchOps)=>{
|
|
152
|
+
const path = batchOps.map((op)=>op.path).join(',');
|
|
153
|
+
const inputs = batchOps.map((op)=>op.input);
|
|
154
|
+
const { promise , cancel } = httpUtils.httpRequest({
|
|
155
|
+
url: opts.url,
|
|
156
|
+
runtime,
|
|
157
|
+
type,
|
|
158
|
+
path,
|
|
159
|
+
inputs
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
promise: promise.then((res)=>{
|
|
163
|
+
const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
|
|
164
|
+
const result = resJSON.map((item)=>({
|
|
165
|
+
meta: res.meta,
|
|
166
|
+
json: item
|
|
167
|
+
}));
|
|
168
|
+
return result;
|
|
169
|
+
}),
|
|
170
|
+
cancel
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
validate,
|
|
175
|
+
fetch
|
|
176
|
+
};
|
|
282
177
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
meta: res.meta
|
|
314
|
-
}));
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
observer.next({
|
|
319
|
-
context: res.meta,
|
|
320
|
-
result: transformed.result
|
|
321
|
-
});
|
|
322
|
-
observer.complete();
|
|
323
|
-
}).catch(function (err) {
|
|
324
|
-
return observer.error(err);
|
|
325
|
-
});
|
|
326
|
-
return function () {
|
|
327
|
-
cancel();
|
|
178
|
+
const query = dataLoader(batchLoader('query'));
|
|
179
|
+
const mutation = dataLoader(batchLoader('mutation'));
|
|
180
|
+
const subscription = dataLoader(batchLoader('subscription'));
|
|
181
|
+
const loaders = {
|
|
182
|
+
query,
|
|
183
|
+
subscription,
|
|
184
|
+
mutation
|
|
185
|
+
};
|
|
186
|
+
return ({ op })=>{
|
|
187
|
+
return observable.observable((observer)=>{
|
|
188
|
+
const loader = loaders[op.type];
|
|
189
|
+
const { promise , cancel } = loader.load(op);
|
|
190
|
+
promise.then((res)=>{
|
|
191
|
+
const transformed = transformResult.transformResult(res.json, runtime);
|
|
192
|
+
if (!transformed.ok) {
|
|
193
|
+
observer.error(transformResult.TRPCClientError.from(transformed.error, {
|
|
194
|
+
meta: res.meta
|
|
195
|
+
}));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
observer.next({
|
|
199
|
+
context: res.meta,
|
|
200
|
+
result: transformed.result
|
|
201
|
+
});
|
|
202
|
+
observer.complete();
|
|
203
|
+
}).catch((err)=>observer.error(err));
|
|
204
|
+
return ()=>{
|
|
205
|
+
cancel();
|
|
206
|
+
};
|
|
207
|
+
});
|
|
328
208
|
};
|
|
329
|
-
});
|
|
330
209
|
};
|
|
331
|
-
};
|
|
332
210
|
}
|
|
333
211
|
|
|
334
212
|
exports.httpBatchLink = httpBatchLink;
|