@trpc/client 9.18.0 → 10.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/TRPCClientError-17b117e1.mjs +81 -0
- package/dist/TRPCClientError-ec6bd2ca.js +94 -0
- package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +29 -33
- package/dist/TRPCClientError.d.ts.map +1 -0
- package/dist/createChain-389cc116.mjs +25 -0
- package/dist/createChain-864dbb30.js +27 -0
- package/dist/{declarations/src/createTRPCClient.d.ts → createTRPCClient.d.ts} +5 -6
- package/dist/createTRPCClient.d.ts.map +1 -0
- package/dist/{declarations/src/getFetch.d.ts → getFetch.d.ts} +1 -1
- package/dist/getFetch.d.ts.map +1 -0
- package/dist/httpUtils-1f9e4e3c.js +97 -0
- package/dist/httpUtils-c09d7b79.mjs +91 -0
- package/dist/{declarations/src/index.d.ts → index.d.ts} +4 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +314 -0
- package/dist/index.mjs +299 -0
- package/dist/index.ts.js +1 -0
- package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +64 -61
- package/dist/internals/TRPCClient.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/dataLoader.d.ts +14 -16
- package/dist/internals/dataLoader.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/fetchHelpers.d.ts +2 -2
- package/dist/internals/fetchHelpers.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/retryDelay.d.ts +1 -1
- package/dist/internals/retryDelay.d.ts.map +1 -0
- package/dist/internals/transformRPCResponse.d.ts +15 -0
- package/dist/internals/transformRPCResponse.d.ts.map +1 -0
- package/dist/links/dedupeLink.d.ts +4 -0
- package/dist/links/dedupeLink.d.ts.map +1 -0
- package/dist/links/httpBatchLink.d.ts +5 -0
- package/dist/links/httpBatchLink.d.ts.map +1 -0
- package/dist/links/httpBatchLink.js +189 -0
- package/dist/links/httpBatchLink.mjs +185 -0
- package/dist/links/httpBatchLink.ts.js +1 -0
- package/dist/{declarations/src/links → links}/httpLink.d.ts +4 -3
- package/dist/links/httpLink.d.ts.map +1 -0
- package/dist/links/httpLink.js +44 -0
- package/dist/links/httpLink.mjs +40 -0
- package/dist/links/httpLink.ts.js +1 -0
- package/dist/links/httpUtils.d.ts +22 -0
- package/dist/links/httpUtils.d.ts.map +1 -0
- package/dist/links/internals/createChain.d.ts +8 -0
- package/dist/links/internals/createChain.d.ts.map +1 -0
- package/dist/links/internals/transformOperationResult.d.ts +16 -0
- package/dist/links/internals/transformOperationResult.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/loggerLink.d.ts +38 -37
- package/dist/links/loggerLink.d.ts.map +1 -0
- package/dist/links/loggerLink.js +108 -0
- package/dist/links/loggerLink.mjs +99 -0
- package/dist/links/loggerLink.ts.js +1 -0
- package/dist/links/retryLink.d.ts +6 -0
- package/dist/links/retryLink.d.ts.map +1 -0
- package/dist/links/splitLink.d.ts +14 -0
- package/dist/links/splitLink.d.ts.map +1 -0
- package/dist/links/splitLink.js +32 -0
- package/dist/links/splitLink.mjs +28 -0
- package/dist/links/splitLink.ts.js +1 -0
- package/dist/links/transformerLink.d.ts +4 -0
- package/dist/links/transformerLink.d.ts.map +1 -0
- package/dist/links/transformerLink.js +75 -0
- package/dist/links/transformerLink.mjs +67 -0
- package/dist/links/transformerLink.ts.js +1 -0
- package/dist/links/types.d.ts +40 -0
- package/dist/links/types.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/wsLink.d.ts +19 -26
- package/dist/links/wsLink.d.ts.map +1 -0
- package/dist/links/wsLink.js +384 -0
- package/dist/links/wsLink.mjs +370 -0
- package/dist/links/wsLink.ts.js +1 -0
- package/dist/observable-7e66cb56.mjs +102 -0
- package/dist/observable-85669100.js +104 -0
- package/dist/rx/index.d.ts +3 -0
- package/dist/rx/index.d.ts.map +1 -0
- package/dist/rx/index.js +9 -0
- package/dist/rx/index.mjs +1 -0
- package/dist/rx/index.ts.js +1 -0
- package/dist/rx/observable.d.ts +4 -0
- package/dist/rx/observable.d.ts.map +1 -0
- package/dist/rx/operators/index.d.ts +4 -0
- package/dist/rx/operators/index.d.ts.map +1 -0
- package/dist/rx/operators/index.js +38 -0
- package/dist/rx/operators/index.mjs +32 -0
- package/dist/rx/operators/index.ts.js +1 -0
- package/dist/rx/operators/map.d.ts +3 -0
- package/dist/rx/operators/map.d.ts.map +1 -0
- package/dist/rx/operators/share.d.ts +6 -0
- package/dist/rx/operators/share.d.ts.map +1 -0
- package/dist/rx/operators/tap.d.ts +3 -0
- package/dist/rx/operators/tap.d.ts.map +1 -0
- package/dist/rx/types.d.ts +29 -0
- package/dist/rx/types.d.ts.map +1 -0
- package/dist/rx/util/identity.d.ts +2 -0
- package/dist/rx/util/identity.d.ts.map +1 -0
- package/dist/rx/util/observableToPromise.d.ts +10 -0
- package/dist/rx/util/observableToPromise.d.ts.map +1 -0
- package/dist/rx/util/pipe.d.ts +4 -0
- package/dist/rx/util/pipe.d.ts.map +1 -0
- package/dist/share-4d79dc49.js +110 -0
- package/dist/share-671b63fa.mjs +108 -0
- package/dist/tap-538fa07f.mjs +30 -0
- package/dist/tap-799a2d33.js +32 -0
- package/links/httpBatchLink/index.d.ts +1 -0
- package/links/httpBatchLink/index.js +1 -0
- package/links/httpLink/index.d.ts +1 -0
- package/links/httpLink/index.js +1 -0
- package/links/loggerLink/index.d.ts +1 -0
- package/links/loggerLink/index.js +1 -0
- package/links/splitLink/index.d.ts +1 -0
- package/links/splitLink/index.js +1 -0
- package/links/transformerLink/index.d.ts +1 -0
- package/links/transformerLink/index.js +1 -0
- package/links/wsLink/index.d.ts +1 -0
- package/links/wsLink/index.js +1 -0
- package/package.json +58 -18
- package/rx/dist/trpc-client-rx.cjs.d.ts +1 -0
- package/rx/dist/trpc-client-rx.cjs.dev.js +9 -0
- package/rx/dist/trpc-client-rx.cjs.js +7 -0
- package/rx/dist/trpc-client-rx.cjs.prod.js +9 -0
- package/rx/dist/trpc-client-rx.esm.js +1 -0
- package/rx/index.d.ts +1 -0
- package/rx/index.js +1 -0
- package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +1 -0
- package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +39 -0
- package/rx/operators/dist/trpc-client-rx-operators.cjs.js +7 -0
- package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +39 -0
- package/rx/operators/dist/trpc-client-rx-operators.esm.js +33 -0
- package/rx/operators/index.d.ts +1 -0
- package/rx/operators/index.js +1 -0
- package/src/TRPCClientError.ts +17 -21
- package/src/createTRPCClient.ts +4 -3
- package/src/index.ts +1 -1
- package/src/internals/TRPCClient.ts +80 -88
- package/src/internals/dataLoader.ts +2 -14
- package/src/internals/transformRPCResponse.ts +2 -2
- package/src/links/dedupeLink.test.ts +134 -0
- package/src/links/dedupeLink.ts +53 -0
- package/src/links/httpBatchLink.ts +36 -52
- package/src/links/httpLink.ts +26 -37
- package/src/{internals/httpRequest.ts → links/httpUtils.ts} +30 -21
- package/src/links/internals/createChain.test.ts +132 -0
- package/src/links/internals/createChain.ts +31 -0
- package/src/links/internals/transformOperationResult.ts +25 -0
- package/src/links/loggerLink.ts +40 -22
- package/src/links/retryLink.ts +45 -14
- package/src/links/splitLink.test.ts +56 -0
- package/src/links/splitLink.ts +23 -38
- package/src/links/transformerLink.ts +70 -0
- package/src/links/{core.ts → types.ts} +40 -46
- package/src/links/wsLink.ts +56 -77
- package/src/rx/index.ts +2 -0
- package/src/rx/observable.test.ts +83 -0
- package/src/rx/observable.ts +70 -0
- package/src/rx/operators/index.ts +3 -0
- package/src/rx/operators/map.test.ts +92 -0
- package/src/rx/operators/map.ts +25 -0
- package/src/rx/operators/share.test.ts +60 -0
- package/src/rx/operators/share.ts +67 -0
- package/src/rx/operators/tap.ts +26 -0
- package/src/rx/types.ts +69 -0
- package/src/rx/util/identity.ts +3 -0
- package/src/rx/util/observableToPromise.ts +49 -0
- package/src/rx/util/pipe.ts +22 -0
- package/dist/TRPCClientError-09b8a26b.esm.js +0 -77
- package/dist/TRPCClientError-bfee2bf5.cjs.dev.js +0 -79
- package/dist/TRPCClientError-e9bf96e9.cjs.prod.js +0 -79
- package/dist/declarations/src/TRPCClientError.d.ts.map +0 -1
- package/dist/declarations/src/createTRPCClient.d.ts.map +0 -1
- package/dist/declarations/src/getFetch.d.ts.map +0 -1
- package/dist/declarations/src/index.d.ts.map +0 -1
- package/dist/declarations/src/internals/TRPCAbortError.d.ts +0 -4
- package/dist/declarations/src/internals/TRPCAbortError.d.ts.map +0 -1
- package/dist/declarations/src/internals/TRPCClient.d.ts.map +0 -1
- package/dist/declarations/src/internals/dataLoader.d.ts.map +0 -1
- package/dist/declarations/src/internals/executeChain.d.ts +0 -8
- package/dist/declarations/src/internals/executeChain.d.ts.map +0 -1
- package/dist/declarations/src/internals/fetchHelpers.d.ts.map +0 -1
- package/dist/declarations/src/internals/httpRequest.d.ts +0 -14
- package/dist/declarations/src/internals/httpRequest.d.ts.map +0 -1
- package/dist/declarations/src/internals/observable.d.ts +0 -18
- package/dist/declarations/src/internals/observable.d.ts.map +0 -1
- package/dist/declarations/src/internals/retryDelay.d.ts.map +0 -1
- package/dist/declarations/src/internals/transformRPCResponse.d.ts +0 -7
- package/dist/declarations/src/internals/transformRPCResponse.d.ts.map +0 -1
- package/dist/declarations/src/links/core.d.ts +0 -45
- package/dist/declarations/src/links/core.d.ts.map +0 -1
- package/dist/declarations/src/links/httpBatchLink.d.ts +0 -7
- package/dist/declarations/src/links/httpBatchLink.d.ts.map +0 -1
- package/dist/declarations/src/links/httpLink.d.ts.map +0 -1
- package/dist/declarations/src/links/loggerLink.d.ts.map +0 -1
- package/dist/declarations/src/links/splitLink.d.ts +0 -24
- package/dist/declarations/src/links/splitLink.d.ts.map +0 -1
- package/dist/declarations/src/links/wsLink.d.ts.map +0 -1
- package/dist/transformRPCResponse-57e80136.cjs.dev.js +0 -133
- package/dist/transformRPCResponse-739c13d0.cjs.prod.js +0 -133
- package/dist/transformRPCResponse-f7f8b0e1.esm.js +0 -129
- package/dist/trpc-client.cjs.d.ts +0 -1
- package/dist/trpc-client.cjs.dev.js +0 -379
- package/dist/trpc-client.cjs.js +0 -7
- package/dist/trpc-client.cjs.prod.js +0 -379
- package/dist/trpc-client.esm.js +0 -374
- package/links/httpBatchLink/package.json +0 -4
- package/links/httpLink/package.json +0 -4
- package/links/loggerLink/package.json +0 -4
- package/links/splitLink/package.json +0 -4
- package/links/wsLink/package.json +0 -4
- package/src/internals/TRPCAbortError.ts +0 -7
- package/src/internals/executeChain.ts +0 -67
- package/src/internals/observable.ts +0 -89
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
6
|
-
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
7
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
8
|
-
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
9
|
-
var transformRPCResponse = require('./transformRPCResponse-57e80136.cjs.dev.js');
|
|
10
|
-
var links_httpBatchLink_dist_trpcClientLinksHttpBatchLink = require('../links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js');
|
|
11
|
-
var TRPCClientError = require('./TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
12
|
-
require('@babel/runtime/helpers/assertThisInitialized');
|
|
13
|
-
require('@babel/runtime/helpers/inherits');
|
|
14
|
-
require('@babel/runtime/helpers/createSuper');
|
|
15
|
-
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
16
|
-
|
|
17
|
-
function observable() {
|
|
18
|
-
var listeners = [];
|
|
19
|
-
var value = null;
|
|
20
|
-
return {
|
|
21
|
-
subscribe: function subscribe(callbacks) {
|
|
22
|
-
var listener = {
|
|
23
|
-
callbacks: callbacks,
|
|
24
|
-
unsubscribe: function unsubscribe() {
|
|
25
|
-
var index = listeners.indexOf(listener);
|
|
26
|
-
|
|
27
|
-
if (index !== -1) {
|
|
28
|
-
var _listener$callbacks$o, _listener$callbacks;
|
|
29
|
-
|
|
30
|
-
listeners.splice(index, 1);
|
|
31
|
-
(_listener$callbacks$o = (_listener$callbacks = listener.callbacks).onDone) === null || _listener$callbacks$o === void 0 ? void 0 : _listener$callbacks$o.call(_listener$callbacks);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
listeners.push(listener);
|
|
36
|
-
return function () {
|
|
37
|
-
listener.unsubscribe();
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
next: function next(newValue) {
|
|
41
|
-
var oldValue = value;
|
|
42
|
-
value = newValue;
|
|
43
|
-
|
|
44
|
-
if (oldValue !== newValue) {
|
|
45
|
-
var _iterator = _createForOfIteratorHelper(listeners),
|
|
46
|
-
_step;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
50
|
-
var _listener$callbacks$o2, _listener$callbacks2;
|
|
51
|
-
|
|
52
|
-
var listener = _step.value;
|
|
53
|
-
(_listener$callbacks$o2 = (_listener$callbacks2 = listener.callbacks).onNext) === null || _listener$callbacks$o2 === void 0 ? void 0 : _listener$callbacks$o2.call(_listener$callbacks2, newValue);
|
|
54
|
-
}
|
|
55
|
-
} catch (err) {
|
|
56
|
-
_iterator.e(err);
|
|
57
|
-
} finally {
|
|
58
|
-
_iterator.f();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
done: function done() {
|
|
63
|
-
while (listeners.length) {
|
|
64
|
-
var _listener$callbacks$o3, _listener$callbacks3;
|
|
65
|
-
|
|
66
|
-
var listener = listeners.pop();
|
|
67
|
-
listener === null || listener === void 0 ? void 0 : (_listener$callbacks$o3 = (_listener$callbacks3 = listener.callbacks).onDone) === null || _listener$callbacks$o3 === void 0 ? void 0 : _listener$callbacks$o3.call(_listener$callbacks3);
|
|
68
|
-
listener === null || listener === void 0 ? void 0 : listener.unsubscribe();
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
error: function (_error) {
|
|
72
|
-
function error(_x) {
|
|
73
|
-
return _error.apply(this, arguments);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
error.toString = function () {
|
|
77
|
-
return _error.toString();
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
return error;
|
|
81
|
-
}(function (error) {
|
|
82
|
-
var _iterator2 = _createForOfIteratorHelper(listeners),
|
|
83
|
-
_step2;
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
87
|
-
var _listener$callbacks$o4, _listener$callbacks4;
|
|
88
|
-
|
|
89
|
-
var listener = _step2.value;
|
|
90
|
-
(_listener$callbacks$o4 = (_listener$callbacks4 = listener.callbacks).onError) === null || _listener$callbacks$o4 === void 0 ? void 0 : _listener$callbacks$o4.call(_listener$callbacks4, error);
|
|
91
|
-
}
|
|
92
|
-
} catch (err) {
|
|
93
|
-
_iterator2.e(err);
|
|
94
|
-
} finally {
|
|
95
|
-
_iterator2.f();
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function observableSubject(initialValue) {
|
|
101
|
-
var $obs = observable();
|
|
102
|
-
var value = initialValue;
|
|
103
|
-
$obs.next(initialValue);
|
|
104
|
-
return _objectSpread(_objectSpread({}, $obs), {}, {
|
|
105
|
-
next: function next(v) {
|
|
106
|
-
value = v;
|
|
107
|
-
$obs.next(v);
|
|
108
|
-
},
|
|
109
|
-
get: function get() {
|
|
110
|
-
return value;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function executeChain(opts) {
|
|
116
|
-
var $result = observableSubject(null);
|
|
117
|
-
|
|
118
|
-
var updateResult = function updateResult(result) {
|
|
119
|
-
if (result instanceof Error) {
|
|
120
|
-
$result.error(result);
|
|
121
|
-
|
|
122
|
-
if (result.isDone) {
|
|
123
|
-
$result.done();
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
$result.next(result);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
function walk(_ref) {
|
|
131
|
-
var index = _ref.index,
|
|
132
|
-
op = _ref.op,
|
|
133
|
-
stack = _ref.stack;
|
|
134
|
-
var link = opts.links[index];
|
|
135
|
-
var prev = index === 0 ? function (value) {
|
|
136
|
-
return updateResult(value);
|
|
137
|
-
} : stack[index - 1];
|
|
138
|
-
link({
|
|
139
|
-
op: op,
|
|
140
|
-
prev: prev,
|
|
141
|
-
next: function next(op, prevOp) {
|
|
142
|
-
var prevStack = stack.slice();
|
|
143
|
-
prevStack[index] = prevOp;
|
|
144
|
-
walk({
|
|
145
|
-
index: index + 1,
|
|
146
|
-
op: op,
|
|
147
|
-
stack: prevStack
|
|
148
|
-
});
|
|
149
|
-
},
|
|
150
|
-
onDestroy: function onDestroy(callback) {
|
|
151
|
-
$result.subscribe({
|
|
152
|
-
onDone: function onDone() {
|
|
153
|
-
callback();
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
walk({
|
|
161
|
-
index: 0,
|
|
162
|
-
op: opts.op,
|
|
163
|
-
stack: []
|
|
164
|
-
});
|
|
165
|
-
return $result;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function getWindow() {
|
|
169
|
-
if (typeof window !== 'undefined') {
|
|
170
|
-
return window;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return global;
|
|
174
|
-
}
|
|
175
|
-
function getAbortController(ac) {
|
|
176
|
-
var win = getWindow();
|
|
177
|
-
return ac || win.AbortController || null;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function getFetch(f) {
|
|
181
|
-
if (f) {
|
|
182
|
-
return f;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
var win = getWindow();
|
|
186
|
-
|
|
187
|
-
if (win.fetch) {
|
|
188
|
-
return typeof win.fetch.bind === 'function' ? win.fetch.bind(win) : win.fetch;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
throw new Error('No fetch implementation found');
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
var idCounter = 0;
|
|
195
|
-
|
|
196
|
-
function getRequestId() {
|
|
197
|
-
return ++idCounter;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
var TRPCClient = /*#__PURE__*/function () {
|
|
201
|
-
function TRPCClient(opts) {
|
|
202
|
-
var _this = this;
|
|
203
|
-
|
|
204
|
-
_classCallCheck(this, TRPCClient);
|
|
205
|
-
|
|
206
|
-
this.links = void 0;
|
|
207
|
-
this.runtime = void 0;
|
|
208
|
-
var transformer = opts.transformer ? 'input' in opts.transformer ? {
|
|
209
|
-
serialize: opts.transformer.input.serialize,
|
|
210
|
-
deserialize: opts.transformer.output.deserialize
|
|
211
|
-
} : opts.transformer : {
|
|
212
|
-
serialize: function serialize(data) {
|
|
213
|
-
return data;
|
|
214
|
-
},
|
|
215
|
-
deserialize: function deserialize(data) {
|
|
216
|
-
return data;
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
|
|
221
|
-
|
|
222
|
-
var AC = getAbortController(opts === null || opts === void 0 ? void 0 : opts.AbortController);
|
|
223
|
-
|
|
224
|
-
function getHeadersFn() {
|
|
225
|
-
if (opts.headers) {
|
|
226
|
-
var headers = opts.headers;
|
|
227
|
-
return typeof headers === 'function' ? headers : function () {
|
|
228
|
-
return headers;
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return function () {
|
|
233
|
-
return {};
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
this.runtime = {
|
|
238
|
-
transformer: transformer,
|
|
239
|
-
AbortController: AC,
|
|
240
|
-
fetch: _fetch,
|
|
241
|
-
headers: getHeadersFn()
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
if ('links' in opts) {
|
|
245
|
-
this.links = opts.links.map(function (link) {
|
|
246
|
-
return link(_this.runtime);
|
|
247
|
-
});
|
|
248
|
-
} else {
|
|
249
|
-
this.links = [links_httpBatchLink_dist_trpcClientLinksHttpBatchLink.httpBatchLink({
|
|
250
|
-
url: opts.url
|
|
251
|
-
})(this.runtime)];
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
_createClass(TRPCClient, [{
|
|
256
|
-
key: "$request",
|
|
257
|
-
value: function $request(_ref) {
|
|
258
|
-
var type = _ref.type,
|
|
259
|
-
input = _ref.input,
|
|
260
|
-
path = _ref.path,
|
|
261
|
-
_ref$context = _ref.context,
|
|
262
|
-
context = _ref$context === void 0 ? {} : _ref$context;
|
|
263
|
-
var $result = executeChain({
|
|
264
|
-
links: this.links,
|
|
265
|
-
op: {
|
|
266
|
-
id: getRequestId(),
|
|
267
|
-
type: type,
|
|
268
|
-
path: path,
|
|
269
|
-
input: input,
|
|
270
|
-
context: context
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
return $result;
|
|
274
|
-
}
|
|
275
|
-
}, {
|
|
276
|
-
key: "requestAsPromise",
|
|
277
|
-
value: function requestAsPromise(opts) {
|
|
278
|
-
var $result = this.$request(opts);
|
|
279
|
-
var promise = new Promise(function (resolve, reject) {
|
|
280
|
-
var res = $result.get();
|
|
281
|
-
|
|
282
|
-
if ((res === null || res === void 0 ? void 0 : res.type) === 'data') {
|
|
283
|
-
resolve(res.data);
|
|
284
|
-
$result.done();
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
$result.subscribe({
|
|
289
|
-
onNext: function onNext(result) {
|
|
290
|
-
if ((result === null || result === void 0 ? void 0 : result.type) !== 'data') {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
resolve(result.data);
|
|
295
|
-
$result.done();
|
|
296
|
-
},
|
|
297
|
-
onError: function onError(err) {
|
|
298
|
-
reject(err);
|
|
299
|
-
$result.done();
|
|
300
|
-
},
|
|
301
|
-
onDone: function onDone() {
|
|
302
|
-
reject(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError()));
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
promise.cancel = function () {
|
|
308
|
-
$result.done();
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
return promise;
|
|
312
|
-
}
|
|
313
|
-
}, {
|
|
314
|
-
key: "query",
|
|
315
|
-
value: function query(path) {
|
|
316
|
-
var _ref2;
|
|
317
|
-
|
|
318
|
-
var context = (_ref2 = arguments.length <= 2 ? undefined : arguments[2]) === null || _ref2 === void 0 ? void 0 : _ref2.context;
|
|
319
|
-
return this.requestAsPromise({
|
|
320
|
-
type: 'query',
|
|
321
|
-
path: path,
|
|
322
|
-
input: arguments.length <= 1 ? undefined : arguments[1],
|
|
323
|
-
context: context
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
}, {
|
|
327
|
-
key: "mutation",
|
|
328
|
-
value: function mutation(path) {
|
|
329
|
-
var _ref3;
|
|
330
|
-
|
|
331
|
-
var context = (_ref3 = arguments.length <= 2 ? undefined : arguments[2]) === null || _ref3 === void 0 ? void 0 : _ref3.context;
|
|
332
|
-
return this.requestAsPromise({
|
|
333
|
-
type: 'mutation',
|
|
334
|
-
path: path,
|
|
335
|
-
input: arguments.length <= 1 ? undefined : arguments[1],
|
|
336
|
-
context: context
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
}, {
|
|
340
|
-
key: "subscription",
|
|
341
|
-
value: function subscription(path, input, opts) {
|
|
342
|
-
var $res = this.$request({
|
|
343
|
-
type: 'subscription',
|
|
344
|
-
path: path,
|
|
345
|
-
input: input,
|
|
346
|
-
context: opts.context
|
|
347
|
-
});
|
|
348
|
-
$res.subscribe({
|
|
349
|
-
onNext: function onNext(output) {
|
|
350
|
-
if (output) {
|
|
351
|
-
var _opts$onNext;
|
|
352
|
-
|
|
353
|
-
(_opts$onNext = opts.onNext) === null || _opts$onNext === void 0 ? void 0 : _opts$onNext.call(opts, output);
|
|
354
|
-
}
|
|
355
|
-
},
|
|
356
|
-
onError: function onError(err) {
|
|
357
|
-
var _opts$onError;
|
|
358
|
-
|
|
359
|
-
(_opts$onError = opts.onError) === null || _opts$onError === void 0 ? void 0 : _opts$onError.call(opts, err);
|
|
360
|
-
},
|
|
361
|
-
onDone: opts.onDone
|
|
362
|
-
});
|
|
363
|
-
return function () {
|
|
364
|
-
$res.done();
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
}]);
|
|
368
|
-
|
|
369
|
-
return TRPCClient;
|
|
370
|
-
}();
|
|
371
|
-
|
|
372
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
373
|
-
function createTRPCClient(opts) {
|
|
374
|
-
return new TRPCClient(opts);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
exports.TRPCClientError = TRPCClientError.TRPCClientError;
|
|
378
|
-
exports.createTRPCClient = createTRPCClient;
|
|
379
|
-
exports.getFetch = getFetch;
|