@trpc/client 9.17.0 → 10.0.0-alpha.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/dist/{TRPCClientError-bfee2bf5.cjs.dev.js → TRPCClientError-a5312a5f.cjs.dev.js} +14 -19
- package/dist/{TRPCClientError-09b8a26b.esm.js → TRPCClientError-e1da1ef0.esm.js} +14 -19
- package/dist/{TRPCClientError-e9bf96e9.cjs.prod.js → TRPCClientError-ea7d89b2.cjs.prod.js} +14 -19
- package/dist/createChain-93a38e1c.cjs.dev.js +27 -0
- package/dist/createChain-e45e052a.cjs.prod.js +27 -0
- package/dist/createChain-e45e6cf2.esm.js +25 -0
- package/dist/declarations/src/TRPCClientError.d.ts +6 -10
- package/dist/declarations/src/TRPCClientError.d.ts.map +1 -1
- package/dist/declarations/src/createTRPCClient.d.ts +1 -2
- package/dist/declarations/src/createTRPCClient.d.ts.map +1 -1
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/index.d.ts.map +1 -1
- package/dist/declarations/src/internals/TRPCClient.d.ts +17 -14
- package/dist/declarations/src/internals/TRPCClient.d.ts.map +1 -1
- package/dist/declarations/src/internals/dataLoader.d.ts +1 -1
- package/dist/declarations/src/internals/dataLoader.d.ts.map +1 -1
- package/dist/declarations/src/links/httpBatchLink.d.ts +2 -1
- package/dist/declarations/src/links/httpBatchLink.d.ts.map +1 -1
- package/dist/declarations/src/links/httpLink.d.ts +2 -1
- package/dist/declarations/src/links/httpLink.d.ts.map +1 -1
- package/dist/declarations/src/links/httpUtils.d.ts +22 -0
- package/dist/declarations/src/links/httpUtils.d.ts.map +1 -0
- package/dist/declarations/src/links/internals/createChain.d.ts +8 -0
- package/dist/declarations/src/links/internals/createChain.d.ts.map +1 -0
- package/dist/declarations/src/links/internals/transformOperationResult.d.ts +16 -0
- package/dist/declarations/src/links/internals/transformOperationResult.d.ts.map +1 -0
- package/dist/declarations/src/links/loggerLink.d.ts +4 -3
- package/dist/declarations/src/links/loggerLink.d.ts.map +1 -1
- package/dist/declarations/src/links/splitLink.d.ts +4 -14
- package/dist/declarations/src/links/splitLink.d.ts.map +1 -1
- package/dist/declarations/src/links/transformerLink.d.ts +4 -0
- package/dist/declarations/src/links/transformerLink.d.ts.map +1 -0
- package/dist/declarations/src/links/types.d.ts +40 -0
- package/dist/declarations/src/links/types.d.ts.map +1 -0
- package/dist/declarations/src/links/wsLink.d.ts +4 -14
- package/dist/declarations/src/links/wsLink.d.ts.map +1 -1
- package/dist/declarations/src/rx/index.d.ts +3 -0
- package/dist/declarations/src/rx/index.d.ts.map +1 -0
- package/dist/declarations/src/rx/observable.d.ts +4 -0
- package/dist/declarations/src/rx/observable.d.ts.map +1 -0
- package/dist/declarations/src/rx/operators/index.d.ts +4 -0
- package/dist/declarations/src/rx/operators/index.d.ts.map +1 -0
- package/dist/declarations/src/rx/operators/map.d.ts +3 -0
- package/dist/declarations/src/rx/operators/map.d.ts.map +1 -0
- package/dist/declarations/src/rx/operators/share.d.ts +6 -0
- package/dist/declarations/src/rx/operators/share.d.ts.map +1 -0
- package/dist/declarations/src/rx/operators/tap.d.ts +3 -0
- package/dist/declarations/src/rx/operators/tap.d.ts.map +1 -0
- package/dist/declarations/src/rx/types.d.ts +29 -0
- package/dist/declarations/src/rx/types.d.ts.map +1 -0
- package/dist/declarations/src/rx/util/identity.d.ts +2 -0
- package/dist/declarations/src/rx/util/identity.d.ts.map +1 -0
- package/dist/declarations/src/rx/util/observableToPromise.d.ts +10 -0
- package/dist/declarations/src/rx/util/observableToPromise.d.ts.map +1 -0
- package/dist/declarations/src/rx/util/pipe.d.ts +4 -0
- package/dist/declarations/src/rx/util/pipe.d.ts.map +1 -0
- package/dist/httpUtils-299a66f6.cjs.prod.js +89 -0
- package/dist/httpUtils-a1426e14.cjs.dev.js +89 -0
- package/dist/httpUtils-e45c9056.esm.js +87 -0
- package/dist/observable-01534ea8.esm.js +102 -0
- package/dist/observable-9aad8c3e.cjs.dev.js +104 -0
- package/dist/observable-ccb54234.cjs.prod.js +104 -0
- package/dist/share-5a8c2543.cjs.prod.js +106 -0
- package/dist/share-ca585761.esm.js +104 -0
- package/dist/share-f2ac9332.cjs.dev.js +106 -0
- package/dist/tap-2d565250.cjs.dev.js +32 -0
- package/dist/tap-606957cb.esm.js +30 -0
- package/dist/tap-d907998d.cjs.prod.js +32 -0
- package/dist/trpc-client.cjs.dev.js +136 -215
- package/dist/trpc-client.cjs.prod.js +136 -215
- package/dist/trpc-client.esm.js +137 -216
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +34 -52
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +34 -52
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +33 -51
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +29 -52
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +29 -52
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +29 -52
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +31 -19
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +31 -19
- package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +31 -19
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +20 -7
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +20 -7
- package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +20 -7
- package/links/transformerLink/package.json +4 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +57 -82
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +57 -82
- package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +57 -82
- package/package.json +12 -8
- 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/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/package.json +4 -0
- package/rx/package.json +4 -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 +1 -1
- 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 +37 -37
- 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 +55 -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/declarations/src/internals/TRPCAbortError.d.ts +0 -4
- package/dist/declarations/src/internals/TRPCAbortError.d.ts.map +0 -1
- package/dist/declarations/src/internals/executeChain.d.ts +0 -9
- package/dist/declarations/src/internals/executeChain.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/transformRPCResponse.d.ts +0 -15
- 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/httpRequest-672ff1f0.esm.js +0 -128
- package/dist/httpRequest-7bfaf300.cjs.dev.js +0 -132
- package/dist/httpRequest-8c422e7a.cjs.prod.js +0 -132
- package/src/internals/TRPCAbortError.ts +0 -7
- package/src/internals/executeChain.ts +0 -67
- package/src/internals/observable.ts +0 -89
package/dist/trpc-client.esm.js
CHANGED
|
@@ -1,166 +1,18 @@
|
|
|
1
1
|
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
|
|
2
2
|
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
|
3
|
-
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
4
|
-
import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
|
|
5
|
-
import { T as TRPCAbortError } from './httpRequest-672ff1f0.esm.js';
|
|
6
3
|
import { httpBatchLink } from '../links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import '
|
|
11
|
-
import '@babel/runtime/helpers/
|
|
12
|
-
import '@babel/runtime/helpers/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var listener = {
|
|
20
|
-
callbacks: callbacks,
|
|
21
|
-
unsubscribe: function unsubscribe() {
|
|
22
|
-
var index = listeners.indexOf(listener);
|
|
23
|
-
|
|
24
|
-
if (index !== -1) {
|
|
25
|
-
var _listener$callbacks$o, _listener$callbacks;
|
|
26
|
-
|
|
27
|
-
listeners.splice(index, 1);
|
|
28
|
-
(_listener$callbacks$o = (_listener$callbacks = listener.callbacks).onDone) === null || _listener$callbacks$o === void 0 ? void 0 : _listener$callbacks$o.call(_listener$callbacks);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
listeners.push(listener);
|
|
33
|
-
return function () {
|
|
34
|
-
listener.unsubscribe();
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
next: function next(newValue) {
|
|
38
|
-
var oldValue = value;
|
|
39
|
-
value = newValue;
|
|
40
|
-
|
|
41
|
-
if (oldValue !== newValue) {
|
|
42
|
-
var _iterator = _createForOfIteratorHelper(listeners),
|
|
43
|
-
_step;
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
47
|
-
var _listener$callbacks$o2, _listener$callbacks2;
|
|
48
|
-
|
|
49
|
-
var listener = _step.value;
|
|
50
|
-
(_listener$callbacks$o2 = (_listener$callbacks2 = listener.callbacks).onNext) === null || _listener$callbacks$o2 === void 0 ? void 0 : _listener$callbacks$o2.call(_listener$callbacks2, newValue);
|
|
51
|
-
}
|
|
52
|
-
} catch (err) {
|
|
53
|
-
_iterator.e(err);
|
|
54
|
-
} finally {
|
|
55
|
-
_iterator.f();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
done: function done() {
|
|
60
|
-
while (listeners.length) {
|
|
61
|
-
var _listener$callbacks$o3, _listener$callbacks3;
|
|
62
|
-
|
|
63
|
-
var listener = listeners.pop();
|
|
64
|
-
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);
|
|
65
|
-
listener === null || listener === void 0 ? void 0 : listener.unsubscribe();
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
error: function (_error) {
|
|
69
|
-
function error(_x) {
|
|
70
|
-
return _error.apply(this, arguments);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
error.toString = function () {
|
|
74
|
-
return _error.toString();
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return error;
|
|
78
|
-
}(function (error) {
|
|
79
|
-
var _iterator2 = _createForOfIteratorHelper(listeners),
|
|
80
|
-
_step2;
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
84
|
-
var _listener$callbacks$o4, _listener$callbacks4;
|
|
85
|
-
|
|
86
|
-
var listener = _step2.value;
|
|
87
|
-
(_listener$callbacks$o4 = (_listener$callbacks4 = listener.callbacks).onError) === null || _listener$callbacks$o4 === void 0 ? void 0 : _listener$callbacks$o4.call(_listener$callbacks4, error);
|
|
88
|
-
}
|
|
89
|
-
} catch (err) {
|
|
90
|
-
_iterator2.e(err);
|
|
91
|
-
} finally {
|
|
92
|
-
_iterator2.f();
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function observableSubject(initialValue) {
|
|
98
|
-
var $obs = observable();
|
|
99
|
-
var value = initialValue;
|
|
100
|
-
$obs.next(initialValue);
|
|
101
|
-
return _objectSpread(_objectSpread({}, $obs), {}, {
|
|
102
|
-
next: function next(v) {
|
|
103
|
-
value = v;
|
|
104
|
-
$obs.next(v);
|
|
105
|
-
},
|
|
106
|
-
get: function get() {
|
|
107
|
-
return value;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function executeChain(opts) {
|
|
113
|
-
var $result = observableSubject(null);
|
|
114
|
-
|
|
115
|
-
var updateResult = function updateResult(result) {
|
|
116
|
-
if (result instanceof Error) {
|
|
117
|
-
$result.error(result);
|
|
118
|
-
|
|
119
|
-
if (result.isDone) {
|
|
120
|
-
$result.done();
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
$result.next(result);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
function walk(_ref) {
|
|
128
|
-
var index = _ref.index,
|
|
129
|
-
op = _ref.op,
|
|
130
|
-
stack = _ref.stack;
|
|
131
|
-
var link = opts.links[index];
|
|
132
|
-
var prev = index === 0 ? function (value) {
|
|
133
|
-
return updateResult(value);
|
|
134
|
-
} : stack[index - 1];
|
|
135
|
-
link({
|
|
136
|
-
op: op,
|
|
137
|
-
prev: prev,
|
|
138
|
-
next: function next(op, prevOp) {
|
|
139
|
-
var prevStack = stack.slice();
|
|
140
|
-
prevStack[index] = prevOp;
|
|
141
|
-
walk({
|
|
142
|
-
index: index + 1,
|
|
143
|
-
op: op,
|
|
144
|
-
stack: prevStack
|
|
145
|
-
});
|
|
146
|
-
},
|
|
147
|
-
onDestroy: function onDestroy(callback) {
|
|
148
|
-
$result.subscribe({
|
|
149
|
-
onDone: function onDone() {
|
|
150
|
-
callback();
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
walk({
|
|
158
|
-
index: 0,
|
|
159
|
-
op: opts.op,
|
|
160
|
-
stack: []
|
|
161
|
-
});
|
|
162
|
-
return $result;
|
|
163
|
-
}
|
|
4
|
+
import { c as createChain } from './createChain-e45e6cf2.esm.js';
|
|
5
|
+
import { T as TRPCClientError } from './TRPCClientError-e1da1ef0.esm.js';
|
|
6
|
+
export { T as TRPCClientError } from './TRPCClientError-e1da1ef0.esm.js';
|
|
7
|
+
import { s as share } from './share-ca585761.esm.js';
|
|
8
|
+
import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
|
|
9
|
+
import _inherits from '@babel/runtime/helpers/esm/inherits';
|
|
10
|
+
import _createSuper from '@babel/runtime/helpers/esm/createSuper';
|
|
11
|
+
import _wrapNativeSuper from '@babel/runtime/helpers/esm/wrapNativeSuper';
|
|
12
|
+
import '@babel/runtime/helpers/createForOfIteratorHelper';
|
|
13
|
+
import './observable-01534ea8.esm.js';
|
|
14
|
+
import './httpUtils-e45c9056.esm.js';
|
|
15
|
+
import '@babel/runtime/helpers/objectSpread2';
|
|
164
16
|
|
|
165
17
|
function getWindow() {
|
|
166
18
|
if (typeof window !== 'undefined') {
|
|
@@ -188,6 +40,87 @@ function getFetch(f) {
|
|
|
188
40
|
throw new Error('No fetch implementation found');
|
|
189
41
|
}
|
|
190
42
|
|
|
43
|
+
/** @internal */
|
|
44
|
+
function transformOperationResult(result) {
|
|
45
|
+
var context = result.context;
|
|
46
|
+
|
|
47
|
+
if ('error' in result.data) {
|
|
48
|
+
var error = TRPCClientError.from(result.data);
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
error: error,
|
|
52
|
+
context: context
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var data = result.data.result.data;
|
|
57
|
+
return {
|
|
58
|
+
ok: true,
|
|
59
|
+
data: data,
|
|
60
|
+
context: context
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var ObservableAbortError = /*#__PURE__*/function (_Error) {
|
|
65
|
+
_inherits(ObservableAbortError, _Error);
|
|
66
|
+
|
|
67
|
+
var _super = /*#__PURE__*/_createSuper(ObservableAbortError);
|
|
68
|
+
|
|
69
|
+
function ObservableAbortError(message) {
|
|
70
|
+
var _this;
|
|
71
|
+
|
|
72
|
+
_classCallCheck(this, ObservableAbortError);
|
|
73
|
+
|
|
74
|
+
_this = _super.call(this, message);
|
|
75
|
+
_this.name = 'ObservableAbortError';
|
|
76
|
+
Object.setPrototypeOf(_assertThisInitialized(_this), ObservableAbortError.prototype);
|
|
77
|
+
return _this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return ObservableAbortError;
|
|
81
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
82
|
+
/** @internal */
|
|
83
|
+
|
|
84
|
+
function observableToPromise(observable) {
|
|
85
|
+
var abort;
|
|
86
|
+
var promise = new Promise(function (resolve, reject) {
|
|
87
|
+
var isDone = false;
|
|
88
|
+
|
|
89
|
+
function onDone() {
|
|
90
|
+
if (isDone) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
isDone = true;
|
|
95
|
+
reject(new ObservableAbortError('This operation was cancelled.'));
|
|
96
|
+
obs$.unsubscribe();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
var obs$ = observable.subscribe({
|
|
100
|
+
next: function next(data) {
|
|
101
|
+
isDone = true;
|
|
102
|
+
resolve(data);
|
|
103
|
+
onDone();
|
|
104
|
+
},
|
|
105
|
+
error: function error(data) {
|
|
106
|
+
isDone = true;
|
|
107
|
+
reject(data);
|
|
108
|
+
onDone();
|
|
109
|
+
},
|
|
110
|
+
complete: function complete() {
|
|
111
|
+
isDone = true;
|
|
112
|
+
onDone();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
abort = onDone;
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
promise: promise,
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
120
|
+
abort: abort
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
191
124
|
var idCounter = 0;
|
|
192
125
|
|
|
193
126
|
function getRequestId() {
|
|
@@ -202,17 +135,6 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
202
135
|
|
|
203
136
|
this.links = void 0;
|
|
204
137
|
this.runtime = void 0;
|
|
205
|
-
var transformer = opts.transformer ? 'input' in opts.transformer ? {
|
|
206
|
-
serialize: opts.transformer.input.serialize,
|
|
207
|
-
deserialize: opts.transformer.output.deserialize
|
|
208
|
-
} : opts.transformer : {
|
|
209
|
-
serialize: function serialize(data) {
|
|
210
|
-
return data;
|
|
211
|
-
},
|
|
212
|
-
deserialize: function deserialize(data) {
|
|
213
|
-
return data;
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
138
|
|
|
217
139
|
var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
|
|
218
140
|
|
|
@@ -232,7 +154,6 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
232
154
|
}
|
|
233
155
|
|
|
234
156
|
this.runtime = {
|
|
235
|
-
transformer: transformer,
|
|
236
157
|
AbortController: AC,
|
|
237
158
|
fetch: _fetch,
|
|
238
159
|
headers: getHeadersFn()
|
|
@@ -257,7 +178,7 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
257
178
|
path = _ref.path,
|
|
258
179
|
_ref$context = _ref.context,
|
|
259
180
|
context = _ref$context === void 0 ? {} : _ref$context;
|
|
260
|
-
var $
|
|
181
|
+
var chain$ = createChain({
|
|
261
182
|
links: this.links,
|
|
262
183
|
op: {
|
|
263
184
|
id: getRequestId(),
|
|
@@ -267,45 +188,33 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
267
188
|
context: context
|
|
268
189
|
}
|
|
269
190
|
});
|
|
270
|
-
return
|
|
191
|
+
return chain$.pipe(share());
|
|
271
192
|
}
|
|
272
193
|
}, {
|
|
273
194
|
key: "requestAsPromise",
|
|
274
195
|
value: function requestAsPromise(opts) {
|
|
275
|
-
var $
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
196
|
+
var req$ = this.$request(opts);
|
|
197
|
+
|
|
198
|
+
var _observableToPromise = observableToPromise(req$),
|
|
199
|
+
promise = _observableToPromise.promise,
|
|
200
|
+
abort = _observableToPromise.abort;
|
|
201
|
+
|
|
202
|
+
var cancellablePromise = new Promise(function (resolve, reject) {
|
|
203
|
+
promise.then(function (result) {
|
|
204
|
+
var transformed = transformOperationResult(result);
|
|
284
205
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
resolve(result.data);
|
|
292
|
-
$result.done();
|
|
293
|
-
},
|
|
294
|
-
onError: function onError(err) {
|
|
295
|
-
reject(err);
|
|
296
|
-
$result.done();
|
|
297
|
-
},
|
|
298
|
-
onDone: function onDone() {
|
|
299
|
-
reject(TRPCClientError.from(new TRPCAbortError()));
|
|
206
|
+
if (transformed.ok) {
|
|
207
|
+
resolve(transformed.data);
|
|
208
|
+
return;
|
|
300
209
|
}
|
|
210
|
+
|
|
211
|
+
reject(transformed.error);
|
|
212
|
+
}).catch(function (err) {
|
|
213
|
+
reject(TRPCClientError.from(err));
|
|
301
214
|
});
|
|
302
215
|
});
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
$result.done();
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
return promise;
|
|
216
|
+
cancellablePromise.cancel = abort;
|
|
217
|
+
return cancellablePromise;
|
|
309
218
|
}
|
|
310
219
|
}, {
|
|
311
220
|
key: "query",
|
|
@@ -336,29 +245,41 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
336
245
|
}, {
|
|
337
246
|
key: "subscription",
|
|
338
247
|
value: function subscription(path, input, opts) {
|
|
339
|
-
var $
|
|
248
|
+
var observable$ = this.$request({
|
|
340
249
|
type: 'subscription',
|
|
341
250
|
path: path,
|
|
342
251
|
input: input,
|
|
343
252
|
context: opts.context
|
|
344
253
|
});
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
254
|
+
var observer = observable$.subscribe({
|
|
255
|
+
next: function next(result) {
|
|
256
|
+
var _opts$next;
|
|
257
|
+
|
|
258
|
+
if ('error' in result.data) {
|
|
259
|
+
var _opts$error;
|
|
260
|
+
|
|
261
|
+
var err = TRPCClientError.from(result.data, {
|
|
262
|
+
meta: result.context
|
|
263
|
+
});
|
|
264
|
+
(_opts$error = opts.error) === null || _opts$error === void 0 ? void 0 : _opts$error.call(opts, err);
|
|
265
|
+
return;
|
|
351
266
|
}
|
|
267
|
+
|
|
268
|
+
(_opts$next = opts.next) === null || _opts$next === void 0 ? void 0 : _opts$next.call(opts, result.data.result);
|
|
352
269
|
},
|
|
353
|
-
|
|
354
|
-
var _opts$
|
|
270
|
+
error: function error(err) {
|
|
271
|
+
var _opts$error2;
|
|
355
272
|
|
|
356
|
-
(_opts$
|
|
273
|
+
(_opts$error2 = opts.error) === null || _opts$error2 === void 0 ? void 0 : _opts$error2.call(opts, err);
|
|
357
274
|
},
|
|
358
|
-
|
|
275
|
+
complete: function complete() {
|
|
276
|
+
var _opts$complete;
|
|
277
|
+
|
|
278
|
+
(_opts$complete = opts.complete) === null || _opts$complete === void 0 ? void 0 : _opts$complete.call(opts);
|
|
279
|
+
}
|
|
359
280
|
});
|
|
360
281
|
return function () {
|
|
361
|
-
|
|
282
|
+
observer.unsubscribe();
|
|
362
283
|
};
|
|
363
284
|
}
|
|
364
285
|
}]);
|
|
@@ -2,16 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
6
5
|
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
7
|
-
var
|
|
6
|
+
var observable = require('../../../dist/observable-9aad8c3e.cjs.dev.js');
|
|
7
|
+
var httpUtils = require('../../../dist/httpUtils-a1426e14.cjs.dev.js');
|
|
8
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
9
|
|
|
16
10
|
/**
|
|
17
11
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
@@ -114,10 +108,8 @@ function dataLoader(fetchMany) {
|
|
|
114
108
|
}
|
|
115
109
|
|
|
116
110
|
function httpBatchLink(opts) {
|
|
117
|
-
var url = opts.url;
|
|
118
|
-
|
|
111
|
+
var url = opts.url;
|
|
119
112
|
return function (runtime) {
|
|
120
|
-
// initialized in app
|
|
121
113
|
var fetcher = function fetcher(type) {
|
|
122
114
|
return function (keyInputPairs) {
|
|
123
115
|
var path = keyInputPairs.map(function (op) {
|
|
@@ -127,7 +119,7 @@ function httpBatchLink(opts) {
|
|
|
127
119
|
return op.input;
|
|
128
120
|
});
|
|
129
121
|
|
|
130
|
-
var _httpRequest =
|
|
122
|
+
var _httpRequest = httpUtils.httpRequest({
|
|
131
123
|
url: url,
|
|
132
124
|
inputs: inputs,
|
|
133
125
|
path: path,
|
|
@@ -139,13 +131,16 @@ function httpBatchLink(opts) {
|
|
|
139
131
|
|
|
140
132
|
return {
|
|
141
133
|
promise: promise.then(function (res) {
|
|
142
|
-
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
134
|
+
var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
|
|
135
|
+
return res.json;
|
|
136
|
+
});
|
|
137
|
+
var result = resJSON.map(function (item) {
|
|
138
|
+
return {
|
|
139
|
+
meta: res.meta,
|
|
140
|
+
json: item
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
return result;
|
|
149
144
|
}),
|
|
150
145
|
cancel: cancel
|
|
151
146
|
};
|
|
@@ -161,39 +156,26 @@ function httpBatchLink(opts) {
|
|
|
161
156
|
mutation: mutation
|
|
162
157
|
};
|
|
163
158
|
return function (_ref) {
|
|
164
|
-
var op = _ref.op
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
onDestroy(function () {
|
|
185
|
-
prevOnce(TRPCClientError.TRPCClientError.from(new httpRequest.TRPCAbortError(), {
|
|
186
|
-
isDone: true
|
|
187
|
-
}));
|
|
188
|
-
cancel();
|
|
189
|
-
});
|
|
190
|
-
promise.then(function (envelope) {
|
|
191
|
-
prevOnce(httpRequest.transformRPCResponse({
|
|
192
|
-
envelope: envelope,
|
|
193
|
-
runtime: runtime
|
|
194
|
-
}));
|
|
195
|
-
}).catch(function (cause) {
|
|
196
|
-
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
159
|
+
var op = _ref.op;
|
|
160
|
+
return observable.observable(function (observer) {
|
|
161
|
+
var loader = loaders[op.type];
|
|
162
|
+
|
|
163
|
+
var _loader$load = loader.load(op),
|
|
164
|
+
promise = _loader$load.promise,
|
|
165
|
+
cancel = _loader$load.cancel;
|
|
166
|
+
|
|
167
|
+
promise.then(function (res) {
|
|
168
|
+
observer.next({
|
|
169
|
+
context: res.meta,
|
|
170
|
+
data: res.json
|
|
171
|
+
});
|
|
172
|
+
observer.complete();
|
|
173
|
+
}).catch(function (err) {
|
|
174
|
+
return observer.error(err);
|
|
175
|
+
});
|
|
176
|
+
return function () {
|
|
177
|
+
cancel();
|
|
178
|
+
};
|
|
197
179
|
});
|
|
198
180
|
};
|
|
199
181
|
};
|
|
@@ -2,16 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
|
|
6
5
|
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
7
|
-
var
|
|
6
|
+
var observable = require('../../../dist/observable-ccb54234.cjs.prod.js');
|
|
7
|
+
var httpUtils = require('../../../dist/httpUtils-299a66f6.cjs.prod.js');
|
|
8
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
9
|
|
|
16
10
|
/**
|
|
17
11
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
@@ -114,10 +108,8 @@ function dataLoader(fetchMany) {
|
|
|
114
108
|
}
|
|
115
109
|
|
|
116
110
|
function httpBatchLink(opts) {
|
|
117
|
-
var url = opts.url;
|
|
118
|
-
|
|
111
|
+
var url = opts.url;
|
|
119
112
|
return function (runtime) {
|
|
120
|
-
// initialized in app
|
|
121
113
|
var fetcher = function fetcher(type) {
|
|
122
114
|
return function (keyInputPairs) {
|
|
123
115
|
var path = keyInputPairs.map(function (op) {
|
|
@@ -127,7 +119,7 @@ function httpBatchLink(opts) {
|
|
|
127
119
|
return op.input;
|
|
128
120
|
});
|
|
129
121
|
|
|
130
|
-
var _httpRequest =
|
|
122
|
+
var _httpRequest = httpUtils.httpRequest({
|
|
131
123
|
url: url,
|
|
132
124
|
inputs: inputs,
|
|
133
125
|
path: path,
|
|
@@ -139,13 +131,16 @@ function httpBatchLink(opts) {
|
|
|
139
131
|
|
|
140
132
|
return {
|
|
141
133
|
promise: promise.then(function (res) {
|
|
142
|
-
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
134
|
+
var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
|
|
135
|
+
return res.json;
|
|
136
|
+
});
|
|
137
|
+
var result = resJSON.map(function (item) {
|
|
138
|
+
return {
|
|
139
|
+
meta: res.meta,
|
|
140
|
+
json: item
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
return result;
|
|
149
144
|
}),
|
|
150
145
|
cancel: cancel
|
|
151
146
|
};
|
|
@@ -161,39 +156,26 @@ function httpBatchLink(opts) {
|
|
|
161
156
|
mutation: mutation
|
|
162
157
|
};
|
|
163
158
|
return function (_ref) {
|
|
164
|
-
var op = _ref.op
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
onDestroy(function () {
|
|
185
|
-
prevOnce(TRPCClientError.TRPCClientError.from(new httpRequest.TRPCAbortError(), {
|
|
186
|
-
isDone: true
|
|
187
|
-
}));
|
|
188
|
-
cancel();
|
|
189
|
-
});
|
|
190
|
-
promise.then(function (envelope) {
|
|
191
|
-
prevOnce(httpRequest.transformRPCResponse({
|
|
192
|
-
envelope: envelope,
|
|
193
|
-
runtime: runtime
|
|
194
|
-
}));
|
|
195
|
-
}).catch(function (cause) {
|
|
196
|
-
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
159
|
+
var op = _ref.op;
|
|
160
|
+
return observable.observable(function (observer) {
|
|
161
|
+
var loader = loaders[op.type];
|
|
162
|
+
|
|
163
|
+
var _loader$load = loader.load(op),
|
|
164
|
+
promise = _loader$load.promise,
|
|
165
|
+
cancel = _loader$load.cancel;
|
|
166
|
+
|
|
167
|
+
promise.then(function (res) {
|
|
168
|
+
observer.next({
|
|
169
|
+
context: res.meta,
|
|
170
|
+
data: res.json
|
|
171
|
+
});
|
|
172
|
+
observer.complete();
|
|
173
|
+
}).catch(function (err) {
|
|
174
|
+
return observer.error(err);
|
|
175
|
+
});
|
|
176
|
+
return function () {
|
|
177
|
+
cancel();
|
|
178
|
+
};
|
|
197
179
|
});
|
|
198
180
|
};
|
|
199
181
|
};
|