@trpc/client 10.0.0-alpha.9 → 10.0.0-proxy-alpha.54
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 +16 -20
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/createTRPCClient.d.ts +5 -3
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClientProxy.d.ts +37 -0
- package/dist/createTRPCClientProxy.d.ts.map +1 -0
- package/dist/httpUtils-44781613.mjs +76 -0
- package/dist/httpUtils-801112a6.js +79 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +262 -280
- package/dist/index.mjs +255 -271
- package/dist/internals/TRPCClient.d.ts +39 -21
- package/dist/internals/TRPCClient.d.ts.map +1 -1
- package/dist/internals/dataLoader.d.ts +7 -6
- package/dist/internals/dataLoader.d.ts.map +1 -1
- package/dist/internals/fetchHelpers.d.ts +1 -1
- package/dist/internals/fetchHelpers.d.ts.map +1 -1
- package/dist/internals/retryDelay.d.ts.map +1 -1
- package/dist/links/dedupeLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts +2 -2
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +189 -172
- package/dist/links/httpBatchLink.mjs +189 -172
- package/dist/links/httpLink.d.ts +1 -1
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +31 -35
- package/dist/links/httpLink.mjs +31 -35
- 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 +31 -0
- package/dist/links/internals/httpUtils.d.ts.map +1 -0
- package/dist/links/internals/transformResult.d.ts +28 -0
- package/dist/links/internals/transformResult.d.ts.map +1 -0
- package/dist/links/loggerLink.d.ts +3 -3
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +90 -96
- package/dist/links/loggerLink.mjs +90 -91
- 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 +13 -12
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts +12 -5
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +250 -358
- package/dist/links/wsLink.mjs +250 -348
- package/dist/splitLink-695ae288.js +48 -0
- package/dist/splitLink-ad44a55d.mjs +45 -0
- package/dist/transformResult-106791d7.mjs +62 -0
- package/dist/transformResult-e15ccdf6.js +65 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +15 -13
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +15 -13
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +12 -10
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +4 -4
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +4 -4
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.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/package.json +23 -34
- package/src/TRPCClientError.ts +38 -28
- package/src/createTRPCClient.ts +11 -3
- package/src/createTRPCClientProxy.ts +113 -0
- package/src/index.ts +2 -1
- package/src/internals/TRPCClient.ts +118 -77
- package/src/internals/dataLoader.ts +116 -53
- package/src/internals/fetchHelpers.ts +2 -2
- package/src/links/dedupeLink.test.ts +9 -15
- package/src/links/dedupeLink.ts +6 -7
- package/src/links/httpBatchLink.ts +73 -36
- package/src/links/httpLink.ts +18 -6
- package/src/links/index.ts +8 -0
- package/src/links/internals/createChain.test.ts +23 -38
- package/src/links/internals/createChain.ts +8 -3
- package/src/links/internals/httpUtils.ts +117 -0
- package/src/links/internals/transformResult.ts +40 -0
- package/src/links/loggerLink.ts +6 -7
- package/src/links/retryLink.ts +2 -3
- package/src/links/splitLink.test.ts +3 -3
- package/src/links/splitLink.ts +5 -5
- package/src/links/types.ts +15 -12
- package/src/links/wsLink.ts +57 -23
- 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/httpUtils-1f9e4e3c.js +0 -97
- package/dist/httpUtils-c09d7b79.mjs +0 -91
- package/dist/index.ts.js +0 -1
- package/dist/links/httpBatchLink.ts.js +0 -1
- package/dist/links/httpLink.ts.js +0 -1
- package/dist/links/httpUtils.d.ts +0 -22
- package/dist/links/httpUtils.d.ts.map +0 -1
- package/dist/links/internals/transformOperationResult.d.ts +0 -16
- package/dist/links/internals/transformOperationResult.d.ts.map +0 -1
- package/dist/links/loggerLink.ts.js +0 -1
- package/dist/links/splitLink.ts.js +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/links/wsLink.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/links/httpUtils.ts +0 -94
- package/src/links/internals/transformOperationResult.ts +0 -25
- 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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { observable } from '@trpc/server/observable';
|
|
2
|
+
|
|
3
|
+
/** @internal */ function createChain(opts) {
|
|
4
|
+
return observable((observer)=>{
|
|
5
|
+
function execute(index = 0, op = opts.op) {
|
|
6
|
+
const next = opts.links[index];
|
|
7
|
+
if (!next) {
|
|
8
|
+
throw new Error('No more links to execute - did you forget to add an ending link?');
|
|
9
|
+
}
|
|
10
|
+
const subscription = next({
|
|
11
|
+
op,
|
|
12
|
+
next (nextOp) {
|
|
13
|
+
const nextObserver = execute(index + 1, nextOp);
|
|
14
|
+
return nextObserver;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return subscription;
|
|
18
|
+
}
|
|
19
|
+
const obs$ = execute();
|
|
20
|
+
return obs$.subscribe(observer);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function asArray(value) {
|
|
25
|
+
return Array.isArray(value) ? value : [
|
|
26
|
+
value
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
function splitLink(opts) {
|
|
30
|
+
return (runtime)=>{
|
|
31
|
+
const yes = asArray(opts.true).map((link)=>link(runtime));
|
|
32
|
+
const no = asArray(opts.false).map((link)=>link(runtime));
|
|
33
|
+
return (props)=>{
|
|
34
|
+
return observable((observer)=>{
|
|
35
|
+
const links = opts.condition(props.op) ? yes : no;
|
|
36
|
+
return createChain({
|
|
37
|
+
op: props.op,
|
|
38
|
+
links
|
|
39
|
+
}).subscribe(observer);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { createChain as c, splitLink as s };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
class TRPCClientError extends Error {
|
|
2
|
+
static from(cause, opts = {}) {
|
|
3
|
+
if (!(cause instanceof Error)) {
|
|
4
|
+
return new TRPCClientError(cause.error.message ?? '', {
|
|
5
|
+
...opts,
|
|
6
|
+
cause: undefined,
|
|
7
|
+
result: cause
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
if (cause.name === 'TRPCClientError') {
|
|
11
|
+
return cause;
|
|
12
|
+
}
|
|
13
|
+
return new TRPCClientError(cause.message, {
|
|
14
|
+
...opts,
|
|
15
|
+
cause,
|
|
16
|
+
result: null
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
constructor(message, opts){
|
|
20
|
+
const cause = opts?.cause;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
23
|
+
super(message, {
|
|
24
|
+
cause
|
|
25
|
+
});
|
|
26
|
+
this.meta = opts?.meta;
|
|
27
|
+
this.cause = cause;
|
|
28
|
+
this.shape = opts?.result?.error;
|
|
29
|
+
this.data = opts?.result?.error.data;
|
|
30
|
+
this.name = 'TRPCClientError';
|
|
31
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// FIXME:
|
|
36
|
+
// - the generics here are probably unnecessary
|
|
37
|
+
// - the RPC-spec could probably be simplified to combine HTTP + WS
|
|
38
|
+
/** @internal */ function transformResult(response, runtime) {
|
|
39
|
+
if ('error' in response) {
|
|
40
|
+
const error = runtime.transformer.deserialize(response.error);
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
error: {
|
|
44
|
+
...response,
|
|
45
|
+
error
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const result = {
|
|
50
|
+
...response.result,
|
|
51
|
+
...(!response.result.type || response.result.type === 'data') && {
|
|
52
|
+
type: 'data',
|
|
53
|
+
data: runtime.transformer.deserialize(response.result.data)
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
ok: true,
|
|
58
|
+
result
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { TRPCClientError as T, transformResult as t };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class TRPCClientError extends Error {
|
|
4
|
+
static from(cause, opts = {}) {
|
|
5
|
+
if (!(cause instanceof Error)) {
|
|
6
|
+
return new TRPCClientError(cause.error.message ?? '', {
|
|
7
|
+
...opts,
|
|
8
|
+
cause: undefined,
|
|
9
|
+
result: cause
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
if (cause.name === 'TRPCClientError') {
|
|
13
|
+
return cause;
|
|
14
|
+
}
|
|
15
|
+
return new TRPCClientError(cause.message, {
|
|
16
|
+
...opts,
|
|
17
|
+
cause,
|
|
18
|
+
result: null
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
constructor(message, opts){
|
|
22
|
+
const cause = opts?.cause;
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
25
|
+
super(message, {
|
|
26
|
+
cause
|
|
27
|
+
});
|
|
28
|
+
this.meta = opts?.meta;
|
|
29
|
+
this.cause = cause;
|
|
30
|
+
this.shape = opts?.result?.error;
|
|
31
|
+
this.data = opts?.result?.error.data;
|
|
32
|
+
this.name = 'TRPCClientError';
|
|
33
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// FIXME:
|
|
38
|
+
// - the generics here are probably unnecessary
|
|
39
|
+
// - the RPC-spec could probably be simplified to combine HTTP + WS
|
|
40
|
+
/** @internal */ function transformResult(response, runtime) {
|
|
41
|
+
if ('error' in response) {
|
|
42
|
+
const error = runtime.transformer.deserialize(response.error);
|
|
43
|
+
return {
|
|
44
|
+
ok: false,
|
|
45
|
+
error: {
|
|
46
|
+
...response,
|
|
47
|
+
error
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const result = {
|
|
52
|
+
...response.result,
|
|
53
|
+
...(!response.result.type || response.result.type === 'data') && {
|
|
54
|
+
type: 'data',
|
|
55
|
+
data: runtime.transformer.deserialize(response.result.data)
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
ok: true,
|
|
60
|
+
result
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.TRPCClientError = TRPCClientError;
|
|
65
|
+
exports.transformResult = transformResult;
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
6
|
-
var transformRPCResponse = require('../../../dist/transformRPCResponse-57e80136.cjs.dev.js');
|
|
7
5
|
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
8
|
-
require('
|
|
6
|
+
var httpRequest = require('../../../dist/httpRequest-6b1f0c6f.cjs.dev.js');
|
|
7
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
8
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
9
9
|
require('@babel/runtime/helpers/classCallCheck');
|
|
10
|
+
require('@babel/runtime/helpers/createClass');
|
|
10
11
|
require('@babel/runtime/helpers/assertThisInitialized');
|
|
11
12
|
require('@babel/runtime/helpers/inherits');
|
|
12
13
|
require('@babel/runtime/helpers/createSuper');
|
|
13
14
|
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
14
|
-
require('@babel/runtime/helpers/objectSpread2');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
@@ -78,6 +78,7 @@ function dataLoader(fetchMany, opts) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
var thisBatch = batch;
|
|
81
|
+
var dispatchImmediately = false;
|
|
81
82
|
var promise = new Promise(function (resolve, reject) {
|
|
82
83
|
var item = batchItem;
|
|
83
84
|
item.reject = reject;
|
|
@@ -85,15 +86,10 @@ function dataLoader(fetchMany, opts) {
|
|
|
85
86
|
thisBatch.items.push(item);
|
|
86
87
|
|
|
87
88
|
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
88
|
-
|
|
89
|
-
return;
|
|
89
|
+
dispatchImmediately = true;
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
if (!dispatchTimer) {
|
|
94
|
-
dispatchTimer = setTimeout(dispatch);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
93
|
var cancel = function cancel() {
|
|
98
94
|
batchItem.cancelled = true;
|
|
99
95
|
|
|
@@ -107,6 +103,12 @@ function dataLoader(fetchMany, opts) {
|
|
|
107
103
|
thisBatch.cancel();
|
|
108
104
|
};
|
|
109
105
|
|
|
106
|
+
if (dispatchImmediately) {
|
|
107
|
+
dispatch();
|
|
108
|
+
} else if (!dispatchTimer) {
|
|
109
|
+
dispatchTimer = setTimeout(dispatch);
|
|
110
|
+
}
|
|
111
|
+
|
|
110
112
|
return {
|
|
111
113
|
promise: promise,
|
|
112
114
|
cancel: cancel
|
|
@@ -133,7 +135,7 @@ function httpBatchLink(opts) {
|
|
|
133
135
|
return op.input;
|
|
134
136
|
});
|
|
135
137
|
|
|
136
|
-
var _httpRequest =
|
|
138
|
+
var _httpRequest = httpRequest.httpRequest({
|
|
137
139
|
url: url,
|
|
138
140
|
inputs: inputs,
|
|
139
141
|
path: path,
|
|
@@ -194,13 +196,13 @@ function httpBatchLink(opts) {
|
|
|
194
196
|
};
|
|
195
197
|
|
|
196
198
|
onDestroy(function () {
|
|
197
|
-
prevOnce(TRPCClientError.TRPCClientError.from(new
|
|
199
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new httpRequest.TRPCAbortError(), {
|
|
198
200
|
isDone: true
|
|
199
201
|
}));
|
|
200
202
|
cancel();
|
|
201
203
|
});
|
|
202
204
|
promise.then(function (envelope) {
|
|
203
|
-
prevOnce(
|
|
205
|
+
prevOnce(httpRequest.transformRPCResponse({
|
|
204
206
|
envelope: envelope,
|
|
205
207
|
runtime: runtime
|
|
206
208
|
}));
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
6
|
-
var transformRPCResponse = require('../../../dist/transformRPCResponse-739c13d0.cjs.prod.js');
|
|
7
5
|
var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
|
|
8
|
-
require('
|
|
6
|
+
var httpRequest = require('../../../dist/httpRequest-66400297.cjs.prod.js');
|
|
7
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
8
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
9
9
|
require('@babel/runtime/helpers/classCallCheck');
|
|
10
|
+
require('@babel/runtime/helpers/createClass');
|
|
10
11
|
require('@babel/runtime/helpers/assertThisInitialized');
|
|
11
12
|
require('@babel/runtime/helpers/inherits');
|
|
12
13
|
require('@babel/runtime/helpers/createSuper');
|
|
13
14
|
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
14
|
-
require('@babel/runtime/helpers/objectSpread2');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
@@ -78,6 +78,7 @@ function dataLoader(fetchMany, opts) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
var thisBatch = batch;
|
|
81
|
+
var dispatchImmediately = false;
|
|
81
82
|
var promise = new Promise(function (resolve, reject) {
|
|
82
83
|
var item = batchItem;
|
|
83
84
|
item.reject = reject;
|
|
@@ -85,15 +86,10 @@ function dataLoader(fetchMany, opts) {
|
|
|
85
86
|
thisBatch.items.push(item);
|
|
86
87
|
|
|
87
88
|
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
88
|
-
|
|
89
|
-
return;
|
|
89
|
+
dispatchImmediately = true;
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
if (!dispatchTimer) {
|
|
94
|
-
dispatchTimer = setTimeout(dispatch);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
93
|
var cancel = function cancel() {
|
|
98
94
|
batchItem.cancelled = true;
|
|
99
95
|
|
|
@@ -107,6 +103,12 @@ function dataLoader(fetchMany, opts) {
|
|
|
107
103
|
thisBatch.cancel();
|
|
108
104
|
};
|
|
109
105
|
|
|
106
|
+
if (dispatchImmediately) {
|
|
107
|
+
dispatch();
|
|
108
|
+
} else if (!dispatchTimer) {
|
|
109
|
+
dispatchTimer = setTimeout(dispatch);
|
|
110
|
+
}
|
|
111
|
+
|
|
110
112
|
return {
|
|
111
113
|
promise: promise,
|
|
112
114
|
cancel: cancel
|
|
@@ -133,7 +135,7 @@ function httpBatchLink(opts) {
|
|
|
133
135
|
return op.input;
|
|
134
136
|
});
|
|
135
137
|
|
|
136
|
-
var _httpRequest =
|
|
138
|
+
var _httpRequest = httpRequest.httpRequest({
|
|
137
139
|
url: url,
|
|
138
140
|
inputs: inputs,
|
|
139
141
|
path: path,
|
|
@@ -194,13 +196,13 @@ function httpBatchLink(opts) {
|
|
|
194
196
|
};
|
|
195
197
|
|
|
196
198
|
onDestroy(function () {
|
|
197
|
-
prevOnce(TRPCClientError.TRPCClientError.from(new
|
|
199
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new httpRequest.TRPCAbortError(), {
|
|
198
200
|
isDone: true
|
|
199
201
|
}));
|
|
200
202
|
cancel();
|
|
201
203
|
});
|
|
202
204
|
promise.then(function (envelope) {
|
|
203
|
-
prevOnce(
|
|
205
|
+
prevOnce(httpRequest.transformRPCResponse({
|
|
204
206
|
envelope: envelope,
|
|
205
207
|
runtime: runtime
|
|
206
208
|
}));
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
|
|
2
|
-
import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest } from '../../../dist/transformRPCResponse-f7f8b0e1.esm.js';
|
|
3
1
|
import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
|
|
4
|
-
import '
|
|
2
|
+
import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest } from '../../../dist/httpRequest-62c5cce4.esm.js';
|
|
3
|
+
import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
|
|
4
|
+
import '@babel/runtime/helpers/objectSpread2';
|
|
5
5
|
import '@babel/runtime/helpers/classCallCheck';
|
|
6
|
+
import '@babel/runtime/helpers/createClass';
|
|
6
7
|
import '@babel/runtime/helpers/assertThisInitialized';
|
|
7
8
|
import '@babel/runtime/helpers/inherits';
|
|
8
9
|
import '@babel/runtime/helpers/createSuper';
|
|
9
10
|
import '@babel/runtime/helpers/wrapNativeSuper';
|
|
10
|
-
import '@babel/runtime/helpers/objectSpread2';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
@@ -74,6 +74,7 @@ function dataLoader(fetchMany, opts) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
var thisBatch = batch;
|
|
77
|
+
var dispatchImmediately = false;
|
|
77
78
|
var promise = new Promise(function (resolve, reject) {
|
|
78
79
|
var item = batchItem;
|
|
79
80
|
item.reject = reject;
|
|
@@ -81,15 +82,10 @@ function dataLoader(fetchMany, opts) {
|
|
|
81
82
|
thisBatch.items.push(item);
|
|
82
83
|
|
|
83
84
|
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
84
|
-
|
|
85
|
-
return;
|
|
85
|
+
dispatchImmediately = true;
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
if (!dispatchTimer) {
|
|
90
|
-
dispatchTimer = setTimeout(dispatch);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
89
|
var cancel = function cancel() {
|
|
94
90
|
batchItem.cancelled = true;
|
|
95
91
|
|
|
@@ -103,6 +99,12 @@ function dataLoader(fetchMany, opts) {
|
|
|
103
99
|
thisBatch.cancel();
|
|
104
100
|
};
|
|
105
101
|
|
|
102
|
+
if (dispatchImmediately) {
|
|
103
|
+
dispatch();
|
|
104
|
+
} else if (!dispatchTimer) {
|
|
105
|
+
dispatchTimer = setTimeout(dispatch);
|
|
106
|
+
}
|
|
107
|
+
|
|
106
108
|
return {
|
|
107
109
|
promise: promise,
|
|
108
110
|
cancel: cancel
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
6
|
-
var
|
|
6
|
+
var httpRequest = require('../../../dist/httpRequest-6b1f0c6f.cjs.dev.js');
|
|
7
7
|
require('@babel/runtime/helpers/objectSpread2');
|
|
8
8
|
require('@babel/runtime/helpers/classCallCheck');
|
|
9
9
|
require('@babel/runtime/helpers/createClass');
|
|
@@ -25,7 +25,7 @@ function httpLink(opts) {
|
|
|
25
25
|
input = op.input,
|
|
26
26
|
type = op.type;
|
|
27
27
|
|
|
28
|
-
var _httpRequest =
|
|
28
|
+
var _httpRequest = httpRequest.httpRequest({
|
|
29
29
|
runtime: runtime,
|
|
30
30
|
type: type,
|
|
31
31
|
input: input,
|
|
@@ -47,13 +47,13 @@ function httpLink(opts) {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
onDestroy(function () {
|
|
50
|
-
prevOnce(TRPCClientError.TRPCClientError.from(new
|
|
50
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new httpRequest.TRPCAbortError(), {
|
|
51
51
|
isDone: true
|
|
52
52
|
}));
|
|
53
53
|
cancel();
|
|
54
54
|
});
|
|
55
55
|
promise.then(function (envelope) {
|
|
56
|
-
prevOnce(
|
|
56
|
+
prevOnce(httpRequest.transformRPCResponse({
|
|
57
57
|
envelope: envelope,
|
|
58
58
|
runtime: runtime
|
|
59
59
|
}));
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
|
|
6
|
-
var
|
|
6
|
+
var httpRequest = require('../../../dist/httpRequest-66400297.cjs.prod.js');
|
|
7
7
|
require('@babel/runtime/helpers/objectSpread2');
|
|
8
8
|
require('@babel/runtime/helpers/classCallCheck');
|
|
9
9
|
require('@babel/runtime/helpers/createClass');
|
|
@@ -25,7 +25,7 @@ function httpLink(opts) {
|
|
|
25
25
|
input = op.input,
|
|
26
26
|
type = op.type;
|
|
27
27
|
|
|
28
|
-
var _httpRequest =
|
|
28
|
+
var _httpRequest = httpRequest.httpRequest({
|
|
29
29
|
runtime: runtime,
|
|
30
30
|
type: type,
|
|
31
31
|
input: input,
|
|
@@ -47,13 +47,13 @@ function httpLink(opts) {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
onDestroy(function () {
|
|
50
|
-
prevOnce(TRPCClientError.TRPCClientError.from(new
|
|
50
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new httpRequest.TRPCAbortError(), {
|
|
51
51
|
isDone: true
|
|
52
52
|
}));
|
|
53
53
|
cancel();
|
|
54
54
|
});
|
|
55
55
|
promise.then(function (envelope) {
|
|
56
|
-
prevOnce(
|
|
56
|
+
prevOnce(httpRequest.transformRPCResponse({
|
|
57
57
|
envelope: envelope,
|
|
58
58
|
runtime: runtime
|
|
59
59
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
|
|
2
|
-
import { h as httpRequest, T as TRPCAbortError, t as transformRPCResponse } from '../../../dist/
|
|
2
|
+
import { h as httpRequest, T as TRPCAbortError, t as transformRPCResponse } from '../../../dist/httpRequest-62c5cce4.esm.js';
|
|
3
3
|
import '@babel/runtime/helpers/objectSpread2';
|
|
4
4
|
import '@babel/runtime/helpers/classCallCheck';
|
|
5
5
|
import '@babel/runtime/helpers/createClass';
|
|
@@ -115,7 +115,7 @@ function createWSClient(opts) {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
function createWS() {
|
|
118
|
-
var conn = new
|
|
118
|
+
var conn = new WebSocketImpl(url);
|
|
119
119
|
clearTimeout(connectTimer);
|
|
120
120
|
connectTimer = null;
|
|
121
121
|
conn.addEventListener('open', function () {
|
|
@@ -275,6 +275,8 @@ function createWSClient(opts) {
|
|
|
275
275
|
close: function close() {
|
|
276
276
|
state = 'closed';
|
|
277
277
|
closeIfNoPending(activeConnection);
|
|
278
|
+
clearTimeout(connectTimer);
|
|
279
|
+
connectTimer = null;
|
|
278
280
|
},
|
|
279
281
|
request: request,
|
|
280
282
|
getConnection: function getConnection() {
|
|
@@ -115,7 +115,7 @@ function createWSClient(opts) {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
function createWS() {
|
|
118
|
-
var conn = new
|
|
118
|
+
var conn = new WebSocketImpl(url);
|
|
119
119
|
clearTimeout(connectTimer);
|
|
120
120
|
connectTimer = null;
|
|
121
121
|
conn.addEventListener('open', function () {
|
|
@@ -275,6 +275,8 @@ function createWSClient(opts) {
|
|
|
275
275
|
close: function close() {
|
|
276
276
|
state = 'closed';
|
|
277
277
|
closeIfNoPending(activeConnection);
|
|
278
|
+
clearTimeout(connectTimer);
|
|
279
|
+
connectTimer = null;
|
|
278
280
|
},
|
|
279
281
|
request: request,
|
|
280
282
|
getConnection: function getConnection() {
|
|
@@ -111,7 +111,7 @@ function createWSClient(opts) {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
function createWS() {
|
|
114
|
-
var conn = new
|
|
114
|
+
var conn = new WebSocketImpl(url);
|
|
115
115
|
clearTimeout(connectTimer);
|
|
116
116
|
connectTimer = null;
|
|
117
117
|
conn.addEventListener('open', function () {
|
|
@@ -271,6 +271,8 @@ function createWSClient(opts) {
|
|
|
271
271
|
close: function close() {
|
|
272
272
|
state = 'closed';
|
|
273
273
|
closeIfNoPending(activeConnection);
|
|
274
|
+
clearTimeout(connectTimer);
|
|
275
|
+
connectTimer = null;
|
|
274
276
|
},
|
|
275
277
|
request: request,
|
|
276
278
|
getConnection: function getConnection() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-proxy-alpha.54",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
"url": "git+https://github.com/trpc/trpc.git",
|
|
11
11
|
"directory": "packages/client"
|
|
12
12
|
},
|
|
13
|
+
"eslintConfig": {
|
|
14
|
+
"rules": {
|
|
15
|
+
"no-restricted-imports": [
|
|
16
|
+
"error",
|
|
17
|
+
"@trpc/client"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
13
21
|
"main": "dist/index.js",
|
|
14
22
|
"module": "dist/index.mjs",
|
|
15
23
|
"typings": "dist/index.d.ts",
|
|
@@ -19,68 +27,49 @@
|
|
|
19
27
|
"require": "./dist/index.js",
|
|
20
28
|
"default": "./dist/index.js"
|
|
21
29
|
},
|
|
22
|
-
"./links/httpBatchLink": {
|
|
23
|
-
"import": "./dist/links/httpBatchLink.mjs",
|
|
24
|
-
"require": "./dist/links/httpBatchLink.js",
|
|
25
|
-
"default": "./dist/links/httpBatchLink.js"
|
|
26
|
-
},
|
|
27
30
|
"./links/httpLink": {
|
|
28
31
|
"import": "./dist/links/httpLink.mjs",
|
|
29
32
|
"require": "./dist/links/httpLink.js",
|
|
30
33
|
"default": "./dist/links/httpLink.js"
|
|
31
34
|
},
|
|
32
|
-
"./links/
|
|
33
|
-
"import": "./dist/links/
|
|
34
|
-
"require": "./dist/links/
|
|
35
|
-
"default": "./dist/links/
|
|
35
|
+
"./links/httpBatchLink": {
|
|
36
|
+
"import": "./dist/links/httpBatchLink.mjs",
|
|
37
|
+
"require": "./dist/links/httpBatchLink.js",
|
|
38
|
+
"default": "./dist/links/httpBatchLink.js"
|
|
36
39
|
},
|
|
37
40
|
"./links/splitLink": {
|
|
38
41
|
"import": "./dist/links/splitLink.mjs",
|
|
39
42
|
"require": "./dist/links/splitLink.js",
|
|
40
43
|
"default": "./dist/links/splitLink.js"
|
|
41
44
|
},
|
|
42
|
-
"./links/
|
|
43
|
-
"import": "./dist/links/
|
|
44
|
-
"require": "./dist/links/
|
|
45
|
-
"default": "./dist/links/
|
|
45
|
+
"./links/loggerLink": {
|
|
46
|
+
"import": "./dist/links/loggerLink.mjs",
|
|
47
|
+
"require": "./dist/links/loggerLink.js",
|
|
48
|
+
"default": "./dist/links/loggerLink.js"
|
|
46
49
|
},
|
|
47
50
|
"./links/wsLink": {
|
|
48
51
|
"import": "./dist/links/wsLink.mjs",
|
|
49
52
|
"require": "./dist/links/wsLink.js",
|
|
50
53
|
"default": "./dist/links/wsLink.js"
|
|
51
|
-
},
|
|
52
|
-
"./rx": {
|
|
53
|
-
"import": "./dist/rx/index.mjs",
|
|
54
|
-
"require": "./dist/rx/index.js",
|
|
55
|
-
"default": "./dist/rx/index.js"
|
|
56
|
-
},
|
|
57
|
-
"./rx/operators": {
|
|
58
|
-
"import": "./dist/rx/operators/index.mjs",
|
|
59
|
-
"require": "./dist/rx/operators/index.js",
|
|
60
|
-
"default": "./dist/rx/operators/index.js"
|
|
61
54
|
}
|
|
62
55
|
},
|
|
63
56
|
"files": [
|
|
64
|
-
"README.md",
|
|
65
57
|
"dist",
|
|
66
|
-
"links",
|
|
67
58
|
"src",
|
|
68
|
-
"
|
|
59
|
+
"README.md",
|
|
60
|
+
"links"
|
|
69
61
|
],
|
|
70
62
|
"scripts": {
|
|
71
|
-
"
|
|
72
|
-
},
|
|
73
|
-
"dependencies": {
|
|
74
|
-
"@babel/runtime": "^7.9.0"
|
|
63
|
+
"ts-watch": "tsc --project tsconfig.watch.json"
|
|
75
64
|
},
|
|
76
65
|
"peerDependencies": {
|
|
77
|
-
"@trpc/server": "10.0.0-alpha.
|
|
66
|
+
"@trpc/server": "10.0.0-proxy-alpha.54"
|
|
78
67
|
},
|
|
79
68
|
"devDependencies": {
|
|
80
|
-
"@trpc/server": "10.0.0-alpha.
|
|
69
|
+
"@trpc/server": "10.0.0-proxy-alpha.54"
|
|
81
70
|
},
|
|
82
71
|
"publishConfig": {
|
|
83
72
|
"access": "public"
|
|
84
73
|
},
|
|
85
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "31315be8455a5bdba0ab49793a7e043b65a9d722"
|
|
86
75
|
}
|