@trpc/client 10.0.0-alpha.4 → 10.0.0-alpha.42
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/README.md +58 -1
- package/dist/TRPCClientError.d.ts +3 -11
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/createTRPCClient.d.ts +2 -3
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClientProxy.d.ts +31 -0
- package/dist/createTRPCClientProxy.d.ts.map +1 -0
- package/dist/{httpUtils-c09d7b79.mjs → httpUtils-089853f6.mjs} +38 -30
- package/dist/{httpUtils-1f9e4e3c.js → httpUtils-a0169eef.js} +38 -29
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +256 -107
- package/dist/index.mjs +244 -99
- package/dist/internals/TRPCClient.d.ts +21 -18
- package/dist/internals/TRPCClient.d.ts.map +1 -1
- package/dist/internals/dataLoader.d.ts +7 -4
- package/dist/internals/dataLoader.d.ts.map +1 -1
- package/dist/links/dedupeLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts +5 -2
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +197 -69
- package/dist/links/httpBatchLink.mjs +197 -69
- package/dist/links/httpLink.d.ts +1 -1
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +5 -5
- package/dist/links/httpLink.mjs +5 -5
- package/dist/links/index.d.ts +9 -0
- package/dist/links/index.d.ts.map +1 -0
- package/dist/links/internals/createChain.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.d.ts +30 -0
- package/dist/links/internals/httpUtils.d.ts.map +1 -0
- package/dist/links/internals/transformOperationResult.d.ts +17 -3
- package/dist/links/internals/transformOperationResult.d.ts.map +1 -1
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +2 -3
- package/dist/links/loggerLink.mjs +1 -2
- package/dist/links/retryLink.d.ts.map +1 -1
- package/dist/links/splitLink.d.ts +1 -1
- package/dist/links/splitLink.d.ts.map +1 -1
- package/dist/links/splitLink.js +3 -25
- package/dist/links/splitLink.mjs +2 -28
- package/dist/links/types.d.ts +12 -9
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts +5 -3
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +12 -376
- package/dist/links/wsLink.mjs +10 -369
- package/dist/splitLink-0202cd7b.mjs +54 -0
- package/dist/splitLink-23c5ce5c.js +57 -0
- package/dist/wsLink-27b93bd0.mjs +451 -0
- package/dist/wsLink-44703a83.js +467 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +4 -4
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +4 -4
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +4 -4
- package/links/httpBatchLink/index.d.ts +1 -1
- package/links/httpBatchLink/index.js +1 -1
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +1 -1
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +1 -1
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.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/dist/trpc-client-links-wsLink.cjs.dev.js +3 -1
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +3 -1
- package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +3 -1
- package/links/wsLink/index.d.ts +1 -1
- package/links/wsLink/index.js +1 -1
- package/package.json +23 -30
- package/src/TRPCClientError.ts +5 -13
- package/src/createTRPCClient.ts +7 -3
- package/src/createTRPCClientProxy.ts +98 -0
- package/src/index.ts +2 -1
- package/src/internals/TRPCClient.ts +70 -42
- package/src/internals/dataLoader.ts +120 -45
- package/src/links/dedupeLink.test.ts +1 -1
- package/src/links/dedupeLink.ts +6 -7
- package/src/links/httpBatchLink.ts +64 -31
- package/src/links/httpLink.ts +4 -4
- package/src/links/index.ts +8 -0
- package/src/links/internals/createChain.test.ts +5 -5
- package/src/links/internals/createChain.ts +8 -3
- package/src/links/internals/httpUtils.ts +116 -0
- package/src/links/internals/transformOperationResult.ts +40 -12
- package/src/links/loggerLink.ts +1 -2
- package/src/links/retryLink.ts +1 -2
- package/src/links/splitLink.test.ts +3 -3
- package/src/links/splitLink.ts +5 -5
- package/src/links/types.ts +14 -9
- package/src/links/wsLink.ts +31 -16
- 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/internals/transformRPCResponse.d.ts +0 -15
- package/dist/internals/transformRPCResponse.d.ts.map +0 -1
- package/dist/links/httpUtils.d.ts +0 -22
- package/dist/links/httpUtils.d.ts.map +0 -1
- package/dist/links/transformerLink.d.ts +0 -4
- package/dist/links/transformerLink.d.ts.map +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/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/index.ts.js +0 -1
- package/dist/rx/observable.d.ts +0 -4
- package/dist/rx/observable.d.ts.map +0 -1
- package/dist/rx/operators/index.d.ts +0 -4
- package/dist/rx/operators/index.d.ts.map +0 -1
- package/dist/rx/operators/index.js +0 -38
- package/dist/rx/operators/index.mjs +0 -32
- package/dist/rx/operators/index.ts.js +0 -1
- package/dist/rx/operators/map.d.ts +0 -3
- package/dist/rx/operators/map.d.ts.map +0 -1
- package/dist/rx/operators/share.d.ts +0 -6
- package/dist/rx/operators/share.d.ts.map +0 -1
- package/dist/rx/operators/tap.d.ts +0 -3
- package/dist/rx/operators/tap.d.ts.map +0 -1
- package/dist/rx/types.d.ts +0 -29
- package/dist/rx/types.d.ts.map +0 -1
- package/dist/rx/util/identity.d.ts +0 -2
- package/dist/rx/util/identity.d.ts.map +0 -1
- package/dist/rx/util/observableToPromise.d.ts +0 -10
- package/dist/rx/util/observableToPromise.d.ts.map +0 -1
- package/dist/rx/util/pipe.d.ts +0 -4
- package/dist/rx/util/pipe.d.ts.map +0 -1
- package/dist/share-4d79dc49.js +0 -110
- package/dist/share-671b63fa.mjs +0 -108
- package/dist/tap-538fa07f.mjs +0 -30
- package/dist/tap-799a2d33.js +0 -32
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.d.ts +0 -1
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.dev.js +0 -67
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.js +0 -7
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.prod.js +0 -67
- package/links/transformerLink/dist/trpc-client-links-transformerLink.esm.js +0 -63
- package/links/transformerLink/index.d.ts +0 -1
- package/links/transformerLink/index.js +0 -1
- package/rx/dist/trpc-client-rx.cjs.d.ts +0 -1
- package/rx/dist/trpc-client-rx.cjs.dev.js +0 -9
- package/rx/dist/trpc-client-rx.cjs.js +0 -7
- package/rx/dist/trpc-client-rx.cjs.prod.js +0 -9
- package/rx/dist/trpc-client-rx.esm.js +0 -1
- package/rx/index.d.ts +0 -1
- package/rx/index.js +0 -1
- package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
- package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +0 -39
- package/rx/operators/dist/trpc-client-rx-operators.cjs.js +0 -7
- package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +0 -39
- package/rx/operators/dist/trpc-client-rx-operators.esm.js +0 -33
- package/rx/operators/index.d.ts +0 -1
- package/rx/operators/index.js +0 -1
- package/src/internals/transformRPCResponse.ts +0 -25
- package/src/links/httpUtils.ts +0 -94
- package/src/links/transformerLink.ts +0 -70
- package/src/rx/index.ts +0 -2
- package/src/rx/observable.test.ts +0 -83
- package/src/rx/observable.ts +0 -70
- package/src/rx/operators/index.ts +0 -3
- package/src/rx/operators/map.test.ts +0 -92
- package/src/rx/operators/map.ts +0 -25
- package/src/rx/operators/share.test.ts +0 -60
- package/src/rx/operators/share.ts +0 -67
- package/src/rx/operators/tap.ts +0 -26
- package/src/rx/types.ts +0 -69
- package/src/rx/util/identity.ts +0 -3
- package/src/rx/util/observableToPromise.ts +0 -49
- package/src/rx/util/pipe.ts +0 -22
package/dist/links/wsLink.mjs
CHANGED
|
@@ -1,370 +1,11 @@
|
|
|
1
|
-
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
2
|
-
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
|
|
3
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
4
|
-
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
5
|
-
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
6
|
-
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
|
|
7
|
-
import { o as observable } from '../observable-7e66cb56.mjs';
|
|
8
|
-
import { T as TRPCClientError } from '../TRPCClientError-17b117e1.mjs';
|
|
9
|
-
import '@babel/runtime/helpers/defineProperty';
|
|
10
1
|
import '@babel/runtime/helpers/createClass';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var url = opts.url,
|
|
22
|
-
_opts$WebSocket = opts.WebSocket,
|
|
23
|
-
WebSocketImpl = _opts$WebSocket === void 0 ? WebSocket : _opts$WebSocket,
|
|
24
|
-
_opts$retryDelayMs = opts.retryDelayMs,
|
|
25
|
-
retryDelayFn = _opts$retryDelayMs === void 0 ? retryDelay : _opts$retryDelayMs;
|
|
26
|
-
/* istanbul ignore next */
|
|
27
|
-
|
|
28
|
-
if (!WebSocketImpl) {
|
|
29
|
-
throw new Error("No WebSocket implementation found - you probably don't want to use this on the server, but if you do you need to pass a `WebSocket`-ponyfill");
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* outgoing messages buffer whilst not open
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var outgoing = [];
|
|
37
|
-
/**
|
|
38
|
-
* pending outgoing requests that are awaiting callback
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
var pendingRequests = Object.create(null);
|
|
42
|
-
var connectAttempt = 0;
|
|
43
|
-
var dispatchTimer = null;
|
|
44
|
-
var connectTimer = null;
|
|
45
|
-
var activeConnection = createWS();
|
|
46
|
-
var state = 'connecting';
|
|
47
|
-
/**
|
|
48
|
-
* tries to send the list of messages
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
function dispatch() {
|
|
52
|
-
if (state !== 'open' || dispatchTimer) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
dispatchTimer = setTimeout(function () {
|
|
57
|
-
dispatchTimer = null;
|
|
58
|
-
|
|
59
|
-
if (outgoing.length === 1) {
|
|
60
|
-
// single send
|
|
61
|
-
activeConnection.send(JSON.stringify(outgoing.pop()));
|
|
62
|
-
} else {
|
|
63
|
-
// batch send
|
|
64
|
-
activeConnection.send(JSON.stringify(outgoing));
|
|
65
|
-
} // clear
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
outgoing = [];
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function tryReconnect() {
|
|
73
|
-
if (connectTimer || state === 'closed') {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
var timeout = retryDelayFn(connectAttempt++);
|
|
78
|
-
reconnectInMs(timeout);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function reconnect() {
|
|
82
|
-
state = 'connecting';
|
|
83
|
-
var oldConnection = activeConnection;
|
|
84
|
-
activeConnection = createWS();
|
|
85
|
-
closeIfNoPending(oldConnection);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function reconnectInMs(ms) {
|
|
89
|
-
if (connectTimer) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
state = 'connecting';
|
|
94
|
-
connectTimer = setTimeout(reconnect, ms);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function closeIfNoPending(conn) {
|
|
98
|
-
// disconnect as soon as there are are no pending result
|
|
99
|
-
var hasPendingRequests = Object.values(pendingRequests).some(function (p) {
|
|
100
|
-
return p.ws === conn;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (!hasPendingRequests) {
|
|
104
|
-
conn.close();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function resumeSubscriptionOnReconnect(req) {
|
|
109
|
-
if (outgoing.some(function (r) {
|
|
110
|
-
return r.id === req.op.id;
|
|
111
|
-
})) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
request(req.op, req.callbacks);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function createWS() {
|
|
119
|
-
var conn = new WebSocket(url);
|
|
120
|
-
clearTimeout(connectTimer);
|
|
121
|
-
connectTimer = null;
|
|
122
|
-
conn.addEventListener('open', function () {
|
|
123
|
-
/* istanbul ignore next */
|
|
124
|
-
if (conn !== activeConnection) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
connectAttempt = 0;
|
|
129
|
-
state = 'open';
|
|
130
|
-
dispatch();
|
|
131
|
-
});
|
|
132
|
-
conn.addEventListener('error', function () {
|
|
133
|
-
if (conn === activeConnection) {
|
|
134
|
-
tryReconnect();
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
var handleIncomingRequest = function handleIncomingRequest(req) {
|
|
139
|
-
if (req.method === 'reconnect' && conn === activeConnection) {
|
|
140
|
-
reconnect(); // notify subscribers
|
|
141
|
-
|
|
142
|
-
for (var _i = 0, _Object$values = Object.values(pendingRequests); _i < _Object$values.length; _i++) {
|
|
143
|
-
var pendingReq = _Object$values[_i];
|
|
144
|
-
|
|
145
|
-
if (pendingReq.type === 'subscription') {
|
|
146
|
-
resumeSubscriptionOnReconnect(pendingReq);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
var handleIncomingResponse = function handleIncomingResponse(data) {
|
|
153
|
-
var _req$callbacks$next, _req$callbacks;
|
|
154
|
-
|
|
155
|
-
var req = data.id !== null && pendingRequests[data.id];
|
|
156
|
-
|
|
157
|
-
if (!req) {
|
|
158
|
-
// do something?
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
(_req$callbacks$next = (_req$callbacks = req.callbacks).next) === null || _req$callbacks$next === void 0 ? void 0 : _req$callbacks$next.call(_req$callbacks, {
|
|
163
|
-
data: data
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
if (req.ws !== activeConnection && conn === activeConnection) {
|
|
167
|
-
var oldWs = req.ws; // gracefully replace old connection with this
|
|
168
|
-
|
|
169
|
-
req.ws = activeConnection;
|
|
170
|
-
closeIfNoPending(oldWs);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if ('result' in data && data.result.type === 'stopped' && conn === activeConnection) {
|
|
174
|
-
req.callbacks.complete();
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
conn.addEventListener('message', function (_ref) {
|
|
179
|
-
var data = _ref.data;
|
|
180
|
-
var msg = JSON.parse(data);
|
|
181
|
-
|
|
182
|
-
if ('method' in msg) {
|
|
183
|
-
handleIncomingRequest(msg);
|
|
184
|
-
} else {
|
|
185
|
-
handleIncomingResponse(msg);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (conn !== activeConnection || state === 'closed') {
|
|
189
|
-
// when receiving a message, we close old connection that has no pending requests
|
|
190
|
-
closeIfNoPending(conn);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
conn.addEventListener('close', function () {
|
|
194
|
-
if (activeConnection === conn) {
|
|
195
|
-
// connection might have been replaced already
|
|
196
|
-
tryReconnect();
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
for (var key in pendingRequests) {
|
|
200
|
-
var _req$callbacks$error, _req$callbacks2;
|
|
201
|
-
|
|
202
|
-
var req = pendingRequests[key];
|
|
203
|
-
|
|
204
|
-
if (req.ws !== conn) {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
(_req$callbacks$error = (_req$callbacks2 = req.callbacks).error) === null || _req$callbacks$error === void 0 ? void 0 : _req$callbacks$error.call(_req$callbacks2, TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
|
|
209
|
-
|
|
210
|
-
if (req.type !== 'subscription') {
|
|
211
|
-
var _req$callbacks$comple, _req$callbacks3;
|
|
212
|
-
|
|
213
|
-
delete pendingRequests[key];
|
|
214
|
-
(_req$callbacks$comple = (_req$callbacks3 = req.callbacks).complete) === null || _req$callbacks$comple === void 0 ? void 0 : _req$callbacks$comple.call(_req$callbacks3);
|
|
215
|
-
} else if (state !== 'closed') {
|
|
216
|
-
// request restart of sub with next connection
|
|
217
|
-
resumeSubscriptionOnReconnect(req);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
return conn;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function request(op, callbacks) {
|
|
225
|
-
var type = op.type,
|
|
226
|
-
input = op.input,
|
|
227
|
-
path = op.path,
|
|
228
|
-
id = op.id;
|
|
229
|
-
var envelope = {
|
|
230
|
-
id: id,
|
|
231
|
-
jsonrpc: '2.0',
|
|
232
|
-
method: type,
|
|
233
|
-
params: {
|
|
234
|
-
input: input,
|
|
235
|
-
path: path
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
pendingRequests[id] = {
|
|
239
|
-
ws: activeConnection,
|
|
240
|
-
type: type,
|
|
241
|
-
callbacks: callbacks,
|
|
242
|
-
op: op
|
|
243
|
-
}; // enqueue message
|
|
244
|
-
|
|
245
|
-
outgoing.push(envelope);
|
|
246
|
-
dispatch();
|
|
247
|
-
return function () {
|
|
248
|
-
var _pendingRequests$id, _callbacks$complete;
|
|
249
|
-
|
|
250
|
-
var callbacks = (_pendingRequests$id = pendingRequests[id]) === null || _pendingRequests$id === void 0 ? void 0 : _pendingRequests$id.callbacks;
|
|
251
|
-
delete pendingRequests[id];
|
|
252
|
-
outgoing = outgoing.filter(function (msg) {
|
|
253
|
-
return msg.id !== id;
|
|
254
|
-
});
|
|
255
|
-
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$complete = callbacks.complete) === null || _callbacks$complete === void 0 ? void 0 : _callbacks$complete.call(callbacks);
|
|
256
|
-
|
|
257
|
-
if (op.type === 'subscription') {
|
|
258
|
-
outgoing.push({
|
|
259
|
-
id: id,
|
|
260
|
-
method: 'subscription.stop',
|
|
261
|
-
params: undefined
|
|
262
|
-
});
|
|
263
|
-
dispatch();
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return {
|
|
269
|
-
close: function close() {
|
|
270
|
-
state = 'closed';
|
|
271
|
-
closeIfNoPending(activeConnection);
|
|
272
|
-
},
|
|
273
|
-
request: request,
|
|
274
|
-
getConnection: function getConnection() {
|
|
275
|
-
return activeConnection;
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
var TRPCWebSocketClosedError = /*#__PURE__*/function (_Error) {
|
|
281
|
-
_inherits(TRPCWebSocketClosedError, _Error);
|
|
282
|
-
|
|
283
|
-
var _super = /*#__PURE__*/_createSuper(TRPCWebSocketClosedError);
|
|
284
|
-
|
|
285
|
-
function TRPCWebSocketClosedError(message) {
|
|
286
|
-
var _this;
|
|
287
|
-
|
|
288
|
-
_classCallCheck(this, TRPCWebSocketClosedError);
|
|
289
|
-
|
|
290
|
-
_this = _super.call(this, message);
|
|
291
|
-
_this.name = 'TRPCWebSocketClosedError';
|
|
292
|
-
Object.setPrototypeOf(_assertThisInitialized(_this), TRPCWebSocketClosedError.prototype);
|
|
293
|
-
return _this;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return TRPCWebSocketClosedError;
|
|
297
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
298
|
-
|
|
299
|
-
var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
|
|
300
|
-
_inherits(TRPCSubscriptionEndedError, _Error2);
|
|
301
|
-
|
|
302
|
-
var _super2 = /*#__PURE__*/_createSuper(TRPCSubscriptionEndedError);
|
|
303
|
-
|
|
304
|
-
function TRPCSubscriptionEndedError(message) {
|
|
305
|
-
var _this2;
|
|
306
|
-
|
|
307
|
-
_classCallCheck(this, TRPCSubscriptionEndedError);
|
|
308
|
-
|
|
309
|
-
_this2 = _super2.call(this, message);
|
|
310
|
-
_this2.name = 'TRPCSubscriptionEndedError';
|
|
311
|
-
Object.setPrototypeOf(_assertThisInitialized(_this2), TRPCSubscriptionEndedError.prototype);
|
|
312
|
-
return _this2;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return TRPCSubscriptionEndedError;
|
|
316
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
317
|
-
|
|
318
|
-
function wsLink(opts) {
|
|
319
|
-
return function () {
|
|
320
|
-
var client = opts.client;
|
|
321
|
-
return function (_ref2) {
|
|
322
|
-
var op = _ref2.op;
|
|
323
|
-
return observable(function (observer) {
|
|
324
|
-
var type = op.type,
|
|
325
|
-
input = op.input,
|
|
326
|
-
path = op.path,
|
|
327
|
-
id = op.id,
|
|
328
|
-
context = op.context;
|
|
329
|
-
var isDone = false;
|
|
330
|
-
var unsub = client.request({
|
|
331
|
-
type: type,
|
|
332
|
-
path: path,
|
|
333
|
-
input: input,
|
|
334
|
-
id: id,
|
|
335
|
-
context: context
|
|
336
|
-
}, {
|
|
337
|
-
error: function error(err) {
|
|
338
|
-
isDone = true;
|
|
339
|
-
observer.error(err);
|
|
340
|
-
unsub();
|
|
341
|
-
},
|
|
342
|
-
complete: function complete() {
|
|
343
|
-
if (!isDone) {
|
|
344
|
-
isDone = true;
|
|
345
|
-
observer.error(TRPCClientError.from(new TRPCSubscriptionEndedError('Operation ended prematurely')));
|
|
346
|
-
} else {
|
|
347
|
-
observer.complete();
|
|
348
|
-
}
|
|
349
|
-
},
|
|
350
|
-
next: function next(result) {
|
|
351
|
-
observer.next(result);
|
|
352
|
-
|
|
353
|
-
if (op.type !== 'subscription') {
|
|
354
|
-
// if it isn't a subscription we don't care about next response
|
|
355
|
-
isDone = true;
|
|
356
|
-
unsub();
|
|
357
|
-
observer.complete();
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
return function () {
|
|
362
|
-
isDone = true;
|
|
363
|
-
unsub();
|
|
364
|
-
};
|
|
365
|
-
});
|
|
366
|
-
};
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
export { createWSClient, wsLink };
|
|
2
|
+
import '@babel/runtime/helpers/classCallCheck';
|
|
3
|
+
import '@babel/runtime/helpers/assertThisInitialized';
|
|
4
|
+
import '@babel/runtime/helpers/inherits';
|
|
5
|
+
import '@babel/runtime/helpers/possibleConstructorReturn';
|
|
6
|
+
import '@babel/runtime/helpers/getPrototypeOf';
|
|
7
|
+
import '@babel/runtime/helpers/wrapNativeSuper';
|
|
8
|
+
import '@babel/runtime/helpers/slicedToArray';
|
|
9
|
+
import '@trpc/server/observable';
|
|
10
|
+
export { c as createWSClient, w as wsLink } from '../wsLink-27b93bd0.mjs';
|
|
11
|
+
import '@babel/runtime/helpers/defineProperty';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { observable } from '@trpc/server/observable';
|
|
2
|
+
|
|
3
|
+
/** @internal */
|
|
4
|
+
function createChain(opts) {
|
|
5
|
+
return observable(function (observer) {
|
|
6
|
+
function execute() {
|
|
7
|
+
var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
8
|
+
var op = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : opts.op;
|
|
9
|
+
var next = opts.links[index];
|
|
10
|
+
|
|
11
|
+
if (!next) {
|
|
12
|
+
throw new Error('No more links to execute - did you forget to add an ending link?');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var subscription = next({
|
|
16
|
+
op: op,
|
|
17
|
+
next: function next(nextOp) {
|
|
18
|
+
var nextObserver = execute(index + 1, nextOp);
|
|
19
|
+
return nextObserver;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return subscription;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var obs$ = execute();
|
|
26
|
+
return obs$.subscribe(observer);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function asArray(value) {
|
|
31
|
+
return Array.isArray(value) ? value : [value];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function splitLink(opts) {
|
|
35
|
+
return function (runtime) {
|
|
36
|
+
var yes = asArray(opts.true).map(function (link) {
|
|
37
|
+
return link(runtime);
|
|
38
|
+
});
|
|
39
|
+
var no = asArray(opts.false).map(function (link) {
|
|
40
|
+
return link(runtime);
|
|
41
|
+
});
|
|
42
|
+
return function (props) {
|
|
43
|
+
return observable(function (observer) {
|
|
44
|
+
var links = opts.condition(props.op) ? yes : no;
|
|
45
|
+
return createChain({
|
|
46
|
+
op: props.op,
|
|
47
|
+
links: links
|
|
48
|
+
}).subscribe(observer);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { createChain as c, splitLink as s };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var observable = require('@trpc/server/observable');
|
|
4
|
+
|
|
5
|
+
/** @internal */
|
|
6
|
+
function createChain(opts) {
|
|
7
|
+
return observable.observable(function (observer) {
|
|
8
|
+
function execute() {
|
|
9
|
+
var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
10
|
+
var op = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : opts.op;
|
|
11
|
+
var next = opts.links[index];
|
|
12
|
+
|
|
13
|
+
if (!next) {
|
|
14
|
+
throw new Error('No more links to execute - did you forget to add an ending link?');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var subscription = next({
|
|
18
|
+
op: op,
|
|
19
|
+
next: function next(nextOp) {
|
|
20
|
+
var nextObserver = execute(index + 1, nextOp);
|
|
21
|
+
return nextObserver;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return subscription;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var obs$ = execute();
|
|
28
|
+
return obs$.subscribe(observer);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function asArray(value) {
|
|
33
|
+
return Array.isArray(value) ? value : [value];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function splitLink(opts) {
|
|
37
|
+
return function (runtime) {
|
|
38
|
+
var yes = asArray(opts.true).map(function (link) {
|
|
39
|
+
return link(runtime);
|
|
40
|
+
});
|
|
41
|
+
var no = asArray(opts.false).map(function (link) {
|
|
42
|
+
return link(runtime);
|
|
43
|
+
});
|
|
44
|
+
return function (props) {
|
|
45
|
+
return observable.observable(function (observer) {
|
|
46
|
+
var links = opts.condition(props.op) ? yes : no;
|
|
47
|
+
return createChain({
|
|
48
|
+
op: props.op,
|
|
49
|
+
links: links
|
|
50
|
+
}).subscribe(observer);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.createChain = createChain;
|
|
57
|
+
exports.splitLink = splitLink;
|