@trpc/client 9.16.0 → 10.0.0-alpha.1
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 -11
- 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/dist/trpc-client-links-transformerLink.cjs.d.ts +1 -0
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.dev.js +67 -0
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.js +7 -0
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.prod.js +67 -0
- package/links/transformerLink/dist/trpc-client-links-transformerLink.esm.js +63 -0
- package/links/transformerLink/package.json +4 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +57 -81
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +57 -81
- package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +57 -81
- 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 +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/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 -8
- 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 -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/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
|
@@ -2,16 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var observable = require('../../../dist/observable-ccb54234.cjs.prod.js');
|
|
6
|
+
var createChain = require('../../../dist/createChain-e45e052a.cjs.prod.js');
|
|
7
|
+
|
|
8
|
+
function asArray(value) {
|
|
9
|
+
return Array.isArray(value) ? value : [value];
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
function splitLink(opts) {
|
|
6
13
|
return function (rt) {
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
var yes = asArray(opts.true).map(function (link) {
|
|
15
|
+
return link(rt);
|
|
16
|
+
});
|
|
17
|
+
var no = asArray(opts.false).map(function (link) {
|
|
18
|
+
return link(rt);
|
|
19
|
+
});
|
|
13
20
|
return function (props) {
|
|
14
|
-
|
|
21
|
+
return observable.observable(function (observer) {
|
|
22
|
+
var links = opts.condition(props.op) ? yes : no;
|
|
23
|
+
return createChain.createChain({
|
|
24
|
+
op: props.op,
|
|
25
|
+
links: links
|
|
26
|
+
}).subscribe(observer);
|
|
27
|
+
});
|
|
15
28
|
};
|
|
16
29
|
};
|
|
17
30
|
}
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
+
import { o as observable } from '../../../dist/observable-01534ea8.esm.js';
|
|
2
|
+
import { c as createChain } from '../../../dist/createChain-e45e6cf2.esm.js';
|
|
3
|
+
|
|
4
|
+
function asArray(value) {
|
|
5
|
+
return Array.isArray(value) ? value : [value];
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
function splitLink(opts) {
|
|
2
9
|
return function (rt) {
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
var yes = asArray(opts.true).map(function (link) {
|
|
11
|
+
return link(rt);
|
|
12
|
+
});
|
|
13
|
+
var no = asArray(opts.false).map(function (link) {
|
|
14
|
+
return link(rt);
|
|
15
|
+
});
|
|
9
16
|
return function (props) {
|
|
10
|
-
|
|
17
|
+
return observable(function (observer) {
|
|
18
|
+
var links = opts.condition(props.op) ? yes : no;
|
|
19
|
+
return createChain({
|
|
20
|
+
op: props.op,
|
|
21
|
+
links: links
|
|
22
|
+
}).subscribe(observer);
|
|
23
|
+
});
|
|
11
24
|
};
|
|
12
25
|
};
|
|
13
26
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../../dist/declarations/src/links/transformerLink";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
|
+
var observable = require('../../../dist/observable-9aad8c3e.cjs.dev.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function transformOperationResult(result, transformer) {
|
|
12
|
+
if ('error' in result.data) {
|
|
13
|
+
return _objectSpread(_objectSpread({}, result), {}, {
|
|
14
|
+
data: _objectSpread(_objectSpread({}, result.data), {}, {
|
|
15
|
+
error: transformer.deserialize(result.data.error)
|
|
16
|
+
})
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (result.data.result.type !== 'data') {
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return _objectSpread(_objectSpread({}, result), {}, {
|
|
25
|
+
data: _objectSpread(_objectSpread({}, result.data), {}, {
|
|
26
|
+
result: _objectSpread(_objectSpread({}, result.data.result), {}, {
|
|
27
|
+
data: transformer.deserialize(result.data.result.data)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function transformerLink(transformer) {
|
|
34
|
+
var _transformer = transformer ? 'input' in transformer ? {
|
|
35
|
+
serialize: transformer.input.serialize,
|
|
36
|
+
deserialize: transformer.output.deserialize
|
|
37
|
+
} : transformer : {
|
|
38
|
+
serialize: function serialize(data) {
|
|
39
|
+
return data;
|
|
40
|
+
},
|
|
41
|
+
deserialize: function deserialize(data) {
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return function () {
|
|
47
|
+
return function (props) {
|
|
48
|
+
var input = _transformer.serialize(props.op.input);
|
|
49
|
+
|
|
50
|
+
return observable.observable(function (observer) {
|
|
51
|
+
var next$ = props.next(_objectSpread(_objectSpread({}, props.op), {}, {
|
|
52
|
+
input: input
|
|
53
|
+
})).subscribe({
|
|
54
|
+
next: function next(value) {
|
|
55
|
+
var transformed = transformOperationResult(value, _transformer);
|
|
56
|
+
observer.next(transformed);
|
|
57
|
+
},
|
|
58
|
+
error: observer.error,
|
|
59
|
+
complete: observer.complete
|
|
60
|
+
});
|
|
61
|
+
return next$;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.transformerLink = transformerLink;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
|
+
var observable = require('../../../dist/observable-ccb54234.cjs.prod.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function transformOperationResult(result, transformer) {
|
|
12
|
+
if ('error' in result.data) {
|
|
13
|
+
return _objectSpread(_objectSpread({}, result), {}, {
|
|
14
|
+
data: _objectSpread(_objectSpread({}, result.data), {}, {
|
|
15
|
+
error: transformer.deserialize(result.data.error)
|
|
16
|
+
})
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (result.data.result.type !== 'data') {
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return _objectSpread(_objectSpread({}, result), {}, {
|
|
25
|
+
data: _objectSpread(_objectSpread({}, result.data), {}, {
|
|
26
|
+
result: _objectSpread(_objectSpread({}, result.data.result), {}, {
|
|
27
|
+
data: transformer.deserialize(result.data.result.data)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function transformerLink(transformer) {
|
|
34
|
+
var _transformer = transformer ? 'input' in transformer ? {
|
|
35
|
+
serialize: transformer.input.serialize,
|
|
36
|
+
deserialize: transformer.output.deserialize
|
|
37
|
+
} : transformer : {
|
|
38
|
+
serialize: function serialize(data) {
|
|
39
|
+
return data;
|
|
40
|
+
},
|
|
41
|
+
deserialize: function deserialize(data) {
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return function () {
|
|
47
|
+
return function (props) {
|
|
48
|
+
var input = _transformer.serialize(props.op.input);
|
|
49
|
+
|
|
50
|
+
return observable.observable(function (observer) {
|
|
51
|
+
var next$ = props.next(_objectSpread(_objectSpread({}, props.op), {}, {
|
|
52
|
+
input: input
|
|
53
|
+
})).subscribe({
|
|
54
|
+
next: function next(value) {
|
|
55
|
+
var transformed = transformOperationResult(value, _transformer);
|
|
56
|
+
observer.next(transformed);
|
|
57
|
+
},
|
|
58
|
+
error: observer.error,
|
|
59
|
+
complete: observer.complete
|
|
60
|
+
});
|
|
61
|
+
return next$;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.transformerLink = transformerLink;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
2
|
+
import { o as observable } from '../../../dist/observable-01534ea8.esm.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
function transformOperationResult(result, transformer) {
|
|
8
|
+
if ('error' in result.data) {
|
|
9
|
+
return _objectSpread(_objectSpread({}, result), {}, {
|
|
10
|
+
data: _objectSpread(_objectSpread({}, result.data), {}, {
|
|
11
|
+
error: transformer.deserialize(result.data.error)
|
|
12
|
+
})
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (result.data.result.type !== 'data') {
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return _objectSpread(_objectSpread({}, result), {}, {
|
|
21
|
+
data: _objectSpread(_objectSpread({}, result.data), {}, {
|
|
22
|
+
result: _objectSpread(_objectSpread({}, result.data.result), {}, {
|
|
23
|
+
data: transformer.deserialize(result.data.result.data)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function transformerLink(transformer) {
|
|
30
|
+
var _transformer = transformer ? 'input' in transformer ? {
|
|
31
|
+
serialize: transformer.input.serialize,
|
|
32
|
+
deserialize: transformer.output.deserialize
|
|
33
|
+
} : transformer : {
|
|
34
|
+
serialize: function serialize(data) {
|
|
35
|
+
return data;
|
|
36
|
+
},
|
|
37
|
+
deserialize: function deserialize(data) {
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return function () {
|
|
43
|
+
return function (props) {
|
|
44
|
+
var input = _transformer.serialize(props.op.input);
|
|
45
|
+
|
|
46
|
+
return observable(function (observer) {
|
|
47
|
+
var next$ = props.next(_objectSpread(_objectSpread({}, props.op), {}, {
|
|
48
|
+
input: input
|
|
49
|
+
})).subscribe({
|
|
50
|
+
next: function next(value) {
|
|
51
|
+
var transformed = transformOperationResult(value, _transformer);
|
|
52
|
+
observer.next(transformed);
|
|
53
|
+
},
|
|
54
|
+
error: observer.error,
|
|
55
|
+
complete: observer.complete
|
|
56
|
+
});
|
|
57
|
+
return next$;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { transformerLink };
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
5
|
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
7
6
|
var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
|
|
8
7
|
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
9
8
|
var _createSuper = require('@babel/runtime/helpers/createSuper');
|
|
10
9
|
var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
|
|
11
|
-
var
|
|
10
|
+
var observable = require('../../../dist/observable-9aad8c3e.cjs.dev.js');
|
|
11
|
+
var TRPCClientError = require('../../../dist/TRPCClientError-a5312a5f.cjs.dev.js');
|
|
12
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
12
13
|
require('@babel/runtime/helpers/createClass');
|
|
13
14
|
|
|
14
15
|
/* istanbul ignore next */
|
|
@@ -148,24 +149,19 @@ function createWSClient(opts) {
|
|
|
148
149
|
}
|
|
149
150
|
};
|
|
150
151
|
|
|
151
|
-
var handleIncomingResponse = function handleIncomingResponse(
|
|
152
|
-
var _req$callbacks$
|
|
152
|
+
var handleIncomingResponse = function handleIncomingResponse(data) {
|
|
153
|
+
var _req$callbacks$next, _req$callbacks;
|
|
153
154
|
|
|
154
|
-
var req =
|
|
155
|
+
var req = data.id !== null && pendingRequests[data.id];
|
|
155
156
|
|
|
156
157
|
if (!req) {
|
|
157
158
|
// do something?
|
|
158
159
|
return;
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
(_req$callbacks$onErro = (_req$callbacks = req.callbacks).onError) === null || _req$callbacks$onErro === void 0 ? void 0 : _req$callbacks$onErro.call(_req$callbacks, res);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
(_req$callbacks$onNext = (_req$callbacks2 = req.callbacks).onNext) === null || _req$callbacks$onNext === void 0 ? void 0 : _req$callbacks$onNext.call(_req$callbacks2, res.result);
|
|
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
|
+
});
|
|
169
165
|
|
|
170
166
|
if (req.ws !== activeConnection && conn === activeConnection) {
|
|
171
167
|
var oldWs = req.ws; // gracefully replace old connection with this
|
|
@@ -174,10 +170,8 @@ function createWSClient(opts) {
|
|
|
174
170
|
closeIfNoPending(oldWs);
|
|
175
171
|
}
|
|
176
172
|
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
(_req$callbacks$onDone = (_req$callbacks3 = req.callbacks).onDone) === null || _req$callbacks$onDone === void 0 ? void 0 : _req$callbacks$onDone.call(_req$callbacks3);
|
|
173
|
+
if ('result' in data && data.result.type === 'stopped' && conn === activeConnection) {
|
|
174
|
+
req.callbacks.complete();
|
|
181
175
|
}
|
|
182
176
|
};
|
|
183
177
|
|
|
@@ -203,7 +197,7 @@ function createWSClient(opts) {
|
|
|
203
197
|
}
|
|
204
198
|
|
|
205
199
|
for (var key in pendingRequests) {
|
|
206
|
-
var _req$callbacks$
|
|
200
|
+
var _req$callbacks$error, _req$callbacks2;
|
|
207
201
|
|
|
208
202
|
var req = pendingRequests[key];
|
|
209
203
|
|
|
@@ -211,13 +205,13 @@ function createWSClient(opts) {
|
|
|
211
205
|
continue;
|
|
212
206
|
}
|
|
213
207
|
|
|
214
|
-
(_req$callbacks$
|
|
208
|
+
(_req$callbacks$error = (_req$callbacks2 = req.callbacks).error) === null || _req$callbacks$error === void 0 ? void 0 : _req$callbacks$error.call(_req$callbacks2, TRPCClientError.TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
|
|
215
209
|
|
|
216
210
|
if (req.type !== 'subscription') {
|
|
217
|
-
var _req$callbacks$
|
|
211
|
+
var _req$callbacks$comple, _req$callbacks3;
|
|
218
212
|
|
|
219
213
|
delete pendingRequests[key];
|
|
220
|
-
(_req$callbacks$
|
|
214
|
+
(_req$callbacks$comple = (_req$callbacks3 = req.callbacks).complete) === null || _req$callbacks$comple === void 0 ? void 0 : _req$callbacks$comple.call(_req$callbacks3);
|
|
221
215
|
} else if (state !== 'closed') {
|
|
222
216
|
// request restart of sub with next connection
|
|
223
217
|
resumeSubscriptionOnReconnect(req);
|
|
@@ -251,14 +245,14 @@ function createWSClient(opts) {
|
|
|
251
245
|
outgoing.push(envelope);
|
|
252
246
|
dispatch();
|
|
253
247
|
return function () {
|
|
254
|
-
var _pendingRequests$id, _callbacks$
|
|
248
|
+
var _pendingRequests$id, _callbacks$complete;
|
|
255
249
|
|
|
256
250
|
var callbacks = (_pendingRequests$id = pendingRequests[id]) === null || _pendingRequests$id === void 0 ? void 0 : _pendingRequests$id.callbacks;
|
|
257
251
|
delete pendingRequests[id];
|
|
258
252
|
outgoing = outgoing.filter(function (msg) {
|
|
259
253
|
return msg.id !== id;
|
|
260
254
|
});
|
|
261
|
-
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$
|
|
255
|
+
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$complete = callbacks.complete) === null || _callbacks$complete === void 0 ? void 0 : _callbacks$complete.call(callbacks);
|
|
262
256
|
|
|
263
257
|
if (op.type === 'subscription') {
|
|
264
258
|
outgoing.push({
|
|
@@ -322,70 +316,52 @@ var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
|
|
|
322
316
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
323
317
|
|
|
324
318
|
function wsLink(opts) {
|
|
325
|
-
|
|
326
|
-
return function (rt) {
|
|
319
|
+
return function () {
|
|
327
320
|
var client = opts.client;
|
|
328
321
|
return function (_ref2) {
|
|
329
|
-
var op = _ref2.op
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (isDone) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if ('data' in result) {
|
|
350
|
-
var data = rt.transformer.deserialize(result.data);
|
|
351
|
-
prev({
|
|
352
|
-
type: 'data',
|
|
353
|
-
data: data
|
|
354
|
-
});
|
|
355
|
-
} else {
|
|
356
|
-
prev(result);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (op.type !== 'subscription') {
|
|
360
|
-
// if it isn't a subscription we don't care about next response
|
|
322
|
+
var op = _ref2.op;
|
|
323
|
+
return observable.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) {
|
|
361
338
|
isDone = true;
|
|
339
|
+
observer.error(err);
|
|
362
340
|
unsub();
|
|
341
|
+
},
|
|
342
|
+
complete: function complete() {
|
|
343
|
+
if (!isDone) {
|
|
344
|
+
isDone = true;
|
|
345
|
+
observer.error(TRPCClientError.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
|
+
}
|
|
363
359
|
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (isDone) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
prev(err instanceof Error ? err : TRPCClientError.TRPCClientError.from(_objectSpread(_objectSpread({}, err), {}, {
|
|
371
|
-
error: rt.transformer.deserialize(err.error)
|
|
372
|
-
})));
|
|
373
|
-
},
|
|
374
|
-
onDone: function onDone() {
|
|
375
|
-
if (isDone) {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
var result = new TRPCSubscriptionEndedError('Operation ended prematurely');
|
|
380
|
-
prev(TRPCClientError.TRPCClientError.from(result, {
|
|
381
|
-
isDone: true
|
|
382
|
-
}));
|
|
360
|
+
});
|
|
361
|
+
return function () {
|
|
383
362
|
isDone = true;
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
onDestroy(function () {
|
|
387
|
-
isDone = true;
|
|
388
|
-
unsub();
|
|
363
|
+
unsub();
|
|
364
|
+
};
|
|
389
365
|
});
|
|
390
366
|
};
|
|
391
367
|
};
|