@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
|
@@ -1,330 +1,208 @@
|
|
|
1
1
|
import { observable } from '@trpc/server/observable';
|
|
2
|
-
import { t as transformResult, T as TRPCClientError } from '../transformResult-
|
|
3
|
-
import { g as getUrl, h as httpRequest } from '../httpUtils-
|
|
4
|
-
import '@babel/runtime/helpers/defineProperty';
|
|
5
|
-
import '@babel/runtime/helpers/classCallCheck';
|
|
6
|
-
import '@babel/runtime/helpers/createClass';
|
|
7
|
-
import '@babel/runtime/helpers/assertThisInitialized';
|
|
8
|
-
import '@babel/runtime/helpers/inherits';
|
|
9
|
-
import '@babel/runtime/helpers/possibleConstructorReturn';
|
|
10
|
-
import '@babel/runtime/helpers/getPrototypeOf';
|
|
11
|
-
import '@babel/runtime/helpers/wrapNativeSuper';
|
|
2
|
+
import { t as transformResult, T as TRPCClientError } from '../transformResult-106791d7.mjs';
|
|
3
|
+
import { g as getUrl, h as httpRequest } from '../httpUtils-44781613.mjs';
|
|
12
4
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
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); }
|
|
16
|
-
|
|
17
|
-
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; }
|
|
18
|
-
|
|
19
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
20
|
-
|
|
21
|
-
/**
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
|
|
22
6
|
* A function that should never be called unless we messed something up.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
throw new Error('Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new');
|
|
7
|
+
*/ const throwFatalError = ()=>{
|
|
8
|
+
throw new Error('Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new');
|
|
26
9
|
};
|
|
27
10
|
/**
|
|
28
11
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
29
12
|
* Less configuration, no caching, and allows you to cancel requests
|
|
30
13
|
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
dispatchTimer = null;
|
|
41
|
-
pendingItems = null;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
14
|
+
*/ function dataLoader(batchLoader) {
|
|
15
|
+
let pendingItems = null;
|
|
16
|
+
let dispatchTimer = null;
|
|
17
|
+
const destroyTimerAndPendingItems = ()=>{
|
|
18
|
+
clearTimeout(dispatchTimer);
|
|
19
|
+
dispatchTimer = null;
|
|
20
|
+
pendingItems = null;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
44
23
|
* Iterate through the items and split them into groups based on the `batchLoader`'s validate function
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
if (lastGroup.length === 0) {
|
|
80
|
-
item.reject(new Error('Input is too big for a single dispatch'));
|
|
81
|
-
index++;
|
|
82
|
-
continue;
|
|
83
|
-
} // Create new group, next iteration will try to add the item to that
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
groupedItems.push([]);
|
|
24
|
+
*/ function groupItems(items) {
|
|
25
|
+
const groupedItems = [
|
|
26
|
+
[]
|
|
27
|
+
];
|
|
28
|
+
let index = 0;
|
|
29
|
+
while(true){
|
|
30
|
+
const item = items[index];
|
|
31
|
+
if (!item) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
const lastGroup = groupedItems[groupedItems.length - 1];
|
|
35
|
+
if (item.aborted) {
|
|
36
|
+
// Item was aborted before it was dispatched
|
|
37
|
+
item.reject(new Error('Aborted'));
|
|
38
|
+
index++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const isValid = batchLoader.validate(lastGroup.concat(item).map((it)=>it.key));
|
|
42
|
+
if (isValid) {
|
|
43
|
+
lastGroup.push(item);
|
|
44
|
+
index++;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (lastGroup.length === 0) {
|
|
48
|
+
item.reject(new Error('Input is too big for a single dispatch'));
|
|
49
|
+
index++;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// Create new group, next iteration will try to add the item to that
|
|
53
|
+
groupedItems.push([]);
|
|
54
|
+
}
|
|
55
|
+
return groupedItems;
|
|
87
56
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
57
|
+
function dispatch() {
|
|
58
|
+
const groupedItems = groupItems(pendingItems);
|
|
59
|
+
destroyTimerAndPendingItems();
|
|
60
|
+
// Create batches for each group of items
|
|
61
|
+
for (const items of groupedItems){
|
|
62
|
+
if (!items.length) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const batch = {
|
|
66
|
+
items,
|
|
67
|
+
cancel: throwFatalError
|
|
68
|
+
};
|
|
69
|
+
for (const item of items){
|
|
70
|
+
item.batch = batch;
|
|
71
|
+
}
|
|
72
|
+
const { promise , cancel } = batchLoader.fetch(batch.items.map((_item)=>_item.key));
|
|
73
|
+
batch.cancel = cancel;
|
|
74
|
+
promise.then((result)=>{
|
|
75
|
+
for(let i = 0; i < result.length; i++){
|
|
76
|
+
const value = result[i];
|
|
77
|
+
const item = batch.items[i];
|
|
78
|
+
item.resolve(value);
|
|
79
|
+
item.batch = null;
|
|
80
|
+
}
|
|
81
|
+
}).catch((cause)=>{
|
|
82
|
+
for (const item of batch.items){
|
|
83
|
+
item.reject(cause);
|
|
84
|
+
item.batch = null;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
105
87
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
88
|
+
}
|
|
89
|
+
function load(key) {
|
|
90
|
+
const item = {
|
|
91
|
+
aborted: false,
|
|
92
|
+
key,
|
|
93
|
+
batch: null,
|
|
94
|
+
resolve: throwFatalError,
|
|
95
|
+
reject: throwFatalError
|
|
110
96
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
117
|
-
var item = _step2.value;
|
|
118
|
-
item.batch = batch;
|
|
119
|
-
}
|
|
120
|
-
} catch (err) {
|
|
121
|
-
_iterator2.e(err);
|
|
122
|
-
} finally {
|
|
123
|
-
_iterator2.f();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
var _batchLoader$fetch = batchLoader.fetch(batch.items.map(function (_item) {
|
|
127
|
-
return _item.key;
|
|
128
|
-
})),
|
|
129
|
-
promise = _batchLoader$fetch.promise,
|
|
130
|
-
cancel = _batchLoader$fetch.cancel;
|
|
131
|
-
|
|
132
|
-
batch.cancel = cancel;
|
|
133
|
-
promise.then(function (result) {
|
|
134
|
-
for (var i = 0; i < result.length; i++) {
|
|
135
|
-
var _value = result[i];
|
|
136
|
-
var item = batch.items[i];
|
|
137
|
-
item.resolve(_value);
|
|
138
|
-
item.batch = null;
|
|
139
|
-
}
|
|
140
|
-
}).catch(function (cause) {
|
|
141
|
-
var _iterator3 = _createForOfIteratorHelper(batch.items),
|
|
142
|
-
_step3;
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
146
|
-
var item = _step3.value;
|
|
147
|
-
item.reject(cause);
|
|
148
|
-
item.batch = null;
|
|
97
|
+
const promise = new Promise((resolve, reject)=>{
|
|
98
|
+
item.reject = reject;
|
|
99
|
+
item.resolve = resolve;
|
|
100
|
+
if (!pendingItems) {
|
|
101
|
+
pendingItems = [];
|
|
149
102
|
}
|
|
150
|
-
|
|
151
|
-
_iterator3.e(err);
|
|
152
|
-
} finally {
|
|
153
|
-
_iterator3.f();
|
|
154
|
-
}
|
|
103
|
+
pendingItems.push(item);
|
|
155
104
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var item = {
|
|
172
|
-
aborted: false,
|
|
173
|
-
key: key,
|
|
174
|
-
batch: null,
|
|
175
|
-
resolve: throwFatalError,
|
|
176
|
-
reject: throwFatalError
|
|
177
|
-
};
|
|
178
|
-
var promise = new Promise(function (resolve, reject) {
|
|
179
|
-
item.reject = reject;
|
|
180
|
-
item.resolve = resolve;
|
|
181
|
-
|
|
182
|
-
if (!pendingItems) {
|
|
183
|
-
pendingItems = [];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
pendingItems.push(item);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
if (!dispatchTimer) {
|
|
190
|
-
dispatchTimer = setTimeout(dispatch);
|
|
105
|
+
if (!dispatchTimer) {
|
|
106
|
+
dispatchTimer = setTimeout(dispatch);
|
|
107
|
+
}
|
|
108
|
+
const cancel = ()=>{
|
|
109
|
+
item.aborted = true;
|
|
110
|
+
if (item.batch?.items.every((item)=>item.aborted)) {
|
|
111
|
+
// All items in the batch have been cancelled
|
|
112
|
+
item.batch.cancel();
|
|
113
|
+
item.batch = null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
promise,
|
|
118
|
+
cancel
|
|
119
|
+
};
|
|
191
120
|
}
|
|
192
|
-
|
|
193
|
-
var cancel = function cancel() {
|
|
194
|
-
var _item$batch;
|
|
195
|
-
|
|
196
|
-
item.aborted = true;
|
|
197
|
-
|
|
198
|
-
if ((_item$batch = item.batch) !== null && _item$batch !== void 0 && _item$batch.items.every(function (item) {
|
|
199
|
-
return item.aborted;
|
|
200
|
-
})) {
|
|
201
|
-
// All items in the batch have been cancelled
|
|
202
|
-
item.batch.cancel();
|
|
203
|
-
item.batch = null;
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
121
|
return {
|
|
208
|
-
|
|
209
|
-
cancel: cancel
|
|
122
|
+
load
|
|
210
123
|
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
load: load
|
|
215
|
-
};
|
|
216
124
|
}
|
|
217
125
|
|
|
218
126
|
function httpBatchLink(opts) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
promise: promise.then(function (res) {
|
|
266
|
-
var resJSON = Array.isArray(res.json) ? res.json : batchOps.map(function () {
|
|
267
|
-
return res.json;
|
|
268
|
-
});
|
|
269
|
-
var result = resJSON.map(function (item) {
|
|
270
|
-
return {
|
|
271
|
-
meta: res.meta,
|
|
272
|
-
json: item
|
|
273
|
-
};
|
|
274
|
-
});
|
|
275
|
-
return result;
|
|
276
|
-
}),
|
|
277
|
-
cancel: cancel
|
|
127
|
+
// initialized config
|
|
128
|
+
return (runtime)=>{
|
|
129
|
+
const maxURLLength = opts.maxURLLength || Infinity;
|
|
130
|
+
const batchLoader = (type)=>{
|
|
131
|
+
const validate = (batchOps)=>{
|
|
132
|
+
if (maxURLLength === Infinity) {
|
|
133
|
+
// escape hatch for quick calcs
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
const path = batchOps.map((op)=>op.path).join(',');
|
|
137
|
+
const inputs = batchOps.map((op)=>op.input);
|
|
138
|
+
const url = getUrl({
|
|
139
|
+
url: opts.url,
|
|
140
|
+
runtime,
|
|
141
|
+
type,
|
|
142
|
+
path,
|
|
143
|
+
inputs
|
|
144
|
+
});
|
|
145
|
+
return url.length <= maxURLLength;
|
|
146
|
+
};
|
|
147
|
+
const fetch = (batchOps)=>{
|
|
148
|
+
const path = batchOps.map((op)=>op.path).join(',');
|
|
149
|
+
const inputs = batchOps.map((op)=>op.input);
|
|
150
|
+
const { promise , cancel } = httpRequest({
|
|
151
|
+
url: opts.url,
|
|
152
|
+
runtime,
|
|
153
|
+
type,
|
|
154
|
+
path,
|
|
155
|
+
inputs
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
promise: promise.then((res)=>{
|
|
159
|
+
const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
|
|
160
|
+
const result = resJSON.map((item)=>({
|
|
161
|
+
meta: res.meta,
|
|
162
|
+
json: item
|
|
163
|
+
}));
|
|
164
|
+
return result;
|
|
165
|
+
}),
|
|
166
|
+
cancel
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
validate,
|
|
171
|
+
fetch
|
|
172
|
+
};
|
|
278
173
|
};
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
meta: res.meta
|
|
310
|
-
}));
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
observer.next({
|
|
315
|
-
context: res.meta,
|
|
316
|
-
result: transformed.result
|
|
317
|
-
});
|
|
318
|
-
observer.complete();
|
|
319
|
-
}).catch(function (err) {
|
|
320
|
-
return observer.error(err);
|
|
321
|
-
});
|
|
322
|
-
return function () {
|
|
323
|
-
cancel();
|
|
174
|
+
const query = dataLoader(batchLoader('query'));
|
|
175
|
+
const mutation = dataLoader(batchLoader('mutation'));
|
|
176
|
+
const subscription = dataLoader(batchLoader('subscription'));
|
|
177
|
+
const loaders = {
|
|
178
|
+
query,
|
|
179
|
+
subscription,
|
|
180
|
+
mutation
|
|
181
|
+
};
|
|
182
|
+
return ({ op })=>{
|
|
183
|
+
return observable((observer)=>{
|
|
184
|
+
const loader = loaders[op.type];
|
|
185
|
+
const { promise , cancel } = loader.load(op);
|
|
186
|
+
promise.then((res)=>{
|
|
187
|
+
const transformed = transformResult(res.json, runtime);
|
|
188
|
+
if (!transformed.ok) {
|
|
189
|
+
observer.error(TRPCClientError.from(transformed.error, {
|
|
190
|
+
meta: res.meta
|
|
191
|
+
}));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
observer.next({
|
|
195
|
+
context: res.meta,
|
|
196
|
+
result: transformed.result
|
|
197
|
+
});
|
|
198
|
+
observer.complete();
|
|
199
|
+
}).catch((err)=>observer.error(err));
|
|
200
|
+
return ()=>{
|
|
201
|
+
cancel();
|
|
202
|
+
};
|
|
203
|
+
});
|
|
324
204
|
};
|
|
325
|
-
});
|
|
326
205
|
};
|
|
327
|
-
};
|
|
328
206
|
}
|
|
329
207
|
|
|
330
208
|
export { httpBatchLink };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/links/httpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,eAAe,EAAe,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,wBAAgB,QAAQ,CAAC,OAAO,SAAS,SAAS,EAChD,IAAI,EAAE,eAAe,GACpB,QAAQ,CAAC,OAAO,CAAC,CAqCnB"}
|
package/dist/links/httpLink.js
CHANGED
|
@@ -3,61 +3,38 @@
|
|
|
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
9
|
function httpLink(opts) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
observer.next({
|
|
48
|
-
context: res.meta,
|
|
49
|
-
result: transformed.result
|
|
50
|
-
});
|
|
51
|
-
observer.complete();
|
|
52
|
-
}).catch(function (cause) {
|
|
53
|
-
return transformResult.TRPCClientError.from(cause);
|
|
54
|
-
});
|
|
55
|
-
return function () {
|
|
56
|
-
cancel();
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
};
|
|
10
|
+
const { url } = opts;
|
|
11
|
+
return (runtime)=>({ op })=>observable.observable((observer)=>{
|
|
12
|
+
const { path , input , type } = op;
|
|
13
|
+
const { promise , cancel } = httpUtils.httpRequest({
|
|
14
|
+
url,
|
|
15
|
+
runtime,
|
|
16
|
+
type,
|
|
17
|
+
path,
|
|
18
|
+
input
|
|
19
|
+
});
|
|
20
|
+
promise.then((res)=>{
|
|
21
|
+
const transformed = transformResult.transformResult(res.json, runtime);
|
|
22
|
+
if (!transformed.ok) {
|
|
23
|
+
observer.error(transformResult.TRPCClientError.from(transformed.error, {
|
|
24
|
+
meta: res.meta
|
|
25
|
+
}));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
observer.next({
|
|
29
|
+
context: res.meta,
|
|
30
|
+
result: transformed.result
|
|
31
|
+
});
|
|
32
|
+
observer.complete();
|
|
33
|
+
}).catch((cause)=>transformResult.TRPCClientError.from(cause));
|
|
34
|
+
return ()=>{
|
|
35
|
+
cancel();
|
|
36
|
+
};
|
|
37
|
+
});
|
|
61
38
|
}
|
|
62
39
|
|
|
63
40
|
exports.httpLink = httpLink;
|