@trpc/client 10.14.0 → 10.15.0
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/package.json +4 -4
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +0 -1
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +0 -216
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +0 -7
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +0 -216
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +0 -212
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +0 -1
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +0 -67
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +0 -7
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +0 -67
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +0 -63
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +0 -1
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +0 -89
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +0 -7
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +0 -89
- package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +0 -85
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +0 -1
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +0 -19
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +0 -7
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +0 -19
- package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +0 -15
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +0 -1
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +0 -397
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +0 -7
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +0 -397
- package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +0 -392
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.15.0",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -69,11 +69,11 @@
|
|
|
69
69
|
"links"
|
|
70
70
|
],
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@trpc/server": "10.
|
|
72
|
+
"@trpc/server": "10.15.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@testing-library/dom": "^9.0.0",
|
|
76
|
-
"@trpc/server": "10.
|
|
76
|
+
"@trpc/server": "10.15.0",
|
|
77
77
|
"@types/isomorphic-fetch": "^0.0.36",
|
|
78
78
|
"@types/node": "^18.7.20",
|
|
79
79
|
"eslint": "^8.30.0",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"access": "public"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "47e6fc5cb80807d4b38f9841e04a1f3a3324831e"
|
|
92
92
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/declarations/src/links/httpBatchLink";
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var TRPCClientError = require('../../../dist/TRPCClientError-679c4492.cjs.dev.js');
|
|
6
|
-
var httpRequest = require('../../../dist/httpRequest-90b85a7e.cjs.dev.js');
|
|
7
|
-
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
8
|
-
require('@babel/runtime/helpers/objectSpread2');
|
|
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/createSuper');
|
|
14
|
-
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
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 dispatchImmediately = false;
|
|
82
|
-
var promise = new Promise(function (resolve, reject) {
|
|
83
|
-
var item = batchItem;
|
|
84
|
-
item.reject = reject;
|
|
85
|
-
item.resolve = resolve;
|
|
86
|
-
thisBatch.items.push(item);
|
|
87
|
-
|
|
88
|
-
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
89
|
-
dispatchImmediately = true;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
var cancel = function cancel() {
|
|
94
|
-
batchItem.cancelled = true;
|
|
95
|
-
|
|
96
|
-
if (thisBatch.items.some(function (item) {
|
|
97
|
-
return !item.cancelled;
|
|
98
|
-
})) {
|
|
99
|
-
// there are still things that can be resolved
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
thisBatch.cancel();
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
if (dispatchImmediately) {
|
|
107
|
-
dispatch();
|
|
108
|
-
} else if (!dispatchTimer) {
|
|
109
|
-
dispatchTimer = setTimeout(dispatch);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
promise: promise,
|
|
114
|
-
cancel: cancel
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
load: load
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function httpBatchLink(opts) {
|
|
124
|
-
var url = opts.url,
|
|
125
|
-
maxBatchSize = opts.maxBatchSize; // initialized config
|
|
126
|
-
|
|
127
|
-
return function (runtime) {
|
|
128
|
-
// initialized in app
|
|
129
|
-
var fetcher = function fetcher(type) {
|
|
130
|
-
return function (keyInputPairs) {
|
|
131
|
-
var path = keyInputPairs.map(function (op) {
|
|
132
|
-
return op.path;
|
|
133
|
-
}).join(',');
|
|
134
|
-
var inputs = keyInputPairs.map(function (op) {
|
|
135
|
-
return op.input;
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
var _httpRequest = httpRequest.httpRequest({
|
|
139
|
-
url: url,
|
|
140
|
-
inputs: inputs,
|
|
141
|
-
path: path,
|
|
142
|
-
runtime: runtime,
|
|
143
|
-
type: type
|
|
144
|
-
}),
|
|
145
|
-
promise = _httpRequest.promise,
|
|
146
|
-
cancel = _httpRequest.cancel;
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
promise: promise.then(function (res) {
|
|
150
|
-
if (!Array.isArray(res)) {
|
|
151
|
-
return keyInputPairs.map(function () {
|
|
152
|
-
return res;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return res;
|
|
157
|
-
}),
|
|
158
|
-
cancel: cancel
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
var query = dataLoader(fetcher('query'), {
|
|
164
|
-
maxBatchSize: maxBatchSize
|
|
165
|
-
});
|
|
166
|
-
var mutation = dataLoader(fetcher('mutation'), {
|
|
167
|
-
maxBatchSize: maxBatchSize
|
|
168
|
-
});
|
|
169
|
-
var subscription = dataLoader(fetcher('subscription'), {
|
|
170
|
-
maxBatchSize: maxBatchSize
|
|
171
|
-
});
|
|
172
|
-
var loaders = {
|
|
173
|
-
query: query,
|
|
174
|
-
subscription: subscription,
|
|
175
|
-
mutation: mutation
|
|
176
|
-
};
|
|
177
|
-
return function (_ref) {
|
|
178
|
-
var op = _ref.op,
|
|
179
|
-
prev = _ref.prev,
|
|
180
|
-
onDestroy = _ref.onDestroy;
|
|
181
|
-
var loader = loaders[op.type];
|
|
182
|
-
|
|
183
|
-
var _loader$load = loader.load(op),
|
|
184
|
-
promise = _loader$load.promise,
|
|
185
|
-
cancel = _loader$load.cancel;
|
|
186
|
-
|
|
187
|
-
var isDone = false;
|
|
188
|
-
|
|
189
|
-
var prevOnce = function prevOnce(result) {
|
|
190
|
-
if (isDone) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
isDone = true;
|
|
195
|
-
prev(result);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
onDestroy(function () {
|
|
199
|
-
prevOnce(TRPCClientError.TRPCClientError.from(new httpRequest.TRPCAbortError(), {
|
|
200
|
-
isDone: true
|
|
201
|
-
}));
|
|
202
|
-
cancel();
|
|
203
|
-
});
|
|
204
|
-
promise.then(function (envelope) {
|
|
205
|
-
prevOnce(httpRequest.transformRPCResponse({
|
|
206
|
-
envelope: envelope,
|
|
207
|
-
runtime: runtime
|
|
208
|
-
}));
|
|
209
|
-
}).catch(function (cause) {
|
|
210
|
-
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
exports.httpBatchLink = httpBatchLink;
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var TRPCClientError = require('../../../dist/TRPCClientError-11a0a976.cjs.prod.js');
|
|
6
|
-
var httpRequest = require('../../../dist/httpRequest-01d5047c.cjs.prod.js');
|
|
7
|
-
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
8
|
-
require('@babel/runtime/helpers/objectSpread2');
|
|
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/createSuper');
|
|
14
|
-
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
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 dispatchImmediately = false;
|
|
82
|
-
var promise = new Promise(function (resolve, reject) {
|
|
83
|
-
var item = batchItem;
|
|
84
|
-
item.reject = reject;
|
|
85
|
-
item.resolve = resolve;
|
|
86
|
-
thisBatch.items.push(item);
|
|
87
|
-
|
|
88
|
-
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
89
|
-
dispatchImmediately = true;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
var cancel = function cancel() {
|
|
94
|
-
batchItem.cancelled = true;
|
|
95
|
-
|
|
96
|
-
if (thisBatch.items.some(function (item) {
|
|
97
|
-
return !item.cancelled;
|
|
98
|
-
})) {
|
|
99
|
-
// there are still things that can be resolved
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
thisBatch.cancel();
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
if (dispatchImmediately) {
|
|
107
|
-
dispatch();
|
|
108
|
-
} else if (!dispatchTimer) {
|
|
109
|
-
dispatchTimer = setTimeout(dispatch);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
promise: promise,
|
|
114
|
-
cancel: cancel
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
load: load
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function httpBatchLink(opts) {
|
|
124
|
-
var url = opts.url,
|
|
125
|
-
maxBatchSize = opts.maxBatchSize; // initialized config
|
|
126
|
-
|
|
127
|
-
return function (runtime) {
|
|
128
|
-
// initialized in app
|
|
129
|
-
var fetcher = function fetcher(type) {
|
|
130
|
-
return function (keyInputPairs) {
|
|
131
|
-
var path = keyInputPairs.map(function (op) {
|
|
132
|
-
return op.path;
|
|
133
|
-
}).join(',');
|
|
134
|
-
var inputs = keyInputPairs.map(function (op) {
|
|
135
|
-
return op.input;
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
var _httpRequest = httpRequest.httpRequest({
|
|
139
|
-
url: url,
|
|
140
|
-
inputs: inputs,
|
|
141
|
-
path: path,
|
|
142
|
-
runtime: runtime,
|
|
143
|
-
type: type
|
|
144
|
-
}),
|
|
145
|
-
promise = _httpRequest.promise,
|
|
146
|
-
cancel = _httpRequest.cancel;
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
promise: promise.then(function (res) {
|
|
150
|
-
if (!Array.isArray(res)) {
|
|
151
|
-
return keyInputPairs.map(function () {
|
|
152
|
-
return res;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return res;
|
|
157
|
-
}),
|
|
158
|
-
cancel: cancel
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
var query = dataLoader(fetcher('query'), {
|
|
164
|
-
maxBatchSize: maxBatchSize
|
|
165
|
-
});
|
|
166
|
-
var mutation = dataLoader(fetcher('mutation'), {
|
|
167
|
-
maxBatchSize: maxBatchSize
|
|
168
|
-
});
|
|
169
|
-
var subscription = dataLoader(fetcher('subscription'), {
|
|
170
|
-
maxBatchSize: maxBatchSize
|
|
171
|
-
});
|
|
172
|
-
var loaders = {
|
|
173
|
-
query: query,
|
|
174
|
-
subscription: subscription,
|
|
175
|
-
mutation: mutation
|
|
176
|
-
};
|
|
177
|
-
return function (_ref) {
|
|
178
|
-
var op = _ref.op,
|
|
179
|
-
prev = _ref.prev,
|
|
180
|
-
onDestroy = _ref.onDestroy;
|
|
181
|
-
var loader = loaders[op.type];
|
|
182
|
-
|
|
183
|
-
var _loader$load = loader.load(op),
|
|
184
|
-
promise = _loader$load.promise,
|
|
185
|
-
cancel = _loader$load.cancel;
|
|
186
|
-
|
|
187
|
-
var isDone = false;
|
|
188
|
-
|
|
189
|
-
var prevOnce = function prevOnce(result) {
|
|
190
|
-
if (isDone) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
isDone = true;
|
|
195
|
-
prev(result);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
onDestroy(function () {
|
|
199
|
-
prevOnce(TRPCClientError.TRPCClientError.from(new httpRequest.TRPCAbortError(), {
|
|
200
|
-
isDone: true
|
|
201
|
-
}));
|
|
202
|
-
cancel();
|
|
203
|
-
});
|
|
204
|
-
promise.then(function (envelope) {
|
|
205
|
-
prevOnce(httpRequest.transformRPCResponse({
|
|
206
|
-
envelope: envelope,
|
|
207
|
-
runtime: runtime
|
|
208
|
-
}));
|
|
209
|
-
}).catch(function (cause) {
|
|
210
|
-
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
exports.httpBatchLink = httpBatchLink;
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { T as TRPCClientError } from '../../../dist/TRPCClientError-9fed9b4d.esm.js';
|
|
2
|
-
import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest } from '../../../dist/httpRequest-b3cc7014.esm.js';
|
|
3
|
-
import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
|
|
4
|
-
import '@babel/runtime/helpers/objectSpread2';
|
|
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/createSuper';
|
|
10
|
-
import '@babel/runtime/helpers/wrapNativeSuper';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
14
|
-
* Less configuration, no caching, and allows you to cancel requests
|
|
15
|
-
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
16
|
-
*/
|
|
17
|
-
function dataLoader(fetchMany, opts) {
|
|
18
|
-
var batch = null;
|
|
19
|
-
var dispatchTimer = null;
|
|
20
|
-
|
|
21
|
-
var destroyTimerAndBatch = function destroyTimerAndBatch() {
|
|
22
|
-
clearTimeout(dispatchTimer);
|
|
23
|
-
dispatchTimer = null;
|
|
24
|
-
batch = null;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
function dispatch() {
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
29
|
-
var batchCopy = batch;
|
|
30
|
-
destroyTimerAndBatch();
|
|
31
|
-
|
|
32
|
-
var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
|
|
33
|
-
return v.key;
|
|
34
|
-
})),
|
|
35
|
-
promise = _fetchMany.promise,
|
|
36
|
-
cancel = _fetchMany.cancel;
|
|
37
|
-
|
|
38
|
-
batchCopy.cancel = cancel;
|
|
39
|
-
promise.then(function (result) {
|
|
40
|
-
for (var i = 0; i < result.length; i++) {
|
|
41
|
-
var _value = result[i];
|
|
42
|
-
batchCopy.items[i].resolve(_value);
|
|
43
|
-
}
|
|
44
|
-
}).catch(function (cause) {
|
|
45
|
-
var _iterator = _createForOfIteratorHelper(batchCopy.items),
|
|
46
|
-
_step;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
50
|
-
var item = _step.value;
|
|
51
|
-
item.reject(cause);
|
|
52
|
-
}
|
|
53
|
-
} catch (err) {
|
|
54
|
-
_iterator.e(err);
|
|
55
|
-
} finally {
|
|
56
|
-
_iterator.f();
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function load(key) {
|
|
62
|
-
var batchItem = {
|
|
63
|
-
cancelled: false,
|
|
64
|
-
key: key
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
if (!batch) {
|
|
68
|
-
batch = {
|
|
69
|
-
items: [],
|
|
70
|
-
cancel: function cancel() {
|
|
71
|
-
destroyTimerAndBatch();
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
var thisBatch = batch;
|
|
77
|
-
var dispatchImmediately = false;
|
|
78
|
-
var promise = new Promise(function (resolve, reject) {
|
|
79
|
-
var item = batchItem;
|
|
80
|
-
item.reject = reject;
|
|
81
|
-
item.resolve = resolve;
|
|
82
|
-
thisBatch.items.push(item);
|
|
83
|
-
|
|
84
|
-
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
85
|
-
dispatchImmediately = true;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
var cancel = function cancel() {
|
|
90
|
-
batchItem.cancelled = true;
|
|
91
|
-
|
|
92
|
-
if (thisBatch.items.some(function (item) {
|
|
93
|
-
return !item.cancelled;
|
|
94
|
-
})) {
|
|
95
|
-
// there are still things that can be resolved
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
thisBatch.cancel();
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
if (dispatchImmediately) {
|
|
103
|
-
dispatch();
|
|
104
|
-
} else if (!dispatchTimer) {
|
|
105
|
-
dispatchTimer = setTimeout(dispatch);
|
|
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 fetcher = function fetcher(type) {
|
|
126
|
-
return function (keyInputPairs) {
|
|
127
|
-
var path = keyInputPairs.map(function (op) {
|
|
128
|
-
return op.path;
|
|
129
|
-
}).join(',');
|
|
130
|
-
var inputs = keyInputPairs.map(function (op) {
|
|
131
|
-
return op.input;
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
var _httpRequest = httpRequest({
|
|
135
|
-
url: url,
|
|
136
|
-
inputs: inputs,
|
|
137
|
-
path: path,
|
|
138
|
-
runtime: runtime,
|
|
139
|
-
type: type
|
|
140
|
-
}),
|
|
141
|
-
promise = _httpRequest.promise,
|
|
142
|
-
cancel = _httpRequest.cancel;
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
promise: promise.then(function (res) {
|
|
146
|
-
if (!Array.isArray(res)) {
|
|
147
|
-
return keyInputPairs.map(function () {
|
|
148
|
-
return res;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return res;
|
|
153
|
-
}),
|
|
154
|
-
cancel: cancel
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
var query = dataLoader(fetcher('query'), {
|
|
160
|
-
maxBatchSize: maxBatchSize
|
|
161
|
-
});
|
|
162
|
-
var mutation = dataLoader(fetcher('mutation'), {
|
|
163
|
-
maxBatchSize: maxBatchSize
|
|
164
|
-
});
|
|
165
|
-
var subscription = dataLoader(fetcher('subscription'), {
|
|
166
|
-
maxBatchSize: maxBatchSize
|
|
167
|
-
});
|
|
168
|
-
var loaders = {
|
|
169
|
-
query: query,
|
|
170
|
-
subscription: subscription,
|
|
171
|
-
mutation: mutation
|
|
172
|
-
};
|
|
173
|
-
return function (_ref) {
|
|
174
|
-
var op = _ref.op,
|
|
175
|
-
prev = _ref.prev,
|
|
176
|
-
onDestroy = _ref.onDestroy;
|
|
177
|
-
var loader = loaders[op.type];
|
|
178
|
-
|
|
179
|
-
var _loader$load = loader.load(op),
|
|
180
|
-
promise = _loader$load.promise,
|
|
181
|
-
cancel = _loader$load.cancel;
|
|
182
|
-
|
|
183
|
-
var isDone = false;
|
|
184
|
-
|
|
185
|
-
var prevOnce = function prevOnce(result) {
|
|
186
|
-
if (isDone) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
isDone = true;
|
|
191
|
-
prev(result);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
onDestroy(function () {
|
|
195
|
-
prevOnce(TRPCClientError.from(new TRPCAbortError(), {
|
|
196
|
-
isDone: true
|
|
197
|
-
}));
|
|
198
|
-
cancel();
|
|
199
|
-
});
|
|
200
|
-
promise.then(function (envelope) {
|
|
201
|
-
prevOnce(transformRPCResponse({
|
|
202
|
-
envelope: envelope,
|
|
203
|
-
runtime: runtime
|
|
204
|
-
}));
|
|
205
|
-
}).catch(function (cause) {
|
|
206
|
-
prevOnce(TRPCClientError.from(cause));
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export { httpBatchLink };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/declarations/src/links/httpLink";
|