@trpc/client 10.0.0-alpha.28 → 10.0.0-alpha.30
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 +5 -1
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/index.js +49 -40
- package/dist/index.mjs +49 -40
- package/dist/internals/TRPCClient.d.ts +3 -5
- package/dist/internals/TRPCClient.d.ts.map +1 -1
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +1 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +280 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +7 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +280 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +272 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +1 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +134 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +7 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +134 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +126 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +1 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +89 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +7 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +89 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +85 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +1 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +19 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +7 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +19 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +15 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +1 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +397 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +7 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +397 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +392 -0
- package/package.json +4 -4
- package/src/createTRPCClient.ts +56 -1
- package/src/internals/TRPCClient.ts +0 -17
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
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
|
+
var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
|
|
11
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-2b5b4bba.cjs.prod.js');
|
|
12
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
13
|
+
require('@babel/runtime/helpers/assertThisInitialized');
|
|
14
|
+
require('@babel/runtime/helpers/inherits');
|
|
15
|
+
require('@babel/runtime/helpers/createSuper');
|
|
16
|
+
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
17
|
+
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
24
|
+
* Less configuration, no caching, and allows you to cancel requests
|
|
25
|
+
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
26
|
+
*/
|
|
27
|
+
function dataLoader(fetchMany, opts) {
|
|
28
|
+
var batch = null;
|
|
29
|
+
var dispatchTimer = null;
|
|
30
|
+
|
|
31
|
+
var destroyTimerAndBatch = function destroyTimerAndBatch() {
|
|
32
|
+
clearTimeout(dispatchTimer);
|
|
33
|
+
dispatchTimer = null;
|
|
34
|
+
batch = null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function dispatch() {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
+
var batchCopy = batch;
|
|
40
|
+
destroyTimerAndBatch();
|
|
41
|
+
|
|
42
|
+
var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
|
|
43
|
+
return v.key;
|
|
44
|
+
})),
|
|
45
|
+
promise = _fetchMany.promise,
|
|
46
|
+
cancel = _fetchMany.cancel;
|
|
47
|
+
|
|
48
|
+
batchCopy.cancel = cancel;
|
|
49
|
+
promise.then(function (result) {
|
|
50
|
+
for (var i = 0; i < result.length; i++) {
|
|
51
|
+
var _value = result[i];
|
|
52
|
+
batchCopy.items[i].resolve(_value);
|
|
53
|
+
}
|
|
54
|
+
}).catch(function (cause) {
|
|
55
|
+
var _iterator = _createForOfIteratorHelper(batchCopy.items),
|
|
56
|
+
_step;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
60
|
+
var item = _step.value;
|
|
61
|
+
item.reject(cause);
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_iterator.e(err);
|
|
65
|
+
} finally {
|
|
66
|
+
_iterator.f();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function load(key) {
|
|
72
|
+
var batchItem = {
|
|
73
|
+
cancelled: false,
|
|
74
|
+
key: key
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (!batch) {
|
|
78
|
+
batch = {
|
|
79
|
+
items: [],
|
|
80
|
+
cancel: function cancel() {
|
|
81
|
+
destroyTimerAndBatch();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var thisBatch = batch;
|
|
87
|
+
var promise = new Promise(function (resolve, reject) {
|
|
88
|
+
var item = batchItem;
|
|
89
|
+
item.reject = reject;
|
|
90
|
+
item.resolve = resolve;
|
|
91
|
+
thisBatch.items.push(item);
|
|
92
|
+
|
|
93
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
94
|
+
dispatch();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if (!dispatchTimer) {
|
|
100
|
+
dispatchTimer = setTimeout(dispatch);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var cancel = function cancel() {
|
|
104
|
+
batchItem.cancelled = true;
|
|
105
|
+
|
|
106
|
+
if (thisBatch.items.some(function (item) {
|
|
107
|
+
return !item.cancelled;
|
|
108
|
+
})) {
|
|
109
|
+
// there are still things that can be resolved
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
thisBatch.cancel();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
promise: promise,
|
|
118
|
+
cancel: cancel
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
load: load
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function httpBatchLink(opts) {
|
|
128
|
+
var url = opts.url,
|
|
129
|
+
maxBatchSize = opts.maxBatchSize; // initialized config
|
|
130
|
+
|
|
131
|
+
return function (runtime) {
|
|
132
|
+
// 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
|
+
var fetcher = function fetcher(type) {
|
|
185
|
+
return function (pairs) {
|
|
186
|
+
var _opts$fetch, _opts$AbortController;
|
|
187
|
+
|
|
188
|
+
var path = pairs.map(function (op) {
|
|
189
|
+
return op.path;
|
|
190
|
+
}).join(',');
|
|
191
|
+
var inputs = pairs.map(function (op) {
|
|
192
|
+
return op.input;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
var _httpRequest = transformRPCResponse.httpRequest({
|
|
196
|
+
url: url,
|
|
197
|
+
inputs: inputs,
|
|
198
|
+
path: path,
|
|
199
|
+
type: type,
|
|
200
|
+
fetch: transformRPCResponse.getFetch((_opts$fetch = opts.fetch) !== null && _opts$fetch !== void 0 ? _opts$fetch : runtime.fetch),
|
|
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
|
|
208
|
+
}),
|
|
209
|
+
promise = _httpRequest.promise,
|
|
210
|
+
cancel = _httpRequest.cancel;
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
promise: promise.then(function (res) {
|
|
214
|
+
if (!Array.isArray(res)) {
|
|
215
|
+
return pairs.map(function () {
|
|
216
|
+
return res;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return res;
|
|
221
|
+
}),
|
|
222
|
+
cancel: cancel
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
var query = dataLoader(fetcher('query'), {
|
|
228
|
+
maxBatchSize: maxBatchSize
|
|
229
|
+
});
|
|
230
|
+
var mutation = dataLoader(fetcher('mutation'), {
|
|
231
|
+
maxBatchSize: maxBatchSize
|
|
232
|
+
});
|
|
233
|
+
var subscription = dataLoader(fetcher('subscription'), {
|
|
234
|
+
maxBatchSize: maxBatchSize
|
|
235
|
+
});
|
|
236
|
+
var loaders = {
|
|
237
|
+
query: query,
|
|
238
|
+
subscription: subscription,
|
|
239
|
+
mutation: mutation
|
|
240
|
+
};
|
|
241
|
+
return function (_ref2) {
|
|
242
|
+
var op = _ref2.op,
|
|
243
|
+
prev = _ref2.prev,
|
|
244
|
+
onDestroy = _ref2.onDestroy;
|
|
245
|
+
var loader = loaders[op.type];
|
|
246
|
+
|
|
247
|
+
var _loader$load = loader.load(op),
|
|
248
|
+
promise = _loader$load.promise,
|
|
249
|
+
cancel = _loader$load.cancel;
|
|
250
|
+
|
|
251
|
+
var isDone = false;
|
|
252
|
+
|
|
253
|
+
var prevOnce = function prevOnce(result) {
|
|
254
|
+
if (isDone) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
isDone = true;
|
|
259
|
+
prev(result);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
onDestroy(function () {
|
|
263
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
|
|
264
|
+
isDone: true
|
|
265
|
+
}));
|
|
266
|
+
cancel();
|
|
267
|
+
});
|
|
268
|
+
promise.then(function (envelope) {
|
|
269
|
+
prevOnce(transformRPCResponse.transformRPCResponse({
|
|
270
|
+
envelope: envelope,
|
|
271
|
+
runtime: runtime
|
|
272
|
+
}));
|
|
273
|
+
}).catch(function (cause) {
|
|
274
|
+
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
exports.httpBatchLink = httpBatchLink;
|
|
@@ -0,0 +1,272 @@
|
|
|
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
|
+
import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
|
|
7
|
+
import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest, g as getFetch, a as getAbortController } from '../../../dist/transformRPCResponse-648d57f1.esm.js';
|
|
8
|
+
import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
|
|
9
|
+
import '@babel/runtime/helpers/assertThisInitialized';
|
|
10
|
+
import '@babel/runtime/helpers/inherits';
|
|
11
|
+
import '@babel/runtime/helpers/createSuper';
|
|
12
|
+
import '@babel/runtime/helpers/wrapNativeSuper';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
16
|
+
* Less configuration, no caching, and allows you to cancel requests
|
|
17
|
+
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
18
|
+
*/
|
|
19
|
+
function dataLoader(fetchMany, opts) {
|
|
20
|
+
var batch = null;
|
|
21
|
+
var dispatchTimer = null;
|
|
22
|
+
|
|
23
|
+
var destroyTimerAndBatch = function destroyTimerAndBatch() {
|
|
24
|
+
clearTimeout(dispatchTimer);
|
|
25
|
+
dispatchTimer = null;
|
|
26
|
+
batch = null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function dispatch() {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
31
|
+
var batchCopy = batch;
|
|
32
|
+
destroyTimerAndBatch();
|
|
33
|
+
|
|
34
|
+
var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
|
|
35
|
+
return v.key;
|
|
36
|
+
})),
|
|
37
|
+
promise = _fetchMany.promise,
|
|
38
|
+
cancel = _fetchMany.cancel;
|
|
39
|
+
|
|
40
|
+
batchCopy.cancel = cancel;
|
|
41
|
+
promise.then(function (result) {
|
|
42
|
+
for (var i = 0; i < result.length; i++) {
|
|
43
|
+
var _value = result[i];
|
|
44
|
+
batchCopy.items[i].resolve(_value);
|
|
45
|
+
}
|
|
46
|
+
}).catch(function (cause) {
|
|
47
|
+
var _iterator = _createForOfIteratorHelper(batchCopy.items),
|
|
48
|
+
_step;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
52
|
+
var item = _step.value;
|
|
53
|
+
item.reject(cause);
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
_iterator.e(err);
|
|
57
|
+
} finally {
|
|
58
|
+
_iterator.f();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function load(key) {
|
|
64
|
+
var batchItem = {
|
|
65
|
+
cancelled: false,
|
|
66
|
+
key: key
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (!batch) {
|
|
70
|
+
batch = {
|
|
71
|
+
items: [],
|
|
72
|
+
cancel: function cancel() {
|
|
73
|
+
destroyTimerAndBatch();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var thisBatch = batch;
|
|
79
|
+
var promise = new Promise(function (resolve, reject) {
|
|
80
|
+
var item = batchItem;
|
|
81
|
+
item.reject = reject;
|
|
82
|
+
item.resolve = resolve;
|
|
83
|
+
thisBatch.items.push(item);
|
|
84
|
+
|
|
85
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
86
|
+
dispatch();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (!dispatchTimer) {
|
|
92
|
+
dispatchTimer = setTimeout(dispatch);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var cancel = function cancel() {
|
|
96
|
+
batchItem.cancelled = true;
|
|
97
|
+
|
|
98
|
+
if (thisBatch.items.some(function (item) {
|
|
99
|
+
return !item.cancelled;
|
|
100
|
+
})) {
|
|
101
|
+
// there are still things that can be resolved
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
thisBatch.cancel();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
promise: promise,
|
|
110
|
+
cancel: cancel
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
load: load
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function httpBatchLink(opts) {
|
|
120
|
+
var url = opts.url,
|
|
121
|
+
maxBatchSize = opts.maxBatchSize; // initialized config
|
|
122
|
+
|
|
123
|
+
return function (runtime) {
|
|
124
|
+
// 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
|
+
var fetcher = function fetcher(type) {
|
|
177
|
+
return function (pairs) {
|
|
178
|
+
var _opts$fetch, _opts$AbortController;
|
|
179
|
+
|
|
180
|
+
var path = pairs.map(function (op) {
|
|
181
|
+
return op.path;
|
|
182
|
+
}).join(',');
|
|
183
|
+
var inputs = pairs.map(function (op) {
|
|
184
|
+
return op.input;
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
var _httpRequest = httpRequest({
|
|
188
|
+
url: url,
|
|
189
|
+
inputs: inputs,
|
|
190
|
+
path: path,
|
|
191
|
+
type: type,
|
|
192
|
+
fetch: getFetch((_opts$fetch = opts.fetch) !== null && _opts$fetch !== void 0 ? _opts$fetch : runtime.fetch),
|
|
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
|
|
200
|
+
}),
|
|
201
|
+
promise = _httpRequest.promise,
|
|
202
|
+
cancel = _httpRequest.cancel;
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
promise: promise.then(function (res) {
|
|
206
|
+
if (!Array.isArray(res)) {
|
|
207
|
+
return pairs.map(function () {
|
|
208
|
+
return res;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return res;
|
|
213
|
+
}),
|
|
214
|
+
cancel: cancel
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
var query = dataLoader(fetcher('query'), {
|
|
220
|
+
maxBatchSize: maxBatchSize
|
|
221
|
+
});
|
|
222
|
+
var mutation = dataLoader(fetcher('mutation'), {
|
|
223
|
+
maxBatchSize: maxBatchSize
|
|
224
|
+
});
|
|
225
|
+
var subscription = dataLoader(fetcher('subscription'), {
|
|
226
|
+
maxBatchSize: maxBatchSize
|
|
227
|
+
});
|
|
228
|
+
var loaders = {
|
|
229
|
+
query: query,
|
|
230
|
+
subscription: subscription,
|
|
231
|
+
mutation: mutation
|
|
232
|
+
};
|
|
233
|
+
return function (_ref2) {
|
|
234
|
+
var op = _ref2.op,
|
|
235
|
+
prev = _ref2.prev,
|
|
236
|
+
onDestroy = _ref2.onDestroy;
|
|
237
|
+
var loader = loaders[op.type];
|
|
238
|
+
|
|
239
|
+
var _loader$load = loader.load(op),
|
|
240
|
+
promise = _loader$load.promise,
|
|
241
|
+
cancel = _loader$load.cancel;
|
|
242
|
+
|
|
243
|
+
var isDone = false;
|
|
244
|
+
|
|
245
|
+
var prevOnce = function prevOnce(result) {
|
|
246
|
+
if (isDone) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
isDone = true;
|
|
251
|
+
prev(result);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
onDestroy(function () {
|
|
255
|
+
prevOnce(TRPCClientError.from(new TRPCAbortError(), {
|
|
256
|
+
isDone: true
|
|
257
|
+
}));
|
|
258
|
+
cancel();
|
|
259
|
+
});
|
|
260
|
+
promise.then(function (envelope) {
|
|
261
|
+
prevOnce(transformRPCResponse({
|
|
262
|
+
envelope: envelope,
|
|
263
|
+
runtime: runtime
|
|
264
|
+
}));
|
|
265
|
+
}).catch(function (cause) {
|
|
266
|
+
prevOnce(TRPCClientError.from(cause));
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export { httpBatchLink };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../../dist/declarations/src/links/httpLink";
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
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
|
+
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
|
+
require('@babel/runtime/helpers/assertThisInitialized');
|
|
14
|
+
require('@babel/runtime/helpers/inherits');
|
|
15
|
+
require('@babel/runtime/helpers/createSuper');
|
|
16
|
+
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
17
|
+
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
21
|
+
|
|
22
|
+
function httpLink(opts) {
|
|
23
|
+
var url = opts.url; // initialized config
|
|
24
|
+
|
|
25
|
+
return function (runtime) {
|
|
26
|
+
// initialized in app
|
|
27
|
+
var getHeaders = /*#__PURE__*/function () {
|
|
28
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(arg1) {
|
|
29
|
+
var val;
|
|
30
|
+
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
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;
|
|
84
|
+
var path = op.path,
|
|
85
|
+
input = op.input,
|
|
86
|
+
type = op.type;
|
|
87
|
+
|
|
88
|
+
var _httpRequest = transformRPCResponse.httpRequest({
|
|
89
|
+
type: type,
|
|
90
|
+
input: input,
|
|
91
|
+
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
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
promise = _httpRequest.promise,
|
|
103
|
+
cancel = _httpRequest.cancel;
|
|
104
|
+
|
|
105
|
+
var isDone = false;
|
|
106
|
+
|
|
107
|
+
var prevOnce = function prevOnce(result) {
|
|
108
|
+
if (isDone) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
isDone = true;
|
|
113
|
+
prev(result);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
onDestroy(function () {
|
|
117
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
|
|
118
|
+
isDone: true
|
|
119
|
+
}));
|
|
120
|
+
cancel();
|
|
121
|
+
});
|
|
122
|
+
promise.then(function (envelope) {
|
|
123
|
+
prevOnce(transformRPCResponse.transformRPCResponse({
|
|
124
|
+
envelope: envelope,
|
|
125
|
+
runtime: runtime
|
|
126
|
+
}));
|
|
127
|
+
}).catch(function (cause) {
|
|
128
|
+
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
exports.httpLink = httpLink;
|