@trpc/client 10.0.0-alpha.15 → 10.0.0-alpha.18
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1081 -18
- package/dist/index.mjs +1064 -13
- package/dist/internals/TRPCClient.d.ts +3 -3
- package/dist/internals/TRPCClient.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts +1 -1
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpLink.d.ts +1 -1
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/index.d.ts +11 -0
- package/dist/links/index.d.ts.map +1 -0
- package/dist/links/{httpUtils.d.ts → internals/httpUtils.d.ts} +1 -1
- package/dist/links/internals/httpUtils.d.ts.map +1 -0
- package/dist/links/transformerLink.d.ts.map +1 -1
- package/dist/links/types.d.ts +1 -1
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts +1 -1
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/observable/index.d.ts +4 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/{rx/operators → observable}/index.js +3 -3
- package/dist/{rx/operators → observable}/index.mjs +1 -2
- package/dist/{rx → observable}/index.ts.js +0 -0
- package/dist/{rx/util → observable/internals}/identity.d.ts +0 -0
- package/dist/observable/internals/identity.d.ts.map +1 -0
- package/dist/{rx/util → observable/internals}/observableToPromise.d.ts +0 -0
- package/dist/observable/internals/observableToPromise.d.ts.map +1 -0
- package/dist/{rx/util → observable/internals}/pipe.d.ts +0 -0
- package/dist/observable/internals/pipe.d.ts.map +1 -0
- package/dist/{rx → observable}/observable.d.ts +0 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/{rx → observable}/operators/index.d.ts +0 -0
- package/dist/observable/operators/index.d.ts.map +1 -0
- package/dist/{rx → observable}/operators/map.d.ts +0 -0
- package/dist/observable/operators/map.d.ts.map +1 -0
- package/dist/{rx → observable}/operators/share.d.ts +0 -0
- package/dist/observable/operators/share.d.ts.map +1 -0
- package/dist/{rx → observable}/operators/tap.d.ts +0 -0
- package/dist/observable/operators/tap.d.ts.map +1 -0
- package/dist/{rx → observable}/types.d.ts +0 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/{share-671b63fa.mjs → tap-4bc60fb0.mjs} +131 -1
- package/dist/{share-4d79dc49.js → tap-fcd41ae6.js} +132 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +1 -11
- package/{dist/links/httpBatchLink.js → links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js} +63 -44
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +6 -15
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +214 -0
- package/{dist/links/httpBatchLink.mjs → links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js} +62 -43
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +1 -11
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +67 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +6 -15
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +67 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +63 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +1 -11
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +89 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +6 -15
- 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 -11
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +19 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +6 -15
- 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 -11
- package/{dist/links/wsLink.js → links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js} +92 -82
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +6 -15
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +395 -0
- package/{dist/links/wsLink.mjs → links/wsLink/dist/trpc-client-links-wsLink.esm.js} +87 -67
- package/package.json +8 -43
- package/src/index.ts +1 -1
- package/src/internals/TRPCClient.ts +8 -11
- package/src/links/dedupeLink.test.ts +1 -1
- package/src/links/dedupeLink.ts +5 -5
- package/src/links/httpBatchLink.ts +6 -2
- package/src/links/httpLink.ts +2 -2
- package/src/links/index.ts +10 -0
- package/src/links/internals/createChain.test.ts +5 -5
- package/src/links/internals/createChain.ts +3 -3
- package/src/links/{httpUtils.ts → internals/httpUtils.ts} +1 -1
- package/src/links/loggerLink.ts +2 -2
- package/src/links/retryLink.ts +2 -2
- package/src/links/splitLink.test.ts +3 -3
- package/src/links/splitLink.ts +1 -1
- package/src/links/transformerLink.ts +9 -5
- package/src/links/types.ts +1 -1
- package/src/links/wsLink.ts +1 -2
- package/src/{rx → observable}/index.ts +1 -0
- package/src/{rx/util → observable/internals}/identity.ts +0 -0
- package/src/{rx/util → observable/internals}/observableToPromise.ts +0 -0
- package/src/{rx/util → observable/internals}/pipe.ts +0 -0
- package/src/{rx → observable}/observable.test.ts +21 -1
- package/src/{rx → observable}/observable.ts +1 -1
- package/src/{rx → observable}/operators/index.ts +0 -0
- package/src/{rx → observable}/operators/map.test.ts +0 -0
- package/src/{rx → observable}/operators/map.ts +0 -0
- package/src/{rx → observable}/operators/share.test.ts +0 -0
- package/src/{rx → observable}/operators/share.ts +0 -0
- package/src/{rx → observable}/operators/tap.ts +0 -0
- package/src/{rx → observable}/types.ts +0 -0
- package/dist/TRPCClientError-17b117e1.mjs +0 -81
- package/dist/TRPCClientError-ec6bd2ca.js +0 -94
- package/dist/createChain-389cc116.mjs +0 -25
- package/dist/createChain-864dbb30.js +0 -27
- package/dist/httpUtils-1f9e4e3c.js +0 -97
- package/dist/httpUtils-c09d7b79.mjs +0 -91
- package/dist/links/httpBatchLink.ts.js +0 -1
- package/dist/links/httpLink.js +0 -44
- package/dist/links/httpLink.mjs +0 -40
- package/dist/links/httpLink.ts.js +0 -1
- package/dist/links/httpUtils.d.ts.map +0 -1
- package/dist/links/loggerLink.js +0 -108
- package/dist/links/loggerLink.mjs +0 -99
- package/dist/links/loggerLink.ts.js +0 -1
- package/dist/links/splitLink.js +0 -32
- package/dist/links/splitLink.mjs +0 -28
- package/dist/links/splitLink.ts.js +0 -1
- package/dist/links/transformerLink.js +0 -75
- package/dist/links/transformerLink.mjs +0 -67
- package/dist/links/transformerLink.ts.js +0 -1
- package/dist/links/wsLink.ts.js +0 -1
- package/dist/observable-7e66cb56.mjs +0 -102
- package/dist/observable-85669100.js +0 -104
- package/dist/rx/index.d.ts +0 -3
- package/dist/rx/index.d.ts.map +0 -1
- package/dist/rx/index.js +0 -9
- package/dist/rx/index.mjs +0 -1
- package/dist/rx/observable.d.ts.map +0 -1
- package/dist/rx/operators/index.d.ts.map +0 -1
- package/dist/rx/operators/index.ts.js +0 -1
- package/dist/rx/operators/map.d.ts.map +0 -1
- package/dist/rx/operators/share.d.ts.map +0 -1
- package/dist/rx/operators/tap.d.ts.map +0 -1
- package/dist/rx/types.d.ts.map +0 -1
- package/dist/rx/util/identity.d.ts.map +0 -1
- package/dist/rx/util/observableToPromise.d.ts.map +0 -1
- package/dist/rx/util/pipe.d.ts.map +0 -1
- package/dist/tap-538fa07f.mjs +0 -30
- package/dist/tap-799a2d33.js +0 -32
- package/links/httpBatchLink/index.d.ts +0 -1
- package/links/httpBatchLink/index.js +0 -1
- package/links/httpLink/index.d.ts +0 -1
- package/links/httpLink/index.js +0 -1
- package/links/loggerLink/index.d.ts +0 -1
- package/links/loggerLink/index.js +0 -1
- package/links/splitLink/index.d.ts +0 -1
- package/links/splitLink/index.js +0 -1
- package/links/transformerLink/index.d.ts +0 -1
- package/links/transformerLink/index.js +0 -1
- package/links/wsLink/index.d.ts +0 -1
- package/links/wsLink/index.js +0 -1
- package/rx/index.d.ts +0 -1
- package/rx/index.js +0 -1
- package/rx/operators/index.d.ts +0 -1
- package/rx/operators/index.js +0 -1
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
require('
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
6
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-57e80136.cjs.dev.js');
|
|
7
|
+
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
8
|
+
require('@babel/runtime/helpers/createClass');
|
|
9
|
+
require('@babel/runtime/helpers/classCallCheck');
|
|
10
|
+
require('@babel/runtime/helpers/assertThisInitialized');
|
|
11
|
+
require('@babel/runtime/helpers/inherits');
|
|
12
|
+
require('@babel/runtime/helpers/createSuper');
|
|
13
|
+
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
14
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
@@ -118,9 +119,11 @@ function dataLoader(fetchMany, opts) {
|
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
function httpBatchLink(opts) {
|
|
121
|
-
var url = opts.url
|
|
122
|
+
var url = opts.url,
|
|
123
|
+
maxBatchSize = opts.maxBatchSize; // initialized config
|
|
122
124
|
|
|
123
125
|
return function (runtime) {
|
|
126
|
+
// initialized in app
|
|
124
127
|
var fetcher = function fetcher(type) {
|
|
125
128
|
return function (keyInputPairs) {
|
|
126
129
|
var path = keyInputPairs.map(function (op) {
|
|
@@ -130,7 +133,7 @@ function httpBatchLink(opts) {
|
|
|
130
133
|
return op.input;
|
|
131
134
|
});
|
|
132
135
|
|
|
133
|
-
var _httpRequest =
|
|
136
|
+
var _httpRequest = transformRPCResponse.httpRequest({
|
|
134
137
|
url: url,
|
|
135
138
|
inputs: inputs,
|
|
136
139
|
path: path,
|
|
@@ -142,51 +145,67 @@ function httpBatchLink(opts) {
|
|
|
142
145
|
|
|
143
146
|
return {
|
|
144
147
|
promise: promise.then(function (res) {
|
|
145
|
-
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
153
|
-
});
|
|
154
|
-
return result;
|
|
148
|
+
if (!Array.isArray(res)) {
|
|
149
|
+
return keyInputPairs.map(function () {
|
|
150
|
+
return res;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return res;
|
|
155
155
|
}),
|
|
156
156
|
cancel: cancel
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
-
var query = dataLoader(fetcher('query'),
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
var query = dataLoader(fetcher('query'), {
|
|
162
|
+
maxBatchSize: maxBatchSize
|
|
163
|
+
});
|
|
164
|
+
var mutation = dataLoader(fetcher('mutation'), {
|
|
165
|
+
maxBatchSize: maxBatchSize
|
|
166
|
+
});
|
|
167
|
+
var subscription = dataLoader(fetcher('subscription'), {
|
|
168
|
+
maxBatchSize: maxBatchSize
|
|
169
|
+
});
|
|
164
170
|
var loaders = {
|
|
165
171
|
query: query,
|
|
166
172
|
subscription: subscription,
|
|
167
173
|
mutation: mutation
|
|
168
174
|
};
|
|
169
175
|
return function (_ref) {
|
|
170
|
-
var op = _ref.op
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
var op = _ref.op,
|
|
177
|
+
prev = _ref.prev,
|
|
178
|
+
onDestroy = _ref.onDestroy;
|
|
179
|
+
var loader = loaders[op.type];
|
|
180
|
+
|
|
181
|
+
var _loader$load = loader.load(op),
|
|
182
|
+
promise = _loader$load.promise,
|
|
183
|
+
cancel = _loader$load.cancel;
|
|
184
|
+
|
|
185
|
+
var isDone = false;
|
|
186
|
+
|
|
187
|
+
var prevOnce = function prevOnce(result) {
|
|
188
|
+
if (isDone) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
isDone = true;
|
|
193
|
+
prev(result);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
onDestroy(function () {
|
|
197
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
|
|
198
|
+
isDone: true
|
|
199
|
+
}));
|
|
200
|
+
cancel();
|
|
201
|
+
});
|
|
202
|
+
promise.then(function (envelope) {
|
|
203
|
+
prevOnce(transformRPCResponse.transformRPCResponse({
|
|
204
|
+
envelope: envelope,
|
|
205
|
+
runtime: runtime
|
|
206
|
+
}));
|
|
207
|
+
}).catch(function (cause) {
|
|
208
|
+
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
190
209
|
});
|
|
191
210
|
};
|
|
192
211
|
};
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unregister();
|
|
3
|
+
if (process.env.NODE_ENV === "production") {
|
|
4
|
+
module.exports = require("./trpc-client-links-httpBatchLink.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./trpc-client-links-httpBatchLink.cjs.dev.js");
|
|
7
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
6
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-739c13d0.cjs.prod.js');
|
|
7
|
+
var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
|
|
8
|
+
require('@babel/runtime/helpers/createClass');
|
|
9
|
+
require('@babel/runtime/helpers/classCallCheck');
|
|
10
|
+
require('@babel/runtime/helpers/assertThisInitialized');
|
|
11
|
+
require('@babel/runtime/helpers/inherits');
|
|
12
|
+
require('@babel/runtime/helpers/createSuper');
|
|
13
|
+
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
14
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
18
|
+
* Less configuration, no caching, and allows you to cancel requests
|
|
19
|
+
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
20
|
+
*/
|
|
21
|
+
function dataLoader(fetchMany, opts) {
|
|
22
|
+
var batch = null;
|
|
23
|
+
var dispatchTimer = null;
|
|
24
|
+
|
|
25
|
+
var destroyTimerAndBatch = function destroyTimerAndBatch() {
|
|
26
|
+
clearTimeout(dispatchTimer);
|
|
27
|
+
dispatchTimer = null;
|
|
28
|
+
batch = null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function dispatch() {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
+
var batchCopy = batch;
|
|
34
|
+
destroyTimerAndBatch();
|
|
35
|
+
|
|
36
|
+
var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
|
|
37
|
+
return v.key;
|
|
38
|
+
})),
|
|
39
|
+
promise = _fetchMany.promise,
|
|
40
|
+
cancel = _fetchMany.cancel;
|
|
41
|
+
|
|
42
|
+
batchCopy.cancel = cancel;
|
|
43
|
+
promise.then(function (result) {
|
|
44
|
+
for (var i = 0; i < result.length; i++) {
|
|
45
|
+
var _value = result[i];
|
|
46
|
+
batchCopy.items[i].resolve(_value);
|
|
47
|
+
}
|
|
48
|
+
}).catch(function (cause) {
|
|
49
|
+
var _iterator = _createForOfIteratorHelper(batchCopy.items),
|
|
50
|
+
_step;
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
+
var item = _step.value;
|
|
55
|
+
item.reject(cause);
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
_iterator.e(err);
|
|
59
|
+
} finally {
|
|
60
|
+
_iterator.f();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function load(key) {
|
|
66
|
+
var batchItem = {
|
|
67
|
+
cancelled: false,
|
|
68
|
+
key: key
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (!batch) {
|
|
72
|
+
batch = {
|
|
73
|
+
items: [],
|
|
74
|
+
cancel: function cancel() {
|
|
75
|
+
destroyTimerAndBatch();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var thisBatch = batch;
|
|
81
|
+
var promise = new Promise(function (resolve, reject) {
|
|
82
|
+
var item = batchItem;
|
|
83
|
+
item.reject = reject;
|
|
84
|
+
item.resolve = resolve;
|
|
85
|
+
thisBatch.items.push(item);
|
|
86
|
+
|
|
87
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
88
|
+
dispatch();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (!dispatchTimer) {
|
|
94
|
+
dispatchTimer = setTimeout(dispatch);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var cancel = function cancel() {
|
|
98
|
+
batchItem.cancelled = true;
|
|
99
|
+
|
|
100
|
+
if (thisBatch.items.some(function (item) {
|
|
101
|
+
return !item.cancelled;
|
|
102
|
+
})) {
|
|
103
|
+
// there are still things that can be resolved
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
thisBatch.cancel();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
promise: promise,
|
|
112
|
+
cancel: cancel
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
load: load
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function httpBatchLink(opts) {
|
|
122
|
+
var url = opts.url,
|
|
123
|
+
maxBatchSize = opts.maxBatchSize; // initialized config
|
|
124
|
+
|
|
125
|
+
return function (runtime) {
|
|
126
|
+
// initialized in app
|
|
127
|
+
var fetcher = function fetcher(type) {
|
|
128
|
+
return function (keyInputPairs) {
|
|
129
|
+
var path = keyInputPairs.map(function (op) {
|
|
130
|
+
return op.path;
|
|
131
|
+
}).join(',');
|
|
132
|
+
var inputs = keyInputPairs.map(function (op) {
|
|
133
|
+
return op.input;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
var _httpRequest = transformRPCResponse.httpRequest({
|
|
137
|
+
url: url,
|
|
138
|
+
inputs: inputs,
|
|
139
|
+
path: path,
|
|
140
|
+
runtime: runtime,
|
|
141
|
+
type: type
|
|
142
|
+
}),
|
|
143
|
+
promise = _httpRequest.promise,
|
|
144
|
+
cancel = _httpRequest.cancel;
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
promise: promise.then(function (res) {
|
|
148
|
+
if (!Array.isArray(res)) {
|
|
149
|
+
return keyInputPairs.map(function () {
|
|
150
|
+
return res;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return res;
|
|
155
|
+
}),
|
|
156
|
+
cancel: cancel
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
var query = dataLoader(fetcher('query'), {
|
|
162
|
+
maxBatchSize: maxBatchSize
|
|
163
|
+
});
|
|
164
|
+
var mutation = dataLoader(fetcher('mutation'), {
|
|
165
|
+
maxBatchSize: maxBatchSize
|
|
166
|
+
});
|
|
167
|
+
var subscription = dataLoader(fetcher('subscription'), {
|
|
168
|
+
maxBatchSize: maxBatchSize
|
|
169
|
+
});
|
|
170
|
+
var loaders = {
|
|
171
|
+
query: query,
|
|
172
|
+
subscription: subscription,
|
|
173
|
+
mutation: mutation
|
|
174
|
+
};
|
|
175
|
+
return function (_ref) {
|
|
176
|
+
var op = _ref.op,
|
|
177
|
+
prev = _ref.prev,
|
|
178
|
+
onDestroy = _ref.onDestroy;
|
|
179
|
+
var loader = loaders[op.type];
|
|
180
|
+
|
|
181
|
+
var _loader$load = loader.load(op),
|
|
182
|
+
promise = _loader$load.promise,
|
|
183
|
+
cancel = _loader$load.cancel;
|
|
184
|
+
|
|
185
|
+
var isDone = false;
|
|
186
|
+
|
|
187
|
+
var prevOnce = function prevOnce(result) {
|
|
188
|
+
if (isDone) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
isDone = true;
|
|
193
|
+
prev(result);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
onDestroy(function () {
|
|
197
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
|
|
198
|
+
isDone: true
|
|
199
|
+
}));
|
|
200
|
+
cancel();
|
|
201
|
+
});
|
|
202
|
+
promise.then(function (envelope) {
|
|
203
|
+
prevOnce(transformRPCResponse.transformRPCResponse({
|
|
204
|
+
envelope: envelope,
|
|
205
|
+
runtime: runtime
|
|
206
|
+
}));
|
|
207
|
+
}).catch(function (cause) {
|
|
208
|
+
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
exports.httpBatchLink = httpBatchLink;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { h as httpRequest } from '
|
|
3
|
-
import '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
|
|
2
|
+
import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest } from '../../../dist/transformRPCResponse-f7f8b0e1.esm.js';
|
|
3
|
+
import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
|
|
4
|
+
import '@babel/runtime/helpers/createClass';
|
|
5
|
+
import '@babel/runtime/helpers/classCallCheck';
|
|
6
|
+
import '@babel/runtime/helpers/assertThisInitialized';
|
|
7
|
+
import '@babel/runtime/helpers/inherits';
|
|
8
|
+
import '@babel/runtime/helpers/createSuper';
|
|
9
|
+
import '@babel/runtime/helpers/wrapNativeSuper';
|
|
10
|
+
import '@babel/runtime/helpers/objectSpread2';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
@@ -114,9 +115,11 @@ function dataLoader(fetchMany, opts) {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
function httpBatchLink(opts) {
|
|
117
|
-
var url = opts.url
|
|
118
|
+
var url = opts.url,
|
|
119
|
+
maxBatchSize = opts.maxBatchSize; // initialized config
|
|
118
120
|
|
|
119
121
|
return function (runtime) {
|
|
122
|
+
// initialized in app
|
|
120
123
|
var fetcher = function fetcher(type) {
|
|
121
124
|
return function (keyInputPairs) {
|
|
122
125
|
var path = keyInputPairs.map(function (op) {
|
|
@@ -138,51 +141,67 @@ function httpBatchLink(opts) {
|
|
|
138
141
|
|
|
139
142
|
return {
|
|
140
143
|
promise: promise.then(function (res) {
|
|
141
|
-
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
return result;
|
|
144
|
+
if (!Array.isArray(res)) {
|
|
145
|
+
return keyInputPairs.map(function () {
|
|
146
|
+
return res;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return res;
|
|
151
151
|
}),
|
|
152
152
|
cancel: cancel
|
|
153
153
|
};
|
|
154
154
|
};
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
-
var query = dataLoader(fetcher('query'),
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
var query = dataLoader(fetcher('query'), {
|
|
158
|
+
maxBatchSize: maxBatchSize
|
|
159
|
+
});
|
|
160
|
+
var mutation = dataLoader(fetcher('mutation'), {
|
|
161
|
+
maxBatchSize: maxBatchSize
|
|
162
|
+
});
|
|
163
|
+
var subscription = dataLoader(fetcher('subscription'), {
|
|
164
|
+
maxBatchSize: maxBatchSize
|
|
165
|
+
});
|
|
160
166
|
var loaders = {
|
|
161
167
|
query: query,
|
|
162
168
|
subscription: subscription,
|
|
163
169
|
mutation: mutation
|
|
164
170
|
};
|
|
165
171
|
return function (_ref) {
|
|
166
|
-
var op = _ref.op
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
172
|
+
var op = _ref.op,
|
|
173
|
+
prev = _ref.prev,
|
|
174
|
+
onDestroy = _ref.onDestroy;
|
|
175
|
+
var loader = loaders[op.type];
|
|
176
|
+
|
|
177
|
+
var _loader$load = loader.load(op),
|
|
178
|
+
promise = _loader$load.promise,
|
|
179
|
+
cancel = _loader$load.cancel;
|
|
180
|
+
|
|
181
|
+
var isDone = false;
|
|
182
|
+
|
|
183
|
+
var prevOnce = function prevOnce(result) {
|
|
184
|
+
if (isDone) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
isDone = true;
|
|
189
|
+
prev(result);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
onDestroy(function () {
|
|
193
|
+
prevOnce(TRPCClientError.from(new TRPCAbortError(), {
|
|
194
|
+
isDone: true
|
|
195
|
+
}));
|
|
196
|
+
cancel();
|
|
197
|
+
});
|
|
198
|
+
promise.then(function (envelope) {
|
|
199
|
+
prevOnce(transformRPCResponse({
|
|
200
|
+
envelope: envelope,
|
|
201
|
+
runtime: runtime
|
|
202
|
+
}));
|
|
203
|
+
}).catch(function (cause) {
|
|
204
|
+
prevOnce(TRPCClientError.from(cause));
|
|
186
205
|
});
|
|
187
206
|
};
|
|
188
207
|
};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
-
|
|
4
|
-
// curious why you need to?
|
|
5
|
-
// this file exists so that you can import from the entrypoint normally
|
|
6
|
-
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
-
// which means we need to re-export all of the modules from your source file
|
|
8
|
-
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
-
// to check for a default export and re-export it if it exists
|
|
10
|
-
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
-
export * from "../../../src/links/httpLink";
|
|
1
|
+
export * from "../../../dist/declarations/src/links/httpLink";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
6
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-57e80136.cjs.dev.js');
|
|
7
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
8
|
+
require('@babel/runtime/helpers/classCallCheck');
|
|
9
|
+
require('@babel/runtime/helpers/createClass');
|
|
10
|
+
require('@babel/runtime/helpers/assertThisInitialized');
|
|
11
|
+
require('@babel/runtime/helpers/inherits');
|
|
12
|
+
require('@babel/runtime/helpers/createSuper');
|
|
13
|
+
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
14
|
+
|
|
15
|
+
function httpLink(opts) {
|
|
16
|
+
var url = opts.url; // initialized config
|
|
17
|
+
|
|
18
|
+
return function (runtime) {
|
|
19
|
+
// initialized in app
|
|
20
|
+
return function (_ref) {
|
|
21
|
+
var op = _ref.op,
|
|
22
|
+
prev = _ref.prev,
|
|
23
|
+
onDestroy = _ref.onDestroy;
|
|
24
|
+
var path = op.path,
|
|
25
|
+
input = op.input,
|
|
26
|
+
type = op.type;
|
|
27
|
+
|
|
28
|
+
var _httpRequest = transformRPCResponse.httpRequest({
|
|
29
|
+
runtime: runtime,
|
|
30
|
+
type: type,
|
|
31
|
+
input: input,
|
|
32
|
+
url: url,
|
|
33
|
+
path: path
|
|
34
|
+
}),
|
|
35
|
+
promise = _httpRequest.promise,
|
|
36
|
+
cancel = _httpRequest.cancel;
|
|
37
|
+
|
|
38
|
+
var isDone = false;
|
|
39
|
+
|
|
40
|
+
var prevOnce = function prevOnce(result) {
|
|
41
|
+
if (isDone) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
isDone = true;
|
|
46
|
+
prev(result);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
onDestroy(function () {
|
|
50
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
|
|
51
|
+
isDone: true
|
|
52
|
+
}));
|
|
53
|
+
cancel();
|
|
54
|
+
});
|
|
55
|
+
promise.then(function (envelope) {
|
|
56
|
+
prevOnce(transformRPCResponse.transformRPCResponse({
|
|
57
|
+
envelope: envelope,
|
|
58
|
+
runtime: runtime
|
|
59
|
+
}));
|
|
60
|
+
}).catch(function (cause) {
|
|
61
|
+
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.httpLink = httpLink;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unregister();
|
|
3
|
+
if (process.env.NODE_ENV === "production") {
|
|
4
|
+
module.exports = require("./trpc-client-links-httpLink.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./trpc-client-links-httpLink.cjs.dev.js");
|
|
7
|
+
}
|